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 LateSimplifyCFG) {
135 bool Changed =
false;
136 bool LocalChange =
true;
141 for (
unsigned i = 0, e = Edges.
size(); i != e; ++i)
142 LoopHeaders.
insert(const_cast<BasicBlock *>(Edges[i].second));
144 while (LocalChange) {
149 if (
SimplifyCFG(&*BBIt++, TTI, BonusInstThreshold, AC, &LoopHeaders, LateSimplifyCFG)) {
154 Changed |= LocalChange;
161 bool LateSimplifyCFG) {
168 if (!EverChanged)
return false;
182 }
while (EverChanged);
189 LateSimplifyCFG(
true) {}
192 : BonusInstThreshold(BonusInstThreshold),
193 LateSimplifyCFG(LateSimplifyCFG) {}
209 unsigned BonusInstThreshold;
210 std::function<bool(const Function &)> PredicateFtor;
211 bool LateSimplifyCFG;
213 BaseCFGSimplifyPass(
int T,
bool LateSimplifyCFG,
217 LateSimplifyCFG(LateSimplifyCFG) {
220 bool runOnFunction(
Function &
F)
override {
221 if (skipFunction(F) || (PredicateFtor && !PredicateFtor(F)))
225 &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
227 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
238 struct CFGSimplifyPass :
public BaseCFGSimplifyPass {
241 CFGSimplifyPass(
int T = -1,
243 : BaseCFGSimplifyPass(T,
false, Ftor, ID) {
248 struct LateCFGSimplifyPass :
public BaseCFGSimplifyPass {
251 LateCFGSimplifyPass(
int T = -1,
253 : BaseCFGSimplifyPass(T,
true, Ftor, ID) {
267 char LateCFGSimplifyPass::ID = 0;
273 "Simplify the CFG more aggressively", false, false)
279 return new CFGSimplifyPass(Threshold, std::move(Ftor));
286 return new LateCFGSimplifyPass(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.
static bool iterativelySimplifyCFG(Function &F, const TargetTransformInfo &TTI, AssumptionCache *AC, unsigned BonusInstThreshold, bool LateSimplifyCFG)
Call SimplifyCFG on all the blocks in the function, iterating until no more changes are made...
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...
STATISTIC(NumFunctions,"Total number of functions")
This is the interface for a simple mod/ref and alias analysis over globals.
Simplify the CFG more aggressively
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)"))
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)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This file contains the simple types necessary to represent the attributes associated with functions a...
FunctionPass * createCFGSimplificationPass(int Threshold=-1, std::function< bool(const Function &)> Ftor=nullptr)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
initializer< Ty > init(const Ty &Val)
A set of analyses that are preserved following a run of a transformation pass.
LLVM Basic Block Representation.
void initializeLateCFGSimplifyPassPass(PassRegistry &)
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.
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
static bool simplifyFunctionCFG(Function &F, const TargetTransformInfo &TTI, AssumptionCache *AC, int BonusInstThreshold, bool LateSimplifyCFG)
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
FunctionPass * createLateCFGSimplificationPass(int Threshold=-1, std::function< bool(const Function &)> Ftor=nullptr)
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.
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 and switch optimizations.
LLVM Value Representation.
print Print MemDeps of function
A container for analyses that lazily runs them and caches their results.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr, SmallPtrSetImpl< BasicBlock * > *LoopHeaders=nullptr, bool LateSimplifyCFG=false)
This function is used to do simplification of a CFG.