23#ifndef LLVM_ANALYSIS_MUSTEXECUTE_H
24#define LLVM_ANALYSIS_MUSTEXECUTE_H
39template <
typename T>
using GetterTy = std::function<
T *(
const Function &
F)>;
60 mutable std::optional<DenseMap<BasicBlock *, ColorVector>> BlockColors;
66 bool allLoopPathsLeadToBlockImpl(
const BasicBlock *BB,
70 void computeBlockColors()
const;
110 bool MayThrow =
false;
112 bool HeaderMayThrow =
false;
114 void computeLoopSafetyInfo();
118 computeLoopSafetyInfo();
121 bool blockMayThrow(
const BasicBlock *BB)
const override;
123 bool anyBlockMayThrow()
const override;
125 bool isGuaranteedToExecute(
const Instruction &Inst,
135 bool MayThrow =
false;
142 void computeLoopSafetyInfo();
146 computeLoopSafetyInfo();
149 bool blockMayThrow(
const BasicBlock *BB)
const override;
151 bool anyBlockMayThrow()
const override;
153 bool isGuaranteedToExecute(
const Instruction &Inst,
158 bool doesNotWriteMemoryBefore(
const BasicBlock *BB)
const;
162 bool doesNotWriteMemoryBefore(
const Instruction &
I)
const;
178struct MustBeExecutedContextExplorer;
295 if (
this != &
Other) {
323 return CurInst ==
Other.CurInst && Head ==
Other.Head && Tail ==
Other.Tail;
327 return !(*
this ==
Other);
355 VisitedSetTy Visited;
400 GetterTy<const LoopInfo> LIGetter =
401 [](
const Function &) {
return nullptr; },
402 GetterTy<const DominatorTree> DTGetter =
403 [](
const Function &) {
return nullptr; },
404 GetterTy<const PostDominatorTree> PDTGetter =
405 [](
const Function &) {
return nullptr; })
409 DTGetter(DTGetter), PDTGetter(PDTGetter), EndIterator(*this, nullptr) {}
418 auto &It = InstructionIteratorMap[PP];
426 return *InstructionIteratorMap.find(PP)->second;
500 GetterTy<const LoopInfo> LIGetter;
501 GetterTy<const DominatorTree> DTGetter;
502 GetterTy<const PostDominatorTree> PDTGetter;
513 InstructionIteratorMap;
551 const ForwardContextTy &getForwardContext(
const BasicBlock *BB);
554 const BackwardContextTy &getBackwardContext(
const BasicBlock *BB);
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This header defines various interfaces for pass management in LLVM.
This file implements a map that provides insertion order iteration.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
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.
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.
This class implements a map that also provides access to all stored values in a deterministic order.
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)
A SetVector that performs no allocations if smaller than a certain size.
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
const_iterator & end() const
iterator & begin(const Instruction *PP)
Return an iterator to explore the context around PP.
LLVM_ABI bool checkForAllTerminatorsInContext(const Instruction *PP, function_ref< bool(const Instruction *)> Pred)
Check Pred on all terminators in the context of PP and return true if it holds for all of them.
llvm::iterator_range< iterator > range(const Instruction *PP)
}
LLVM_ABI bool isInContextOf(const Instruction *I, const Instruction *PP)
}
LLVM_ABI const Instruction * getMustBeExecutedPrevInstruction(MustBeExecutedIterator &It, const Instruction *PP)
Return the previous instr.
LLVM_ABI const BasicBlock * findForwardJoinPoint(const BasicBlock *InitBB)
Find the next join point from InitBB in forward direction.
const_iterator & end(const Instruction *) const
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
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)
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.