43 #define DEBUG_TYPE "simplifycfg"
47 cl::desc(
"Control the number of bonus instructions (default = 1)"));
49 STATISTIC(NumSimpl,
"Number of blocks simplified");
68 if (Ret != &BB.
front()) {
73 while (isa<DbgInfoIntrinsic>(I) && I != BB.
begin())
75 if (!isa<DbgInfoIntrinsic>(I) &&
76 (!isa<PHINode>(
I) || I != BB.
begin() ||
108 std::distance(PB, PE),
"merge",
131 unsigned BonusInstThreshold) {
132 bool Changed =
false;
133 bool LocalChange =
true;
134 while (LocalChange) {
139 if (
SimplifyCFG(BBIt++, TTI, BonusInstThreshold, AC)) {
144 Changed |= LocalChange;
156 if (!EverChanged)
return false;
169 }
while (EverChanged);
178 : BonusInstThreshold(BonusInstThreshold) {}
194 unsigned BonusInstThreshold;
195 std::function<bool(const Function &)> PredicateFtor;
197 CFGSimplifyPass(
int T = -1,
203 bool runOnFunction(
Function &
F)
override {
204 if (PredicateFtor && !PredicateFtor(F))
207 if (skipOptnoneFunction(F))
211 &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
213 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
236 return new CFGSimplifyPass(Threshold, Ftor);
This file provides the interface for the pass responsible for both simplifying and canonicalizing the...
ReturnInst - Return a value (possibly void), from a function.
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void addIncoming(Value *V, BasicBlock *BB)
addIncoming - 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")
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)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
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 PreservedAnalyses none()
Convenience factory function for the empty preserved set.
initializer< Ty > init(const Ty &Val)
An abstract set of preserved analyses following a transformation pass run.
LLVM Basic Block Representation.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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.
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr)
SimplifyCFG - This function is used to do simplification of a CFG.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A function analysis which provides an AssumptionCache.
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
PassT::Result & getResult(IRUnitT &IR)
Get the result of an analysis pass for this module.
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)
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
PreservedAnalyses run(Function &F, AnalysisManager< Function > *AM)
Run the pass over the function.
iplist< 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...
INITIALIZE_PASS_BEGIN(CFGSimplifyPass,"simplifycfg","Simplify the CFG", false, false) INITIALIZE_PASS_END(CFGSimplifyPass
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
bool removeUnreachableBlocks(Function &F)
Remove all blocks that can not be reached from the function's entry.
A generic analysis pass manager with lazy running and caching of 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...