23 #ifndef LLVM_ANALYSIS_MUSTEXECUTE_H 24 #define LLVM_ANALYSIS_MUSTEXECUTE_H 37 template <
typename T>
using GetterTy = std::function<T *(const Function &F)>;
42 class PostDominatorTree;
98 const Loop *CurLoop)
const = 0;
110 bool MayThrow =
false;
112 bool HeaderMayThrow =
false;
123 const Loop *CurLoop)
const;
136 bool MayThrow =
false;
152 const Loop *CurLoop)
const;
156 bool doesNotWriteMemoryBefore(
const BasicBlock *BB,
const Loop *CurLoop)
284 : Visited(Other.Visited), Explorer(Other.Explorer),
285 CurInst(Other.CurInst) {}
288 : Visited(
std::move(
Other.Visited)), Explorer(
Other.Explorer),
289 CurInst(
Other.CurInst) {}
292 if (
this != &
Other) {
318 return CurInst == Other.CurInst;
322 return !(*
this ==
Other);
383 bool ExploreInterBlock,
384 GetterTy<const LoopInfo> LIGetter =
385 [](
const Function &) {
return nullptr; },
386 GetterTy<const PostDominatorTree> PDTGetter =
387 [](
const Function &) {
return nullptr; })
388 : ExploreInterBlock(ExploreInterBlock), LIGetter(LIGetter),
389 PDTGetter(PDTGetter), EndIterator(*
this,
nullptr) {}
403 auto *&It = InstructionIteratorMap[PP];
411 return *InstructionIteratorMap.lookup(PP);
441 auto EIt =
begin(PP), EEnd =
end(PP);
442 return findInContextOf(I, EIt, EEnd);
452 bool Found = EIt.
count(I);
453 while (!Found && EIt != EEnd)
454 Found = (++EIt).getCurrentInst() ==
I;
481 GetterTy<const LoopInfo> LIGetter;
482 GetterTy<const PostDominatorTree> PDTGetter;
493 InstructionIteratorMap;
void DeleteContainerSeconds(Container &C)
In a container of pairs (usually a map) whose second element is a pointer, deletes the second element...
const_iterator end(StringRef path)
Get end iterator over path.
std::input_iterator_tag iterator_category
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 *)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
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.
Implements a dense probed hash-table based set.
MustBeExecutedIterator(MustBeExecutedIterator &&Other)
iterator & end()
Return an universal end iterator.
const_iterator & end() const
virtual bool anyBlockMayThrow() const =0
Returns true iff any block of the loop for which this info is contains an instruction that may throw ...
const Instruction *& operator*()
}
~MustBeExecutedContextExplorer()
Clean up the dynamically allocated iterators.
Simple and conservative implementation of LoopSafetyInfo that can give false-positive answers to its ...
const Instruction * value_type
Type declarations that make his class an input iterator.
This implementation of LoopSafetyInfo use ImplicitControlFlowTracking to give precise answers on "may...
MustBeExecutedIterator & operator=(MustBeExecutedIterator &&Other)
const_iterator & begin(const Instruction *PP) const
Return an iterator to explore the cached context around PP.
llvm::iterator_range< iterator > range(const Instruction *PP)
}
Must be executed iterators visit stretches of instructions that are guaranteed to be executed togethe...
const Instruction ** pointer
MustBeExecutedIterator & operator++()
Pre- and post-increment operators.
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...
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...
LLVM Basic Block Representation.
ICFLoopSafetyInfo(DominatorTree *DT)
MustBeExecutedIterator(const MustBeExecutedIterator &Other)
std::ptrdiff_t difference_type
bool operator==(const MustBeExecutedIterator &Other) const
}
llvm::iterator_range< const_iterator > range(const Instruction *PP) const
Return an iterator range to explore the cached context around PP.
virtual ~LoopSafetyInfo()=default
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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...
bool count(const Instruction *I) const
Return true if I was encountered by this iterator already.
MustBeExecutedIterator operator++(int)
const_iterator & end(const Instruction *) const
void computeBlockColors(const Loop *CurLoop)
Computes block colors.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A range adaptor for a pair of iterators.
A "must be executed context" for a given program point PP is the set of instructions, potentially before and after PP, that are executed always when PP is reached.
bool findInContextOf(const Instruction *I, const Instruction *PP)
}
virtual ~ICFLoopSafetyInfo()
bool operator!=(const MustBeExecutedIterator &Other) const
const bool ExploreInterBlock
Parameter that limit the performed exploration.
Represents a single loop in the control flow graph.
virtual ~SimpleLoopSafetyInfo()
const Instruction * getCurrentInst() const
Captures loop safety information.
This class allows to keep track on instructions with implicit control flow.
virtual void computeLoopSafetyInfo(const Loop *CurLoop)=0
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
const Instruction *& reference
~MustBeExecutedIterator()
MustBeExecutedContextExplorer(bool ExploreInterBlock, GetterTy< const LoopInfo > LIGetter=[](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...
iterator & begin(const Instruction *PP)
Return an iterator to explore the context around PP.
const DenseMap< BasicBlock *, ColorVector > & getBlockColors() const
Returns block colors map that is used to update funclet operand bundles.