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_ADDRESSABLE and trivial dead stores before inlining


> Jan Hubicka wrote on 02/04/07 14:41:
> 
> >Well, it depends if we decide that aliasing with VOPS at IPA is what we
> >want, that don't seem quite clear to me still, but lets give it a try.
> >(my view of those two passes is to allow fast cleanup before we go to
> >full aliasing so the unnecesary datastructures don't need to be built.
> >It seems to pay back in compile times as we tested tonight on C++
> >tester.  It is however possible that doing aliasing early will help too
> >since we don't need to duplicate effort after inlining).
> 
> If enabling aliasing doesn't work, then I'm willing to try the 
> workaround.  But I want to avoid these hacks as much as possible.
> 
> >>How about this?  We create a partitioning heuristic that puts *every* 
> >>symbol inside the same partition.  This way we can run all the usual 
> >
> >Will DSE work then?
> 
> Yes, it should.  A single partition holding all symbols will only tie 
> the optimizers hands, it should not cause correctness issues.
> 
> 
> >I will need a help here since when I try to enable aliasing pre-inline I
> >get number of interesting failures and I am not terribly familiar with
> >the code.  I will update patch I have and send it shortly.
> >
> Sure.  Send me the patch and I'll work on it next week.

Hi,
this is what I ended up with my past expriments.
The problems I got into are:

 1) release_ssa_name is checking name_registered_for_update_p that is
 not localized (and if possible I would preffer to avoid localizing
 too much of such temporary containers).  This screws up when inliner
 has already registered something in outer function and then decided
 to remove inlined function that calls delete_ssa that in turn attempts
 to release ssa_name of the inlined function while
 cfun/name_registered_for_update_p is set for the callee function.
 I fixed this by release_ssa_name_now that avoids this check used
 by delete_ssa.
 Similarly we need to skip !need_ssa_update_p for the same reasons.
 2) We need to find way to do create_structure_vars after inlining since
 inlining brings in new structures and accesses.  I think it should be
 possible to simply split only the vars not split previous but it don't
 seem to quite work, so I disabled the pass for time being.
 3) ipa-reference and ipa-pure-consts changes TREE_ADDRESSABLE and
 side effects.  We need to update operand caches in execute_fixup_cfg.
 4) heapvar_for_stmt is non-localized.  I think it is just avoiding
 structalias to introduce too many redundant heapvars, so it is safe
 to free it after early passes and allocate again later.

Well, those are all hacks or bigger hacks, but I am quite unsure how to
fix that all properly.  Hopefully you will know ;)

Honza

Index: tree.h
===================================================================
--- tree.h	(revision 121569)
+++ tree.h	(working copy)
@@ -3588,6 +3588,7 @@ extern tree make_ssa_name (tree, tree);
 extern tree duplicate_ssa_name (tree, tree);
 extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
 extern void release_ssa_name (tree);
+extern void release_ssa_name_now (tree);
 extern void release_defs (tree);
 extern void replace_ssa_name_symbol (tree, tree);
 
Index: tree-ssa-alias.c
===================================================================
--- tree-ssa-alias.c	(revision 121569)
+++ tree-ssa-alias.c	(working copy)
@@ -3192,10 +3192,11 @@ create_structure_vars (void)
     {
       /* The C++ FE creates vars without DECL_SIZE set, for some reason.  */
       if (var 	  
+	  && !MTAG_P (var)
 	  && DECL_SIZE (var)
 	  && var_can_have_subvars (var)
-	  && !MTAG_P (var)
-	  && TREE_CODE (DECL_SIZE (var)) == INTEGER_CST)
+	  && TREE_CODE (DECL_SIZE (var)) == INTEGER_CST
+	  && !get_subvars_for_var (var))
 	create_overlap_variables_for (var);
     }
   htab_delete (used_portions);
@@ -3274,7 +3275,7 @@ struct tree_opt_pass pass_create_structu
   0,			 /* properties_provided */
   0,			 /* properties_destroyed */
   0,			 /* todo_flags_start */
-  TODO_dump_func,	 /* todo_flags_finish */
+  TODO_dump_func | TODO_update_ssa, /* todo_flags_finish */
   0			 /* letter */
 };
 
Index: tree-ssa.c
===================================================================
--- tree-ssa.c	(revision 121569)
+++ tree-ssa.c	(working copy)
@@ -805,8 +805,8 @@ delete_tree_ssa (void)
         {
 	  SSA_NAME_IMM_USE_NODE (var).prev = &(SSA_NAME_IMM_USE_NODE (var));
 	  SSA_NAME_IMM_USE_NODE (var).next = &(SSA_NAME_IMM_USE_NODE (var));
+          release_ssa_name_now (var);
 	}
-      release_ssa_name (var);
     }
 
   /* Remove annotations from every tree in the function.  */
@@ -851,7 +851,9 @@ delete_tree_ssa (void)
   if (gimple_aliases_computed_p (cfun))
     {
       delete_alias_heapvars ();
-      gcc_assert (!need_ssa_update_p ());
+      /* We can't check gcc_assert (!need_ssa_update_p ()) since inliner calls
+	 node removal when inling is being processed and that calls us on
+	 different function body than symbols to rename are computed.  */
     }
   cfun->gimple_df->aliases_computed_p = false;
 
Index: tree-inline.c
===================================================================
--- tree-inline.c	(revision 121572)
+++ tree-inline.c	(working copy)
@@ -2466,6 +2466,7 @@ expand_call_inline (basic_block bb, tree
       bsi_insert_before (&bsi, stmt, BSI_NEW_STMT);
       purge_dead_abnormal_edges = false;
     }
+  mark_symbols_for_renaming (stmt);
 
   stmt_bsi = bsi_start (return_block);
 
Index: tree-ssa-structalias.c
===================================================================
--- tree-ssa-structalias.c	(revision 121569)
+++ tree-ssa-structalias.c	(working copy)
@@ -4939,7 +4939,8 @@ init_alias_heapvars (void)
 void
 delete_alias_heapvars (void)
 {
-  htab_delete (heapvar_for_stmt);
+  if (heapvar_for_stmt)
+    htab_delete (heapvar_for_stmt);
   heapvar_for_stmt = NULL;
 }
 
Index: passes.c
===================================================================
--- passes.c	(revision 121573)
+++ passes.c	(working copy)
@@ -486,12 +486,16 @@ init_optimization_passes (void)
 	  NEXT_PASS (pass_early_inline);
 	  NEXT_PASS (pass_cleanup_cfg);
 	  NEXT_PASS (pass_rename_ssa_copies);
+	  NEXT_PASS (pass_may_alias);
 	  NEXT_PASS (pass_ccp);
 	  NEXT_PASS (pass_forwprop);
+          NEXT_PASS (pass_dse);
 	  NEXT_PASS (pass_sra);
 	  NEXT_PASS (pass_copy_prop);
 	  NEXT_PASS (pass_merge_phi);
 	  NEXT_PASS (pass_dce);
+	  NEXT_PASS (pass_may_alias);
+          NEXT_PASS (pass_dse);
 	  NEXT_PASS (pass_tail_recursion);
 	  NEXT_PASS (pass_release_ssa_names);
 	}
@@ -501,8 +505,10 @@ init_optimization_passes (void)
   NEXT_PASS (pass_ipa_increase_alignment);
   NEXT_PASS (pass_ipa_cp);
   NEXT_PASS (pass_ipa_inline);
+#if 0
   NEXT_PASS (pass_ipa_reference);
   NEXT_PASS (pass_ipa_pure_const); 
+#endif
   NEXT_PASS (pass_ipa_type_escape);
   NEXT_PASS (pass_ipa_pta);
   *p = NULL;
@@ -514,7 +520,9 @@ init_optimization_passes (void)
   NEXT_PASS (pass_all_optimizations);
     {
       struct tree_opt_pass **p = &pass_all_optimizations.sub;
+#if 0
       NEXT_PASS (pass_create_structure_vars);
+#endif
       NEXT_PASS (pass_may_alias);
       NEXT_PASS (pass_return_slot);
       NEXT_PASS (pass_rename_ssa_copies);
Index: tree-ssanames.c
===================================================================
--- tree-ssanames.c	(revision 121569)
+++ tree-ssanames.c	(working copy)
@@ -163,7 +163,6 @@ make_ssa_name (tree var, tree stmt)
   return t;
 }
 
-
 /* We no longer need the SSA_NAME expression VAR, release it so that
    it may be reused. 
 
@@ -173,24 +172,8 @@ make_ssa_name (tree var, tree stmt)
    other fields must be assumed clobbered.  */
 
 void
-release_ssa_name (tree var)
+release_ssa_name_now (tree var)
 {
-  if (!var)
-    return;
-
-  /* Never release the default definition for a symbol.  It's a
-     special SSA name that should always exist once it's created.  */
-  if (SSA_NAME_IS_DEFAULT_DEF (var))
-    return;
-
-  /* If VAR has been registered for SSA updating, don't remove it.
-     After update_ssa has run, the name will be released.  */
-  if (name_registered_for_update_p (var))
-    {
-      release_ssa_name_after_update_ssa (var);
-      return;
-    }
-
   /* release_ssa_name can be called multiple times on a single SSA_NAME.
      However, it should only end up on our free list one time.   We
      keep a status bit in the SSA_NAME node itself to indicate it has
@@ -237,6 +220,29 @@ release_ssa_name (tree var)
     }
 }
 
+/* Like release_ssa_name but postnote names after update_ssa if needed.  */
+
+void
+release_ssa_name (tree var)
+{
+  if (!var)
+    return;
+
+  /* Never release the default definition for a symbol.  It's a
+     special SSA name that should always exist once it's created.  */
+  if (SSA_NAME_IS_DEFAULT_DEF (var))
+    return;
+
+  /* If VAR has been registered for SSA updating, don't remove it.
+     After update_ssa has run, the name will be released.  */
+  if (name_registered_for_update_p (var))
+    {
+      release_ssa_name_after_update_ssa (var);
+      return;
+    }
+  release_ssa_name_now (var);
+}
+
 /* Creates a duplicate of a ssa name NAME defined in statement STMT.  */
 
 tree
@@ -341,6 +347,7 @@ release_dead_ssa_names (void)
 
   if (dump_file)
     fprintf (dump_file, "Released %i names, %.2f%%\n", n, n * 100.0 / num_ssa_names);
+  delete_alias_heapvars ();
   return 0;
 }
 
Index: tree-optimize.c
===================================================================
--- tree-optimize.c	(revision 121572)
+++ tree-optimize.c	(working copy)
@@ -280,6 +280,7 @@ execute_fixup_cfg (void)
   basic_block bb;
   block_stmt_iterator bsi;
   int todo = gimple_in_ssa_p (cfun) ? TODO_verify_ssa : 0;
+  bool aliases = optimize ? gimple_aliases_computed_p (cfun) : false;
 
   cfun->after_inlining = true;
 
@@ -292,6 +293,11 @@ execute_fixup_cfg (void)
 	    tree call = get_call_expr_in (stmt);
 	    tree decl = call ? get_callee_fndecl (call) : NULL;
 
+	    if (aliases)
+	      {
+	        update_stmt (stmt);
+                mark_symbols_for_renaming (stmt);
+	      }
 	    if (decl && call_expr_flags (call) & (ECF_CONST | ECF_PURE)
 		&& TREE_SIDE_EFFECTS (call))
 	      {
@@ -315,7 +321,7 @@ execute_fixup_cfg (void)
   if (dump_file)
     dump_tree_cfg (dump_file, dump_flags);
 
-  return todo;
+  return todo | (aliases ? TODO_update_ssa : 0);
 }
 
 /* Do the actions required to initialize internal data structures used


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