diff mbox

move phiopt, ssa-dce and ssa-dom prototypes.

Message ID 524C343D.5010105@redhat.com
State New
Headers show

Commit Message

Andrew MacLeod Oct. 2, 2013, 2:57 p.m. UTC
Handle a few more prototypes in tree-flow.h

There were only 2 routines exported from tree-ssa-phiopts, and neither 
really belonged there.
* I moved nonfreeing_call_p() to gimple.c since it is gimple dependent.
blocks_in_phiopt_order() returns basic blocks in an order that 
guarantees any single predecessor is visited before its successor. After 
looking around, i think it really belongs in cfganal.c, so I moved it 
there... unless you can think of somewhere better.  I also renamed it to 
be more generally descriptive: single_pred_before_succ_order...  for 
lack of anything better.

tree-ssa-dom.h needed to be created for a few prototypes.

The only 2 exports from tree-ssa-dce.c were 
mark_virtual_operand_for_renaming and 
mark_virtual_phi_result_for_renaming. I moved them to tree-into-ssa.c 
which already has mark_virtual_operands_for_renaming ().   Names are 
confusing a bit I find... and do we even need these routines? Aren't all 
virtual uses based off the one root variable? so isn't all that walking 
and SET_USE-ing a waste of time?  Or is that still needed
by the incremental bits? I never really paid attention to how that 
worked :-)

Bootstrapped on x86_64-unknown-linux-gnu, and currently running 
regressions.  Assuming it passes, OK?

Andrew

Comments

Richard Biener Oct. 2, 2013, 5:11 p.m. UTC | #1
Andrew MacLeod <amacleod@redhat.com> wrote:
>Handle a few more prototypes in tree-flow.h
>
>There were only 2 routines exported from tree-ssa-phiopts, and neither 
>really belonged there.
>* I moved nonfreeing_call_p() to gimple.c since it is gimple dependent.
>blocks_in_phiopt_order() returns basic blocks in an order that 
>guarantees any single predecessor is visited before its successor.
>After 
>looking around, i think it really belongs in cfganal.c, so I moved it 
>there... unless you can think of somewhere better.  I also renamed it
>to 
>be more generally descriptive: single_pred_before_succ_order...  for 
>lack of anything better.
>
>tree-ssa-dom.h needed to be created for a few prototypes.
>
>The only 2 exports from tree-ssa-dce.c were 
>mark_virtual_operand_for_renaming and 
>mark_virtual_phi_result_for_renaming. I moved them to tree-into-ssa.c 
>which already has mark_virtual_operands_for_renaming ().   Names are 
>confusing a bit I find... and do we even need these routines? Aren't
>all 
>virtual uses based off the one root variable? so isn't all that walking
>
>and SET_USE-ing a waste of time?  Or is that still needed
>by the incremental bits? I never really paid attention to how that 
>worked :-)

It can be a bit tricky sometimes, but yes, another cleanup is on my long todo list.

>Bootstrapped on x86_64-unknown-linux-gnu, and currently running 
>regressions.  Assuming it passes, OK?

Ok.
Thanks,
Richard.
>Andrew
diff mbox

Patch


	* tree-flow.h: Remove some prototypes.
	* tree-ssa-dce.c (mark_virtual_operand_for_renaming,
	mark_virtual_phi_result_for_renaming): Move to tree-into-ssa.c.
	* tree-into-ssa.c (mark_virtual_operand_for_renaming,
	mark_virtual_phi_result_for_renaming): Relocate here.
	* tree-into-ssa.h: Add prototypes.
	* tree-ssa-phiopt.c: (tree_ssa_phiopt_worker) Use 
	single_pred_before_succ_order.
	(blocks_in_phiopt_order): Rename and move to cfganal.c.
	(nonfreeing_call_p) Move to gimple.c.
	* cfganal.c (single_pred_before_succ_order): Move and renamed from
	tree-ssa-phiopt.c.
	* basic-block.h (single_pred_before_succ_order): Add prototype.
	* gimple.c (nonfreeing_call_p): Relocate here.
	* gimple.h: Add prototype.
	* tree-ssa-ifcombine.c: Include tree-ssa-phiopt.h.
	* tree-ssa-dom.h: New file.  Relocate prototypes here.
	* tree-ssa.h: Include tree-ssa-dom.h.

Index: tree-flow.h
===================================================================
*** tree-flow.h	(revision 203113)
--- tree-flow.h	(working copy)
*************** bool tree_node_can_be_shared (tree);
*** 248,260 ****
  tree fold_const_aggregate_ref (tree);
  tree gimple_fold_stmt_to_constant (gimple, tree (*)(tree));
  
- /* In tree-ssa-dom.c  */
- extern void dump_dominator_optimization_stats (FILE *);
- extern void debug_dominator_optimization_stats (void);
- int loop_depth_of_name (tree);
- tree degenerate_phi_result (gimple);
- bool simple_iv_increment_p (gimple);
- 
  /* In tree-ssa-copy.c  */
  extern void propagate_value (use_operand_p, tree);
  extern void propagate_tree_value (tree *, tree);
--- 248,253 ----
*************** struct tree_niter_desc
*** 309,318 ****
    enum tree_code cmp;
  };
  
- /* In tree-ssa-phiopt.c */
- bool empty_block_p (basic_block);
- basic_block *blocks_in_phiopt_order (void);
- bool nonfreeing_call_p (gimple);
  
  /* In tree-ssa-loop*.c  */
  
--- 302,307 ----
*************** void tree_transform_and_unroll_loop (str
*** 372,381 ****
  bool contains_abnormal_ssa_name_p (tree);
  bool stmt_dominates_stmt_p (gimple, gimple);
  
- /* In tree-ssa-dce.c */
- void mark_virtual_operand_for_renaming (tree);
- void mark_virtual_phi_result_for_renaming (gimple);
- 
  /* In tree-ssa-threadedge.c */
  extern void threadedge_initialize_values (void);
  extern void threadedge_finalize_values (void);
--- 361,366 ----
Index: tree-ssa-dce.c
===================================================================
*** tree-ssa-dce.c	(revision 203112)
--- tree-ssa-dce.c	(working copy)
*************** propagate_necessity (bool aggressive)
*** 907,954 ****
      }
  }
  
- /* Replace all uses of NAME by underlying variable and mark it
-    for renaming.  This assumes the defining statement of NAME is
-    going to be removed.  */
- 
- void
- mark_virtual_operand_for_renaming (tree name)
- {
-   tree name_var = SSA_NAME_VAR (name);
-   bool used = false;
-   imm_use_iterator iter;
-   use_operand_p use_p;
-   gimple stmt;
- 
-   gcc_assert (VAR_DECL_IS_VIRTUAL_OPERAND (name_var));
-   FOR_EACH_IMM_USE_STMT (stmt, iter, name)
-     {
-       FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
-         SET_USE (use_p, name_var);
-       used = true;
-     }
-   if (used)
-     mark_virtual_operands_for_renaming (cfun);
- }
- 
- /* Replace all uses of the virtual PHI result by its underlying variable
-    and mark it for renaming.  This assumes the PHI node is going to be
-    removed.  */
- 
- void
- mark_virtual_phi_result_for_renaming (gimple phi)
- {
-   if (dump_file && (dump_flags & TDF_DETAILS))
-     {
-       fprintf (dump_file, "Marking result for renaming : ");
-       print_gimple_stmt (dump_file, phi, 0, TDF_SLIM);
-       fprintf (dump_file, "\n");
-     }
- 
-   mark_virtual_operand_for_renaming (gimple_phi_result (phi));
- }
- 
- 
  /* Remove dead PHI nodes from block BB.  */
  
  static bool
--- 907,912 ----
Index: tree-into-ssa.c
===================================================================
*** tree-into-ssa.c	(revision 203113)
--- tree-into-ssa.c	(working copy)
*************** mark_virtual_operands_for_renaming (stru
*** 2869,2874 ****
--- 2869,2914 ----
    fn->gimple_df->rename_vops = 1;
  }
  
+ /* Replace all uses of NAME by underlying variable and mark it
+    for renaming.  This assumes the defining statement of NAME is
+    going to be removed.  */
+ 
+ void
+ mark_virtual_operand_for_renaming (tree name)
+ {
+   tree name_var = SSA_NAME_VAR (name);
+   bool used = false;
+   imm_use_iterator iter;
+   use_operand_p use_p;
+   gimple stmt;
+ 
+   gcc_assert (VAR_DECL_IS_VIRTUAL_OPERAND (name_var));
+   FOR_EACH_IMM_USE_STMT (stmt, iter, name)
+     {
+       FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
+         SET_USE (use_p, name_var);
+       used = true;
+     }
+   if (used)
+     mark_virtual_operands_for_renaming (cfun);
+ }
+ 
+ /* Replace all uses of the virtual PHI result by its underlying variable
+    and mark it for renaming.  This assumes the PHI node is going to be
+    removed.  */
+ 
+ void
+ mark_virtual_phi_result_for_renaming (gimple phi)
+ {
+   if (dump_file && (dump_flags & TDF_DETAILS))
+     {
+       fprintf (dump_file, "Marking result for renaming : ");
+       print_gimple_stmt (dump_file, phi, 0, TDF_SLIM);
+       fprintf (dump_file, "\n");
+     }
+ 
+   mark_virtual_operand_for_renaming (gimple_phi_result (phi));
+ }
  
  /* Return true if there is any work to be done by update_ssa
     for function FN.  */
Index: tree-into-ssa.h
===================================================================
*** tree-into-ssa.h	(revision 203113)
--- tree-into-ssa.h	(working copy)
*************** extern void set_current_def (tree, tree)
*** 25,30 ****
--- 25,32 ----
  void delete_update_ssa (void);
  tree create_new_def_for (tree, gimple, def_operand_p);
  void mark_virtual_operands_for_renaming (struct function *);
+ void mark_virtual_operand_for_renaming (tree);
+ void mark_virtual_phi_result_for_renaming (gimple);
  bool need_ssa_update_p (struct function *);
  bool name_registered_for_update_p (tree);
  void release_ssa_name_after_update_ssa (tree);
Index: tree-ssa-phiopt.c
===================================================================
*** tree-ssa-phiopt.c	(revision 203112)
--- tree-ssa-phiopt.c	(working copy)
*************** tree_ssa_phiopt_worker (bool do_store_el
*** 308,314 ****
       This ensures that we collapse inner ifs before visiting the
       outer ones, and also that we do not try to visit a removed
       block.  */
!   bb_order = blocks_in_phiopt_order ();
    n = n_basic_blocks - NUM_FIXED_BLOCKS;
  
    for (i = 0; i < n; i++)
--- 308,314 ----
       This ensures that we collapse inner ifs before visiting the
       outer ones, and also that we do not try to visit a removed
       block.  */
!   bb_order = single_pred_before_succ_order ();
    n = n_basic_blocks - NUM_FIXED_BLOCKS;
  
    for (i = 0; i < n; i++)
*************** tree_ssa_phiopt_worker (bool do_store_el
*** 476,534 ****
    return 0;
  }
  
- /* Returns the list of basic blocks in the function in an order that guarantees
-    that if a block X has just a single predecessor Y, then Y is after X in the
-    ordering.  */
- 
- basic_block *
- blocks_in_phiopt_order (void)
- {
-   basic_block x, y;
-   basic_block *order = XNEWVEC (basic_block, n_basic_blocks);
-   unsigned n = n_basic_blocks - NUM_FIXED_BLOCKS;
-   unsigned np, i;
-   sbitmap visited = sbitmap_alloc (last_basic_block);
- 
- #define MARK_VISITED(BB) (bitmap_set_bit (visited, (BB)->index))
- #define VISITED_P(BB) (bitmap_bit_p (visited, (BB)->index))
- 
-   bitmap_clear (visited);
- 
-   MARK_VISITED (ENTRY_BLOCK_PTR);
-   FOR_EACH_BB (x)
-     {
-       if (VISITED_P (x))
- 	continue;
- 
-       /* Walk the predecessors of x as long as they have precisely one
- 	 predecessor and add them to the list, so that they get stored
- 	 after x.  */
-       for (y = x, np = 1;
- 	   single_pred_p (y) && !VISITED_P (single_pred (y));
- 	   y = single_pred (y))
- 	np++;
-       for (y = x, i = n - np;
- 	   single_pred_p (y) && !VISITED_P (single_pred (y));
- 	   y = single_pred (y), i++)
- 	{
- 	  order[i] = y;
- 	  MARK_VISITED (y);
- 	}
-       order[i] = y;
-       MARK_VISITED (y);
- 
-       gcc_assert (i == n - 1);
-       n -= np;
-     }
- 
-   sbitmap_free (visited);
-   gcc_assert (n == 0);
-   return order;
- 
- #undef MARK_VISITED
- #undef VISITED_P
- }
- 
  /* Replace PHI node element whose edge is E in block BB with variable NEW.
     Remove the edge from COND_BLOCK which does not lead to BB (COND_BLOCK
     is known to have two edges, one of which must reach BB).  */
--- 476,481 ----
*************** add_or_mark_expr (basic_block bb, tree e
*** 1353,1380 ****
      }
  }
  
- /* Return true when CALL is a call stmt that definitely doesn't
-    free any memory or makes it unavailable otherwise.  */
- bool
- nonfreeing_call_p (gimple call)
- {
-   if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)
-       && gimple_call_flags (call) & ECF_LEAF)
-     switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call)))
-       {
- 	/* Just in case these become ECF_LEAF in the future.  */
- 	case BUILT_IN_FREE:
- 	case BUILT_IN_TM_FREE:
- 	case BUILT_IN_REALLOC:
- 	case BUILT_IN_STACK_RESTORE:
- 	  return false;
- 	default:
- 	  return true;
-       }
- 
-   return false;
- }
- 
  class nontrapping_dom_walker : public dom_walker
  {
  public:
--- 1300,1305 ----
Index: cfganal.c
===================================================================
*** cfganal.c	(revision 203112)
--- cfganal.c	(working copy)
*************** bitmap_union_of_preds (sbitmap dst, sbit
*** 1465,1467 ****
--- 1465,1520 ----
  	  *r++ |= *p++;
        }
  }
+ 
+ /* Returns the list of basic blocks in the function in an order that guarantees
+    that if a block X has just a single predecessor Y, then Y is after X in the
+    ordering.  */
+ 
+ basic_block *
+ single_pred_before_succ_order (void)
+ {
+   basic_block x, y;
+   basic_block *order = XNEWVEC (basic_block, n_basic_blocks);
+   unsigned n = n_basic_blocks - NUM_FIXED_BLOCKS;
+   unsigned np, i;
+   sbitmap visited = sbitmap_alloc (last_basic_block);
+ 
+ #define MARK_VISITED(BB) (bitmap_set_bit (visited, (BB)->index))
+ #define VISITED_P(BB) (bitmap_bit_p (visited, (BB)->index))
+ 
+   bitmap_clear (visited);
+ 
+   MARK_VISITED (ENTRY_BLOCK_PTR);
+   FOR_EACH_BB (x)
+     {
+       if (VISITED_P (x))
+ 	continue;
+ 
+       /* Walk the predecessors of x as long as they have precisely one
+ 	 predecessor and add them to the list, so that they get stored
+ 	 after x.  */
+       for (y = x, np = 1;
+ 	   single_pred_p (y) && !VISITED_P (single_pred (y));
+ 	   y = single_pred (y))
+ 	np++;
+       for (y = x, i = n - np;
+ 	   single_pred_p (y) && !VISITED_P (single_pred (y));
+ 	   y = single_pred (y), i++)
+ 	{
+ 	  order[i] = y;
+ 	  MARK_VISITED (y);
+ 	}
+       order[i] = y;
+       MARK_VISITED (y);
+ 
+       gcc_assert (i == n - 1);
+       n -= np;
+     }
+ 
+   sbitmap_free (visited);
+   gcc_assert (n == 0);
+   return order;
+ 
+ #undef MARK_VISITED
+ #undef VISITED_P
+ }
Index: basic-block.h
===================================================================
*** basic-block.h	(revision 203112)
--- basic-block.h	(working copy)
*************** extern int dfs_enumerate_from (basic_blo
*** 803,808 ****
--- 803,809 ----
  			       basic_block *, int, const void *);
  extern void compute_dominance_frontiers (struct bitmap_head_def *);
  extern bitmap compute_idf (bitmap, struct bitmap_head_def *);
+ extern basic_block * single_pred_before_succ_order (void);
  
  /* In cfgrtl.c  */
  extern rtx block_label (basic_block);
Index: gimple.c
===================================================================
*** gimple.c	(revision 203112)
--- gimple.c	(working copy)
*************** gimple_can_coalesce_p (tree name1, tree
*** 4418,4421 ****
--- 4418,4444 ----
  
    return false;
  }
+ 
+ /* Return true when CALL is a call stmt that definitely doesn't
+    free any memory or makes it unavailable otherwise.  */
+ bool
+ nonfreeing_call_p (gimple call)
+ {
+   if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)
+       && gimple_call_flags (call) & ECF_LEAF)
+     switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call)))
+       {
+ 	/* Just in case these become ECF_LEAF in the future.  */
+ 	case BUILT_IN_FREE:
+ 	case BUILT_IN_TM_FREE:
+ 	case BUILT_IN_REALLOC:
+ 	case BUILT_IN_STACK_RESTORE:
+ 	  return false;
+ 	default:
+ 	  return true;
+       }
+ 
+   return false;
+ }
+ 
  #include "gt-gimple.h"
Index: gimple.h
===================================================================
*** gimple.h	(revision 203112)
--- gimple.h	(working copy)
*************** extern tree gimple_boolify (tree);
*** 1055,1060 ****
--- 1055,1061 ----
  extern gimple_predicate rhs_predicate_for (tree);
  extern tree canonicalize_cond_expr_cond (tree);
  extern void dump_decl_set (FILE *, bitmap);
+ extern bool nonfreeing_call_p (gimple);
  
  /* In omp-low.c.  */
  extern tree omp_reduction_init (tree, tree);
Index: tree-ssa-ifcombine.c
===================================================================
*** tree-ssa-ifcombine.c	(revision 203112)
--- tree-ssa-ifcombine.c	(working copy)
*************** tree_ssa_ifcombine (void)
*** 624,630 ****
    bool cfg_changed = false;
    int i;
  
!   bbs = blocks_in_phiopt_order ();
    calculate_dominance_info (CDI_DOMINATORS);
  
    for (i = 0; i < n_basic_blocks - NUM_FIXED_BLOCKS; ++i)
--- 624,630 ----
    bool cfg_changed = false;
    int i;
  
!   bbs = single_pred_before_succ_order ();
    calculate_dominance_info (CDI_DOMINATORS);
  
    for (i = 0; i < n_basic_blocks - NUM_FIXED_BLOCKS; ++i)
Index: tree-ssa-dom.h
===================================================================
*** tree-ssa-dom.h	(revision 0)
--- tree-ssa-dom.h	(working copy)
***************
*** 0 ****
--- 1,29 ----
+ /* Header file for SSA dominator optimizations.
+    Copyright (C) 2013 Free Software Foundation, Inc.
+ 
+ This file is part of GCC.
+ 
+ GCC is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 3, or (at your option) any later
+ version.
+ 
+ GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3.  If not see
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #ifndef GCC_TREE_SSA_DOM_H
+ #define GCC_TREE_SSA_DOM_H
+ 
+ extern void dump_dominator_optimization_stats (FILE *);
+ extern void debug_dominator_optimization_stats (void);
+ extern int loop_depth_of_name (tree);
+ extern bool simple_iv_increment_p (gimple);
+ extern tree degenerate_phi_result (gimple);
+ 
+ #endif /* GCC_TREE_SSA_DOM_H */
Index: tree-ssa.h
===================================================================
*** tree-ssa.h	(revision 203112)
--- tree-ssa.h	(working copy)
*************** along with GCC; see the file COPYING3.
*** 26,31 ****
--- 26,32 ----
  #include "gimple-ssa.h"
  #include "ssa-iterators.h"
  #include "tree-ssanames.h"
+ #include "tree-ssa-dom.h"
  #include "tree-flow.h"
  
  /* Mapping for redirected edges.  */