This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: IPA merge: make fixup_cfg to deal with SSA


> Hi,
> this patch makes execute_fixup_cfg to work fluently in all side cases on SSA.
> There are two extra cases to care on SSA: when new edges to nonlocal goto
> receivers are added, the appropriate PHI node has to be updated. THe update_ssa
> has to be called manually (instead of using TODO flag) as fixup_cfg is used
> with and without optimizing.  This is probably cleaner than making
> tree-optimize to silently ignore the flag when function don't seem to be in SSA
> or having two fixup passes (SSA and non-SSA one).

As Andrew reminded me, we can do that with returning TODO flags from
execute functions.  Bootstrapped/regtested with IPA-SSA on x86_64-linux,
mainline bootstrap/regtesting running on i686-linux, OK if it passes?
> 
> Honza
> 
	* tree-optimize (execute_fixup_cfg): Set after_inlining flag;
	set NOTHROW flag on call statements proved to be nothrow;
	update statement of local calls so new pure/const functions are
	updated; update_ssa when in ssa form; mark PHI nodes of nonlocal
	goto receivers.
	(tree_rest_of_compilation): Register hooks and initialize bitmap
	(pass_fixup_cfg): Add appropriate TODOs.


Index: tree-optimize.c
===================================================================
*** tree-optimize.c	(revision 120209)
--- tree-optimize.c	(working copy)
*************** execute_fixup_cfg (void)
*** 263,268 ****
--- 317,325 ----
  {
    basic_block bb;
    block_stmt_iterator bsi;
+   int todo = gimple_in_ssa_p (cfun) ? TODO_verify_ssa : 0;
+ 
+   cfun->after_inlining = true;
  
    if (cfun->eh)
      FOR_EACH_BB (bb)
*************** execute_fixup_cfg (void)
*** 271,279 ****
  	  {
  	    tree stmt = bsi_stmt (bsi);
  	    tree call = get_call_expr_in (stmt);
  
! 	    if (call && call_expr_flags (call) & (ECF_CONST | ECF_PURE))
! 	      TREE_SIDE_EFFECTS (call) = 0;
  	    if (!tree_could_throw_p (stmt) && lookup_stmt_eh_region (stmt))
  	      remove_stmt_from_eh_region (stmt);
  	  }
--- 328,347 ----
  	  {
  	    tree stmt = bsi_stmt (bsi);
  	    tree call = get_call_expr_in (stmt);
+ 	    tree decl = call ? get_callee_fndecl (call) : NULL;
  
! 	    if (decl && call_expr_flags (call) & (ECF_CONST | ECF_PURE)
! 		&& TREE_SIDE_EFFECTS (call))
! 	      {
! 		if (gimple_in_ssa_p (cfun))
! 		  {
! 		    todo |= TODO_update_ssa;
! 	            update_stmt (stmt);
! 		  }
! 	        TREE_SIDE_EFFECTS (call) = 0;
! 	      }
! 	    if (decl && TREE_NOTHROW (decl))
! 	      TREE_NOTHROW (call) = 1;
  	    if (!tree_could_throw_p (stmt) && lookup_stmt_eh_region (stmt))
  	      remove_stmt_from_eh_region (stmt);
  	  }
*************** execute_fixup_cfg (void)
*** 281,316 ****
        }
  
    if (current_function_has_nonlocal_label)
!     FOR_EACH_BB (bb)
!       {
! 	for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
! 	  {
! 	    tree stmt = bsi_stmt (bsi);
! 	    if (tree_can_make_abnormal_goto (stmt))
! 	      {
! 		if (stmt == bsi_stmt (bsi_last (bb)))
! 		  {
! 		    if (!has_abnormal_outgoing_edge_p (bb))
  		      make_abnormal_goto_edges (bb, true);
! 		  }
! 		else
! 		  {
! 		    edge e = split_block (bb, stmt);
! 		    bb = e->src;
! 		    make_abnormal_goto_edges (bb, true);
! 		  }
! 		break;
! 	      }
! 	  }
!       }
! 
!   cleanup_tree_cfg ();
  
    /* Dump a textual representation of the flowgraph.  */
    if (dump_file)
      dump_tree_cfg (dump_file, dump_flags);
  
!   return 0;
  }
  
  struct tree_opt_pass pass_fixup_cfg =
--- 349,405 ----
        }
  
    if (current_function_has_nonlocal_label)
!     {
!       FOR_EACH_BB (bb)
! 	{
! 	  for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
! 	    {
! 	      tree stmt = bsi_stmt (bsi);
! 	      if (tree_can_make_abnormal_goto (stmt))
! 		{
! 		  if (stmt == bsi_stmt (bsi_last (bb)))
! 		    {
! 		      if (!has_abnormal_outgoing_edge_p (bb))
! 			make_abnormal_goto_edges (bb, true);
! 		    }
! 		  else
! 		    {
! 		      edge e = split_block (bb, stmt);
! 		      bb = e->src;
  		      make_abnormal_goto_edges (bb, true);
! 		    }
! 		  break;
! 		}
! 
! 	      /* Update PHIs on nonlocal goto receivers we (possibly)
! 		 just created new edges into.  */
! 	      if (TREE_CODE (stmt) == LABEL_EXPR
! 		  && gimple_in_ssa_p (cfun))
! 		{
! 		  tree target = LABEL_EXPR_LABEL (stmt);
! 		  if (DECL_NONLOCAL (target))
! 		    {
! 		      tree phi;
! 
! 		      for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
! 			{
! 		          todo |= TODO_update_ssa;
! 			  gcc_assert (SSA_NAME_OCCURS_IN_ABNORMAL_PHI
! 				      (PHI_RESULT (phi)));
! 			  mark_sym_for_renaming
! 			    (SSA_NAME_VAR (PHI_RESULT (phi)));
! 			}
! 		    }
! 		}
! 	    }
! 	}
!     }
  
    /* Dump a textual representation of the flowgraph.  */
    if (dump_file)
      dump_tree_cfg (dump_file, dump_flags);
  
!   return todo;
  }
  
  struct tree_opt_pass pass_fixup_cfg =
*************** struct tree_opt_pass pass_fixup_cfg =
*** 326,334 ****
    0,					/* properties_provided */
    0,					/* properties_destroyed */
    0,					/* todo_flags_start */
!   0,					/* todo_flags_finish */
!   0					/* letter */
! };
  
  /* Do the actions required to initialize internal data structures used
     in tree-ssa optimization passes.  */
--- 415,424 ----
    0,					/* properties_provided */
    0,					/* properties_destroyed */
    0,					/* todo_flags_start */
!   TODO_cleanup_cfg | TODO_ggc_collect
!   | TODO_dump_func | TODO_verify_flow
!   | TODO_verify_stmts,		/* todo_flags_finish */
!   0					/* letter */ };
  
  /* Do the actions required to initialize internal data structures used
     in tree-ssa optimization passes.  */
*************** tree_rest_of_compilation (tree fndecl)
*** 408,413 ****
--- 509,517 ----
  
    node = cgraph_node (fndecl);
  
+   /* Initialize the default bitmap obstack.  */
+   bitmap_obstack_initialize (NULL);
+ 
    /* We might need the body of this function so that we can expand
       it inline somewhere else.  */
    if (cgraph_preserve_function_body_p (fndecl))
*************** tree_rest_of_compilation (tree fndecl)
*** 424,430 ****
       We haven't necessarily assigned RTL to all variables yet, so it's
       not safe to try to expand expressions involving them.  */
    cfun->x_dont_save_pending_sizes_p = 1;
!   cfun->after_inlining = true;
  
    if (flag_inline_trees)
      {
--- 528,535 ----
       We haven't necessarily assigned RTL to all variables yet, so it's
       not safe to try to expand expressions involving them.  */
    cfun->x_dont_save_pending_sizes_p = 1;
!   
!   tree_register_cfg_hooks ();
  
    if (flag_inline_trees)
      {
*************** tree_rest_of_compilation (tree fndecl)
*** 453,464 ****
       Kill it so it won't confuse us.  */
    cgraph_node_remove_callees (node);
  
- 
-   /* Initialize the default bitmap obstack.  */
-   bitmap_obstack_initialize (NULL);
    bitmap_obstack_initialize (&reg_obstack); /* FIXME, only at RTL generation*/
-   
-   tree_register_cfg_hooks ();
    /* Perform all tree transforms and optimizations.  */
    execute_pass_list (all_passes);
    
--- 558,564 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]