bb-reorder: Add -freorder-blocks-algorithm= and wire it up
authorSegher Boessenkool <segher@kernel.crashing.org>
Thu, 1 Oct 2015 06:38:24 +0000 (08:38 +0200)
committerSegher Boessenkool <segher@gcc.gnu.org>
Thu, 1 Oct 2015 06:38:24 +0000 (08:38 +0200)
This adds an -freorder-blocks-algorithm=[simple|stc] flag, with "simple"
as default.  For -O2 and up (except -Os) it is switched to "stc" instead.
Targets that never want STC can override this.  This changes -freorder-blocks
to be on at -O1 and up (was -O2 and up).

In effect, the changes are for -O1 (which now gets "simple" instead of
nothing), -Os (which now gets "simple" instead of "stc", since STC results
in much bigger code), and for targets that wish to never use STC (not in
this patch though).

2015-09-23   Segher Boessenkool  <segher@kernel.crashing.org>

* bb-reorder.c (reorder_basic_blocks): Use the algorithm selected
with flag_reorder_blocks_algorithm.
* common.opt (freorder-blocks-algorithm=): New flag.
(reorder_blocks_algorithm): New enum.
* flag-types.h (reorder_blocks_algorithm): New enum.
* opts.c (default_options_table): Use -freorder-blocks at -O1 and up,
and -freorder-blocks-algorithm=stc at -O2 and up (not at -Os).

From-SVN: r228318

gcc/ChangeLog
gcc/bb-reorder.c
gcc/common.opt
gcc/flag-types.h
gcc/opts.c

index 92fcb0febe578066b22e4bda28e20bac2b5f42cd..8bfff2b106fd71df201418ee7da97627d7f81245 100644 (file)
@@ -1,3 +1,13 @@
+2015-10-01  Segher Boessenkool  <segher@kernel.crashing.org>
+
+       * bb-reorder.c (reorder_basic_blocks): Use the algorithm selected
+       with flag_reorder_blocks_algorithm.
+       * common.opt (freorder-blocks-algorithm=): New flag.
+       (reorder_blocks_algorithm): New enum.
+       * flag-types.h (reorder_blocks_algorithm): New enum.
+       * opts.c (default_options_table): Use -freorder-blocks at -O1 and up,
+       and -freorder-blocks-algorithm=stc at -O2 and up (not at -Os).
+
 2015-10-01  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * bb-reorder.c: Add intro comment.
index 4d07b2e136966f54262d04c99856529477cad223..cb001e89f21ba6da336ecedb81fe111ddcf81939 100644 (file)
@@ -2444,10 +2444,19 @@ reorder_basic_blocks (void)
   set_edge_can_fallthru_flag ();
   mark_dfs_back_edges ();
 
-  if (1)
-    reorder_basic_blocks_software_trace_cache ();
-  else
-    reorder_basic_blocks_simple ();
+  switch (flag_reorder_blocks_algorithm)
+    {
+    case REORDER_BLOCKS_ALGORITHM_SIMPLE:
+      reorder_basic_blocks_simple ();
+      break;
+
+    case REORDER_BLOCKS_ALGORITHM_STC:
+      reorder_basic_blocks_software_trace_cache ();
+      break;
+
+    default:
+      gcc_unreachable ();
+    }
 
   relink_block_chain (/*stay_in_cfglayout_mode=*/true);
 
index 94d1d88483327b56c65bfa06afdf77abf9310ab4..b0f70fb4e9ec3c1b78aa7128e9d308479428df03 100644 (file)
@@ -1910,6 +1910,19 @@ freorder-blocks
 Common Report Var(flag_reorder_blocks) Optimization
 Reorder basic blocks to improve code placement
 
+freorder-blocks-algorithm=
+Common Joined RejectNegative Enum(reorder_blocks_algorithm) Var(flag_reorder_blocks_algorithm) Init(REORDER_BLOCKS_ALGORITHM_SIMPLE) Optimization
+-freorder-blocks-algorithm=[simple|stc] Set the used basic block reordering algorithm
+
+Enum
+Name(reorder_blocks_algorithm) Type(enum reorder_blocks_algorithm) UnknownError(unknown basic block reordering algorithm %qs)
+
+EnumValue
+Enum(reorder_blocks_algorithm) String(simple) Value(REORDER_BLOCKS_ALGORITHM_SIMPLE)
+
+EnumValue
+Enum(reorder_blocks_algorithm) String(stc) Value(REORDER_BLOCKS_ALGORITHM_STC)
+
 freorder-blocks-and-partition
 Common Report Var(flag_reorder_blocks_and_partition) Optimization
 Reorder basic blocks and partition into hot and cold sections
index ac9ca0b75e0ecf7fc9727bf7bd664a0dcbf9851f..6301cea48076c09ed4094526bbe4c5a400e797a8 100644 (file)
@@ -109,6 +109,13 @@ enum stack_reuse_level
   SR_ALL
 };
 
+/* The algorithm used for basic block reordering.  */
+enum reorder_blocks_algorithm
+{
+  REORDER_BLOCKS_ALGORITHM_SIMPLE,
+  REORDER_BLOCKS_ALGORITHM_STC
+};
+
 /* The algorithm used for the integrated register allocator (IRA).  */
 enum ira_algorithm
 {
index 2bbf6534077984ed2266f25cf9a206e8861ccfc9..896875b40e455f7bf1b30d5bae5e1856d35e76ac 100644 (file)
@@ -441,6 +441,7 @@ static const struct default_options default_options_table[] =
     { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
@@ -483,7 +484,8 @@ static const struct default_options default_options_table[] =
 #endif
     { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_freorder_blocks, NULL, 1 },
+    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_freorder_blocks_algorithm_, NULL,
+      REORDER_BLOCKS_ALGORITHM_STC },
     { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },