41 dbgs() <<
"Starting CGSCC pass manager run.\n";
47 for (
auto &
Pass : Passes) {
49 dbgs() <<
"Running pass: " <<
Pass->name() <<
" on " << *C <<
"\n";
82 dbgs() <<
"Finished CGSCC pass manager run.\n";
116 bool AreSCCAnalysesPreserved =
121 for (
auto &RC :
G->postorder_ref_sccs())
128 if (
auto *OuterProxy =
130 for (
const auto &OuterInvalidationPair :
131 OuterProxy->getOuterInvalidations()) {
132 AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
133 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
137 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
138 InnerPA->
abandon(InnerAnalysisID);
145 InnerAM->invalidate(
C, *InnerPA);
151 if (!AreSCCAnalysesPreserved)
152 InnerAM->invalidate(
C, PA);
171 AnalysisKey FunctionAnalysisManagerCGSCCProxy::Key;
183 Module &M = *C.begin()->getFunction().getParent();
185 assert(FAMProxy &&
"The CGSCC pass manager requires that the FAM module "
186 "proxy is run on the module prior to entering the CGSCC "
193 return Result(FAMProxy->getManager());
214 FAM->clear(
N.getFunction());
220 bool AreFunctionAnalysesPreserved =
232 if (
auto *OuterProxy =
234 for (
const auto &OuterInvalidationPair :
235 OuterProxy->getOuterInvalidations()) {
236 AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
237 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
241 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
242 FunctionPA->
abandon(InnerAnalysisID);
249 FAM->invalidate(F, *FunctionPA);
255 if (!AreFunctionAnalysesPreserved)
256 FAM->invalidate(F, PA);
298 for (
const auto &OuterInvalidationPair :
299 OuterProxy->getOuterInvalidations()) {
300 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
301 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
306 FAM.invalidate(F, PA);
321 template <
typename SCCRangeT>
323 incorporateNewSCCRange(
const SCCRangeT &NewSCCRange,
LazyCallGraph &
G,
326 bool DebugLogging =
false) {
329 if (NewSCCRange.begin() == NewSCCRange.end())
335 dbgs() <<
"Enqueuing the existing SCC in the worklist:" << *C <<
"\n";
342 "Cannot insert new SCCs without changing current SCC!");
343 C = &*NewSCCRange.
begin();
368 assert(C != &NewC &&
"No need to re-visit the current SCC!");
369 assert(OldC != &NewC &&
"Already handled the original SCC!");
372 dbgs() <<
"Enqueuing a newly formed SCC:" << NewC <<
"\n";
396 RefSCC *RC = &InitialRC;
412 if (
Function *Callee = CS.getCalledFunction())
413 if (Visited.
insert(Callee).second && !Callee->isDeclaration()) {
414 Node &CalleeN = *G.
lookup(*Callee);
421 assert(E &&
"No function transformations should introduce *new* "
422 "call edges! Any new calls should be modeled as "
423 "promoted existing ref edges!");
424 RetainedEdges.
insert(&CalleeN);
426 PromotedRefTargets.
insert(&CalleeN);
431 for (
Value *
Op :
I.operand_values())
433 if (Visited.
insert(C).second)
436 auto VisitRef = [&](
Function &Referee) {
437 Node &RefereeN = *G.
lookup(Referee);
441 assert(E &&
"No function transformations should introduce *new* ref "
442 "edges! Any new ref edges would require IPO which "
443 "function passes aren't allowed to do!");
444 RetainedEdges.
insert(&RefereeN);
446 DemotedCallTargets.
insert(&RefereeN);
459 if (!RetainedEdges.
count(&
E.getNode()))
460 DeadTargets.
push_back({&
E.getNode(),
E.getKind()});
461 for (
auto DeadTarget : DeadTargets) {
462 Node &TargetN = *DeadTarget.getPointer();
463 bool IsCall = DeadTarget.getInt() ==
Edge::Call;
467 if (&TargetRC != RC) {
470 dbgs() <<
"Deleting outgoing edge from '" << N <<
"' to '" << TargetN
475 dbgs() <<
"Deleting internal " << (IsCall ?
"call" :
"ref")
476 <<
" edge from '" << N <<
"' to '" << TargetN <<
"'\n";
481 RC->switchTrivialInternalEdgeToRef(N, TargetN);
484 C = incorporateNewSCCRange(RC->switchInternalEdgeToRef(N, TargetN),
G,
485 N,
C, AM, UR, DebugLogging);
489 auto NewRefSCCs = RC->removeInternalRefEdge(N, TargetN);
490 if (!NewRefSCCs.empty()) {
503 dbgs() <<
"Enqueuing the existing RefSCC in the update worklist: "
506 assert(G.
lookupSCC(N) == C &&
"Changed the SCC when splitting RefSCCs!");
507 RC = &C->getOuterRefSCC();
509 assert(NewRefSCCs.front() == RC &&
510 "New current RefSCC not first in the returned list!");
512 make_range(std::next(NewRefSCCs.begin()), NewRefSCCs.end()))) {
513 assert(NewRC != RC &&
"Should not encounter the current RefSCC further "
514 "in the postorder list of new RefSCCs.");
517 dbgs() <<
"Enqueuing a new RefSCC in the update worklist: " << *NewRC
526 for (Node *RefTarget : DemotedCallTargets) {
532 if (&TargetRC != RC) {
533 assert(RC->isAncestorOf(TargetRC) &&
534 "Cannot potentially form RefSCC cycles here!");
535 RC->switchOutgoingEdgeToRef(N, *RefTarget);
537 dbgs() <<
"Switch outgoing call edge to a ref edge from '" << N
538 <<
"' to '" << *RefTarget <<
"'\n";
546 RC->switchTrivialInternalEdgeToRef(N, *RefTarget);
551 C = incorporateNewSCCRange(RC->switchInternalEdgeToRef(N, *RefTarget),
G,
N,
552 C, AM, UR, DebugLogging);
556 for (Node *CallTarget : PromotedRefTargets) {
557 SCC &TargetC = *G.
lookupSCC(*CallTarget);
562 if (&TargetRC != RC) {
563 assert(RC->isAncestorOf(TargetRC) &&
564 "Cannot potentially form RefSCC cycles here!");
565 RC->switchOutgoingEdgeToCall(N, *CallTarget);
567 dbgs() <<
"Switch outgoing ref edge to a call edge from '" << N
568 <<
"' to '" << *CallTarget <<
"'\n";
572 dbgs() <<
"Switch an internal ref edge to a call edge from '" << N
573 <<
"' to '" << *CallTarget <<
"'\n";
579 bool HasFunctionAnalysisProxy =
false;
580 auto InitialSCCIndex = RC->find(*C) - RC->begin();
581 bool FormedCycle = RC->switchInternalEdgeToCall(
583 for (SCC *MergedC : MergedSCCs) {
584 assert(MergedC != &TargetC &&
"Cannot merge away the target SCC!");
586 HasFunctionAnalysisProxy |=
588 *MergedC) !=
nullptr;
596 auto PA = PreservedAnalyses::allInSet<AllAnalysesOn<Function>>();
611 if (HasFunctionAnalysisProxy)
617 auto PA = PreservedAnalyses::allInSet<AllAnalysesOn<Function>>();
621 auto NewSCCIndex = RC->find(*C) - RC->begin();
622 if (InitialSCCIndex < NewSCCIndex) {
629 dbgs() <<
"Enqueuing the existing SCC in the worklist: " << *C <<
"\n";
632 RC->begin() + NewSCCIndex))) {
635 dbgs() <<
"Enqueuing a newly earlier in post-order SCC: " << MovedC
643 assert(&C->getOuterRefSCC() == RC &&
"Current SCC not in current RefSCC!");
647 if (RC != &InitialRC)
Pass interface - Implemented by all 'passes'.
void abandon()
Mark an analysis as abandoned.
SCC * lookupSCC(Node &N) const
Lookup a function's SCC in the graph.
void push_back(const T &Elt)
Result run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &)
Computes the FunctionAnalysisManager and stores it in the result proxy.
void removeOutgoingEdge(Node &SourceN, Node &TargetN)
Remove an edge whose source is in this RefSCC and target is not.
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. ...
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...
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
LazyCallGraph::SCC * UpdatedC
If non-null, the updated current SCC being processed.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
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.
void invalidate(IRUnitT &IR)
Invalidate a specific analysis pass for an IR module.
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.
Result run(IRUnitT &IR, AnalysisManager< IRUnitT, ExtraArgTs...> &AM, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
A set of analyses that are preserved following a run of a transformation pass.
This is an important base class in LLVM.
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.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
RefSCC & getOuterRefSCC() const
A node in the call graph.
A class used to represent edges in the call graph.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
bool areAllPreserved() const
Test whether all analyses are preserved (and none are abandoned).
SmallPriorityWorklist< LazyCallGraph::SCC *, 1 > & CWorklist
Worklist of the SCCs queued for processing.
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.
Function & getFunction() const
A SetVector that performs no allocations if smaller than a certain size.
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...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
ArrayRef< Function * > getLibFunctions() const
Get the sequence of known and defined library functions.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA, typename AnalysisManager< IRUnitT, ExtraArgTs...>::Invalidator &Inv)
Handler for invalidation of the outer IR unit, IRUnitT.
Node * lookup(const Function &F) const
Lookup a function in the graph which has already been scanned and added.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Manages a sequence of passes over a particular unit of IR.
void preserveSet()
Mark an analysis set as preserved.
void preserve()
Mark an analysis as preserved.
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...
bool allAnalysesInSetPreserved() const
Directly test whether a set of analyses is preserved.
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.
RefSCC * lookupRefSCC(Node &N) const
Lookup a function's RefSCC in the graph.
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
LazyCallGraph::SCC & updateCGAndAnalysisManagerForFunctionPass(LazyCallGraph &G, LazyCallGraph::SCC &C, LazyCallGraph::Node &N, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR, bool DebugLogging=false)
Helper to update the call graph after running a function pass.
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...