45#ifndef LLVM_ANALYSIS_CALLGRAPH_H
46#define LLVM_ANALYSIS_CALLGRAPH_H
60template <
class GraphType>
struct GraphTraits;
75 std::map<const Function *, std::unique_ptr<CallGraphNode>>;
78 FunctionMapTy FunctionMap;
86 std::unique_ptr<CallGraphNode> CallsExternalNode;
113 assert(
I != FunctionMap.end() &&
"Function not in callgraph!");
114 return I->second.get();
120 assert(
I != FunctionMap.end() &&
"Function not in callgraph!");
121 return I->second.get();
129 return CallsExternalNode.get();
189 assert(NumReferences == 0 &&
"Node deleted while references remain");
192 using iterator = std::vector<CallRecord>::iterator;
202 inline bool empty()
const {
return CalledFunctions.empty(); }
203 inline unsigned size()
const {
return (
unsigned)CalledFunctions.size(); }
211 assert(i < CalledFunctions.size() &&
"Invalid index");
212 return CalledFunctions[i].second;
227 while (!CalledFunctions.empty()) {
228 CalledFunctions.back().second->DropRef();
229 CalledFunctions.pop_back();
235 assert(CalledFunctions.empty() &&
236 "Cannot steal callsite information if I already have some");
237 std::swap(CalledFunctions,
N->CalledFunctions);
242 CalledFunctions.emplace_back(Call ? std::optional<WeakTrackingVH>(Call)
243 : std::optional<WeakTrackingVH>(),
249 I->second->DropRef();
250 *
I = CalledFunctions.back();
251 CalledFunctions.pop_back();
283 std::vector<CallRecord> CalledFunctions;
287 unsigned NumReferences = 0;
289 void DropRef() { --NumReferences; }
290 void AddRef() { ++NumReferences; }
293 void allReferencesDropped() { NumReferences = 0; }
349 std::unique_ptr<CallGraph> G;
384 return G->getExternalCallingNode();
388 return G->getCallsExternalNode();
403 return G->removeFunctionFromModule(CGN);
409 return G->getOrInsertFunction(
F);
481 std::pair<const Function *const, std::unique_ptr<CallGraphNode>>;
488 return P.second.get();
508 std::pair<const Function *const, std::unique_ptr<CallGraphNode>>;
515 return P.second.get();
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Machine Check Debug Module
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
An analysis pass to compute the CallGraph for a Module.
CallGraph run(Module &M, ModuleAnalysisManager &)
Compute the CallGraph for the module M.
A node in the call graph for a module.
void removeCallEdgeFor(CallBase &Call)
Removes the edge in the node for the specified call site.
void print(raw_ostream &OS) const
std::vector< CallRecord >::const_iterator const_iterator
std::vector< CallRecord > CalledFunctionsVector
CallGraphNode(const CallGraphNode &)=delete
void addCalledFunction(CallBase *Call, CallGraphNode *M)
Adds a function to the list of functions called by this one.
CallGraphNode(CallGraph *CG, Function *F)
Creates a node for the specified function.
void replaceCallEdge(CallBase &Call, CallBase &NewCall, CallGraphNode *NewNode)
Replaces the edge in the node for the specified call site with a new one.
const_iterator end() const
CallGraphNode * operator[](unsigned i) const
Returns the i'th called function.
void dump() const
Print out this call graph node.
void stealCalledFunctionsFrom(CallGraphNode *N)
Moves all the callee information from N to this node.
Function * getFunction() const
Returns the function that this call graph node represents.
const_iterator begin() const
void removeOneAbstractEdgeTo(CallGraphNode *Callee)
Removes one edge associated with a null callsite from this node to the specified callee function.
void removeAllCalledFunctions()
Removes all edges from this CallGraphNode to any functions it calls.
std::vector< CallRecord >::iterator iterator
unsigned getNumReferences() const
Returns the number of other CallGraphNodes in this CallGraph that reference this node in their callee...
void removeAnyCallEdgeTo(CallGraphNode *Callee)
Removes all call edges from this node to the specified callee function.
CallGraphNode & operator=(const CallGraphNode &)=delete
void removeCallEdge(iterator I)
std::pair< std::optional< WeakTrackingVH >, CallGraphNode * > CallRecord
A pair of the calling instruction (a call or invoke) and the call graph node being called.
Printer pass for the CallGraphAnalysis results.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
CallGraphPrinterPass(raw_ostream &OS)
Printer pass for the summarized CallGraphAnalysis results.
CallGraphSCCsPrinterPass(raw_ostream &OS)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
The ModulePass which wraps up a CallGraph and the logic to build it.
CallGraph::const_iterator const_iterator
const CallGraph & getCallGraph() const
The internal CallGraph around which the rest of this interface is wrapped.
const_iterator begin() const
CallGraphNode * getCallsExternalNode() const
const_iterator end() const
const CallGraphNode * operator[](const Function *F) const
Returns the call graph node for the provided function.
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
CallGraphNode * operator[](const Function *F)
Returns the call graph node for the provided function.
CallGraph::iterator iterator
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
void print(raw_ostream &o, const Module *) const override
print - Print out the internal state of the pass.
Module & getModule() const
Returns the module the call graph corresponds to.
CallGraphNode * getOrInsertFunction(const Function *F)
Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist.
CallGraphNode * getExternalCallingNode() const
Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.
~CallGraphWrapperPass() override
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Function * removeFunctionFromModule(CallGraphNode *CGN)
Unlink the function from this module, returning it.
CallGraph & getCallGraph()
The basic data container for the call graph of a Module of IR.
Function * removeFunctionFromModule(CallGraphNode *CGN)
Unlink the function from this module, returning it.
void print(raw_ostream &OS) const
const CallGraphNode * operator[](const Function *F) const
Returns the call graph node for the provided function.
void populateCallGraphNode(CallGraphNode *CGN)
Populate CGN based on the calls inside the associated function.
void addToCallGraph(Function *F)
Add a function to the call graph, and link the node to all of the functions that it calls.
const_iterator begin() const
CallGraphNode * getOrInsertFunction(const Function *F)
Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist.
bool invalidate(Module &, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &)
FunctionMapTy::const_iterator const_iterator
CallGraphNode * getCallsExternalNode() const
Module & getModule() const
Returns the module the call graph corresponds to.
FunctionMapTy::iterator iterator
CallGraphNode * getExternalCallingNode() const
Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.
CallGraphNode * operator[](const Function *F)
Returns the call graph node for the provided function.
void ReplaceExternalCallEdge(CallGraphNode *Old, CallGraphNode *New)
Old node has been deleted, and New is to be used in its place, update the ExternalCallingNode.
const_iterator end() const
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
static NodeRef getEntryNode(CallGraphNode *CGN)
static ChildIteratorType child_end(NodeRef N)
static CallGraphNode * CGNGetValue(CGNPairTy P)
CallGraphNode::CallRecord CGNPairTy
static ChildIteratorType child_begin(NodeRef N)
std::pair< const Function *const, std::unique_ptr< CallGraphNode > > PairTy
static CallGraphNode * CGGetValuePtr(const PairTy &P)
static nodes_iterator nodes_begin(CallGraph *CG)
static nodes_iterator nodes_end(CallGraph *CG)
static NodeRef getEntryNode(CallGraph *CGN)
static ChildIteratorType child_begin(NodeRef N)
static ChildEdgeIteratorType child_edge_begin(NodeRef N)
const CallGraphNode::CallRecord & EdgeRef
CallGraphNode::CallRecord CGNPairTy
static NodeRef edge_dest(EdgeRef E)
static ChildIteratorType child_end(NodeRef N)
static ChildEdgeIteratorType child_edge_end(NodeRef N)
static NodeRef getEntryNode(const CallGraphNode *CGN)
CallGraphNode::const_iterator ChildEdgeIteratorType
static const CallGraphNode * CGNGetValue(CGNPairTy P)
static NodeRef getEntryNode(const CallGraph *CGN)
static nodes_iterator nodes_begin(const CallGraph *CG)
static const CallGraphNode * CGGetValuePtr(const PairTy &P)
static nodes_iterator nodes_end(const CallGraph *CG)
std::pair< const Function *const, std::unique_ptr< CallGraphNode > > PairTy
A CRTP mix-in to automatically provide informational APIs needed for passes.