From: Adrian Kuegel Date: Thu, 16 Jul 2020 08:54:10 +0000 (+0200) Subject: Revert "[NFCI] createCFGSimplificationPass(): migrate to also take SimplifyCFGOptions" X-Git-Tag: llvmorg-13-init~17778 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1067d3e176ea7b0b1942c163bf8c6c90107768c1;p=platform%2Fupstream%2Fllvm.git Revert "[NFCI] createCFGSimplificationPass(): migrate to also take SimplifyCFGOptions" This reverts commit b2018198c32a0535bb1f5bb5b40fbcf50d8d47b7. 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. --- diff --git a/llvm/include/llvm/Transforms/Scalar.h b/llvm/include/llvm/Transforms/Scalar.h index 19d158a..a1aacec 100644 --- a/llvm/include/llvm/Transforms/Scalar.h +++ b/llvm/include/llvm/Transforms/Scalar.h @@ -14,7 +14,6 @@ #ifndef LLVM_TRANSFORMS_SCALAR_H #define LLVM_TRANSFORMS_SCALAR_H -#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h" #include namespace llvm { @@ -257,7 +256,8 @@ FunctionPass *createJumpThreadingPass(int Threshold = -1); // simplify terminator instructions, convert switches to lookup tables, etc. // FunctionPass *createCFGSimplificationPass( - SimplifyCFGOptions Options = SimplifyCFGOptions(), + unsigned Threshold = 1, bool ForwardSwitchCond = false, + bool ConvertSwitch = false, bool KeepLoops = true, bool SinkCommon = false, std::function Ftor = nullptr); //===----------------------------------------------------------------------===// diff --git a/llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h b/llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h index 026c183..f9792d3 100644 --- a/llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h +++ b/llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h @@ -14,9 +14,9 @@ #ifndef LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFG_H #define LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFG_H +#include "llvm/Transforms/Utils/Local.h" #include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" -#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h" namespace llvm { diff --git a/llvm/include/llvm/Transforms/Scalar/SimplifyCFGOptions.h b/llvm/include/llvm/Transforms/Scalar/SimplifyCFGOptions.h deleted file mode 100644 index 42df3af..0000000 --- a/llvm/include/llvm/Transforms/Scalar/SimplifyCFGOptions.h +++ /dev/null @@ -1,86 +0,0 @@ -//===- SimplifyCFGOptions.h - Control structure for SimplifyCFG -*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// A set of parameters used to control the transforms in the SimplifyCFG pass. -// Options may change depending on the position in the optimization pipeline. -// For example, canonical form that includes switches and branches may later be -// replaced by lookup tables and selects. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFGOPTIONS_H -#define LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFGOPTIONS_H - -namespace llvm { - -class AssumptionCache; - -struct SimplifyCFGOptions { - int BonusInstThreshold; - bool ForwardSwitchCondToPhi; - bool ConvertSwitchToLookupTable; - bool NeedCanonicalLoop; - bool SinkCommonInsts; - bool SimplifyCondBranch; - bool FoldTwoEntryPHINode; - - AssumptionCache *AC; - - SimplifyCFGOptions(unsigned BonusThreshold = 1, - bool ForwardSwitchCond = false, - bool SwitchToLookup = false, bool CanonicalLoops = true, - bool SinkCommon = false, - AssumptionCache *AssumpCache = nullptr, - bool SimplifyCondBranch = true, - bool FoldTwoEntryPHINode = true) - : BonusInstThreshold(BonusThreshold), - ForwardSwitchCondToPhi(ForwardSwitchCond), - ConvertSwitchToLookupTable(SwitchToLookup), - NeedCanonicalLoop(CanonicalLoops), SinkCommonInsts(SinkCommon), - SimplifyCondBranch(SimplifyCondBranch), - FoldTwoEntryPHINode(FoldTwoEntryPHINode), AC(AssumpCache) {} - - // Support 'builder' pattern to set members by name at construction time. - SimplifyCFGOptions &bonusInstThreshold(int I) { - BonusInstThreshold = I; - return *this; - } - SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) { - ForwardSwitchCondToPhi = B; - return *this; - } - SimplifyCFGOptions &convertSwitchToLookupTable(bool B) { - ConvertSwitchToLookupTable = B; - return *this; - } - SimplifyCFGOptions &needCanonicalLoops(bool B) { - NeedCanonicalLoop = B; - return *this; - } - SimplifyCFGOptions &sinkCommonInsts(bool B) { - SinkCommonInsts = B; - return *this; - } - SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) { - AC = Cache; - return *this; - } - SimplifyCFGOptions &setSimplifyCondBranch(bool B) { - SimplifyCondBranch = B; - return *this; - } - - SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) { - FoldTwoEntryPHINode = B; - return *this; - } -}; - -} // namespace llvm - -#endif // LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFGOPTIONS_H diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index 3595dd6..3fab3bc 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -30,7 +30,6 @@ #include "llvm/IR/Value.h" #include "llvm/IR/ValueHandle.h" #include "llvm/Support/Casting.h" -#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h" #include #include @@ -59,6 +58,73 @@ class StoreInst; class TargetLibraryInfo; class TargetTransformInfo; +/// A set of parameters used to control the transforms in the SimplifyCFG pass. +/// Options may change depending on the position in the optimization pipeline. +/// For example, canonical form that includes switches and branches may later be +/// replaced by lookup tables and selects. +struct SimplifyCFGOptions { + int BonusInstThreshold; + bool ForwardSwitchCondToPhi; + bool ConvertSwitchToLookupTable; + bool NeedCanonicalLoop; + bool SinkCommonInsts; + bool SimplifyCondBranch; + bool FoldTwoEntryPHINode; + + AssumptionCache *AC; + + SimplifyCFGOptions(unsigned BonusThreshold = 1, + bool ForwardSwitchCond = false, + bool SwitchToLookup = false, bool CanonicalLoops = true, + bool SinkCommon = false, + AssumptionCache *AssumpCache = nullptr, + bool SimplifyCondBranch = true, + bool FoldTwoEntryPHINode = true) + : BonusInstThreshold(BonusThreshold), + ForwardSwitchCondToPhi(ForwardSwitchCond), + ConvertSwitchToLookupTable(SwitchToLookup), + NeedCanonicalLoop(CanonicalLoops), + SinkCommonInsts(SinkCommon), + SimplifyCondBranch(SimplifyCondBranch), + FoldTwoEntryPHINode(FoldTwoEntryPHINode), + AC(AssumpCache) {} + + // Support 'builder' pattern to set members by name at construction time. + SimplifyCFGOptions &bonusInstThreshold(int I) { + BonusInstThreshold = I; + return *this; + } + SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) { + ForwardSwitchCondToPhi = B; + return *this; + } + SimplifyCFGOptions &convertSwitchToLookupTable(bool B) { + ConvertSwitchToLookupTable = B; + return *this; + } + SimplifyCFGOptions &needCanonicalLoops(bool B) { + NeedCanonicalLoop = B; + return *this; + } + SimplifyCFGOptions &sinkCommonInsts(bool B) { + SinkCommonInsts = B; + return *this; + } + SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) { + AC = Cache; + return *this; + } + SimplifyCFGOptions &setSimplifyCondBranch(bool B) { + SimplifyCondBranch = B; + return *this; + } + + SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) { + FoldTwoEntryPHINode = B; + return *this; + } +}; + //===----------------------------------------------------------------------===// // Local constant propagation. // diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp index b0cef9b..a63b9a9 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp @@ -453,11 +453,7 @@ void AArch64PassConfig::addIRPasses() { // determine whether it succeeded. We can exploit existing control-flow in // ldrex/strex loops to simplify this, but it needs tidying up. if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy) - addPass(createCFGSimplificationPass(SimplifyCFGOptions() - .forwardSwitchCondToPhi(true) - .convertSwitchToLookupTable(true) - .needCanonicalLoops(false) - .sinkCommonInsts(true))); + addPass(createCFGSimplificationPass(1, true, true, false, true)); // Run LoopDataPrefetch // diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp index b316b10..9ead5fa 100644 --- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp +++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp @@ -409,7 +409,7 @@ void ARMPassConfig::addIRPasses() { // ldrex/strex loops to simplify this, but it needs tidying up. if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy) addPass(createCFGSimplificationPass( - SimplifyCFGOptions().sinkCommonInsts(true), [this](const Function &F) { + 1, false, false, true, true, [this](const Function &F) { const auto &ST = this->TM->getSubtarget(F); return ST.hasAnyDataBarrier() && !ST.isThumb1Only(); })); diff --git a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp index 49d9862..3fe42ea 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp @@ -320,11 +320,7 @@ void HexagonPassConfig::addIRPasses() { if (!NoOpt) { if (EnableInitialCFGCleanup) - addPass(createCFGSimplificationPass(SimplifyCFGOptions() - .forwardSwitchCondToPhi(true) - .convertSwitchToLookupTable(true) - .needCanonicalLoops(false) - .sinkCommonInsts(true))); + addPass(createCFGSimplificationPass(1, true, true, false, true)); if (EnableLoopPrefetch) addPass(createLoopDataPrefetchPass()); if (EnableCommGEP) diff --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp index 460297a..d73d42c 100644 --- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -777,11 +777,7 @@ void PassManagerBuilder::populateModulePassManager( // convert to more optimized IR using more aggressive simplify CFG options. // The extra sinking transform can create larger basic blocks, so do this // before SLP vectorization. - MPM.add(createCFGSimplificationPass(SimplifyCFGOptions() - .forwardSwitchCondToPhi(true) - .convertSwitchToLookupTable(true) - .needCanonicalLoops(false) - .sinkCommonInsts(true))); + MPM.add(createCFGSimplificationPass(1, true, true, false, true)); if (SLPVectorize) { MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains. diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp index 42f79d8..9d08854 100644 --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -139,7 +139,7 @@ void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) { } void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) { - unwrap(PM)->add(createCFGSimplificationPass()); + unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true)); } void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) { diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp index f4ed24c..4187d5b 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -39,7 +39,6 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/SimplifyCFG.h" -#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h" #include "llvm/Transforms/Utils/Local.h" #include using namespace llvm; @@ -305,7 +304,15 @@ INITIALIZE_PASS_END(CFGSimplifyPass, "simplifycfg", "Simplify the CFG", false, // Public interface to the CFGSimplification pass FunctionPass * -llvm::createCFGSimplificationPass(SimplifyCFGOptions Options, +llvm::createCFGSimplificationPass(unsigned Threshold, bool ForwardSwitchCond, + bool ConvertSwitch, bool KeepLoops, + bool SinkCommon, std::function Ftor) { - return new CFGSimplifyPass(Options, std::move(Ftor)); + return new CFGSimplifyPass(SimplifyCFGOptions() + .bonusInstThreshold(Threshold) + .forwardSwitchCondToPhi(ForwardSwitchCond) + .convertSwitchToLookupTable(ConvertSwitch) + .needCanonicalLoops(KeepLoops) + .sinkCommonInsts(SinkCommon), + std::move(Ftor)); }