tree-cfg.c (tree_duplicate_sese_region): Update profile.
authorZdenek Dvorak <dvorakz@suse.cz>
Tue, 10 May 2005 22:33:30 +0000 (00:33 +0200)
committerZdenek Dvorak <rakdver@gcc.gnu.org>
Tue, 10 May 2005 22:33:30 +0000 (22:33 +0000)
* tree-cfg.c (tree_duplicate_sese_region): Update profile.
* tree-optimize.c (init_tree_optimization_passes) Swap
pass_ch and pass_profile.
* tree-ssa-loop-ch.c (copy_loop_headers): Do not update profile
here.  Remove rewrite_into_loop_closed_ssa call.

From-SVN: r99547

gcc/ChangeLog
gcc/tree-cfg.c
gcc/tree-optimize.c
gcc/tree-ssa-loop-ch.c

index 59f058bcc63522925e7abc1c8eacc39ae1069466..7699a48945a96880547b66ef46dae69c75ebfa39 100644 (file)
@@ -1,3 +1,11 @@
+2005-05-10  Zdenek Dvorak  <dvorakz@suse.cz>
+
+       * tree-cfg.c (tree_duplicate_sese_region): Update profile.
+       * tree-optimize.c (init_tree_optimization_passes) Swap
+       pass_ch and pass_profile.
+       * tree-ssa-loop-ch.c (copy_loop_headers): Do not update profile
+       here.  Remove rewrite_into_loop_closed_ssa call.
+
 2005-05-10  Adrian Straetling  <straetling@de.ibm.com>
 
        * config/s390/s390.c: (s390_const_double_ok_for_constraint_p): New
index ccafd9a783217d03b4a9c96ec7921746e08d8989..c54305c898b5402de3e3887c9a647b6248197a6c 100644 (file)
@@ -4847,6 +4847,7 @@ tree_duplicate_sese_region (edge entry, edge exit,
   edge exit_copy;
   basic_block *doms;
   edge redirected;
+  int total_freq, entry_freq;
 
   if (!can_copy_bbs_p (region, n_region))
     return false;
@@ -4893,12 +4894,24 @@ tree_duplicate_sese_region (edge entry, edge exit,
 
   gcc_assert (!need_ssa_update_p ());
 
-  /* Record blocks outside the region that are duplicated by something
+  /* Record blocks outside the region that are dominated by something
      inside.  */
   doms = xmalloc (sizeof (basic_block) * n_basic_blocks);
   n_doms = get_dominated_by_region (CDI_DOMINATORS, region, n_region, doms);
 
+  total_freq = entry->dest->frequency;
+  entry_freq = EDGE_FREQUENCY (entry);
+  /* Fix up corner cases, to avoid division by zero or creation of negative
+     frequencies.  */
+  if (total_freq == 0)
+    total_freq = 1;
+  else if (entry_freq > total_freq)
+    entry_freq = total_freq;
+
   copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop);
+  scale_bbs_frequencies_int (region, n_region, total_freq - entry_freq,
+                            total_freq);
+  scale_bbs_frequencies_int (region_copy, n_region, entry_freq, total_freq);
 
   if (copying_header)
     {
index e77c29c573a041a5757d89ca940e25880de3a7ae..6b1d35554f4fa8686636fcf3c4b55eb4e45f1ee7 100644 (file)
@@ -374,8 +374,8 @@ init_tree_optimization_passes (void)
   NEXT_PASS (pass_phiopt);
   NEXT_PASS (pass_may_alias);
   NEXT_PASS (pass_tail_recursion);
-  NEXT_PASS (pass_ch);
   NEXT_PASS (pass_profile);
+  NEXT_PASS (pass_ch);
   NEXT_PASS (pass_stdarg);
   NEXT_PASS (pass_sra);
   /* FIXME: SRA may generate arbitrary gimple code, exposing new
index 18afec1e079265f458678f9dfb92c2b5555c7e78..378755c9eaa36791a93dc37bfd19a7ce944f2738 100644 (file)
@@ -131,12 +131,10 @@ copy_loop_headers (void)
   basic_block *bbs, *copied_bbs;
   unsigned n_bbs;
   unsigned bbs_size;
-  gcov_type entry_count, body_count, total_count;
 
   loops = loop_optimizer_init (dump_file);
   if (!loops)
     return;
-  rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
   
   /* We do not try to keep the information about irreducible regions
      up-to-date.  */
@@ -202,8 +200,6 @@ copy_loop_headers (void)
        exit = single_succ_edge (loop_split_edge_with (exit, NULL));
 
       entry = loop_preheader_edge (loop);
-      entry_count = entry->src->count;
-      body_count = exit->dest->count;
 
       if (!tree_duplicate_sese_region (entry, exit, bbs, n_bbs, copied_bbs))
        {
@@ -211,23 +207,6 @@ copy_loop_headers (void)
          continue;
        }
 
-      /* Fix profiling info.  Scaling is done in gcov_type arithmetic to
-        avoid losing information; this is slow, but is done at most
-        once per loop.  We special case 0 to avoid division by 0;
-         probably other special cases exist.  */
-      total_count = body_count + entry_count;
-      if (total_count == 0LL)
-       {
-         scale_bbs_frequencies_int (bbs, n_bbs, 0, 1);
-         scale_bbs_frequencies_int (copied_bbs, n_bbs, 0, 1);
-       }
-      else
-       {
-         scale_bbs_frequencies_gcov_type (bbs, n_bbs, body_count, total_count);
-         scale_bbs_frequencies_gcov_type (copied_bbs, n_bbs, entry_count, 
-                                          total_count);
-       }
-
       /* Ensure that the latch and the preheader is simple (we know that they
         are not now, since there was the loop exit condition.  */
       loop_split_edge_with (loop_preheader_edge (loop), NULL);