33 ColorsForNewBlock = ColorsForOldBlock;
46 assert(CurLoop !=
nullptr &&
"CurLoop can't be null");
50 MayThrow = HeaderMayThrow;
55 "First block must be header");
58 (BB != BBE) && !MayThrow; ++BB)
65 return ICF.hasICF(BB);
73 assert(CurLoop !=
nullptr &&
"CurLoop can't be null");
78 for (
auto &BB : CurLoop->
blocks())
79 if (ICF.hasICF(&*BB)) {
88 ICF.insertInstructionTo(Inst, BB);
89 MW.insertInstructionTo(Inst, BB);
93 ICF.removeInstruction(Inst);
94 MW.removeInstruction(Inst);
112 const Loop *CurLoop) {
117 assert(CurLoop->
contains(CondExitBlock) &&
"meaning of exit block");
119 if (!BI || !BI->isConditional())
123 if (
auto *Cond = dyn_cast<ConstantInt>(BI->getCondition()))
124 return BI->
getSuccessor(Cond->getZExtValue() ? 1 : 0) == ExitBlock;
133 if (!LHS || LHS->getParent() != CurLoop->
getHeader())
141 auto *SimpleCst = dyn_cast_or_null<Constant>(SimpleValOrNull);
144 if (ExitBlock == BI->getSuccessor(0))
145 return SimpleCst->isZeroValue();
146 assert(ExitBlock == BI->getSuccessor(1) &&
"implied by above");
147 return SimpleCst->isAllOnesValue();
156 assert(Predecessors.
empty() &&
"Garbage in predecessors set?");
157 assert(CurLoop->
contains(BB) &&
"Should only be called for loop blocks!");
162 Predecessors.
insert(Pred);
165 while (!WorkList.
empty()) {
167 assert(CurLoop->
contains(Pred) &&
"Should only reach loop blocks!");
178 if (Predecessors.
insert(PredPred).second)
186 assert(CurLoop->
contains(BB) &&
"Should only be called for loop blocks!");
203 for (
auto *Pred : Predecessors) {
208 if (CheckedSuccessors.
insert(Succ).second &&
209 Succ != BB && !Predecessors.count(Succ))
237 const Loop *CurLoop)
const {
246 return !HeaderMayThrow ||
256 const Loop *CurLoop)
const {
257 return !ICF.isDominatedByICFIFromSameBlock(&Inst) &&
262 const Loop *CurLoop)
const {
263 assert(CurLoop->
contains(BB) &&
"Should only be called for loop blocks!");
275 for (
auto *Pred : Predecessors)
276 if (MW.mayWriteToMemory(Pred))
282 const Loop *CurLoop)
const {
284 assert(CurLoop->
contains(BB) &&
"Should only be called for loop blocks!");
285 return !MW.isDominatedByMemoryWriteFromSameBlock(&I) &&
286 doesNotWriteMemoryBefore(BB, CurLoop);
307 "Instructions which execute on loop entry",
false,
true)
314 return new MustExecutePrinter();
334 MustExecuteAnnotatedWriter(
const Function &
F,
340 MustExec[&
I].push_back(L);
346 MustExecuteAnnotatedWriter(
const Module &M,
353 MustExec[&
I].push_back(L);
362 if (!MustExec.
count(&V))
366 const auto NumLoops =
Loops.size();
368 OS <<
" ; (mustexec in " << NumLoops <<
" loops: ";
370 OS <<
" ; (mustexec in: ";
377 OS << L->getHeader()->getName();
385 auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
386 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
388 MustExecuteAnnotatedWriter Writer(F, DT, LI);
virtual void computeLoopSafetyInfo(const Loop *CurLoop)
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
void insertInstructionTo(const Instruction *Inst, const BasicBlock *BB)
Inform the safety info that we are planning to insert a new instruction Inst into the basic block BB...
This class is the base class for the comparison instructions.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual bool blockMayThrow(const BasicBlock *BB) const =0
Returns true iff the block BB potentially may throw exception.
This class represents lattice values for constants.
static bool CanProveNotTakenFirstIteration(const 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...
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
virtual bool anyBlockMayThrow() const =0
Returns true iff any block of the loop for which this info is contains an instruction that may throw ...
virtual bool blockMayThrow(const BasicBlock *BB) const
Returns true iff the block BB potentially may throw exception.
BasicBlock * getSuccessor(unsigned i) const
block Block Frequency true
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Simple and conservative implementation of LoopSafetyInfo that can give false-positive answers to its ...
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)
virtual void computeLoopSafetyInfo(const Loop *CurLoop)
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
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 ...
virtual bool anyBlockMayThrow() const
Returns true iff any block of the loop for which this info is contains an instruction that may throw ...
BlockT * getHeader() const
static void collectTransitivePredecessors(const Loop *CurLoop, const BasicBlock *BB, SmallPtrSetImpl< const BasicBlock *> &Predecessors)
Collect all blocks from CurLoop which lie on all possible paths from the header of CurLoop (inclusive...
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch, catchpad/ret, and cleanuppad/ret.
Value * SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.
virtual bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop) const
Returns true if the instruction in a loop is guaranteed to execute at least once. ...
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.
void copyColors(BasicBlock *New, BasicBlock *Old)
Copy colors of block Old into the block New.
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...
virtual bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop) const
Returns true if the instruction in a loop is guaranteed to execute at least once (under the assumptio...
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.
LLVM_NODISCARD bool empty() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
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.
bool allLoopPathsLeadToBlock(const Loop *CurLoop, const BasicBlock *BB, const DominatorTree *DT) const
Return true if we must reach the block BB under assumption that the loop CurLoop is entered...
void removeInstruction(const Instruction *Inst)
Inform safety info that we are planning to remove the instruction Inst from its block.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool doesNotWriteMemoryBefore(const BasicBlock *BB, const Loop *CurLoop) const
Returns true if we could not execute a memory-modifying instruction before we enter BB under assumpti...
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.
static bool isMustExecuteIn(const Instruction &I, Loop *L, DominatorTree *DT)
LLVM_NODISCARD T pop_back_val()
void computeBlockColors(const Loop *CurLoop)
Computes block colors.
pred_range predecessors(BasicBlock *BB)
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
LLVM_NODISCARD bool empty() const
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
virtual bool blockMayThrow(const BasicBlock *BB) const
Returns true iff the block BB potentially may throw exception.
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.
succ_range successors(Instruction *I)
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.
virtual bool anyBlockMayThrow() const
Returns true iff any block of the loop for which this info is contains an instruction that may throw ...
DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
iterator_range< block_iterator > blocks() const
block_iterator block_begin() const
const BasicBlock * getParent() const
const DenseMap< BasicBlock *, ColorVector > & getBlockColors() const
Returns block colors map that is used to update funclet operand bundles.