88 #ifndef LLVM_ANALYSIS_CGSCCPASSMANAGER_H 89 #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 {
329 template <
typename CGSCCPassT>
331 :
public PassInfoMixin<ModuleToPostOrderCGSCCPassAdaptor<CGSCCPassT>> {
334 : Pass(
std::move(Pass)) {}
365 template <
typename CGSCCPassT>
397 Result run(LazyCallGraph::SCC &
C, CGSCCAnalysisManager &AM, LazyCallGraph &);
419 CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR);
429 template <
typename FunctionPassT>
434 : Pass(
std::move(Pass)) {}
456 LazyCallGraph &CG, CGSCCUpdateResult &UR) {
468 LazyCallGraph::SCC *CurrentC = &
C;
470 LLVM_DEBUG(
dbgs() <<
"Running function passes across an SCC: " << C
509 "Current SCC not updated to the SCC containing the current node!");
532 template <
typename FunctionPassT>
552 template <
typename PassT>
557 : Pass(
std::move(Pass)), MaxIterations(MaxIterations) {}
562 LazyCallGraph &CG, CGSCCUpdateResult &UR) {
569 LazyCallGraph::SCC *
C = &InitialC;
583 auto ScanSCC = [](LazyCallGraph::SCC &
C,
585 assert(CallHandles.
empty() &&
"Must start with a clear set of handles.");
588 CallCount CountLocal = {0, 0};
591 CallCounts.
insert(std::make_pair(&
N.getFunction(), CountLocal))
595 if (CS.getCalledFunction()) {
608 auto CallCounts = ScanSCC(*C, CallHandles);
610 for (
int Iteration = 0;; ++Iteration) {
647 << CS.getParent()->getParent()->getName() <<
" to " 654 bool Devirt =
llvm::any_of(CallHandles, IsDevirtualizedHandle);
660 auto NewCallCounts = ScanSCC(*C, CallHandles);
670 for (
auto &Pair : NewCallCounts) {
671 auto &CallCountNew = Pair.second;
672 auto CountIt = CallCounts.find(Pair.first);
673 if (CountIt != CallCounts.end()) {
674 const auto &CallCountOld = CountIt->second;
675 if (CallCountOld.Indirect > CallCountNew.Indirect &&
676 CallCountOld.Direct < CallCountNew.Direct) {
691 dbgs() <<
"Found another devirtualization after hitting the max " 692 "number of repetitions (" 700 <<
"Repeating an SCC pass after finding a devirtualization in: " << *C
704 CallCounts = std::move(NewCallCounts);
725 template <
typename PassT>
733 template <
typename CGSCCPassT>
736 ModuleAnalysisManager &AM) {
738 CGSCCAnalysisManager &CGAM =
755 InlinedInternalEdges;
757 CGSCCUpdateResult UR = {
758 RCWorklist, CWorklist, InvalidRefSCCSet, InvalidSCCSet,
770 assert(RCWorklist.empty() &&
771 "Should always start with an empty RefSCC worklist");
783 RCWorklist.insert(&*RCI++);
787 if (InvalidRefSCCSet.
count(RC)) {
793 "Should always start with an empty SCC worklist");
795 LLVM_DEBUG(
dbgs() <<
"Running an SCC pass across the RefSCC: " << *RC
809 if (InvalidSCCSet.
count(C)) {
814 LLVM_DEBUG(
dbgs() <<
"Skipping an SCC that is now part of some other " 849 assert(!InvalidSCCSet.
count(C) &&
"Processing an invalid SCC!");
852 "Processing an SCC in a different RefSCC!");
877 LLVM_DEBUG(
dbgs() <<
"Skipping invalidated root or island SCC!\n");
896 PA.intersect(std::move(PassPA));
909 <<
"Re-running SCC passes after a refinement of the " 917 }
while (!CWorklist.
empty());
922 InlinedInternalEdges.clear();
923 }
while (!RCWorklist.empty());
940 #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.
bool empty() const
Determine if the PriorityWorklist is empty or not.
CGSCCToFunctionPassAdaptor< FunctionPassT > createCGSCCToFunctionPassAdaptor(FunctionPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
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.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
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.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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.
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.
PreservedAnalyses CrossSCCPA
Preserved analyses across SCCs.
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...