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};
376 assert(RCWorklist.empty() &&
377 "Should always start with an empty RefSCC worklist");
389 RCWorklist.insert(&*RCI++);
393 if (InvalidRefSCCSet.
count(RC)) {
399 "Should always start with an empty SCC worklist");
401 LLVM_DEBUG(
dbgs() <<
"Running an SCC pass across the RefSCC: " << *RC
415 if (InvalidSCCSet.
count(C)) {
421 <<
"Skipping an SCC that is now part of some other " 428 assert(!InvalidSCCSet.
count(C) &&
"Processing an invalid SCC!");
431 "Processing an SCC in a different RefSCC!");
457 <<
"Skipping invalidated root or island SCC!\n");
473 PA.intersect(std::move(PassPA));
486 <<
"Re-running SCC passes after a refinement of the " 494 }
while (!CWorklist.
empty());
499 InlinedInternalEdges.clear();
500 }
while (!RCWorklist.empty());
518 template <
typename CGSCCPassT>
550 Result run(LazyCallGraph::SCC &
C, CGSCCAnalysisManager &AM, LazyCallGraph &);
572 CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR);
582 template <
typename FunctionPassT>
587 : Pass(
std::move(Pass)) {}
609 LazyCallGraph &CG, CGSCCUpdateResult &UR) {
621 LazyCallGraph::SCC *CurrentC = &
C;
623 LLVM_DEBUG(
dbgs() <<
"Running function passes across an SCC: " << C
662 "Current SCC not updated to the SCC containing the current node!");
685 template <
typename FunctionPassT>
705 template <
typename PassT>
710 : Pass(
std::move(Pass)), MaxIterations(MaxIterations) {}
715 LazyCallGraph &CG, CGSCCUpdateResult &UR) {
722 LazyCallGraph::SCC *
C = &InitialC;
736 auto ScanSCC = [](LazyCallGraph::SCC &
C,
738 assert(CallHandles.
empty() &&
"Must start with a clear set of handles.");
743 CallCount &Count = CallCounts.back();
746 if (CS.getCalledFunction()) {
759 auto CallCounts = ScanSCC(*C, CallHandles);
761 for (
int Iteration = 0;; ++Iteration) {
784 "Cannot have changed the size of the SCC!");
800 << CS.getParent()->getParent()->getName() <<
" to " 807 bool Devirt =
llvm::any_of(CallHandles, IsDevirtualizedHandle);
813 auto NewCallCounts = ScanSCC(*C, CallHandles);
822 if (CallCounts[i].Indirect > NewCallCounts[i].Indirect &&
823 CallCounts[i].Direct < NewCallCounts[i].Direct) {
836 dbgs() <<
"Found another devirtualization after hitting the max " 837 "number of repetitions (" 845 <<
"Repeating an SCC pass after finding a devirtualization in: " << *C
849 CallCounts = std::move(NewCallCounts);
870 template <
typename PassT>
881 #endif // LLVM_ANALYSIS_CGSCCPASSMANAGER_H Pass interface - Implemented by all 'passes'.
This file provides a priority worklist.
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.
This class represents lattice values for constants.
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)
void push_back(const T &Elt)
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.
bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const
BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...
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.
Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.
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...
void runAfterPass(const PassT &Pass, const IRUnitT &IR) const
AfterPass instrumentation point - takes Pass instance that has just been executed and constant refere...
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...
void runAfterPassInvalidated(const PassT &Pass) const
AfterPassInvalidated instrumentation point - takes Pass instance that has just been executed...
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.
DevirtSCCRepeatedPass(PassT Pass, int MaxIterations)
inst_range instructions(Function *F)
A container for analyses that lazily runs them and caches their results.
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
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...