1 //===- ReduceUsingSimplifyCFG.h - Specialized Delta Pass ------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements a function which calls the Generic Delta pass in order
10 // to call SimplifyCFG on individual basic blocks.
12 //===----------------------------------------------------------------------===//
14 #include "ReduceUsingSimplifyCFG.h"
15 #include "llvm/Analysis/TargetTransformInfo.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/Transforms/Utils/Local.h"
22 static void reduceUsingSimplifyCFG(Oracle
&O
, ReducerWorkItem
&WorkItem
) {
23 Module
&Program
= WorkItem
.getModule();
24 SmallVector
<BasicBlock
*, 16> ToSimplify
;
25 for (auto &F
: Program
)
28 ToSimplify
.push_back(&BB
);
29 TargetTransformInfo
TTI(Program
.getDataLayout());
30 for (auto *BB
: ToSimplify
)
34 void llvm::reduceUsingSimplifyCFGDeltaPass(TestRunner
&Test
) {
35 runDeltaPass(Test
, reduceUsingSimplifyCFG
, "Reducing using SimplifyCFG");
37 static void reduceConditionals(Oracle
&O
, ReducerWorkItem
&WorkItem
,
39 Module
&M
= WorkItem
.getModule();
40 SmallVector
<BasicBlock
*, 16> ToSimplify
;
44 auto *BR
= dyn_cast
<BranchInst
>(BB
.getTerminator());
45 if (!BR
|| !BR
->isConditional() || O
.shouldKeep())
49 BR
->setCondition(ConstantInt::getTrue(BR
->getContext()));
51 BR
->setCondition(ConstantInt::getFalse(BR
->getContext()));
53 ToSimplify
.push_back(&BB
);
57 TargetTransformInfo
TTI(M
.getDataLayout());
58 for (auto *BB
: ToSimplify
)
62 void llvm::reduceConditionalsTrueDeltaPass(TestRunner
&Test
) {
65 [](Oracle
&O
, ReducerWorkItem
&WorkItem
) {
66 reduceConditionals(O
, WorkItem
, true);
68 "Reducing conditional branches to true");
71 void llvm::reduceConditionalsFalseDeltaPass(TestRunner
&Test
) {
74 [](Oracle
&O
, ReducerWorkItem
&WorkItem
) {
75 reduceConditionals(O
, WorkItem
, false);
77 "Reducing conditional branches to false");