30 #define DEBUG_TYPE "cgscc" 45 LazyCallGraph::SCC, LazyCallGraph &>;
53 CGSCCUpdateResult &>::run(LazyCallGraph::SCC &InitialC,
54 CGSCCAnalysisManager &AM,
55 LazyCallGraph &
G, CGSCCUpdateResult &UR) {
64 dbgs() <<
"Starting CGSCC pass manager run.\n";
68 LazyCallGraph::SCC *
C = &InitialC;
70 for (
auto &
Pass : Passes) {
72 dbgs() <<
"Running pass: " <<
Pass->name() <<
" on " << *C <<
"\n";
92 LLVM_DEBUG(
dbgs() <<
"Skipping invalidated root or island SCC!\n");
104 PA.intersect(std::move(PassPA));
126 dbgs() <<
"Finished CGSCC pass manager run.\n";
160 bool AreSCCAnalysesPreserved =
165 for (
auto &RC :
G->postorder_ref_sccs())
172 if (
auto *OuterProxy =
174 for (
const auto &OuterInvalidationPair :
175 OuterProxy->getOuterInvalidations()) {
176 AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
177 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
181 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
182 InnerPA->
abandon(InnerAnalysisID);
189 InnerAM->invalidate(
C, *InnerPA);
195 if (!AreSCCAnalysesPreserved)
196 InnerAM->invalidate(
C, PA);
215 AnalysisKey FunctionAnalysisManagerCGSCCProxy::Key;
219 CGSCCAnalysisManager &AM,
227 Module &M = *C.begin()->getFunction().getParent();
229 assert(FAMProxy &&
"The CGSCC pass manager requires that the FAM module " 230 "proxy is run on the module prior to entering the CGSCC " 237 return Result(FAMProxy->getManager());
258 FAM->clear(
N.getFunction(),
N.getFunction().getName());
264 bool AreFunctionAnalysesPreserved =
276 if (
auto *OuterProxy =
278 for (
const auto &OuterInvalidationPair :
279 OuterProxy->getOuterInvalidations()) {
280 AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
281 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
285 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
286 FunctionPA->
abandon(InnerAnalysisID);
293 FAM->invalidate(F, *FunctionPA);
299 if (!AreFunctionAnalysesPreserved)
300 FAM->invalidate(F, PA);
342 for (
const auto &OuterInvalidationPair :
343 OuterProxy->getOuterInvalidations()) {
344 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
345 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
346 PA.abandon(InnerAnalysisID);
350 FAM.invalidate(F, PA);
364 template <
typename SCCRangeT>
371 if (NewSCCRange.begin() == NewSCCRange.end())
376 LLVM_DEBUG(
dbgs() <<
"Enqueuing the existing SCC in the worklist:" << *C
384 "Cannot insert new SCCs without changing current SCC!");
385 C = &*NewSCCRange.
begin();
409 NewSCCRange.end()))) {
410 assert(C != &NewC &&
"No need to re-visit the current SCC!");
411 assert(OldC != &NewC &&
"Already handled the original SCC!");
413 LLVM_DEBUG(
dbgs() <<
"Enqueuing a newly formed SCC:" << NewC <<
"\n");
436 RefSCC *RC = &InitialRC;
461 assert(E &&
"No function transformations should introduce *new* " 462 "call edges! Any new calls should be modeled as " 463 "promoted existing ref edges!");
464 bool Inserted = RetainedEdges.
insert(&CalleeN).second;
466 assert(Inserted &&
"We should never visit a function twice.");
468 PromotedRefTargets.
insert(&CalleeN);
473 for (
Value *
Op :
I.operand_values())
474 if (
auto *C = dyn_cast<Constant>(
Op))
475 if (Visited.
insert(C).second)
478 auto VisitRef = [&](
Function &Referee) {
479 Node &RefereeN = *G.
lookup(Referee);
483 assert(E &&
"No function transformations should introduce *new* ref " 484 "edges! Any new ref edges would require IPO which " 485 "function passes aren't allowed to do!");
486 bool Inserted = RetainedEdges.
insert(&RefereeN).second;
488 assert(Inserted &&
"We should never visit a function twice.");
490 DemotedCallTargets.
insert(&RefereeN);
498 if (!Visited.
count(F))
506 if (RetainedEdges.
count(&
E.getNode()))
511 if (&TargetRC == RC &&
E.isCall()) {
539 << N <<
"' to '" << TargetN <<
"'\n");
545 auto NewRefSCCs = RC->removeInternalRefEdge(N, DeadTargets);
546 if (!NewRefSCCs.empty()) {
556 assert(G.
lookupSCC(N) == C &&
"Changed the SCC when splitting RefSCCs!");
557 RC = &C->getOuterRefSCC();
563 assert(NewRefSCCs.front() == RC &&
564 "New current RefSCC not first in the returned list!");
566 NewRefSCCs.end()))) {
567 assert(NewRC != RC &&
"Should not encounter the current RefSCC further " 568 "in the postorder list of new RefSCCs.");
570 LLVM_DEBUG(
dbgs() <<
"Enqueuing a new RefSCC in the update worklist: " 578 for (Node *RefTarget : DemotedCallTargets) {
584 if (&TargetRC != RC) {
585 assert(RC->isAncestorOf(TargetRC) &&
586 "Cannot potentially form RefSCC cycles here!");
587 RC->switchOutgoingEdgeToRef(N, *RefTarget);
588 LLVM_DEBUG(
dbgs() <<
"Switch outgoing call edge to a ref edge from '" << N
589 <<
"' to '" << *RefTarget <<
"'\n");
597 RC->switchTrivialInternalEdgeToRef(N, *RefTarget);
607 for (Node *CallTarget : PromotedRefTargets) {
608 SCC &TargetC = *G.
lookupSCC(*CallTarget);
613 if (&TargetRC != RC) {
614 assert(RC->isAncestorOf(TargetRC) &&
615 "Cannot potentially form RefSCC cycles here!");
616 RC->switchOutgoingEdgeToCall(N, *CallTarget);
617 LLVM_DEBUG(
dbgs() <<
"Switch outgoing ref edge to a call edge from '" << N
618 <<
"' to '" << *CallTarget <<
"'\n");
621 LLVM_DEBUG(
dbgs() <<
"Switch an internal ref edge to a call edge from '" 622 << N <<
"' to '" << *CallTarget <<
"'\n");
628 bool HasFunctionAnalysisProxy =
false;
629 auto InitialSCCIndex = RC->find(*C) - RC->begin();
630 bool FormedCycle = RC->switchInternalEdgeToCall(
632 for (SCC *MergedC : MergedSCCs) {
633 assert(MergedC != &TargetC &&
"Cannot merge away the target SCC!");
635 HasFunctionAnalysisProxy |=
637 *MergedC) !=
nullptr;
645 auto PA = PreservedAnalyses::allInSet<AllAnalysesOn<Function>>();
660 if (HasFunctionAnalysisProxy)
666 auto PA = PreservedAnalyses::allInSet<AllAnalysesOn<Function>>();
670 auto NewSCCIndex = RC->find(*C) - RC->begin();
679 if (InitialSCCIndex < NewSCCIndex) {
685 LLVM_DEBUG(
dbgs() <<
"Enqueuing the existing SCC in the worklist: " << *C
689 RC->begin() + NewSCCIndex))) {
691 LLVM_DEBUG(
dbgs() <<
"Enqueuing a newly earlier in post-order SCC: " 699 assert(&C->getOuterRefSCC() == RC &&
"Current SCC not in current RefSCC!");
703 if (RC != &InitialRC)
Pass interface - Implemented by all 'passes'.
void abandon()
Mark an analysis as abandoned.
Result run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &)
Computes the FunctionAnalysisManager and stores it in the result proxy.
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
void removeOutgoingEdge(Node &SourceN, Node &TargetN)
Remove an edge whose source is in this RefSCC and target is not.
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.
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.
void push_back(const T &Elt)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
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.
Function & getFunction() const
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...
RefSCC * lookupRefSCC(Node &N) const
Lookup a function's RefSCC in the graph.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
RefSCC & getOuterRefSCC() const
LazyCallGraph::SCC * UpdatedC
If non-null, the updated current SCC being processed.
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()))
A RefSCC of the call graph.
bool insert(const value_type &X)
Insert a new element into the SetVector.
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
static void updateNewSCCFunctionAnalyses(LazyCallGraph::SCC &C, LazyCallGraph &G, CGSCCAnalysisManager &AM)
When a new SCC is created for the graph and there might be function analysis results cached for the f...
A lazily constructed view of the call graph of a module.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const
BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...
A set of analyses that are preserved following a run of a transformation pass.
bool areAllPreserved() const
Test whether all analyses are preserved (and none are abandoned).
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
LazyCallGraph::RefSCC * UpdatedRC
If non-null, the updated current RefSCC being processed.
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.
A class used to represent edges in the call graph.
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
iterator erase(const_iterator CI)
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.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
A SetVector that performs no allocations if smaller than a certain size.
print lazy value Lazy Value Info Printer Pass
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.
ArrayRef< Function * > getLibFunctions() const
Get the sequence of known and defined library functions.
void invalidate(IRUnitT &IR)
Invalidate a specific analysis pass for an IR module.
Node * lookup(const Function &F) const
Lookup a function in the graph which has already been scanned and added.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Result(AnalysisManagerT &InnerAM)
amdgpu Simplify well known AMD library false FunctionCallee Callee
void switchTrivialInternalEdgeToRef(Node &SourceN, Node &TargetN)
Make an existing internal call edge between separate SCCs into a ref edge.
Manages a sequence of passes over a particular unit of IR.
PreservedAnalyses CrossSCCPA
Preserved analyses across SCCs.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
void preserve()
Mark an analysis as preserved.
static LazyCallGraph::SCC * incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G, LazyCallGraph::Node &N, LazyCallGraph::SCC *C, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR)
Helper function to update both the CGSCCAnalysisManager AM and the CGSCCPassManager's CGSCCUpdateResu...
An analysis pass which computes the call graph for a module.
This header provides classes for managing passes over SCCs of the call graph.
API to communicate dependencies between analyses during invalidation.
bool invalidate(LazyCallGraph::SCC &C, const PreservedAnalyses &PA, CGSCCAnalysisManager::Invalidator &Inv)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
LLVM Value Representation.
An SCC of the call graph.
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.
static void visitReferences(SmallVectorImpl< Constant *> &Worklist, SmallPtrSetImpl< Constant *> &Visited, CallbackT Callback)
Recursively visits the defined functions whose address is reachable from every constant in the Workli...
A special type used by analysis passes to provide an address that identifies that particular analysis...
bool allAnalysesInSetPreserved() const
Directly test whether a set of analyses is preserved.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...