Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 72428f5

Browse files
committed
[SimplifyCFG] use pass options and remove the latesimplifycfg pass
This is no-functional-change-intended. This is repackaging the functionality of D30333 (defer switch-to-lookup-tables) and D35411 (defer folding unconditional branches) with pass parameters rather than a named "latesimplifycfg" pass. Now that we have individual options to control the functionality, we could decouple when these fire (but that's an independent patch if desired). The next planned step would be to add another option bit to disable the sinking transform mentioned in D38566. This should also make it clear that the new pass manager needs to be updated to limit simplifycfg in the same way as the old pass manager. Differential Revision: https://reviews.llvm.org/D38631 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316835 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 2146c5a commit 72428f5

25 files changed

+187
-137
lines changed

include/llvm-c/Transforms/Scalar.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM);
4444
/** See llvm::createCFGSimplificationPass function. */
4545
void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM);
4646

47-
/** See llvm::createLateCFGSimplificationPass function. */
48-
void LLVMAddLateCFGSimplificationPass(LLVMPassManagerRef PM);
49-
5047
/** See llvm::createDeadStoreEliminationPass function. */
5148
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM);
5249

include/llvm/InitializePasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ void initializeIntervalPartitionPass(PassRegistry&);
174174
void initializeJumpThreadingPass(PassRegistry&);
175175
void initializeLCSSAVerificationPassPass(PassRegistry&);
176176
void initializeLCSSAWrapperPassPass(PassRegistry&);
177-
void initializeLateCFGSimplifyPassPass(PassRegistry&);
178177
void initializeLazyBlockFrequencyInfoPassPass(PassRegistry&);
179178
void initializeLazyBranchProbabilityInfoPassPass(PassRegistry&);
180179
void initializeLazyMachineBlockFrequencyInfoPassPass(PassRegistry&);

include/llvm/LinkAllPasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ namespace {
7575
(void) llvm::createCallGraphDOTPrinterPass();
7676
(void) llvm::createCallGraphViewerPass();
7777
(void) llvm::createCFGSimplificationPass();
78-
(void) llvm::createLateCFGSimplificationPass();
7978
(void) llvm::createCFLAndersAAWrapperPass();
8079
(void) llvm::createCFLSteensAAWrapperPass();
8180
(void) llvm::createStructurizeCFGPass();

include/llvm/Transforms/Scalar.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,12 @@ FunctionPass *createJumpThreadingPass(int Threshold = -1);
255255
//===----------------------------------------------------------------------===//
256256
//
257257
// CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
258-
// simplify terminator instructions, etc...
258+
// simplify terminator instructions, convert switches to lookup tables, etc.
259259
//
260260
FunctionPass *createCFGSimplificationPass(
261-
int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
262-
263-
//===----------------------------------------------------------------------===//
264-
//
265-
// LateCFGSimplification - Like CFGSimplification, but may also
266-
// convert switches to lookup tables.
267-
//
268-
FunctionPass *createLateCFGSimplificationPass(
269-
int Threshold = -1, std::function<bool(const Function &)> Ftor = nullptr);
261+
unsigned Threshold = 1, bool ForwardSwitchCond = false,
262+
bool ConvertSwitch = false, bool KeepLoops = true,
263+
std::function<bool(const Function &)> Ftor = nullptr);
270264

271265
//===----------------------------------------------------------------------===//
272266
//

include/llvm/Transforms/Scalar/SimplifyCFG.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ class SimplifyCFGPass : public PassInfoMixin<SimplifyCFGPass> {
3131
SimplifyCFGOptions Options;
3232

3333
public:
34-
/// Construct a pass with default options.
35-
SimplifyCFGPass();
34+
/// The default constructor sets the pass options to create optimal IR,
35+
/// rather than canonical IR. That is, by default we do transformations that
36+
/// are likely to improve performance but make analysis more difficult.
37+
/// FIXME: This is inverted from what most instantiations of the pass should
38+
/// be.
39+
SimplifyCFGPass()
40+
: SimplifyCFGPass(SimplifyCFGOptions()
41+
.forwardSwitchCondToPhi(true)
42+
.convertSwitchToLookupTable(true)
43+
.needCanonicalLoops(false)) {}
3644

3745
/// Construct a pass with optional optimizations.
3846
SimplifyCFGPass(const SimplifyCFGOptions &PassOptions);

include/llvm/Transforms/Utils/Local.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,36 @@ struct SimplifyCFGOptions {
6565
bool NeedCanonicalLoop;
6666
AssumptionCache *AC;
6767

68-
SimplifyCFGOptions(int BonusThreshold = 1, bool ForwardSwitchCond = false,
68+
SimplifyCFGOptions(unsigned BonusThreshold = 1,
69+
bool ForwardSwitchCond = false,
6970
bool SwitchToLookup = false, bool CanonicalLoops = true,
7071
AssumptionCache *AssumpCache = nullptr)
7172
: BonusInstThreshold(BonusThreshold),
7273
ForwardSwitchCondToPhi(ForwardSwitchCond),
7374
ConvertSwitchToLookupTable(SwitchToLookup),
7475
NeedCanonicalLoop(CanonicalLoops), AC(AssumpCache) {}
76+
77+
// Support 'builder' pattern to set members by name at construction time.
78+
SimplifyCFGOptions &bonusInstThreshold(int I) {
79+
BonusInstThreshold = I;
80+
return *this;
81+
}
82+
SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) {
83+
ForwardSwitchCondToPhi = B;
84+
return *this;
85+
}
86+
SimplifyCFGOptions &convertSwitchToLookupTable(bool B) {
87+
ConvertSwitchToLookupTable = B;
88+
return *this;
89+
}
90+
SimplifyCFGOptions &needCanonicalLoops(bool B) {
91+
NeedCanonicalLoop = B;
92+
return *this;
93+
}
94+
SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) {
95+
AC = Cache;
96+
return *this;
97+
}
7598
};
7699

77100
//===----------------------------------------------------------------------===//

lib/LTO/LTOCodeGenerator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ void LTOCodeGenerator::initializeLTOPasses() {
131131
initializeMemCpyOptLegacyPassPass(R);
132132
initializeDCELegacyPassPass(R);
133133
initializeCFGSimplifyPassPass(R);
134-
initializeLateCFGSimplifyPassPass(R);
135134
}
136135

137136
void LTOCodeGenerator::setAsmUndefinedRefs(LTOModule *Mod) {

lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void AArch64PassConfig::addIRPasses() {
365365
// determine whether it succeeded. We can exploit existing control-flow in
366366
// ldrex/strex loops to simplify this, but it needs tidying up.
367367
if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy)
368-
addPass(createLateCFGSimplificationPass());
368+
addPass(createCFGSimplificationPass(1, true, true, false));
369369

370370
// Run LoopDataPrefetch
371371
//

lib/Target/ARM/ARMTargetMachine.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,11 @@ void ARMPassConfig::addIRPasses() {
384384
// determine whether it succeeded. We can exploit existing control-flow in
385385
// ldrex/strex loops to simplify this, but it needs tidying up.
386386
if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy)
387-
addPass(createCFGSimplificationPass(-1, [this](const Function &F) {
388-
const auto &ST = this->TM->getSubtarget<ARMSubtarget>(F);
389-
return ST.hasAnyDataBarrier() && !ST.isThumb1Only();
390-
}));
387+
addPass(createCFGSimplificationPass(
388+
1, false, false, true, [this](const Function &F) {
389+
const auto &ST = this->TM->getSubtarget<ARMSubtarget>(F);
390+
return ST.hasAnyDataBarrier() && !ST.isThumb1Only();
391+
}));
391392

392393
TargetPassConfig::addIRPasses();
393394

lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,9 @@ void PassManagerBuilder::populateModulePassManager(
625625
}
626626

627627
addExtensionsToPM(EP_Peephole, MPM);
628-
MPM.add(createLateCFGSimplificationPass()); // Switches to lookup tables
628+
// Switches to lookup tables and other transforms that may not be considered
629+
// canonical by other IR passes.
630+
MPM.add(createCFGSimplificationPass(1, true, true, false));
629631
addInstructionCombiningPass(MPM);
630632

631633
if (!DisableUnrollLoops) {

0 commit comments

Comments
 (0)