23#ifndef LLVM_ANALYSIS_MUSTEXECUTE_H
24#define LLVM_ANALYSIS_MUSTEXECUTE_H
35template <
typename T>
using GetterTy = std::function<
T *(
const Function &
F)>;
42class PostDominatorTree;
98 const Loop *CurLoop)
const = 0;
110 bool MayThrow =
false;
112 bool HeaderMayThrow =
false;
123 const Loop *CurLoop)
const override;
132 bool MayThrow =
false;
148 const Loop *CurLoop)
const override;
290 if (
this != &
Other) {
318 return CurInst ==
Other.CurInst && Head ==
Other.Head && Tail ==
Other.Tail;
322 return !(*
this ==
Other);
333 Visited.
count({I, ExplorationDirection::BACKWARD});
357 VisitedSetTy Visited;
402 GetterTy<const LoopInfo> LIGetter =
403 [](
const Function &) {
return nullptr; },
404 GetterTy<const DominatorTree> DTGetter =
405 [](
const Function &) {
return nullptr; },
406 GetterTy<const PostDominatorTree> PDTGetter =
407 [](
const Function &) {
return nullptr; })
411 DTGetter(DTGetter), PDTGetter(PDTGetter), EndIterator(*
this,
nullptr) {}
420 auto &It = InstructionIteratorMap[PP];
428 return *InstructionIteratorMap.find(PP)->second;
457 for (
auto EIt =
begin(PP), EEnd =
end(PP); EIt != EEnd; ++EIt)
470 auto EIt =
begin(PP), EEnd =
end(PP);
481 bool Found = EIt.
count(
I);
482 while (!Found && EIt != EEnd)
483 Found = (++EIt).getCurrentInst() ==
I;
524 GetterTy<const LoopInfo> LIGetter;
525 GetterTy<const DominatorTree> DTGetter;
526 GetterTy<const PostDominatorTree> PDTGetter;
537 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...
bool blockMayThrow(const BasicBlock *BB) const override
Returns true iff the block BB potentially may throw exception.
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...
void removeInstruction(const Instruction *Inst)
Inform safety info that we are planning to remove the instruction Inst from its block.
bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop) const override
Returns true if the instruction in a loop is guaranteed to execute at least once (under the assumptio...
bool anyBlockMayThrow() const override
Returns true iff any block of the loop for which this info is contains an instruction that may throw ...
void computeLoopSafetyInfo(const Loop *CurLoop) override
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 allows to keep track on instructions with implicit control flow.
Captures loop safety information.
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 copyColors(BasicBlock *New, BasicBlock *Old)
Copy colors of block Old into the block New.
void computeBlockColors(const Loop *CurLoop)
Computes block colors.
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.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
MustBeExecutedContextPrinterPass(raw_ostream &OS)
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 ...
bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop) const override
Returns true if the instruction in a loop is guaranteed to execute at least once.
void computeLoopSafetyInfo(const Loop *CurLoop) override
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
bool anyBlockMayThrow() const override
Returns true iff any block of the loop for which this info is contains an instruction that may throw ...
bool blockMayThrow(const BasicBlock *BB) const override
Returns true iff the block BB potentially may throw exception.
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.
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.
const BasicBlock * findBackwardJoinPoint(const BasicBlock *InitBB)
Find the next join point from InitBB in backward direction.
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)
}
const Instruction * getMustBeExecutedPrevInstruction(MustBeExecutedIterator &It, const Instruction *PP)
Return the previous instr.
bool checkForAllContext(const Instruction *PP, function_ref< bool(const Instruction *)> Pred)
}
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.