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: [tree-ssa] Minor cleanup for dominator walker


In message <20040209204729.GA29131@atrey.karlin.mff.cuni.cz>, Zdenek Dvorak wri
tes:
 >Hello,
 >
 >> This minor cleanup has been on my todo list for awhile.
 >> 
 >> Basically this changes the last argument in the dominator walker callbacks
 >> to be the parent block in the dominator tree rather than the last statement
 >> in the parent block.
 >
 >would not it be easier just not to pass this argument at all and just
 >use get_immediate_dominator in the places where it is needed?

Bootstrapped and regression tested i686-pc-linux-gnu.



	* domwalk.c (walk_dominator_tree): Completely lose PARENT argument.
	Callers updated.  No longer pass PARENT to callbacks.
	* domwalk.h (struct dom_walk_data): Corresponding changes.
	* tree-ssa-dom.c: Likewise.
	* tree-ssa.c: Likewise.

Index: domwalk.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/domwalk.c,v
retrieving revision 1.1.2.8
diff -c -p -r1.1.2.8 domwalk.c
*** domwalk.c	9 Feb 2004 20:07:08 -0000	1.1.2.8
--- domwalk.c	9 Feb 2004 22:17:12 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 135,148 ****
     actions during the dominator walk as well as a stack of block local
     data maintained during the dominator walk.
  
!    BB is the basic block we are currently visiting.
! 
!    PARENT is BB's parent block in the dominator tree.  */
  
  void
! walk_dominator_tree (struct dom_walk_data *walk_data,
! 		     basic_block bb,
! 		     basic_block parent)
  {
    void *bd = NULL;
    basic_block dest;
--- 135,144 ----
     actions during the dominator walk as well as a stack of block local
     data maintained during the dominator walk.
  
!    BB is the basic block we are currently visiting.  */
  
  void
! walk_dominator_tree (struct dom_walk_data *walk_data, basic_block bb)
  {
    void *bd = NULL;
    basic_block dest;
*************** walk_dominator_tree (struct dom_walk_dat
*** 177,192 ****
    /* Callback for operations to execute before we have walked the
       dominator children, but before we walk statements.  */
    if (walk_data->before_dom_children_before_stmts)
!     (*walk_data->before_dom_children_before_stmts) (walk_data, bb, parent);
  
    /* Statement walk before walking dominator children.  */
    if (walk_data->before_dom_children_walk_stmts)
!     (*walk_data->before_dom_children_walk_stmts) (walk_data, bb, parent);
  
    /* Callback for operations to execute before we have walked the
       dominator children, and after we walk statements.  */
    if (walk_data->before_dom_children_after_stmts)
!     (*walk_data->before_dom_children_after_stmts) (walk_data, bb, parent);
  
    /* Recursively call ourselves on the dominator children of BB.  */
    for (dest = first_dom_son (CDI_DOMINATORS, bb);
--- 173,188 ----
    /* Callback for operations to execute before we have walked the
       dominator children, but before we walk statements.  */
    if (walk_data->before_dom_children_before_stmts)
!     (*walk_data->before_dom_children_before_stmts) (walk_data, bb);
  
    /* Statement walk before walking dominator children.  */
    if (walk_data->before_dom_children_walk_stmts)
!     (*walk_data->before_dom_children_walk_stmts) (walk_data, bb);
  
    /* Callback for operations to execute before we have walked the
       dominator children, and after we walk statements.  */
    if (walk_data->before_dom_children_after_stmts)
!     (*walk_data->before_dom_children_after_stmts) (walk_data, bb);
  
    /* Recursively call ourselves on the dominator children of BB.  */
    for (dest = first_dom_son (CDI_DOMINATORS, bb);
*************** walk_dominator_tree (struct dom_walk_dat
*** 196,217 ****
        /* The destination block may have become unreachable, in
  	 which case there's no point in optimizing it.  */
        if (dest->pred)
! 	walk_dominator_tree (walk_data, dest, bb);
      }
  
    /* Callback for operations to execute after we have walked the
       dominator children, but before we walk statements.  */
    if (walk_data->after_dom_children_before_stmts)
!     (*walk_data->after_dom_children_before_stmts) (walk_data, bb, parent);
  
    /* Statement walk after walking dominator children.  */
    if (walk_data->after_dom_children_walk_stmts)
!     (*walk_data->after_dom_children_walk_stmts) (walk_data, bb, parent);
  
    /* Callback for operations to execute after we have walked the
       dominator children and after we have walked statements.  */
    if (walk_data->after_dom_children_after_stmts)
!     (*walk_data->after_dom_children_after_stmts) (walk_data, bb, parent);
  
    if (walk_data->initialize_block_local_data)
      {
--- 192,213 ----
        /* The destination block may have become unreachable, in
  	 which case there's no point in optimizing it.  */
        if (dest->pred)
! 	walk_dominator_tree (walk_data, dest);
      }
  
    /* Callback for operations to execute after we have walked the
       dominator children, but before we walk statements.  */
    if (walk_data->after_dom_children_before_stmts)
!     (*walk_data->after_dom_children_before_stmts) (walk_data, bb);
  
    /* Statement walk after walking dominator children.  */
    if (walk_data->after_dom_children_walk_stmts)
!     (*walk_data->after_dom_children_walk_stmts) (walk_data, bb);
  
    /* Callback for operations to execute after we have walked the
       dominator children and after we have walked statements.  */
    if (walk_data->after_dom_children_after_stmts)
!     (*walk_data->after_dom_children_after_stmts) (walk_data, bb);
  
    if (walk_data->initialize_block_local_data)
      {
Index: domwalk.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/domwalk.h,v
retrieving revision 1.1.2.5
diff -c -p -r1.1.2.5 domwalk.h
*** domwalk.h	9 Feb 2004 20:07:08 -0000	1.1.2.5
--- domwalk.h	9 Feb 2004 22:17:13 -0000
***************
*** 1,5 ****
  /* Generic dominator tree walker
!    Copyright (C) 2003 Free Software Foundation, Inc.
     Contributed by Diego Novillo <dnovillo@redhat.com>
  
  This file is part of GCC.
--- 1,5 ----
  /* Generic dominator tree walker
!    Copyright (C) 2003, 2004 Free Software Foundation, Inc.
     Contributed by Diego Novillo <dnovillo@redhat.com>
  
  This file is part of GCC.
*************** struct dom_walk_data
*** 43,69 ****
       This typically initializes an block local data and pushes that
       data onto BLOCK_DATA_STACK.  */
    void (*before_dom_children_before_stmts) (struct dom_walk_data *,
! 					    basic_block, basic_block);
  
    /* Function to call to walk statements before the recursive walk
       of the dominator children.  */
    void (*before_dom_children_walk_stmts) (struct dom_walk_data *,
! 					  basic_block, basic_block);
  
    /* Function to call after the statement walk occurring before the
       recursive walk of the dominator children.  */
    void (*before_dom_children_after_stmts) (struct dom_walk_data *,
! 					   basic_block, basic_block);
  
    /* Function to call before the statement walk occurring after the
       recursive walk of the dominator children.  */
    void (*after_dom_children_before_stmts) (struct dom_walk_data *,
! 					   basic_block, basic_block);
  
    /* Function to call to walk statements after the recursive walk
       of the dominator children.  */
    void (*after_dom_children_walk_stmts) (struct dom_walk_data *,
! 					 basic_block, basic_block);
  
    /* Function to call after the statement walk occurring after the
       recursive walk of the dominator children. 
--- 43,69 ----
       This typically initializes an block local data and pushes that
       data onto BLOCK_DATA_STACK.  */
    void (*before_dom_children_before_stmts) (struct dom_walk_data *,
! 					    basic_block);
  
    /* Function to call to walk statements before the recursive walk
       of the dominator children.  */
    void (*before_dom_children_walk_stmts) (struct dom_walk_data *,
! 					  basic_block);
  
    /* Function to call after the statement walk occurring before the
       recursive walk of the dominator children.  */
    void (*before_dom_children_after_stmts) (struct dom_walk_data *,
! 					   basic_block);
  
    /* Function to call before the statement walk occurring after the
       recursive walk of the dominator children.  */
    void (*after_dom_children_before_stmts) (struct dom_walk_data *,
! 					   basic_block);
  
    /* Function to call to walk statements after the recursive walk
       of the dominator children.  */
    void (*after_dom_children_walk_stmts) (struct dom_walk_data *,
! 					 basic_block);
  
    /* Function to call after the statement walk occurring after the
       recursive walk of the dominator children. 
*************** struct dom_walk_data
*** 71,77 ****
       This typically finalizes any block local data and pops
       that data from BLOCK_DATA_STACK.  */
    void (*after_dom_children_after_stmts) (struct dom_walk_data *,
! 					  basic_block, basic_block);
  
    /* Global data for a walk through the dominator tree.  */
    void *global_data;
--- 71,77 ----
       This typically finalizes any block local data and pops
       that data from BLOCK_DATA_STACK.  */
    void (*after_dom_children_after_stmts) (struct dom_walk_data *,
! 					  basic_block);
  
    /* Global data for a walk through the dominator tree.  */
    void *global_data;
*************** struct dom_walk_data
*** 92,97 ****
    varray_type free_block_data;
  };
  
! void walk_dominator_tree (struct dom_walk_data *, basic_block, basic_block);
  void init_walk_dominator_tree (struct dom_walk_data *);
  void fini_walk_dominator_tree (struct dom_walk_data *);
--- 92,97 ----
    varray_type free_block_data;
  };
  
! void walk_dominator_tree (struct dom_walk_data *, basic_block);
  void init_walk_dominator_tree (struct dom_walk_data *);
  void fini_walk_dominator_tree (struct dom_walk_data *);
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.128
diff -c -p -r1.1.2.128 tree-ssa-dom.c
*** tree-ssa-dom.c	9 Feb 2004 20:07:08 -0000	1.1.2.128
--- tree-ssa-dom.c	9 Feb 2004 22:17:23 -0000
*************** static bool extract_range_from_cond (tre
*** 238,258 ****
  static bool cprop_into_stmt (tree);
  static void record_equivalences_from_phis (struct dom_walk_data *, 
basic_block);
  static void record_equivalences_from_incoming_edge (struct dom_walk_data *,
! 						    basic_block, basic_block);
  static bool eliminate_redundant_computations (struct dom_walk_data *,
  					      tree, stmt_ann_t);
  static void record_equivalences_from_stmt (tree, struct dom_walk_block_data 
*,
  					   int, stmt_ann_t);
  static void thread_across_edge (struct dom_walk_data *, edge);
! static void dom_opt_finalize_block (struct dom_walk_data *,
! 				    basic_block, basic_block);
  static void dom_opt_initialize_block_local_data (struct dom_walk_data *,
  						 basic_block, bool);
! static void dom_opt_initialize_block (struct dom_walk_data *,
! 				      basic_block, basic_block);
! static void dom_opt_walk_stmts (struct dom_walk_data *,
! 				basic_block, basic_block);
! static void cprop_into_phis (struct dom_walk_data *, basic_block, 
basic_block);
  static void remove_local_expressions_from_table (varray_type locals,
  						 unsigned limit,
  						 htab_t table);
--- 238,255 ----
  static bool cprop_into_stmt (tree);
  static void record_equivalences_from_phis (struct dom_walk_data *, 
basic_block);
  static void record_equivalences_from_incoming_edge (struct dom_walk_data *,
! 						    basic_block);
  static bool eliminate_redundant_computations (struct dom_walk_data *,
  					      tree, stmt_ann_t);
  static void record_equivalences_from_stmt (tree, struct dom_walk_block_data 
*,
  					   int, stmt_ann_t);
  static void thread_across_edge (struct dom_walk_data *, edge);
! static void dom_opt_finalize_block (struct dom_walk_data *, basic_block);
  static void dom_opt_initialize_block_local_data (struct dom_walk_data *,
  						 basic_block, bool);
! static void dom_opt_initialize_block (struct dom_walk_data *, basic_block);
! static void dom_opt_walk_stmts (struct dom_walk_data *, basic_block);
! static void cprop_into_phis (struct dom_walk_data *, basic_block);
  static void remove_local_expressions_from_table (varray_type locals,
  						 unsigned limit,
  						 htab_t table);
*************** tree_ssa_dominator_optimize (void)
*** 612,618 ****
        cfg_altered = false;
  
        /* Recursively walk the dominator tree optimizing statements.  */
!       walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR, NULL);
  
        /* Wipe the hash tables.  */
        htab_empty (avail_exprs);
--- 609,615 ----
        cfg_altered = false;
  
        /* Recursively walk the dominator tree optimizing statements.  */
!       walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR);
  
        /* Wipe the hash tables.  */
        htab_empty (avail_exprs);
*************** dom_opt_initialize_block_local_data (str
*** 1025,1038 ****
     reach BB or they may come from PHI nodes at the start of BB.  */
  
  static void
! dom_opt_initialize_block (struct dom_walk_data *walk_data,
! 			  basic_block bb,
! 			  basic_block parent)
  {
    if (tree_dump_file && (tree_dump_flags & TDF_DETAILS))
      fprintf (tree_dump_file, "\n\nOptimizing block #%d\n\n", bb->index);
  
!   record_equivalences_from_incoming_edge (walk_data, bb, parent);
  
    /* PHI nodes can create equivalences too.  */
    record_equivalences_from_phis (walk_data, bb);
--- 1022,1033 ----
     reach BB or they may come from PHI nodes at the start of BB.  */
  
  static void
! dom_opt_initialize_block (struct dom_walk_data *walk_data, basic_block bb)
  {
    if (tree_dump_file && (tree_dump_flags & TDF_DETAILS))
      fprintf (tree_dump_file, "\n\nOptimizing block #%d\n\n", bb->index);
  
!   record_equivalences_from_incoming_edge (walk_data, bb);
  
    /* PHI nodes can create equivalences too.  */
    record_equivalences_from_phis (walk_data, bb);
*************** extract_true_false_edges_from_block (bas
*** 1112,1120 ****
     the dominator tree.  */
  
  static void
! dom_opt_finalize_block (struct dom_walk_data *walk_data,
! 			basic_block bb,
! 			basic_block parent ATTRIBUTE_UNUSED)
  {
    struct dom_walk_block_data *bd
      = VARRAY_TOP_GENERIC_PTR (walk_data->block_data_stack);
--- 1107,1113 ----
     the dominator tree.  */
  
  static void
! dom_opt_finalize_block (struct dom_walk_data *walk_data, basic_block bb)
  {
    struct dom_walk_block_data *bd
      = VARRAY_TOP_GENERIC_PTR (walk_data->block_data_stack);
*************** record_equivalences_from_phis (struct do
*** 1351,1360 ****
  
  static void
  record_equivalences_from_incoming_edge (struct dom_walk_data *walk_data,
! 					basic_block bb,
! 					basic_block parent)
  {
    int edge_flags;
    struct eq_expr_value eq_expr_value;
    tree parent_block_last_stmt = NULL;
    struct dom_walk_block_data *bd
--- 1344,1353 ----
  
  static void
  record_equivalences_from_incoming_edge (struct dom_walk_data *walk_data,
! 					basic_block bb)
  {
    int edge_flags;
+   basic_block parent;
    struct eq_expr_value eq_expr_value;
    tree parent_block_last_stmt = NULL;
    struct dom_walk_block_data *bd
*************** record_equivalences_from_incoming_edge (
*** 1363,1369 ****
    /* If our parent block ended with a control statment, then we may be
       able to record some equivalences based on which outgoing edge from
       the parent was followed.  */
! 	
    if (parent)
      {
        parent_block_last_stmt = last_stmt (parent);
--- 1356,1362 ----
    /* If our parent block ended with a control statment, then we may be
       able to record some equivalences based on which outgoing edge from
       the parent was followed.  */
!   parent = get_immediate_dominator (CDI_DOMINATORS, bb);
    if (parent)
      {
        parent_block_last_stmt = last_stmt (parent);
*************** record_equivalences_from_incoming_edge (
*** 1490,1498 ****
     CFG_ALTERED is set to true if cfg is altered.  */
  
  static void
! dom_opt_walk_stmts (struct dom_walk_data *walk_data,
! 		    basic_block bb,
! 		    basic_block parent ATTRIBUTE_UNUSED)
  {
    block_stmt_iterator si;
    struct dom_walk_block_data *bd
--- 1483,1489 ----
     CFG_ALTERED is set to true if cfg is altered.  */
  
  static void
! dom_opt_walk_stmts (struct dom_walk_data *walk_data, basic_block bb)
  {
    block_stmt_iterator si;
    struct dom_walk_block_data *bd
*************** cprop_into_stmt (tree stmt)
*** 2378,2385 ****
  
  static void
  cprop_into_phis (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
! 		 basic_block bb,
! 		 basic_block parent ATTRIBUTE_UNUSED)
  {
    edge e;
  
--- 2369,2375 ----
  
  static void
  cprop_into_phis (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
! 		 basic_block bb)
  {
    edge e;
  
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.193
diff -c -p -r1.1.4.193 tree-ssa.c
*** tree-ssa.c	9 Feb 2004 20:07:08 -0000	1.1.4.193
--- tree-ssa.c	9 Feb 2004 22:17:28 -0000
*************** struct rewrite_block_data
*** 160,178 ****
  static struct ssa_stats_d ssa_stats;
  
  /* Local functions.  */
! static void rewrite_finalize_block (struct dom_walk_data *,
! 				    basic_block, basic_block);
  static void rewrite_initialize_block_local_data (struct dom_walk_data *,
  						 basic_block, bool);
! static void rewrite_initialize_block (struct dom_walk_data *,
! 				      basic_block, basic_block);
! static void rewrite_walk_stmts (struct dom_walk_data *,
! 				basic_block, basic_block);
! static void rewrite_add_phi_arguments (struct dom_walk_data *,
! 				       basic_block, basic_block);
! static void mark_def_sites (struct dom_walk_data *walk_data,
! 			    basic_block bb,
! 			    basic_block parent ATTRIBUTE_UNUSED);
  static void compute_global_livein (bitmap, bitmap);
  static void set_def_block (tree, basic_block);
  static void set_livein_block (tree, basic_block);
--- 160,172 ----
  static struct ssa_stats_d ssa_stats;
  
  /* Local functions.  */
! static void rewrite_finalize_block (struct dom_walk_data *, basic_block);
  static void rewrite_initialize_block_local_data (struct dom_walk_data *,
  						 basic_block, bool);
! static void rewrite_initialize_block (struct dom_walk_data *, basic_block);
! static void rewrite_walk_stmts (struct dom_walk_data *, basic_block);
! static void rewrite_add_phi_arguments (struct dom_walk_data *, basic_block);
! static void mark_def_sites (struct dom_walk_data *walk_data, basic_block bb);
  static void compute_global_livein (bitmap, bitmap);
  static void set_def_block (tree, basic_block);
  static void set_livein_block (tree, basic_block);
*************** rewrite_into_ssa (void)
*** 391,397 ****
    init_walk_dominator_tree (&walk_data);
  
    /* Recursively walk the dominator tree.  */
!   walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR, NULL);
  
    /* Finalize the dominator walker.  */
    fini_walk_dominator_tree (&walk_data);
--- 385,391 ----
    init_walk_dominator_tree (&walk_data);
  
    /* Recursively walk the dominator tree.  */
!   walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR);
  
    /* Finalize the dominator walker.  */
    fini_walk_dominator_tree (&walk_data);
*************** rewrite_into_ssa (void)
*** 421,427 ****
  
    /* Recursively walk the dominator tree rewriting each statement in
       each basic block.  */
!   walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR, NULL);
  
    /* Finalize the dominator walker.  */
    fini_walk_dominator_tree (&walk_data);
--- 415,421 ----
  
    /* Recursively walk the dominator tree rewriting each statement in
       each basic block.  */
!   walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR);
  
    /* Finalize the dominator walker.  */
    fini_walk_dominator_tree (&walk_data);
*************** compute_global_livein (bitmap livein, bi
*** 521,529 ****
     we create.  */
  
  static void
! mark_def_sites (struct dom_walk_data *walk_data,
!                 basic_block bb,
!                 basic_block parent ATTRIBUTE_UNUSED)
  {
    struct mark_def_sites_global_data *gd = walk_data->global_data;
    sbitmap kills = gd->kills;
--- 515,521 ----
     we create.  */
  
  static void
! mark_def_sites (struct dom_walk_data *walk_data, basic_block bb)
  {
    struct mark_def_sites_global_data *gd = walk_data->global_data;
    sbitmap kills = gd->kills;
*************** rewrite_initialize_block_local_data (str
*** 822,830 ****
     block.  */
  
  static void
! rewrite_initialize_block (struct dom_walk_data *walk_data,
! 			  basic_block bb,
! 			  basic_block parent ATTRIBUTE_UNUSED)
  {
    tree phi;
    struct rewrite_block_data *bd
--- 814,820 ----
     block.  */
  
  static void
! rewrite_initialize_block (struct dom_walk_data *walk_data, basic_block bb)
  {
    tree phi;
    struct rewrite_block_data *bd
*************** rewrite_initialize_block (struct dom_wal
*** 851,858 ****
  
  static void
  rewrite_walk_stmts (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
! 		    basic_block bb,
! 		    basic_block parent ATTRIBUTE_UNUSED)
  {
    block_stmt_iterator si;
    struct rewrite_block_data *bd
--- 841,847 ----
  
  static void
  rewrite_walk_stmts (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
! 		    basic_block bb)
  {
    block_stmt_iterator si;
    struct rewrite_block_data *bd
*************** rewrite_walk_stmts (struct dom_walk_data
*** 870,877 ****
  
  static void
  rewrite_add_phi_arguments (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
! 			   basic_block bb,
! 			   basic_block parent ATTRIBUTE_UNUSED)
  {
    edge e;
  
--- 859,865 ----
  
  static void
  rewrite_add_phi_arguments (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
! 			   basic_block bb)
  {
    edge e;
  
*************** rewrite_add_phi_arguments (struct dom_wa
*** 900,907 ****
  
  static void
  rewrite_finalize_block (struct dom_walk_data *walk_data,
! 			basic_block bb ATTRIBUTE_UNUSED,
! 			basic_block parent ATTRIBUTE_UNUSED)
  {
    struct rewrite_block_data *bd
      = (struct rewrite_block_data *)VARRAY_TOP_GENERIC_PTR (walk_data->
block_data_stack);
--- 888,894 ----
  
  static void
  rewrite_finalize_block (struct dom_walk_data *walk_data,
! 			basic_block bb ATTRIBUTE_UNUSED)
  {
    struct rewrite_block_data *bd
      = (struct rewrite_block_data *)VARRAY_TOP_GENERIC_PTR (walk_data->
block_data_stack);



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