LLVM 22.0.0git
CallGraphSCCPass.h
Go to the documentation of this file.
1//===- CallGraphSCCPass.h - Pass that operates BU on call graph -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the CallGraphSCCPass class, which is used for passes which
10// are implemented as bottom-up traversals on the call graph. Because there may
11// be cycles in the call graph, passes of this type operate on the call-graph in
12// SCC order: that is, they process function bottom-up, except for recursive
13// functions, which they process all at once.
14//
15// These passes are inherently interprocedural, and are required to keep the
16// call graph up-to-date if they do anything which could modify it.
17//
18//===----------------------------------------------------------------------===//
19
20#ifndef LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
21#define LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
22
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/Pass.h"
26#include <vector>
27
28namespace llvm {
29
30class CallGraph;
31class CallGraphNode;
32class CallGraphSCC;
33class PMStack;
34
36public:
37 explicit CallGraphSCCPass(char &pid) : Pass(PT_CallGraphSCC, pid) {}
38
39 /// createPrinterPass - Get a pass that prints the Module
40 /// corresponding to a CallGraph.
41 Pass *createPrinterPass(raw_ostream &OS,
42 const std::string &Banner) const override;
43
46
47 /// doInitialization - This method is called before the SCC's of the program
48 /// has been processed, allowing the pass to do initialization as necessary.
49 virtual bool doInitialization(CallGraph &CG) {
50 return false;
51 }
52
53 /// runOnSCC - This method should be implemented by the subclass to perform
54 /// whatever action is necessary for the specified SCC. Note that
55 /// non-recursive (or only self-recursive) functions will have an SCC size of
56 /// 1, where recursive portions of the call graph will have SCC size > 1.
57 ///
58 /// SCC passes that add or delete functions to the SCC are required to update
59 /// the SCC list, otherwise stale pointers may be dereferenced.
60 virtual bool runOnSCC(CallGraphSCC &SCC) = 0;
61
62 /// doFinalization - This method is called after the SCC's of the program has
63 /// been processed, allowing the pass to do final cleanup as necessary.
64 virtual bool doFinalization(CallGraph &CG) {
65 return false;
66 }
67
68 /// Assign pass manager to manager this pass
69 void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
70
71 /// Return what kind of Pass Manager can manage this pass.
74 }
75
76 /// getAnalysisUsage - For this class, we declare that we require and preserve
77 /// the call graph. If the derived class implements this method, it should
78 /// always explicitly call the implementation here.
79 void getAnalysisUsage(AnalysisUsage &Info) const override;
80};
81
82/// CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
84 const CallGraph &CG; // The call graph for this SCC.
85 void *Context; // The CGPassManager object that is vending this.
86 std::vector<CallGraphNode *> Nodes;
87
88public:
89 CallGraphSCC(CallGraph &cg, void *context) : CG(cg), Context(context) {}
90
92 Nodes.assign(NewNodes.begin(), NewNodes.end());
93 }
94
95 bool isSingular() const { return Nodes.size() == 1; }
96 unsigned size() const { return Nodes.size(); }
97
98 /// ReplaceNode - This informs the SCC and the pass manager that the specified
99 /// Old node has been deleted, and New is to be used in its place.
101
102 /// DeleteNode - This informs the SCC and the pass manager that the specified
103 /// Old node has been deleted.
105
106 using iterator = std::vector<CallGraphNode *>::const_iterator;
107
108 iterator begin() const { return Nodes.begin(); }
109 iterator end() const { return Nodes.end(); }
110
111 const CallGraph &getCallGraph() { return CG; }
112};
113
115
116/// This pass is required by interprocedural register allocation. It forces
117/// codegen to follow bottom up order on call graph.
119public:
120 LLVM_ABI static char ID;
121
125 }
126
127 bool runOnSCC(CallGraphSCC &SCC) override { return false; }
128
129 void getAnalysisUsage(AnalysisUsage &AU) const override {
130 AU.setPreservesAll();
131 }
132};
133
134} // end namespace llvm
135
136#endif // LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:136
iterator begin() const
Definition: ArrayRef.h:135
A node in the call graph for a module.
Definition: CallGraph.h:162
virtual bool doFinalization(CallGraph &CG)
doFinalization - This method is called after the SCC's of the program has been processed,...
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
virtual bool runOnSCC(CallGraphSCC &SCC)=0
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
virtual bool doInitialization(CallGraph &CG)
doInitialization - This method is called before the SCC's of the program has been processed,...
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
bool isSingular() const
std::vector< CallGraphNode * >::const_iterator iterator
const CallGraph & getCallGraph()
LLVM_ABI void ReplaceNode(CallGraphNode *Old, CallGraphNode *New)
ReplaceNode - This informs the SCC and the pass manager that the specified Old node has been deleted,...
LLVM_ABI void DeleteNode(CallGraphNode *Old)
DeleteNode - This informs the SCC and the pass manager that the specified Old node has been deleted.
void initialize(ArrayRef< CallGraphNode * > NewNodes)
unsigned size() const
iterator begin() const
iterator end() const
CallGraphSCC(CallGraph &cg, void *context)
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:72
This pass is required by interprocedural register allocation.
static LLVM_ABI char ID
bool runOnSCC(CallGraphSCC &SCC) override
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph.
PMStack - This class implements a stack data structure of PMDataManager pointers.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:128
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:132
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ PT_CallGraphSCC
Definition: Pass.h:71
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:56
@ PMT_CallGraphPassManager
CGPassManager.
Definition: Pass.h:59
LLVM_ABI void initializeDummyCGSCCPassPass(PassRegistry &)