23#ifndef LLVM_ANALYSIS_MUSTEXECUTE_H
24#define LLVM_ANALYSIS_MUSTEXECUTE_H
36template <
typename T>
using GetterTy = std::function<
T *(
const Function &
F)>;
43class PostDominatorTree;
100 const Loop *CurLoop)
const = 0;
112 bool MayThrow =
false;
114 bool HeaderMayThrow =
false;
117 bool blockMayThrow(
const BasicBlock *BB)
const override;
119 bool anyBlockMayThrow()
const override;
121 void computeLoopSafetyInfo(
const Loop *CurLoop)
override;
123 bool isGuaranteedToExecute(
const Instruction &Inst,
125 const Loop *CurLoop)
const override;
134 bool MayThrow =
false;
142 bool blockMayThrow(
const BasicBlock *BB)
const override;
144 bool anyBlockMayThrow()
const override;
146 void computeLoopSafetyInfo(
const Loop *CurLoop)
override;
148 bool isGuaranteedToExecute(
const Instruction &Inst,
150 const Loop *CurLoop)
const override;
154 bool doesNotWriteMemoryBefore(
const BasicBlock *BB,
const Loop *CurLoop)
293 if (
this != &
Other) {
321 return CurInst ==
Other.CurInst && Head ==
Other.Head && Tail ==
Other.Tail;
325 return !(*
this ==
Other);
336 Visited.
count({I, ExplorationDirection::BACKWARD});
360 VisitedSetTy Visited;
405 GetterTy<const LoopInfo> LIGetter =
406 [](
const Function &) {
return nullptr; },
407 GetterTy<const DominatorTree> DTGetter =
408 [](
const Function &) {
return nullptr; },
409 GetterTy<const PostDominatorTree> PDTGetter =
410 [](
const Function &) {
return nullptr; })
414 DTGetter(DTGetter), PDTGetter(PDTGetter), EndIterator(*
this,
nullptr) {}
423 auto &It = InstructionIteratorMap[PP];
431 return *InstructionIteratorMap.find(PP)->second;
460 for (
auto EIt =
begin(PP), EEnd =
end(PP); EIt != EEnd; ++EIt)
473 auto EIt =
begin(PP), EEnd =
end(PP);
484 bool Found = EIt.
count(
I);
485 while (!Found && EIt != EEnd)
486 Found = (++EIt).getCurrentInst() ==
I;
527 GetterTy<const LoopInfo> LIGetter;
528 GetterTy<const DominatorTree> DTGetter;
529 GetterTy<const PostDominatorTree> PDTGetter;
540 InstructionIteratorMap;
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This header defines various interfaces for pass management in LLVM.
A container for analyses that lazily runs them and caches their results.
LLVM Basic Block Representation.
Implements a dense probed hash-table based set.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
This implementation of LoopSafetyInfo use ImplicitControlFlowTracking to give precise answers on "may...
This class allows to keep track on instructions with implicit control flow.
Captures loop safety information.
LLVM_ABI 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.
LLVM_ABI void copyColors(BasicBlock *New, BasicBlock *Old)
Copy colors of block Old into the block New.
LLVM_ABI void computeBlockColors(const Loop *CurLoop)
Computes block colors.
LLVM_ABI const DenseMap< BasicBlock *, ColorVector > & getBlockColors() const
Returns block colors map that is used to update funclet operand bundles.
virtual ~LoopSafetyInfo()=default
virtual void computeLoopSafetyInfo(const Loop *CurLoop)=0
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
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 =0
Returns true iff the block BB potentially may throw exception.
virtual bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop) const =0
Returns true if the instruction in a loop is guaranteed to execute at least once (under the assumptio...
Represents a single loop in the control flow graph.
A Module instance is used to store all the information related to an LLVM module.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
MustBeExecutedContextPrinterPass(raw_ostream &OS)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
MustExecutePrinterPass(raw_ostream &OS)
A set of analyses that are preserved following a run of a transformation pass.
Simple and conservative implementation of LoopSafetyInfo that can give false-positive answers to its ...
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool mayContainIrreducibleControl(const Function &F, const LoopInfo *LI)
ExplorationDirection
Enum that allows us to spell out the direction.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A "must be executed context" for a given program point PP is the set of instructions,...
const bool ExploreInterBlock
Parameter that limit the performed exploration.
const_iterator & begin(const Instruction *PP) const
Return an iterator to explore the cached context around PP.
LLVM_ABI const BasicBlock * findBackwardJoinPoint(const BasicBlock *InitBB)
Find the next join point from InitBB in backward direction.
LLVM_ABI const Instruction * getMustBeExecutedNextInstruction(MustBeExecutedIterator &It, const Instruction *PP)
Return the next instruction that is guaranteed to be executed after PP.
iterator & end()
Return an universal end iterator.
MustBeExecutedContextExplorer(bool ExploreInterBlock, bool ExploreCFGForward, bool ExploreCFGBackward, GetterTy< const LoopInfo > LIGetter=[](const Function &) { return nullptr;}, GetterTy< const DominatorTree > DTGetter=[](const Function &) { return nullptr;}, GetterTy< const PostDominatorTree > PDTGetter=[](const Function &) { return nullptr;})
In the description of the parameters we use PP to denote a program point for which the must be execut...
const bool ExploreCFGBackward
const bool ExploreCFGForward
bool findInContextOf(const Instruction *I, const Instruction *PP)
Helper to look for I in the context of PP.
const_iterator & end() const
iterator & begin(const Instruction *PP)
Return an iterator to explore the context around PP.
llvm::iterator_range< iterator > range(const Instruction *PP)
}
LLVM_ABI const Instruction * getMustBeExecutedPrevInstruction(MustBeExecutedIterator &It, const Instruction *PP)
Return the previous instr.
bool checkForAllContext(const Instruction *PP, function_ref< bool(const Instruction *)> Pred)
}
LLVM_ABI const BasicBlock * findForwardJoinPoint(const BasicBlock *InitBB)
Find the next join point from InitBB in forward direction.
const_iterator & end(const Instruction *) const
bool findInContextOf(const Instruction *I, iterator &EIt, iterator &EEnd)
Helper to look for I in the context defined by EIt and EEnd.
iterator & end(const Instruction *)
llvm::iterator_range< const_iterator > range(const Instruction *PP) const
Return an iterator range to explore the cached context around PP.
MustBeExecutedIterator iterator
Iterator-based interface.
Must be executed iterators visit stretches of instructions that are guaranteed to be executed togethe...
bool operator!=(const MustBeExecutedIterator &Other) const
const Instruction * value_type
Type declarations that make his class an input iterator.
MustBeExecutedIterator(const MustBeExecutedIterator &Other)=default
MustBeExecutedContextExplorer ExplorerTy
}
const Instruction *& reference
const Instruction ** pointer
const Instruction * getCurrentInst() const
bool operator==(const MustBeExecutedIterator &Other) const
}
~MustBeExecutedIterator()=default
std::input_iterator_tag iterator_category
MustBeExecutedIterator(MustBeExecutedIterator &&Other)
std::ptrdiff_t difference_type
MustBeExecutedIterator & operator=(MustBeExecutedIterator &&Other)
bool count(const Instruction *I) const
Return true if I was encountered by this iterator already.
MustBeExecutedIterator operator++(int)
friend struct MustBeExecutedContextExplorer
MustBeExecutedIterator & operator++()
Pre- and post-increment operators.
const Instruction *& operator*()
}
A CRTP mix-in to automatically provide informational APIs needed for passes.