23#ifndef LLVM_ANALYSIS_MUSTEXECUTE_H
24#define LLVM_ANALYSIS_MUSTEXECUTE_H
36template <
typename T>
using GetterTy = std::function<
T *(
const Function &
F)>;
63 bool allLoopPathsLeadToBlockImpl(
const BasicBlock *BB,
107 bool MayThrow =
false;
109 bool HeaderMayThrow =
false;
111 void computeLoopSafetyInfo();
115 computeLoopSafetyInfo();
118 bool blockMayThrow(
const BasicBlock *BB)
const override;
120 bool anyBlockMayThrow()
const override;
122 bool isGuaranteedToExecute(
const Instruction &Inst,
132 bool MayThrow =
false;
139 void computeLoopSafetyInfo();
143 computeLoopSafetyInfo();
146 bool blockMayThrow(
const BasicBlock *BB)
const override;
148 bool anyBlockMayThrow()
const override;
150 bool isGuaranteedToExecute(
const Instruction &Inst,
155 bool doesNotWriteMemoryBefore(
const BasicBlock *BB)
const;
159 bool doesNotWriteMemoryBefore(
const Instruction &
I)
const;
175struct MustBeExecutedContextExplorer;
292 if (
this != &
Other) {
320 return CurInst ==
Other.CurInst && Head ==
Other.Head && Tail ==
Other.Tail;
324 return !(*
this ==
Other);
335 Visited.count({I, ExplorationDirection::BACKWARD});
359 VisitedSetTy Visited;
404 GetterTy<const LoopInfo> LIGetter =
405 [](
const Function &) {
return nullptr; },
406 GetterTy<const DominatorTree> DTGetter =
407 [](
const Function &) {
return nullptr; },
408 GetterTy<const PostDominatorTree> PDTGetter =
409 [](
const Function &) {
return nullptr; })
413 DTGetter(DTGetter), PDTGetter(PDTGetter), EndIterator(*this, nullptr) {}
422 auto &It = InstructionIteratorMap[PP];
430 return *InstructionIteratorMap.find(PP)->second;
459 for (
auto EIt =
begin(PP), EEnd =
end(PP); EIt != EEnd; ++EIt)
472 auto EIt =
begin(PP), EEnd =
end(PP);
483 bool Found = EIt.
count(
I);
484 while (!Found && EIt != EEnd)
485 Found = (++EIt).getCurrentInst() ==
I;
526 GetterTy<const LoopInfo> LIGetter;
527 GetterTy<const DominatorTree> DTGetter;
528 GetterTy<const PostDominatorTree> PDTGetter;
539 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.
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.
ICFLoopSafetyInfo(const Loop *L)
This class allows to keep track on instructions with implicit control flow.
LLVM_ABI void copyColors(BasicBlock *New, BasicBlock *Old)
Copy colors of block Old into the block New.
LoopSafetyInfo(const Loop *CurLoop)
LLVM_ABI const DenseMap< BasicBlock *, ColorVector > & getBlockColors() const
Returns block colors map that is used to update funclet operand bundles.
LLVM_ABI void computeBlockColors()
Computes block colors.
virtual ~LoopSafetyInfo()=default
LLVM_ABI bool allLoopPathsLeadToBlock(const BasicBlock *BB, const DominatorTree *DT) const
Return true if we must reach the block BB under assumption that the loop is entered.
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 =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)
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
A set of analyses that are preserved following a run of a transformation pass.
SimpleLoopSafetyInfo(const Loop *L)
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.
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.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI bool mayContainIrreducibleControl(const Function &F, const LoopInfo *LI)
ExplorationDirection
Enum that allows us to spell out the direction.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
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.
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.
const MustBeExecutedIterator const_iterator
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 for passes that should not be skipped.