Skip to content

Commit 1067d3e

Browse files
committed
Revert "[NFCI] createCFGSimplificationPass(): migrate to also take SimplifyCFGOptions"
This reverts commit b201819. This commit introduced a Dependency Cycle between Transforms/Scalar and Transforms/Utils. Transforms/Scalar already depends on Transforms/Utils, so if SimplifyCFGOptions.h is moved to Scalar, and Utils/Local.h still depends on it, we have a cycle.
1 parent 5831e86 commit 1067d3e

File tree

10 files changed

+85
-110
lines changed

10 files changed

+85
-110
lines changed

llvm/include/llvm/Transforms/Scalar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_TRANSFORMS_SCALAR_H
1515
#define LLVM_TRANSFORMS_SCALAR_H
1616

17-
#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h"
1817
#include <functional>
1918

2019
namespace llvm {
@@ -257,7 +256,8 @@ FunctionPass *createJumpThreadingPass(int Threshold = -1);
257256
// simplify terminator instructions, convert switches to lookup tables, etc.
258257
//
259258
FunctionPass *createCFGSimplificationPass(
260-
SimplifyCFGOptions Options = SimplifyCFGOptions(),
259+
unsigned Threshold = 1, bool ForwardSwitchCond = false,
260+
bool ConvertSwitch = false, bool KeepLoops = true, bool SinkCommon = false,
261261
std::function<bool(const Function &)> Ftor = nullptr);
262262

263263
//===----------------------------------------------------------------------===//

llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#ifndef LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFG_H
1515
#define LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFG_H
1616

17+
#include "llvm/Transforms/Utils/Local.h"
1718
#include "llvm/IR/Function.h"
1819
#include "llvm/IR/PassManager.h"
19-
#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h"
2020

2121
namespace llvm {
2222

llvm/include/llvm/Transforms/Scalar/SimplifyCFGOptions.h

Lines changed: 0 additions & 86 deletions
This file was deleted.

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "llvm/IR/Value.h"
3131
#include "llvm/IR/ValueHandle.h"
3232
#include "llvm/Support/Casting.h"
33-
#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h"
3433
#include <cstdint>
3534
#include <limits>
3635

@@ -59,6 +58,73 @@ class StoreInst;
5958
class TargetLibraryInfo;
6059
class TargetTransformInfo;
6160

61+
/// A set of parameters used to control the transforms in the SimplifyCFG pass.
62+
/// Options may change depending on the position in the optimization pipeline.
63+
/// For example, canonical form that includes switches and branches may later be
64+
/// replaced by lookup tables and selects.
65+
struct SimplifyCFGOptions {
66+
int BonusInstThreshold;
67+
bool ForwardSwitchCondToPhi;
68+
bool ConvertSwitchToLookupTable;
69+
bool NeedCanonicalLoop;
70+
bool SinkCommonInsts;
71+
bool SimplifyCondBranch;
72+
bool FoldTwoEntryPHINode;
73+
74+
AssumptionCache *AC;
75+
76+
SimplifyCFGOptions(unsigned BonusThreshold = 1,
77+
bool ForwardSwitchCond = false,
78+
bool SwitchToLookup = false, bool CanonicalLoops = true,
79+
bool SinkCommon = false,
80+
AssumptionCache *AssumpCache = nullptr,
81+
bool SimplifyCondBranch = true,
82+
bool FoldTwoEntryPHINode = true)
83+
: BonusInstThreshold(BonusThreshold),
84+
ForwardSwitchCondToPhi(ForwardSwitchCond),
85+
ConvertSwitchToLookupTable(SwitchToLookup),
86+
NeedCanonicalLoop(CanonicalLoops),
87+
SinkCommonInsts(SinkCommon),
88+
SimplifyCondBranch(SimplifyCondBranch),
89+
FoldTwoEntryPHINode(FoldTwoEntryPHINode),
90+
AC(AssumpCache) {}
91+
92+
// Support 'builder' pattern to set members by name at construction time.
93+
SimplifyCFGOptions &bonusInstThreshold(int I) {
94+
BonusInstThreshold = I;
95+
return *this;
96+
}
97+
SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) {
98+
ForwardSwitchCondToPhi = B;
99+
return *this;
100+
}
101+
SimplifyCFGOptions &convertSwitchToLookupTable(bool B) {
102+
ConvertSwitchToLookupTable = B;
103+
return *this;
104+
}
105+
SimplifyCFGOptions &needCanonicalLoops(bool B) {
106+
NeedCanonicalLoop = B;
107+
return *this;
108+
}
109+
SimplifyCFGOptions &sinkCommonInsts(bool B) {
110+
SinkCommonInsts = B;
111+
return *this;
112+
}
113+
SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) {
114+
AC = Cache;
115+
return *this;
116+
}
117+
SimplifyCFGOptions &setSimplifyCondBranch(bool B) {
118+
SimplifyCondBranch = B;
119+
return *this;
120+
}
121+
122+
SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) {
123+
FoldTwoEntryPHINode = B;
124+
return *this;
125+
}
126+
};
127+
62128
//===----------------------------------------------------------------------===//
63129
// Local constant propagation.
64130
//

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,7 @@ void AArch64PassConfig::addIRPasses() {
453453
// determine whether it succeeded. We can exploit existing control-flow in
454454
// ldrex/strex loops to simplify this, but it needs tidying up.
455455
if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy)
456-
addPass(createCFGSimplificationPass(SimplifyCFGOptions()
457-
.forwardSwitchCondToPhi(true)
458-
.convertSwitchToLookupTable(true)
459-
.needCanonicalLoops(false)
460-
.sinkCommonInsts(true)));
456+
addPass(createCFGSimplificationPass(1, true, true, false, true));
461457

462458
// Run LoopDataPrefetch
463459
//

llvm/lib/Target/ARM/ARMTargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void ARMPassConfig::addIRPasses() {
409409
// ldrex/strex loops to simplify this, but it needs tidying up.
410410
if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy)
411411
addPass(createCFGSimplificationPass(
412-
SimplifyCFGOptions().sinkCommonInsts(true), [this](const Function &F) {
412+
1, false, false, true, true, [this](const Function &F) {
413413
const auto &ST = this->TM->getSubtarget<ARMSubtarget>(F);
414414
return ST.hasAnyDataBarrier() && !ST.isThumb1Only();
415415
}));

llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,7 @@ void HexagonPassConfig::addIRPasses() {
320320

321321
if (!NoOpt) {
322322
if (EnableInitialCFGCleanup)
323-
addPass(createCFGSimplificationPass(SimplifyCFGOptions()
324-
.forwardSwitchCondToPhi(true)
325-
.convertSwitchToLookupTable(true)
326-
.needCanonicalLoops(false)
327-
.sinkCommonInsts(true)));
323+
addPass(createCFGSimplificationPass(1, true, true, false, true));
328324
if (EnableLoopPrefetch)
329325
addPass(createLoopDataPrefetchPass());
330326
if (EnableCommGEP)

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,7 @@ void PassManagerBuilder::populateModulePassManager(
777777
// convert to more optimized IR using more aggressive simplify CFG options.
778778
// The extra sinking transform can create larger basic blocks, so do this
779779
// before SLP vectorization.
780-
MPM.add(createCFGSimplificationPass(SimplifyCFGOptions()
781-
.forwardSwitchCondToPhi(true)
782-
.convertSwitchToLookupTable(true)
783-
.needCanonicalLoops(false)
784-
.sinkCommonInsts(true)));
780+
MPM.add(createCFGSimplificationPass(1, true, true, false, true));
785781

786782
if (SLPVectorize) {
787783
MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.

llvm/lib/Transforms/Scalar/Scalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) {
139139
}
140140

141141
void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
142-
unwrap(PM)->add(createCFGSimplificationPass());
142+
unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
143143
}
144144

145145
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {

llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "llvm/Support/CommandLine.h"
4040
#include "llvm/Transforms/Scalar.h"
4141
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
42-
#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h"
4342
#include "llvm/Transforms/Utils/Local.h"
4443
#include <utility>
4544
using namespace llvm;
@@ -305,7 +304,15 @@ INITIALIZE_PASS_END(CFGSimplifyPass, "simplifycfg", "Simplify the CFG", false,
305304

306305
// Public interface to the CFGSimplification pass
307306
FunctionPass *
308-
llvm::createCFGSimplificationPass(SimplifyCFGOptions Options,
307+
llvm::createCFGSimplificationPass(unsigned Threshold, bool ForwardSwitchCond,
308+
bool ConvertSwitch, bool KeepLoops,
309+
bool SinkCommon,
309310
std::function<bool(const Function &)> Ftor) {
310-
return new CFGSimplifyPass(Options, std::move(Ftor));
311+
return new CFGSimplifyPass(SimplifyCFGOptions()
312+
.bonusInstThreshold(Threshold)
313+
.forwardSwitchCondToPhi(ForwardSwitchCond)
314+
.convertSwitchToLookupTable(ConvertSwitch)
315+
.needCanonicalLoops(KeepLoops)
316+
.sinkCommonInsts(SinkCommon),
317+
std::move(Ftor));
311318
}

0 commit comments

Comments
 (0)