#ifndef LLVM_TRANSFORMS_SCALAR_H
#define LLVM_TRANSFORMS_SCALAR_H
-#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h"
#include <functional>
namespace llvm {
// 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<bool(const Function &)> Ftor = nullptr);
//===----------------------------------------------------------------------===//
#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 {
+++ /dev/null
-//===- 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
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/Casting.h"
-#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h"
#include <cstdint>
#include <limits>
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.
//
// 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
//
// 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<ARMSubtarget>(F);
return ST.hasAnyDataBarrier() && !ST.isThumb1Only();
}));
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)
// 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.
}
void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
- unwrap(PM)->add(createCFGSimplificationPass());
+ unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
}
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
#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 <utility>
using namespace llvm;
// 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<bool(const 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));
}