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]

cleanup_tree_cfg invocation cleanups


Hi,
this patch replaces couple of direct calls to cleanup_cfg with proper TODOs and
teach passmanager to remove unused locals when cleanup_cfg suceeded.  The
removal of unused locals might be called more frequently than needed (not every
cleanup_cfg transformation removes some variable accesses), but I didn't
measure any slowdown via the patch at all, so perhaps it is easier to not worry
about that.  

Bootstrapped/regtested i686-linux, OK?
:ADDPATCH tree-optimization:
Honza

	* tree-vrp.c (finalize_jump_threads): Do not call cleanup_cfg by hand.
	* tree-tailcall (add_virtual_phis): Likewise.
	(optimize_tail_call): Return TODOs.
	(execute_tail_calls): Return TODOs.
	* tree-ssa-ccp (execute_fold_all_builtins): Do cleanup_cfg via TODO.
	* tree-cfgcleanup.c (cleanup_tree_cfg_loop): Return if something changed.
	* tree-ssa-forwprop.c (tree_ssa_forward_propagate_single_use_value): Cleanup cfg
	using TODO.
	* tree-flow.h (cleanup_tree_cfg_loop): Update prototype.
	* passes.c (execute_function_todo): When cleanup did something, remove unused
	locals.
	* tree-cfg.c (pass_build_cfg): Add cleanup_cfg TODO.
	(make_edges): Don't cleanup_cfg.
Index: tree-vrp.c
===================================================================
*** tree-vrp.c	(revision 120835)
--- tree-vrp.c	(working copy)
*************** finalize_jump_threads (void)
*** 4745,4757 ****
    cfg_altered = thread_through_all_blocks ();
  
    /* If we threaded jumps, then we need to recompute the dominance
!      information, to safely do that we must clean up the CFG first.  */
    if (cfg_altered)
!     {
!       free_dominance_info (CDI_DOMINATORS);
!       cleanup_tree_cfg ();
!       calculate_dominance_info (CDI_DOMINATORS);
!     }
    VEC_free (tree, heap, stack);
  }
  
--- 4745,4753 ----
    cfg_altered = thread_through_all_blocks ();
  
    /* If we threaded jumps, then we need to recompute the dominance
!      information.  */
    if (cfg_altered)
!     free_dominance_info (CDI_DOMINATORS);
    VEC_free (tree, heap, stack);
  }
  
Index: tree-tailcall.c
===================================================================
*** tree-tailcall.c	(revision 120835)
--- tree-tailcall.c	(working copy)
*************** add_virtual_phis (void)
*** 829,836 ****
        if (!is_gimple_reg (var) && gimple_default_def (cfun, var) != NULL_TREE)
  	mark_sym_for_renaming (var);
      }
- 
-   update_ssa (TODO_update_ssa_only_virtuals);
  }
  
  /* Optimizes the tailcall described by T.  If OPT_TAILCALLS is true, also
--- 829,834 ----
*************** optimize_tail_call (struct tailcall *t, 
*** 865,871 ****
  /* Optimizes tail calls in the function, turning the tail recursion
     into iteration.  */
  
! static void
  tree_optimize_tail_calls_1 (bool opt_tailcalls)
  {
    edge e;
--- 863,869 ----
  /* Optimizes tail calls in the function, turning the tail recursion
     into iteration.  */
  
! static unsigned int
  tree_optimize_tail_calls_1 (bool opt_tailcalls)
  {
    edge e;
*************** tree_optimize_tail_calls_1 (bool opt_tai
*** 877,883 ****
    edge_iterator ei;
  
    if (!suitable_for_tail_opt_p ())
!     return;
    if (opt_tailcalls)
      opt_tailcalls = suitable_for_tail_call_opt_p ();
  
--- 875,881 ----
    edge_iterator ei;
  
    if (!suitable_for_tail_opt_p ())
!     return 0;
    if (opt_tailcalls)
      opt_tailcalls = suitable_for_tail_call_opt_p ();
  
*************** tree_optimize_tail_calls_1 (bool opt_tai
*** 985,1004 ****
      }
  
    if (changed)
!     {
!       free_dominance_info (CDI_DOMINATORS);
!       cleanup_tree_cfg ();
!     }
  
    if (phis_constructed)
      add_virtual_phis ();
  }
  
  static unsigned int
  execute_tail_recursion (void)
  {
!   tree_optimize_tail_calls_1 (false);
!   return 0;
  }
  
  static bool
--- 983,1002 ----
      }
  
    if (changed)
!     free_dominance_info (CDI_DOMINATORS);
  
    if (phis_constructed)
      add_virtual_phis ();
+   if (changed)
+     return TODO_cleanup_cfg | TODO_update_ssa_only_virtuals;
+   else
+     return 0;
  }
  
  static unsigned int
  execute_tail_recursion (void)
  {
!   return tree_optimize_tail_calls_1 (false);
  }
  
  static bool
*************** gate_tail_calls (void)
*** 1010,1017 ****
  static unsigned int
  execute_tail_calls (void)
  {
!   tree_optimize_tail_calls_1 (true);
!   return 0;
  }
  
  struct tree_opt_pass pass_tail_recursion = 
--- 1008,1014 ----
  static unsigned int
  execute_tail_calls (void)
  {
!   return tree_optimize_tail_calls_1 (true);
  }
  
  struct tree_opt_pass pass_tail_recursion = 
Index: tree-ssa-ccp.c
===================================================================
*** tree-ssa-ccp.c	(revision 120835)
--- tree-ssa-ccp.c	(working copy)
*************** execute_fold_all_builtins (void)
*** 2635,2643 ****
      }
  
    /* Delete unreachable blocks.  */
!   if (cfg_changed)
!     cleanup_tree_cfg ();
!   return 0;
  }
  
  
--- 2635,2641 ----
      }
  
    /* Delete unreachable blocks.  */
!   return cfg_changed ? TODO_cleanup_cfg : 0;
  }
  
  
Index: tree-cfgcleanup.c
===================================================================
*** tree-cfgcleanup.c	(revision 120835)
--- tree-cfgcleanup.c	(working copy)
*************** cleanup_tree_cfg (void)
*** 574,580 ****
  
  /* Cleanup cfg and repair loop structures.  */
  
! void
  cleanup_tree_cfg_loop (void)
  {
    bool changed = cleanup_tree_cfg ();
--- 574,580 ----
  
  /* Cleanup cfg and repair loop structures.  */
  
! bool
  cleanup_tree_cfg_loop (void)
  {
    bool changed = cleanup_tree_cfg ();
*************** cleanup_tree_cfg_loop (void)
*** 597,602 ****
--- 597,603 ----
  #endif
        scev_reset ();
      }
+   return changed;
  }
  
  /* Merge the PHI nodes at BB into those at BB's sole successor.  */
Index: tree-ssa-forwprop.c
===================================================================
*** tree-ssa-forwprop.c	(revision 120835)
--- tree-ssa-forwprop.c	(working copy)
*************** tree_ssa_forward_propagate_single_use_va
*** 1041,1047 ****
      }
  
    if (cfg_changed)
!     cleanup_tree_cfg ();
    return todoflags;
  }
  
--- 1041,1047 ----
      }
  
    if (cfg_changed)
!     todoflags |= TODO_cleanup_cfg;
    return todoflags;
  }
  
Index: tree-flow.h
===================================================================
*** tree-flow.h	(revision 120835)
--- tree-flow.h	(working copy)
*************** extern basic_block move_sese_region_to_f
*** 678,684 ****
  
  /* In tree-cfgcleanup.c  */
  extern bool cleanup_tree_cfg (void);
! extern void cleanup_tree_cfg_loop (void);
  
  /* In tree-pretty-print.c.  */
  extern void dump_generic_bb (FILE *, basic_block, int, int);
--- 678,684 ----
  
  /* In tree-cfgcleanup.c  */
  extern bool cleanup_tree_cfg (void);
! extern bool cleanup_tree_cfg_loop (void);
  
  /* In tree-pretty-print.c.  */
  extern void dump_generic_bb (FILE *, basic_block, int, int);
Index: passes.c
===================================================================
*** passes.c	(revision 120835)
--- passes.c	(working copy)
*************** execute_function_todo (void *data)
*** 818,831 ****
    if (!flags)
      return;
    
!   /* Always cleanup the CFG before trying to update SSA .  */
    if (flags & TODO_cleanup_cfg)
      {
        if (current_loops)
! 	cleanup_tree_cfg_loop ();
        else
! 	cleanup_tree_cfg ();
  
        /* When cleanup_tree_cfg merges consecutive blocks, it may
  	 perform some simplistic propagation when removing single
  	 valued PHI nodes.  This propagation may, in turn, cause the
--- 818,836 ----
    if (!flags)
      return;
    
!   /* Always cleanup the CFG before trying to update SSA.  */
    if (flags & TODO_cleanup_cfg)
      {
+       bool cleanup;
+ 
        if (current_loops)
! 	cleanup = cleanup_tree_cfg_loop ();
        else
! 	cleanup = cleanup_tree_cfg ();
  
+       if (cleanup && (cfun->curr_properties & PROP_ssa))
+ 	flags |= TODO_remove_unused_locals;
+ 	
        /* When cleanup_tree_cfg merges consecutive blocks, it may
  	 perform some simplistic propagation when removing single
  	 valued PHI nodes.  This propagation may, in turn, cause the
Index: tree-cfg.c
===================================================================
--- tree-cfg.c	(revision 120835)
+++ tree-cfg.c	(working copy)
@@ -237,7 +237,7 @@ struct tree_opt_pass pass_build_cfg =
   PROP_cfg,				/* properties_provided */
   0,					/* properties_destroyed */
   0,					/* todo_flags_start */
-  TODO_verify_stmts,			/* todo_flags_finish */
+  TODO_verify_stmts | TODO_cleanup_cfg,	/* todo_flags_finish */
   0					/* letter */
 };
 
@@ -579,9 +579,6 @@ make_edges (void)
 
   /* Fold COND_EXPR_COND of each COND_EXPR.  */
   fold_cond_expr_cond ();
-
-  /* Clean up the graph and warn for unreachable code.  */
-  cleanup_tree_cfg ();
 }
 
 


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