bb-reorder.c (find_rarely_executed_basic_blocks_and_crossing_edges): Put all BBs...
authorJan Hubicka <hubicka@ucw.cz>
Fri, 21 Jul 2017 07:17:22 +0000 (09:17 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Fri, 21 Jul 2017 07:17:22 +0000 (07:17 +0000)
* bb-reorder.c (find_rarely_executed_basic_blocks_and_crossing_edges):
Put all BBs reachable only via paths crossing cold region to cold
region.
* cfgrtl.c (find_bbs_reachable_by_hot_paths): New function.

From-SVN: r250417

gcc/ChangeLog
gcc/bb-reorder.c
gcc/cfgrtl.c
gcc/cfgrtl.h

index e5bd2bf58bc8e69622fa9b0feabd24238d9fe801..7e87d432662000b88e6a99becd8b6b4e7be84a82 100644 (file)
@@ -1,3 +1,10 @@
+2016-07-21  Jan Hubicka  <hubicka@ucw.cz>
+
+       * bb-reorder.c (find_rarely_executed_basic_blocks_and_crossing_edges):
+       Put all BBs reachable only via paths crossing cold region to cold
+       region.
+       * cfgrtl.c (find_bbs_reachable_by_hot_paths): New function.
+
 2016-07-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/81303
index 3b7278f2be1243ba35c477601915105e75c3e64d..dc50546ab63d4d5531f8bddbe319f6491a9b07d9 100644 (file)
@@ -1665,6 +1665,12 @@ find_rarely_executed_basic_blocks_and_crossing_edges (void)
                                           &bbs_in_hot_partition);
       if (cold_bb_count)
         sanitize_hot_paths (false, cold_bb_count, &bbs_in_hot_partition);
+
+      hash_set <basic_block> set;
+      find_bbs_reachable_by_hot_paths (&set);
+      FOR_EACH_BB_FN (bb, cfun)
+       if (!set.contains (bb))
+         BB_SET_PARTITION (bb, BB_COLD_PARTITION);
     }
 
   /* The format of .gcc_except_table does not allow landing pads to
index 8c60eede0b972ebc012bed58afc77589fc44e661..58d87fe09aeec97cc5d0f34c7f7f2bc48018e20e 100644 (file)
@@ -2282,6 +2282,29 @@ get_last_bb_insn (basic_block bb)
   return end;
 }
 
+/* Add all BBs reachable from entry via hot paths into the SET.  */
+
+void
+find_bbs_reachable_by_hot_paths (hash_set<basic_block> *set)
+{
+  auto_vec<basic_block, 64> worklist;
+
+  set->add (ENTRY_BLOCK_PTR_FOR_FN (cfun));
+  worklist.safe_push (ENTRY_BLOCK_PTR_FOR_FN (cfun));
+
+  while (worklist.length () > 0)
+    {
+      basic_block bb = worklist.pop ();
+      edge_iterator ei;
+      edge e;
+
+      FOR_EACH_EDGE (e, ei, bb->succs)
+       if (BB_PARTITION (e->dest) != BB_COLD_PARTITION
+           && !set->add (e->dest))
+         worklist.safe_push (e->dest);
+    }
+}
+
 /* Sanity check partition hotness to ensure that basic blocks in
    the cold partition don't dominate basic blocks in the hot partition.
    If FLAG_ONLY is true, report violations as errors. Otherwise
@@ -2295,49 +2318,25 @@ find_partition_fixes (bool flag_only)
   basic_block bb;
   vec<basic_block> bbs_in_cold_partition = vNULL;
   vec<basic_block> bbs_to_fix = vNULL;
+  hash_set<basic_block> set;
 
   /* Callers check this.  */
   gcc_checking_assert (crtl->has_bb_partition);
 
-  FOR_EACH_BB_FN (bb, cfun)
-    if ((BB_PARTITION (bb) == BB_COLD_PARTITION))
-      bbs_in_cold_partition.safe_push (bb);
-
-  if (bbs_in_cold_partition.is_empty ())
-    return vNULL;
-
-  bool dom_calculated_here = !dom_info_available_p (CDI_DOMINATORS);
-
-  if (dom_calculated_here)
-    calculate_dominance_info (CDI_DOMINATORS);
-
-  while (! bbs_in_cold_partition.is_empty  ())
-    {
-      bb = bbs_in_cold_partition.pop ();
-      /* Any blocks dominated by a block in the cold section
-         must also be cold.  */
-      basic_block son;
-      for (son = first_dom_son (CDI_DOMINATORS, bb);
-           son;
-           son = next_dom_son (CDI_DOMINATORS, son))
-        {
-          /* If son is not yet cold, then mark it cold here and
-             enqueue it for further processing.  */
-          if ((BB_PARTITION (son) != BB_COLD_PARTITION))
-            {
-              if (flag_only)
-                error ("non-cold basic block %d dominated "
-                       "by a block in the cold partition (%d)", son->index, bb->index);
-              else
-                BB_SET_PARTITION (son, BB_COLD_PARTITION);
-              bbs_to_fix.safe_push (son);
-              bbs_in_cold_partition.safe_push (son);
-            }
-        }
-    }
+  find_bbs_reachable_by_hot_paths (&set);
 
-  if (dom_calculated_here)
-    free_dominance_info (CDI_DOMINATORS);
+  FOR_EACH_BB_FN (bb, cfun)
+    if (!set.contains (bb)
+       && BB_PARTITION (bb) != BB_COLD_PARTITION)
+      {
+       if (flag_only)
+         error ("non-cold basic block %d reachable only "
+                "by paths crossing the cold partition", bb->index);
+       else
+         BB_SET_PARTITION (bb, BB_COLD_PARTITION);
+       bbs_to_fix.safe_push (bb);
+       bbs_in_cold_partition.safe_push (bb);
+      }
 
   return bbs_to_fix;
 }
index 9235b50ed665fcbe6f4d4944a8b1cbcc4050c903..93cb75d041e0a4f3d66e839cf555237cde31ab5f 100644 (file)
@@ -54,5 +54,6 @@ extern void cfg_layout_initialize (int);
 extern void cfg_layout_finalize (void);
 extern void break_superblocks (void);
 extern void init_rtl_bb_info (basic_block);
+extern void find_bbs_reachable_by_hot_paths (hash_set <basic_block> *);
 
 #endif /* GCC_CFGRTL_H */