89 #ifndef LLVM_ANALYSIS_CGSCCPASSMANAGER_H 90 #define LLVM_ANALYSIS_CGSCCPASSMANAGER_H 111 struct CGSCCUpdateResult;
115 #define DEBUG_TYPE "cgscc" 118 extern template class AllAnalysesOn<LazyCallGraph::SCC>;
120 extern template class AnalysisManager<LazyCallGraph::SCC, LazyCallGraph &>;
138 CGSCCAnalysisManager &AM,
150 CGSCCUpdateResult &>;
153 template <
typename AnalysisT>
155 LazyCallGraph &, CGSCCUpdateResult &>
156 :
PassInfoMixin<RequireAnalysisPass<AnalysisT, LazyCallGraph::SCC,
157 CGSCCAnalysisManager, LazyCallGraph &,
158 CGSCCUpdateResult &>> {
160 LazyCallGraph &CG, CGSCCUpdateResult &) {
161 (void)AM.template getResult<AnalysisT>(C, CG);
175 explicit Result(CGSCCAnalysisManager &InnerAM, LazyCallGraph &
G)
176 : InnerAM(&InnerAM), G(&G) {}
195 CGSCCAnalysisManager *InnerAM;
232 struct CGSCCUpdateResult {
314 template <
typename CGSCCPassT>
316 :
public PassInfoMixin<ModuleToPostOrderCGSCCPassAdaptor<CGSCCPassT>> {
319 : Pass(
std::move(Pass)) {}
344 CGSCCAnalysisManager &CGAM =
361 InlinedInternalEdges;
363 CGSCCUpdateResult UR = {RCWorklist, CWorklist, InvalidRefSCCSet,
364 InvalidSCCSet,
nullptr,
nullptr,
365 InlinedInternalEdges};
372 assert(RCWorklist.empty() &&
373 "Should always start with an empty RefSCC worklist");
385 RCWorklist.insert(&*RCI++);
389 if (InvalidRefSCCSet.
count(RC)) {
395 "Should always start with an empty SCC worklist");
397 LLVM_DEBUG(
dbgs() <<
"Running an SCC pass across the RefSCC: " << *RC
411 if (InvalidSCCSet.
count(C)) {
417 <<
"Skipping an SCC that is now part of some other " 424 assert(!InvalidSCCSet.
count(C) &&
"Processing an invalid SCC!");
427 "Processing an SCC in a different RefSCC!");
441 <<
"Skipping invalidated root or island SCC!\n");
470 <<
"Re-running SCC passes after a refinement of the " 478 }
while (!CWorklist.
empty());
483 InlinedInternalEdges.clear();
484 }
while (!RCWorklist.empty());
502 template <
typename CGSCCPassT>
534 Result run(LazyCallGraph::SCC &
C, CGSCCAnalysisManager &AM, LazyCallGraph &);
556 CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR);
566 template <
typename FunctionPassT>
571 : Pass(
std::move(Pass)) {}
593 LazyCallGraph &CG, CGSCCUpdateResult &UR) {
605 LazyCallGraph::SCC *CurrentC = &
C;
607 LLVM_DEBUG(
dbgs() <<
"Running function passes across an SCC: " << C
638 "Current SCC not updated to the SCC containing the current node!");
661 template <
typename FunctionPassT>
681 template <
typename PassT>
686 : Pass(
std::move(Pass)), MaxIterations(MaxIterations) {}
691 LazyCallGraph &CG, CGSCCUpdateResult &UR) {
696 LazyCallGraph::SCC *
C = &InitialC;
710 auto ScanSCC = [](LazyCallGraph::SCC &
C,
712 assert(CallHandles.
empty() &&
"Must start with a clear set of handles.");
717 CallCount &Count = CallCounts.back();
720 if (CS.getCalledFunction()) {
733 auto CallCounts = ScanSCC(*C, CallHandles);
735 for (
int Iteration = 0;; ++Iteration) {
749 "Cannot have changed the size of the SCC!");
765 << CS.getParent()->getParent()->getName() <<
" to " 772 bool Devirt =
llvm::any_of(CallHandles, IsDevirtualizedHandle);
778 auto NewCallCounts = ScanSCC(*C, CallHandles);
787 if (CallCounts[i].Indirect > NewCallCounts[i].Indirect &&
788 CallCounts[i].Direct < NewCallCounts[i].Direct) {
801 dbgs() <<
"Found another devirtualization after hitting the max " 802 "number of repetitions (" 810 <<
"Repeating an SCC pass after finding a devirtualization in: " << *C
814 CallCounts = std::move(NewCallCounts);
835 template <
typename PassT>
846 #endif // LLVM_ANALYSIS_CGSCCPASSMANAGER_H Pass interface - Implemented by all 'passes'.
This file provides a priority worklist.
void push_back(const T &Elt)
ModuleToPostOrderCGSCCPassAdaptor(ModuleToPostOrderCGSCCPassAdaptor &&Arg)
PreservedAnalyses run(LazyCallGraph::SCC &InitialC, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Runs the wrapped pass up to MaxIterations on the SCC, iterating whenever an indirect call is refined...
bool insert(const T &X)
Insert a new element into the PriorityWorklist.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Compute iterated dominance frontiers using a linear time algorithm.
LLVM_NODISCARD T pop_back_val()
SmallPriorityWorklist< LazyCallGraph::RefSCC *, 1 > & RCWorklist
Worklist of the RefSCCs queued for processing.
void intersect(const PreservedAnalyses &Arg)
Intersect this set with another in place.
A Module instance is used to store all the information related to an LLVM module. ...
LazyCallGraph::SCC & updateCGAndAnalysisManagerForFunctionPass(LazyCallGraph &G, LazyCallGraph::SCC &C, LazyCallGraph::Node &N, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR)
Helper to update the call graph after running a function pass.
CGSCCToFunctionPassAdaptor & operator=(CGSCCToFunctionPassAdaptor RHS)
SCC * lookupSCC(Node &N) const
Lookup a function's SCC in the graph.
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA, typename AnalysisManager< IRUnitT, ExtraArgTs... >::Invalidator &Inv)
Handler for invalidation of the outer IR unit, IRUnitT.
Implements a lazy call graph analysis and related passes for the new pass manager.
Result(FunctionAnalysisManager &FAM)
ModuleToPostOrderCGSCCPassAdaptor< CGSCCPassT > createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
CGSCCToFunctionPassAdaptor< FunctionPassT > createCGSCCToFunctionPassAdaptor(FunctionPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
bool empty() const
Determine if the PriorityWorklist is empty or not.
ModuleToPostOrderCGSCCPassAdaptor & operator=(ModuleToPostOrderCGSCCPassAdaptor RHS)
A utility pass template to force an analysis result to be available.
Result(CGSCCAnalysisManager &InnerAM, LazyCallGraph &G)
A proxy from a FunctionAnalysisManager to an SCC.
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
RefSCC & getOuterRefSCC() const
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Runs the function pass across every function in the module.
LazyCallGraph::SCC * UpdatedC
If non-null, the updated current SCC being processed.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
postorder_ref_scc_iterator postorder_ref_scc_begin()
ModuleToPostOrderCGSCCPassAdaptor(const ModuleToPostOrderCGSCCPassAdaptor &Arg)
AnalysisManagerT & getManager()
Accessor for the analysis manager.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
CGSCCToFunctionPassAdaptor(const CGSCCToFunctionPassAdaptor &Arg)
A RefSCC of the call graph.
Value handle that is nullable, but tries to track the Value.
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
A CRTP mix-in to automatically provide informational APIs needed for passes.
A lazily constructed view of the call graph of a module.
static cl::opt< unsigned > MaxIterations("max-cg-scc-iterations", cl::ReallyHidden, cl::init(4))
ModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass)
A set of analyses that are preserved following a run of a transformation pass.
The core module pass which does a post-order walk of the SCCs and runs a CGSCC pass over each one...
SmallPtrSetImpl< LazyCallGraph::RefSCC * > & InvalidatedRefSCCs
The set of invalidated RefSCCs which should be skipped if they are found in RCWorklist.
SmallPtrSetImpl< LazyCallGraph::SCC * > & InvalidatedSCCs
The set of invalidated SCCs which should be skipped if they are found in CWorklist.
A CRTP mix-in that provides informational APIs needed for analysis passes.
friend void swap(ModuleToPostOrderCGSCCPassAdaptor &LHS, ModuleToPostOrderCGSCCPassAdaptor &RHS)
LazyCallGraph::RefSCC * UpdatedRC
If non-null, the updated current RefSCC being processed.
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
friend void swap(CGSCCToFunctionPassAdaptor &LHS, CGSCCToFunctionPassAdaptor &RHS)
FunctionAnalysisManager & getManager()
Accessor for the analysis manager.
A node in the call graph.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
CGSCCToFunctionPassAdaptor(FunctionPassT Pass)
A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...
DevirtSCCRepeatedPass< PassT > createDevirtSCCRepeatedPass(PassT Pass, int MaxIterations)
A function to deduce a function pass type and wrap it in the templated adaptor.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
SmallPriorityWorklist< LazyCallGraph::SCC *, 1 > & CWorklist
Worklist of the SCCs queued for processing.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Runs the CGSCC pass across every SCC in the module.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
print lazy value Lazy Value Info Printer Pass
CGSCCAnalysisManager & getManager()
Accessor for the analysis manager.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Result run(IRUnitT &IR, AnalysisManager< IRUnitT, ExtraArgTs... > &AM, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
void invalidate(IRUnitT &IR)
Invalidate a specific analysis pass for an IR module.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Implements a dense probed hash-table based set with some number of buckets stored inline...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A helper that repeats an SCC pass each time an indirect call is refined to a direct call by that pass...
CGSCCToFunctionPassAdaptor(CGSCCToFunctionPassAdaptor &&Arg)
Adaptor that maps from a SCC to its functions.
amdgpu Simplify well known AMD library false Value Value * Arg
Manages a sequence of passes over a particular unit of IR.
LLVM_NODISCARD bool empty() const
void preserveSet()
Mark an analysis set as preserved.
StringRef getName() const
Return a constant reference to the value's name.
void preserve()
Mark an analysis as preserved.
PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT &AM, ExtraArgTs &&... Args)
Run this pass over some unit of IR.
An analysis pass which computes the call graph for a module.
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &)
API to communicate dependencies between analyses during invalidation.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
An SCC of the call graph.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
DevirtSCCRepeatedPass(PassT Pass, int MaxIterations)
inst_range instructions(Function *F)
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
postorder_ref_scc_iterator postorder_ref_scc_end()
SmallDenseSet< std::pair< LazyCallGraph::Node *, LazyCallGraph::SCC * >, 4 > & InlinedInternalEdges
A hacky area where the inliner can retain history about inlining decisions that mutated the call grap...
A special type used by analysis passes to provide an address that identifies that particular analysis...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...