[llvm] r358379 - [NewPM] Add Option handling for SimplifyCFG

Serguei Katkov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 15 01:57:53 PDT 2019


Author: skatkov
Date: Mon Apr 15 01:57:53 2019
New Revision: 358379

URL: http://llvm.org/viewvc/llvm-project?rev=358379&view=rev
Log:
[NewPM] Add Option handling for SimplifyCFG

This patch enables passing options to SimplifyCFGPass via the passes pipeline.

Reviewers: chandlerc, fedor.sergeev, leonardchan, philip.pfaffe
Reviewed By: fedor.sergeev
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D60675

Modified:
    llvm/trunk/lib/Passes/PassBuilder.cpp
    llvm/trunk/lib/Passes/PassRegistry.def
    llvm/trunk/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll
    llvm/trunk/test/Transforms/SimplifyCFG/CoveredLookupTable.ll
    llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll
    llvm/trunk/test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll
    llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll
    llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-table-bug.ll
    llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
    llvm/trunk/test/Transforms/SimplifyCFG/branch-fold-threshold.ll
    llvm/trunk/test/Transforms/SimplifyCFG/multiple-phis.ll
    llvm/trunk/test/Transforms/SimplifyCFG/no-md-sink.ll
    llvm/trunk/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll
    llvm/trunk/test/Transforms/SimplifyCFG/rangereduce.ll
    llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll
    llvm/trunk/test/Transforms/SimplifyCFG/switch_undef.ll

Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Mon Apr 15 01:57:53 2019
@@ -1422,6 +1422,40 @@ Expected<MemorySanitizerOptions> parseMS
   return Result;
 }
 
+/// Parser of parameters for SimplifyCFG pass.
+Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
+  SimplifyCFGOptions Result;
+  while (!Params.empty()) {
+    StringRef ParamName;
+    std::tie(ParamName, Params) = Params.split(';');
+
+    bool Enable = !ParamName.consume_front("no-");
+    if (ParamName == "forward-switch-cond") {
+      Result.forwardSwitchCondToPhi(Enable);
+    } else if (ParamName == "switch-to-lookup") {
+      Result.convertSwitchToLookupTable(Enable);
+    } else if (ParamName == "keep-loops") {
+      Result.needCanonicalLoops(Enable);
+    } else if (ParamName == "sink-common-insts") {
+      Result.sinkCommonInsts(Enable);
+    } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
+      APInt BonusInstThreshold;
+      if (ParamName.getAsInteger(0, BonusInstThreshold))
+        return make_error<StringError>(
+            formatv("invalid argument to SimplifyCFG pass bonus-threshold "
+                    "parameter: '{0}' ",
+                    ParamName).str(),
+            inconvertibleErrorCode());
+      Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
+    } else {
+      return make_error<StringError>(
+          formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
+          inconvertibleErrorCode());
+    }
+  }
+  return Result;
+}
+
 } // namespace
 
 /// Tests whether a pass name starts with a valid prefix for a default pipeline

Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Mon Apr 15 01:57:53 2019
@@ -218,7 +218,6 @@ FUNCTION_PASS("print<stack-safety-local>
 FUNCTION_PASS("reassociate", ReassociatePass())
 FUNCTION_PASS("scalarizer", ScalarizerPass())
 FUNCTION_PASS("sccp", SCCPPass())
-FUNCTION_PASS("simplify-cfg", SimplifyCFGPass())
 FUNCTION_PASS("sink", SinkingPass())
 FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
 FUNCTION_PASS("speculative-execution", SpeculativeExecutionPass())
@@ -253,6 +252,11 @@ FUNCTION_PASS_WITH_PARAMS("msan",
                              return MemorySanitizerPass(Opts);
                            },
                            parseMSanPassOptions)
+FUNCTION_PASS_WITH_PARAMS("simplify-cfg",
+                           [](SimplifyCFGOptions Opts) {
+                             return SimplifyCFGPass(Opts);
+                           },
+                           parseSimplifyCFGOptions)
 #undef FUNCTION_PASS_WITH_PARAMS
 
 #ifndef LOOP_ANALYSIS

Modified: llvm/trunk/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll Mon Apr 15 01:57:53 2019
@@ -4,6 +4,12 @@
 ; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=rwpi      < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
 ; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=ropi-rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
 
+; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' -mtriple=arm -relocation-model=static    < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
+; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' -mtriple=arm -relocation-model=pic       < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
+; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' -mtriple=arm -relocation-model=ropi      < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
+; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' -mtriple=arm -relocation-model=rwpi      < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
+; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' -mtriple=arm -relocation-model=ropi-rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
+
 ; CHECK:       @{{.*}} = private unnamed_addr constant [3 x i32] [i32 1234, i32 5678, i32 15532]
 ; ENABLE:      @{{.*}} = private unnamed_addr constant [3 x i32*] [i32* @c1, i32* @c2, i32* @c3]
 ; DISABLE-NOT: @{{.*}} = private unnamed_addr constant [3 x i32*] [i32* @c1, i32* @c2, i32* @c3]

Modified: llvm/trunk/test/Transforms/SimplifyCFG/CoveredLookupTable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/CoveredLookupTable.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/CoveredLookupTable.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/CoveredLookupTable.ll Mon Apr 15 01:57:53 2019
@@ -1,4 +1,5 @@
 ; RUN: opt -simplifycfg -switch-to-lookup -S %s | FileCheck %s
+; RUN: opt -passes='simplify-cfg<switch-to-lookup>' -S %s | FileCheck %s
 ; rdar://15268442
 
 target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"

Modified: llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll Mon Apr 15 01:57:53 2019
@@ -2,6 +2,9 @@
 ; RUN: opt < %s -simplifycfg -forward-switch-cond=false -S | FileCheck %s --check-prefix=NO_FWD
 ; RUN: opt < %s -simplifycfg -forward-switch-cond=true  -S | FileCheck %s --check-prefix=FWD
 
+; RUN: opt < %s -passes='simplify-cfg<no-forward-switch-cond>' -S | FileCheck %s --check-prefix=NO_FWD
+; RUN: opt < %s -passes='simplify-cfg<forward-switch-cond>' -S | FileCheck %s --check-prefix=FWD
+
 ; PR10131
 
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"

Modified: llvm/trunk/test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll Mon Apr 15 01:57:53 2019
@@ -1,4 +1,5 @@
 ; RUN: opt < %s -simplifycfg -switch-to-lookup -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+; RUN: opt < %s -passes='simplify-cfg<switch-to-lookup>' -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
 
 ; In the presence of "-no-jump-tables"="true", simplifycfg should not convert switches to lookup tables.
 

Modified: llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll Mon Apr 15 01:57:53 2019
@@ -1,4 +1,6 @@
 ; RUN: opt -S -simplifycfg -switch-to-lookup < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s
+; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s
+
 ; rdar://17887153
 target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-apple-darwin12.0.0"

Modified: llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-table-bug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-table-bug.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-table-bug.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/X86/switch-table-bug.ll Mon Apr 15 01:57:53 2019
@@ -1,4 +1,6 @@
 ; RUN: opt -S -simplifycfg -switch-to-lookup < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s
+; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s
+
 ; rdar://17735071
 target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-apple-darwin12.0.0"

Modified: llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll Mon Apr 15 01:57:53 2019
@@ -1,5 +1,5 @@
 ; RUN: opt < %s -simplifycfg -switch-to-lookup=true -keep-loops=false -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
-
+; RUN: opt < %s -passes='simplify-cfg<no-keep-loops;switch-to-lookup>' -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 

Modified: llvm/trunk/test/Transforms/SimplifyCFG/branch-fold-threshold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/branch-fold-threshold.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/branch-fold-threshold.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/branch-fold-threshold.ll Mon Apr 15 01:57:53 2019
@@ -1,6 +1,9 @@
 ; RUN: opt %s -simplifycfg -S | FileCheck %s --check-prefix=NORMAL
 ; RUN: opt %s -simplifycfg -S -bonus-inst-threshold=2 | FileCheck %s --check-prefix=AGGRESSIVE
 ; RUN: opt %s -simplifycfg -S -bonus-inst-threshold=4 | FileCheck %s --check-prefix=WAYAGGRESSIVE
+; RUN: opt %s -passes=simplify-cfg -S | FileCheck %s --check-prefix=NORMAL
+; RUN: opt %s -passes='simplify-cfg<bonus-inst-threshold=2>' -S | FileCheck %s --check-prefix=AGGRESSIVE
+; RUN: opt %s -passes='simplify-cfg<bonus-inst-threshold=4>' -S | FileCheck %s --check-prefix=WAYAGGRESSIVE
 
 define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d, i32* %input) {
 ; NORMAL-LABEL: @foo(

Modified: llvm/trunk/test/Transforms/SimplifyCFG/multiple-phis.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/multiple-phis.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/multiple-phis.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/multiple-phis.ll Mon Apr 15 01:57:53 2019
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -simplifycfg -keep-loops=false -S < %s | FileCheck %s
+; RUN: opt -passes='simplify-cfg<no-keep-loops>' -S < %s | FileCheck %s
 
 ; It's not worthwhile to if-convert one of the phi nodes and leave
 ; the other behind, because that still requires a branch. If

Modified: llvm/trunk/test/Transforms/SimplifyCFG/no-md-sink.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/no-md-sink.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/no-md-sink.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/no-md-sink.ll Mon Apr 15 01:57:53 2019
@@ -1,4 +1,5 @@
 ; RUN: opt < %s -simplifycfg -sink-common-insts -S | FileCheck %s
+; RUN: opt < %s -passes='simplify-cfg<sink-common-insts>' -S | FileCheck %s
 
 define i1 @test1(i1 zeroext %flag, i8* %y) #0 {
 entry:

Modified: llvm/trunk/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/preserve-llvm-loop-metadata.ll Mon Apr 15 01:57:53 2019
@@ -1,4 +1,5 @@
 ; RUN: opt -simplifycfg -keep-loops=false -S < %s | FileCheck %s
+; RUN: opt -passes='simplify-cfg<no-keep-loops>' -S < %s | FileCheck %s
 
 define void @test1(i32 %n) #0 {
 entry:

Modified: llvm/trunk/test/Transforms/SimplifyCFG/rangereduce.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/rangereduce.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/rangereduce.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/rangereduce.ll Mon Apr 15 01:57:53 2019
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -simplifycfg -switch-to-lookup -S | FileCheck %s
+; RUN: opt < %s -passes='simplify-cfg<switch-to-lookup>' -S | FileCheck %s
 
 target datalayout = "e-n32"
 

Modified: llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll Mon Apr 15 01:57:53 2019
@@ -1,4 +1,5 @@
 ; RUN: opt < %s -simplifycfg -sink-common-insts -S | FileCheck -enable-var-scope %s
+; RUN: opt < %s -passes='simplify-cfg<sink-common-insts>' -S | FileCheck -enable-var-scope %s
 
 define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
 entry:

Modified: llvm/trunk/test/Transforms/SimplifyCFG/switch_undef.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/switch_undef.ll?rev=358379&r1=358378&r2=358379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/switch_undef.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/switch_undef.ll Mon Apr 15 01:57:53 2019
@@ -1,4 +1,5 @@
 ; RUN: opt %s -keep-loops=false -switch-to-lookup=true -simplifycfg -S | FileCheck %s
+; RUN: opt %s -passes='simplify-cfg<no-keep-loops;switch-to-lookup>' -S | FileCheck %s
 
 define void @f6() #0 {
 ; CHECK-LABEL: entry:




More information about the llvm-commits mailing list