llvm.org GIT mirror llvm / d6b200d
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358379 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 6 months ago
16 changed file(s) with 64 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
14211421 return Result;
14221422 }
14231423
1424 /// Parser of parameters for SimplifyCFG pass.
1425 Expected parseSimplifyCFGOptions(StringRef Params) {
1426 SimplifyCFGOptions Result;
1427 while (!Params.empty()) {
1428 StringRef ParamName;
1429 std::tie(ParamName, Params) = Params.split(';');
1430
1431 bool Enable = !ParamName.consume_front("no-");
1432 if (ParamName == "forward-switch-cond") {
1433 Result.forwardSwitchCondToPhi(Enable);
1434 } else if (ParamName == "switch-to-lookup") {
1435 Result.convertSwitchToLookupTable(Enable);
1436 } else if (ParamName == "keep-loops") {
1437 Result.needCanonicalLoops(Enable);
1438 } else if (ParamName == "sink-common-insts") {
1439 Result.sinkCommonInsts(Enable);
1440 } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
1441 APInt BonusInstThreshold;
1442 if (ParamName.getAsInteger(0, BonusInstThreshold))
1443 return make_error(
1444 formatv("invalid argument to SimplifyCFG pass bonus-threshold "
1445 "parameter: '{0}' ",
1446 ParamName).str(),
1447 inconvertibleErrorCode());
1448 Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
1449 } else {
1450 return make_error(
1451 formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
1452 inconvertibleErrorCode());
1453 }
1454 }
1455 return Result;
1456 }
1457
14241458 } // namespace
14251459
14261460 /// Tests whether a pass name starts with a valid prefix for a default pipeline
217217 FUNCTION_PASS("reassociate", ReassociatePass())
218218 FUNCTION_PASS("scalarizer", ScalarizerPass())
219219 FUNCTION_PASS("sccp", SCCPPass())
220 FUNCTION_PASS("simplify-cfg", SimplifyCFGPass())
221220 FUNCTION_PASS("sink", SinkingPass())
222221 FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
223222 FUNCTION_PASS("speculative-execution", SpeculativeExecutionPass())
252251 return MemorySanitizerPass(Opts);
253252 },
254253 parseMSanPassOptions)
254 FUNCTION_PASS_WITH_PARAMS("simplify-cfg",
255 [](SimplifyCFGOptions Opts) {
256 return SimplifyCFGPass(Opts);
257 },
258 parseSimplifyCFGOptions)
255259 #undef FUNCTION_PASS_WITH_PARAMS
256260
257261 #ifndef LOOP_ANALYSIS
22 ; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=ropi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
33 ; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
44 ; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=ropi-rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
5
6 ; RUN: opt -S -passes='simplify-cfg' -mtriple=arm -relocation-model=static < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
7 ; RUN: opt -S -passes='simplify-cfg' -mtriple=arm -relocation-model=pic < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
8 ; RUN: opt -S -passes='simplify-cfg' -mtriple=arm -relocation-model=ropi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
9 ; RUN: opt -S -passes='simplify-cfg' -mtriple=arm -relocation-model=rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
10 ; RUN: opt -S -passes='simplify-cfg' -mtriple=arm -relocation-model=ropi-rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
511
612 ; CHECK: @{{.*}} = private unnamed_addr constant [3 x i32] [i32 1234, i32 5678, i32 15532]
713 ; ENABLE: @{{.*}} = private unnamed_addr constant [3 x i32*] [i32* @c1, i32* @c2, i32* @c3]
0 ; RUN: opt -simplifycfg -switch-to-lookup -S %s | FileCheck %s
1 ; RUN: opt -passes='simplify-cfg' -S %s | FileCheck %s
12 ; rdar://15268442
23
34 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"
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
11 ; RUN: opt < %s -simplifycfg -forward-switch-cond=false -S | FileCheck %s --check-prefix=NO_FWD
22 ; RUN: opt < %s -simplifycfg -forward-switch-cond=true -S | FileCheck %s --check-prefix=FWD
3
4 ; RUN: opt < %s -passes='simplify-cfg' -S | FileCheck %s --check-prefix=NO_FWD
5 ; RUN: opt < %s -passes='simplify-cfg' -S | FileCheck %s --check-prefix=FWD
36
47 ; PR10131
58
0 ; RUN: opt < %s -simplifycfg -switch-to-lookup -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
1 ; RUN: opt < %s -passes='simplify-cfg' -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
12
23 ; In the presence of "-no-jump-tables"="true", simplifycfg should not convert switches to lookup tables.
34
0 ; RUN: opt -S -simplifycfg -switch-to-lookup < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s
1 ; RUN: opt -S -passes='simplify-cfg' < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s
2
13 ; rdar://17887153
24 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"
35 target triple = "x86_64-apple-darwin12.0.0"
0 ; RUN: opt -S -simplifycfg -switch-to-lookup < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s
1 ; RUN: opt -S -passes='simplify-cfg' < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s
2
13 ; rdar://17735071
24 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"
35 target triple = "x86_64-apple-darwin12.0.0"
0 ; RUN: opt < %s -simplifycfg -switch-to-lookup=true -keep-loops=false -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
1
1 ; RUN: opt < %s -passes='simplify-cfg' -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
22 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"
33 target triple = "x86_64-unknown-linux-gnu"
44
0 ; RUN: opt %s -simplifycfg -S | FileCheck %s --check-prefix=NORMAL
11 ; RUN: opt %s -simplifycfg -S -bonus-inst-threshold=2 | FileCheck %s --check-prefix=AGGRESSIVE
22 ; RUN: opt %s -simplifycfg -S -bonus-inst-threshold=4 | FileCheck %s --check-prefix=WAYAGGRESSIVE
3 ; RUN: opt %s -passes=simplify-cfg -S | FileCheck %s --check-prefix=NORMAL
4 ; RUN: opt %s -passes='simplify-cfg' -S | FileCheck %s --check-prefix=AGGRESSIVE
5 ; RUN: opt %s -passes='simplify-cfg' -S | FileCheck %s --check-prefix=WAYAGGRESSIVE
36
47 define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d, i32* %input) {
58 ; NORMAL-LABEL: @foo(
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
11 ; RUN: opt -simplifycfg -keep-loops=false -S < %s | FileCheck %s
2 ; RUN: opt -passes='simplify-cfg' -S < %s | FileCheck %s
23
34 ; It's not worthwhile to if-convert one of the phi nodes and leave
45 ; the other behind, because that still requires a branch. If
0 ; RUN: opt < %s -simplifycfg -sink-common-insts -S | FileCheck %s
1 ; RUN: opt < %s -passes='simplify-cfg' -S | FileCheck %s
12
23 define i1 @test1(i1 zeroext %flag, i8* %y) #0 {
34 entry:
0 ; RUN: opt -simplifycfg -keep-loops=false -S < %s | FileCheck %s
1 ; RUN: opt -passes='simplify-cfg' -S < %s | FileCheck %s
12
23 define void @test1(i32 %n) #0 {
34 entry:
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
11 ; RUN: opt < %s -simplifycfg -switch-to-lookup -S | FileCheck %s
2 ; RUN: opt < %s -passes='simplify-cfg' -S | FileCheck %s
23
34 target datalayout = "e-n32"
45
0 ; RUN: opt < %s -simplifycfg -sink-common-insts -S | FileCheck -enable-var-scope %s
1 ; RUN: opt < %s -passes='simplify-cfg' -S | FileCheck -enable-var-scope %s
12
23 define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
34 entry:
0 ; RUN: opt %s -keep-loops=false -switch-to-lookup=true -simplifycfg -S | FileCheck %s
1 ; RUN: opt %s -passes='simplify-cfg' -S | FileCheck %s
12
23 define void @f6() #0 {
34 ; CHECK-LABEL: entry: