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: [PATCH] profile feedback: -fprofile-use= and -fprofile-correction, correctness fixes and option semantic changes.


...
>  >  I see, there is code to move the histograms, I think it is better to use
>  >  it.  It is used at same places as we move EH info.  If this place is
>  >  replacing statement without moving EH info and histograms, we ought to
>  >  fix both problems.
>  >
>  >  We do some work to replace one stringop by different and in that case
>  >  the histogram might be still useful.  Of course in case of replacing by
>  >  NOP it is best to kill it, but I think it is easier to just keep
>  >  shuffling the histograms around until they are finally ignored by
>  >  expansion instead of trying to figure out in what cases it might be
>  >  still useful (that can be probably done by calling back to value
>  >  profiling code)
>  >
>  >  Honza
>
>  Ok. I'll drop the hunk from this patch, and submit a separate patch
>  that will keep the histograms around in set_rhs.
>  Thanks!

Attached is the separate patch that preserves the value histogram
when replacing a whole statement in set_rhs.
I'm trying to reduce the testcase that causes the ICE
but no luck so far - I'll add the testcase as soon as I can.
Bootstrapped and regtested with other patches.
Ok for mainline ?

Seongbae

2008-04-02  Seongbae Park  <seongbae.park@gmail.com>

        * tree-ssa-propagate.c (set_rhs): Preserve the histogram.
        * value-prof.c (gimple_move_stmt_histograms): New function.
        * value-prof.h (gimple_move_stmt_histograms): New function declaration.
diff -r d366cc0ab0fe gcc/tree-ssa-propagate.c
--- a/gcc/tree-ssa-propagate.c	Tue Apr 01 15:29:24 2008 -0700
+++ b/gcc/tree-ssa-propagate.c	Wed Apr 02 15:12:08 2008 -0700
@@ -681,6 +681,7 @@ set_rhs (tree *stmt_p, tree expr)
 set_rhs (tree *stmt_p, tree expr)
 {
   tree stmt = *stmt_p, op;
+  tree new_stmt;
   stmt_ann_t ann;
   tree var;
   ssa_op_iter iter;
@@ -735,8 +736,10 @@ set_rhs (tree *stmt_p, tree expr)
       /* Replace the whole statement with EXPR.  If EXPR has no side
 	 effects, then replace *STMT_P with an empty statement.  */
       ann = stmt_ann (stmt);
-      gimple_remove_stmt_histograms (cfun, stmt);
-      *stmt_p = TREE_SIDE_EFFECTS (expr) ? expr : build_empty_stmt ();
+      new_stmt = TREE_SIDE_EFFECTS (expr) ? expr : build_empty_stmt ();
+      /* Preserve the histograms associated with the original statement. */
+      gimple_move_stmt_histograms (cfun, new_stmt, stmt);
+      *stmt_p = new_stmt;
       (*stmt_p)->base.ann = (tree_ann_t) ann;
 
       if (gimple_in_ssa_p (cfun)
diff -r d366cc0ab0fe gcc/value-prof.c
--- a/gcc/value-prof.c	Tue Apr 01 15:29:24 2008 -0700
+++ b/gcc/value-prof.c	Wed Apr 02 15:12:08 2008 -0700
@@ -333,6 +333,25 @@ gimple_duplicate_stmt_histograms (struct
       new->hvalue.counters = xmalloc (sizeof (*new->hvalue.counters) * new->n_counters);
       memcpy (new->hvalue.counters, val->hvalue.counters, sizeof (*new->hvalue.counters) * new->n_counters);
       gimple_add_histogram_value (fun, stmt, new);
+    }
+}
+
+
+/* Move all histograms associated with OSTMT to STMT.  */
+
+void
+gimple_move_stmt_histograms (struct function *fun, tree stmt, tree ostmt)
+{
+  histogram_value val = gimple_histogram_value (fun, ostmt);
+  if (val)
+    {
+      /* The following three statements can't be reordered,
+         because histogram hashtab relies on stmt field value
+	 for finding the exact slot. */
+      set_histogram_value (fun, ostmt, NULL);
+      for (; val != NULL; val = val->hvalue.next)
+	val->hvalue.stmt = stmt;
+      set_histogram_value (fun, stmt, val);
     }
 }
 
diff -r d366cc0ab0fe gcc/value-prof.h
--- a/gcc/value-prof.h	Tue Apr 01 15:29:24 2008 -0700
+++ b/gcc/value-prof.h	Wed Apr 02 15:12:08 2008 -0700
@@ -116,6 +116,7 @@ void gimple_remove_histogram_value (stru
 void gimple_remove_histogram_value (struct function *, tree, histogram_value);
 void gimple_remove_stmt_histograms (struct function *, tree);
 void gimple_duplicate_stmt_histograms (struct function *, tree, struct function *, tree);
+void gimple_move_stmt_histograms (struct function *, tree, tree);
 void verify_histograms (void);
 void free_histograms (void);
 void stringop_block_profile (tree, unsigned int *, HOST_WIDE_INT *);

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