31 #define DEBUG_TYPE "cgscc" 46 LazyCallGraph::SCC, LazyCallGraph &>;
54 CGSCCUpdateResult &>::run(LazyCallGraph::SCC &InitialC,
55 CGSCCAnalysisManager &AM,
56 LazyCallGraph &
G, CGSCCUpdateResult &UR) {
60 dbgs() <<
"Starting CGSCC pass manager run.\n";
64 LazyCallGraph::SCC *
C = &InitialC;
66 for (
auto &
Pass : Passes) {
68 dbgs() <<
"Running pass: " <<
Pass->name() <<
" on " << *C <<
"\n";
78 LLVM_DEBUG(
dbgs() <<
"Skipping invalidated root or island SCC!\n");
106 dbgs() <<
"Finished CGSCC pass manager run.\n";
140 bool AreSCCAnalysesPreserved =
145 for (
auto &RC :
G->postorder_ref_sccs())
152 if (
auto *OuterProxy =
154 for (
const auto &OuterInvalidationPair :
155 OuterProxy->getOuterInvalidations()) {
156 AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
157 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
161 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
162 InnerPA->
abandon(InnerAnalysisID);
169 InnerAM->invalidate(
C, *InnerPA);
175 if (!AreSCCAnalysesPreserved)
176 InnerAM->invalidate(
C, PA);
195 AnalysisKey FunctionAnalysisManagerCGSCCProxy::Key;
199 CGSCCAnalysisManager &AM,
207 Module &M = *C.begin()->getFunction().getParent();
209 assert(FAMProxy &&
"The CGSCC pass manager requires that the FAM module " 210 "proxy is run on the module prior to entering the CGSCC " 217 return Result(FAMProxy->getManager());
238 FAM->clear(
N.getFunction(),
N.getFunction().getName());
244 bool AreFunctionAnalysesPreserved =
256 if (
auto *OuterProxy =
258 for (
const auto &OuterInvalidationPair :
259 OuterProxy->getOuterInvalidations()) {
260 AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
261 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
265 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
266 FunctionPA->
abandon(InnerAnalysisID);
273 FAM->invalidate(F, *FunctionPA);
279 if (!AreFunctionAnalysesPreserved)
280 FAM->invalidate(F, PA);
322 for (
const auto &OuterInvalidationPair :
323 OuterProxy->getOuterInvalidations()) {
324 const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
325 for (
AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
326 PA.abandon(InnerAnalysisID);
330 FAM.invalidate(F, PA);
344 template <
typename SCCRangeT>
351 if (NewSCCRange.begin() == NewSCCRange.end())
356 LLVM_DEBUG(
dbgs() <<
"Enqueuing the existing SCC in the worklist:" << *C
364 "Cannot insert new SCCs without changing current SCC!");
365 C = &*NewSCCRange.
begin();
389 NewSCCRange.end()))) {
390 assert(C != &NewC &&
"No need to re-visit the current SCC!");
391 assert(OldC != &NewC &&
"Already handled the original SCC!");
393 LLVM_DEBUG(
dbgs() <<
"Enqueuing a newly formed SCC:" << NewC <<
"\n");
416 RefSCC *RC = &InitialRC;
441 assert(E &&
"No function transformations should introduce *new* " 442 "call edges! Any new calls should be modeled as " 443 "promoted existing ref edges!");
444 bool Inserted = RetainedEdges.
insert(&CalleeN).second;
446 assert(Inserted &&
"We should never visit a function twice.");
448 PromotedRefTargets.
insert(&CalleeN);
453 for (
Value *
Op :
I.operand_values())
454 if (
auto *C = dyn_cast<Constant>(
Op))
455 if (Visited.
insert(C).second)
458 auto VisitRef = [&](
Function &Referee) {
459 Node &RefereeN = *G.
lookup(Referee);
463 assert(E &&
"No function transformations should introduce *new* ref " 464 "edges! Any new ref edges would require IPO which " 465 "function passes aren't allowed to do!");
466 bool Inserted = RetainedEdges.
insert(&RefereeN).second;
468 assert(Inserted &&
"We should never visit a function twice.");
470 DemotedCallTargets.
insert(&RefereeN);
478 if (!Visited.
count(F))
486 if (RetainedEdges.
count(&
E.getNode()))
491 if (&TargetRC == RC &&
E.isCall()) {
519 << N <<
"' to '" << TargetN <<
"'\n");
525 auto NewRefSCCs = RC->removeInternalRefEdge(N, DeadTargets);
526 if (!NewRefSCCs.empty()) {
536 assert(G.
lookupSCC(N) == C &&
"Changed the SCC when splitting RefSCCs!");
537 RC = &C->getOuterRefSCC();
543 assert(NewRefSCCs.front() == RC &&
544 "New current RefSCC not first in the returned list!");
546 NewRefSCCs.end()))) {
547 assert(NewRC != RC &&
"Should not encounter the current RefSCC further " 548 "in the postorder list of new RefSCCs.");
550 LLVM_DEBUG(
dbgs() <<
"Enqueuing a new RefSCC in the update worklist: " 558 for (Node *RefTarget : DemotedCallTargets) {
564 if (&TargetRC != RC) {
565 assert(RC->isAncestorOf(TargetRC) &&
566 "Cannot potentially form RefSCC cycles here!");
567 RC->switchOutgoingEdgeToRef(N, *RefTarget);
568 LLVM_DEBUG(
dbgs() <<
"Switch outgoing call edge to a ref edge from '" << N
569 <<
"' to '" << *RefTarget <<
"'\n");
577 RC->switchTrivialInternalEdgeToRef(N, *RefTarget);
587 for (Node *CallTarget : PromotedRefTargets) {
588 SCC &TargetC = *G.
lookupSCC(*CallTarget);
593 if (&TargetRC != RC) {
594 assert(RC->isAncestorOf(TargetRC) &&
595 "Cannot potentially form RefSCC cycles here!");
596 RC->switchOutgoingEdgeToCall(N, *CallTarget);
597 LLVM_DEBUG(
dbgs() <<
"Switch outgoing ref edge to a call edge from '" << N
598 <<
"' to '" << *CallTarget <<
"'\n");
601 LLVM_DEBUG(
dbgs() <<
"Switch an internal ref edge to a call edge from '" 602 << N <<
"' to '" << *CallTarget <<
"'\n");
608 bool HasFunctionAnalysisProxy =
false;
609 auto InitialSCCIndex = RC->find(*C) - RC->begin();
610 bool FormedCycle = RC->switchInternalEdgeToCall(
612 for (SCC *MergedC : MergedSCCs) {
613 assert(MergedC != &TargetC &&
"Cannot merge away the target SCC!");
615 HasFunctionAnalysisProxy |=
617 *MergedC) !=
nullptr;
625 auto PA = PreservedAnalyses::allInSet<AllAnalysesOn<Function>>();
640 if (HasFunctionAnalysisProxy)
646 auto PA = PreservedAnalyses::allInSet<AllAnalysesOn<Function>>();
650 auto NewSCCIndex = RC->find(*C) - RC->begin();
659 if (InitialSCCIndex < NewSCCIndex) {
665 LLVM_DEBUG(
dbgs() <<
"Enqueuing the existing SCC in the worklist: " << *C
669 RC->begin() + NewSCCIndex))) {
671 LLVM_DEBUG(
dbgs() <<
"Enqueuing a newly earlier in post-order SCC: " 679 assert(&C->getOuterRefSCC() == RC &&
"Current SCC not in current RefSCC!");
683 if (RC != &InitialRC)
Pass interface - Implemented by all 'passes'.
void abandon()
Mark an analysis as abandoned.
void push_back(const T &Elt)
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.
Compute iterated dominance frontiers using a linear time algorithm.
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.
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)...
amdgpu Simplify well known AMD library false Value * Callee
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.
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.
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.
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)
void switchTrivialInternalEdgeToRef(Node &SourceN, Node &TargetN)
Make an existing internal call edge between separate SCCs into a ref edge.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Manages a sequence of passes over a particular unit of IR.
void preserveSet()
Mark an analysis set as preserved.
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 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...