46 #define DEBUG_TYPE "simplifycfg"
50 cl::desc(
"Control the number of bonus instructions (default = 1)"));
52 STATISTIC(NumSimpl,
"Number of blocks simplified");
71 if (Ret != &BB.
front()) {
76 while (isa<DbgInfoIntrinsic>(I) && I != BB.
begin())
78 if (!isa<DbgInfoIntrinsic>(I) &&
110 std::distance(PB, PE),
"merge",
133 unsigned BonusInstThreshold) {
134 bool Changed =
false;
135 bool LocalChange =
true;
140 for (
unsigned i = 0, e = Edges.
size();
i != e; ++
i)
141 LoopHeaders.
insert(const_cast<BasicBlock *>(Edges[
i].second));
143 while (LocalChange) {
148 if (
SimplifyCFG(&*BBIt++, TTI, BonusInstThreshold, AC, &LoopHeaders)) {
153 Changed |= LocalChange;
165 if (!EverChanged)
return false;
178 }
while (EverChanged);
187 : BonusInstThreshold(BonusInstThreshold) {}
204 unsigned BonusInstThreshold;
205 std::function<bool(const Function &)> PredicateFtor;
207 CFGSimplifyPass(
int T = -1,
213 bool runOnFunction(
Function &
F)
override {
214 if (skipFunction(F) || (PredicateFtor && !PredicateFtor(F)))
218 &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
220 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
244 return new CFGSimplifyPass(Threshold, std::move(Ftor));
Legacy wrapper pass to provide the GlobalsAAResult object.
This file provides the interface for the pass responsible for both simplifying and canonicalizing the...
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr, SmallPtrSetImpl< BasicBlock * > *LoopHeaders=nullptr)
This function is used to do simplification of a CFG.
STATISTIC(NumFunctions,"Total number of functions")
This is the interface for a simple mod/ref and alias analysis over globals.
unsigned getNumOperands() const
An immutable pass that tracks lazily created AssumptionCache objects.
static cl::opt< unsigned > UserBonusInstThreshold("bonus-inst-threshold", cl::Hidden, cl::init(1), cl::desc("Control the number of bonus instructions (default = 1)"))
static bool simplifyFunctionCFG(Function &F, const TargetTransformInfo &TTI, AssumptionCache *AC, int BonusInstThreshold)
A cache of .assume calls within a function.
Analysis pass providing the TargetTransformInfo.
const Instruction & front() const
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
This file contains the simple types necessary to represent the attributes associated with functions a...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
initializer< Ty > init(const Ty &Val)
A set of analyses that are preserved following a run of a transformation pass.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
FunctionPass * createCFGSimplificationPass(int Threshold=-1, std::function< bool(const Function &)> Ftor=nullptr)
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Represent the analysis usage information of a pass.
Analysis pass providing a never-invalidated alias analysis result.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A function analysis which provides an AssumptionCache.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void FindFunctionBackedges(const Function &F, SmallVectorImpl< std::pair< const BasicBlock *, const BasicBlock * > > &Result)
Analyze the specified function to find all of the loop backedges in the function and return them...
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr)
Remove all blocks that can not be reached from the function's entry.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
void setOperand(unsigned i, Value *Val)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
INITIALIZE_PASS_BEGIN(CFGSimplifyPass,"simplifycfg","Simplify the CFG", false, false) INITIALIZE_PASS_END(CFGSimplifyPass
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void preserve()
Mark an analysis as preserved.
static bool mergeEmptyReturnBlocks(Function &F)
If we have more than one empty (other than phi node) return blocks, merge them together to promote re...
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
void initializeCFGSimplifyPassPass(PassRegistry &)
SimplifyCFGPass()
Construct a pass with the default thresholds.
LLVM Value Representation.
print Print MemDeps of function
A container for analyses that lazily runs them and caches their results.
static bool iterativelySimplifyCFG(Function &F, const TargetTransformInfo &TTI, AssumptionCache *AC, unsigned BonusInstThreshold)
Call SimplifyCFG on all the blocks in the function, iterating until no more changes are made...