29 assert(CurLoop !=
nullptr &&
"CurLoop can't be null");
43 "First block must be header");
46 (BB != BBE) && !SafetyInfo->
MayThrow; ++BB)
64 const Loop *CurLoop) {
69 assert(CurLoop->
contains(CondExitBlock) &&
"meaning of exit block");
71 if (!BI || !BI->isConditional())
75 if (
auto *Cond = dyn_cast<ConstantInt>(BI->getCondition()))
76 return BI->
getSuccessor(Cond->getZExtValue() ? 1 : 0) == ExitBlock;
85 if (!LHS || LHS->getParent() != CurLoop->
getHeader())
93 auto *SimpleCst = dyn_cast_or_null<Constant>(SimpleValOrNull);
96 if (ExitBlock == BI->getSuccessor(0))
97 return SimpleCst->isZeroValue();
98 assert(ExitBlock == BI->getSuccessor(1) &&
"implied by above");
99 return SimpleCst->isAllOnesValue();
139 const bool InstDominatesLatch =
150 if (!InstDominatesLatch ||
156 if (ExitBlocks.empty())
184 "Instructions which execute on loop entry",
false,
true)
191 return new MustExecutePrinter();
211 MustExecuteAnnotatedWriter(
const Function &
F,
217 MustExec[&
I].push_back(L);
223 MustExecuteAnnotatedWriter(
const Module &M,
230 MustExec[&
I].push_back(L);
239 if (!MustExec.
count(&V))
243 const auto NumLoops =
Loops.size();
245 OS <<
" ; (mustexec in " << NumLoops <<
" loops: ";
247 OS <<
" ; (mustexec in: ";
254 OS << L->getHeader()->getName();
262 auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
263 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
265 MustExecuteAnnotatedWriter Writer(F, DT, LI);
This class is the base class for the comparison instructions.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
BasicBlock * getSuccessor(unsigned i) const
block Block Frequency true
DenseMap< BasicBlock *, ColorVector > BlockColors
AnalysisUsage & addRequired()
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
#define INITIALIZE_PASS_DEPENDENCY(depName)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Contains a collection of routines for determining if a given instruction is guaranteed to execute if ...
BlockT * getHeader() const
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch, catchpad/ret, and cleanuppad/ret.
void getExitBlocks(SmallVectorImpl< BlockT *> &ExitBlocks) const
Return all of the successor blocks of this loop.
void computeLoopSafetyInfo(LoopSafetyInfo *, Loop *)
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
Value * SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the function to an output stream with an optional AssemblyAnnotationWriter. ...
bool hasPersonalityFn() const
Check whether this function has a personality function.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Value * getOperand(unsigned i) const
FunctionPass * createMustExecutePrinter()
static bool runOnFunction(Function &F, bool PostInlining)
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
This is an important base class in LLVM.
static bool CanProveNotTakenFirstIteration(BasicBlock *ExitBlock, const DominatorTree *DT, const Loop *CurLoop)
Return true if we can prove that the given ExitBlock is not reached on the first iteration of the giv...
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
INITIALIZE_PASS_BEGIN(MustExecutePrinter, "print-mustexecute", "Instructions which execute on loop entry", false, true) INITIALIZE_PASS_END(MustExecutePrinter
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Module.h This file contains the declarations for the Module class.
static bool isMustExecuteIn(const Instruction &I, Loop *L, DominatorTree *DT)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LoopT * getParentLoop() const
Captures loop safety information.
Represents a single loop in the control flow graph.
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
block_iterator block_end() const
bool isGuaranteedToExecuteForEveryIteration(const Instruction *I, const Loop *L)
Return true if this function can prove that the instruction I is executed for every iteration of the ...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
The legacy pass manager's analysis pass to compute loop information.
print Instructions which execute on loop entry
inst_range instructions(Function *F)
void initializeMustExecutePrinterPass(PassRegistry &)
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
Legacy analysis pass which computes a DominatorTree.
DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo)
Returns true if the instruction in a loop is guaranteed to execute at least once (under the assumptio...
block_iterator block_begin() const
const BasicBlock * getParent() const