52 #ifndef LLVM_ANALYSIS_CALLGRAPH_H
53 #define LLVM_ANALYSIS_CALLGRAPH_H
79 typedef std::map<const Function *, std::unique_ptr<CallGraphNode>>
83 FunctionMapTy FunctionMap;
95 std::unique_ptr<CallGraphNode> CallsExternalNode;
130 assert(I != FunctionMap.end() &&
"Function not in callgraph!");
131 return I->second.get();
137 assert(I != FunctionMap.end() &&
"Function not in callgraph!");
138 return I->second.get();
146 return CallsExternalNode.get();
184 assert(NumReferences == 0 &&
"Node deleted while references remain");
187 typedef std::vector<CallRecord>::iterator
iterator;
197 inline bool empty()
const {
return CalledFunctions.empty(); }
198 inline unsigned size()
const {
return (
unsigned)CalledFunctions.size(); }
206 assert(i < CalledFunctions.size() &&
"Invalid index");
207 return CalledFunctions[
i].second;
222 while (!CalledFunctions.empty()) {
223 CalledFunctions.back().second->DropRef();
224 CalledFunctions.pop_back();
230 assert(CalledFunctions.empty() &&
231 "Cannot steal callsite information if I already have some");
232 std::swap(CalledFunctions, N->CalledFunctions);
245 I->second->DropRef();
246 *I = CalledFunctions.back();
247 CalledFunctions.pop_back();
277 std::vector<CallRecord> CalledFunctions;
281 unsigned NumReferences;
286 void DropRef() { --NumReferences; }
287 void AddRef() { ++NumReferences; }
290 void allReferencesDropped() { NumReferences = 0; }
329 std::unique_ptr<CallGraph> G;
364 return G->getExternalCallingNode();
368 return G->getCallsExternalNode();
383 return G->removeFunctionFromModule(CGN);
389 return G->getOrInsertFunction(F);
456 typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
459 return P.second.get();
479 typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
482 return P.second.get();
static const CallGraphNode * CGNGetValue(CGNPairTy P)
const_iterator begin() const
const CallGraphNode * operator[](const Function *F) const
Returns the call graph node for the provided function.
const_iterator begin() const
static CallGraphNode * CGNGetValue(CGNPairTy P)
A Module instance is used to store all the information related to an LLVM module. ...
void dump() const
Print out this call graph node.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
const CallGraphNode * NodeRef
FunctionMapTy::iterator iterator
mapped_iterator< CallGraph::iterator, decltype(&CGGetValuePtr)> nodes_iterator
CallGraphNode::CallRecord CGNPairTy
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on...
A node in the call graph for a module.
Module & getModule() const
Returns the module the call graph corresponds to.
Function * getFunction() const
Returns the function that this call graph node represents.
unsigned getNumReferences() const
Returns the number of other CallGraphNodes in this CallGraph that reference this node in their callee...
void removeOneAbstractEdgeTo(CallGraphNode *Callee)
Removes one edge associated with a null callsite from this node to the specified callee function...
const_iterator begin() const
static ChildIteratorType child_end(NodeRef N)
void addCalledFunction(CallSite CS, CallGraphNode *M)
Adds a function to the list of functions called by this one.
std::vector< CallRecord >::iterator iterator
static nodes_iterator nodes_end(const CallGraph *CG)
CallGraphNode * getOrInsertFunction(const Function *F)
Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist...
const_iterator end() const
void print(raw_ostream &OS) const
void replaceCallEdge(CallSite CS, CallSite NewCS, CallGraphNode *NewNode)
Replaces the edge in the node for the specified call site with a new one.
Function * removeFunctionFromModule(CallGraphNode *CGN)
Unlink the function from this module, returning it.
CallGraphNode * operator[](const Function *F)
Returns the call graph node for the provided function.
static nodes_iterator nodes_begin(const CallGraph *CG)
static const CallGraphNode * CGGetValuePtr(const PairTy &P)
static ChildIteratorType child_begin(NodeRef N)
static NodeRef getEntryNode(CallGraph *CGN)
A CRTP mix-in to automatically provide informational APIs needed for passes.
FunctionMapTy::const_iterator const_iterator
static NodeRef getEntryNode(CallGraphNode *CGN)
CallGraph::iterator iterator
std::pair< const Function *const, std::unique_ptr< CallGraphNode > > PairTy
const_iterator end() const
mapped_iterator< CallGraphNode::iterator, decltype(&CGNGetValue)> ChildIteratorType
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void removeAnyCallEdgeTo(CallGraphNode *Callee)
Removes all call edges from this node to the specified callee function.
A set of analyses that are preserved following a run of a transformation pass.
The ModulePass which wraps up a CallGraph and the logic to build it.
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
CallGraphNode * operator[](const Function *F)
Returns the call graph node for the provided function.
static nodes_iterator nodes_end(CallGraph *CG)
static nodes_iterator nodes_begin(CallGraph *CG)
CallGraphNode * getCallsExternalNode() const
void stealCalledFunctionsFrom(CallGraphNode *N)
Moves all the callee information from N to this node.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Represent the analysis usage information of a pass.
CallGraph run(Module &M, ModuleAnalysisManager &)
Compute the CallGraph for the module M.
~CallGraphWrapperPass() override
static ChildIteratorType child_begin(NodeRef N)
Module & getModule() const
Returns the module the call graph corresponds to.
static ChildIteratorType child_end(NodeRef N)
static NodeRef getEntryNode(const CallGraph *CGN)
CallGraph::const_iterator const_iterator
std::pair< const Function *const, std::unique_ptr< CallGraphNode > > PairTy
InstrTy * getInstruction() const
CallGraphNode(Function *F)
Creates a node for the specified function.
CallGraphNode::CallRecord CGNPairTy
static NodeRef getEntryNode(const CallGraphNode *CGN)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
mapped_iterator< CallGraphNode::const_iterator, decltype(&CGNGetValue)> ChildIteratorType
Function * removeFunctionFromModule(CallGraphNode *CGN)
Unlink the function from this module, returning it.
CallGraphNode * getExternalCallingNode() const
Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.
Value handle that asserts if the Value is deleted.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
void print(raw_ostream &OS) const
void removeCallEdge(iterator I)
An analysis pass to compute the CallGraph for a Module.
The basic data container for the call graph of a Module of IR.
void removeAllCalledFunctions()
Removes all edges from this CallGraphNode to any functions it calls.
CallGraphNode * operator[](unsigned i) const
Returns the i'th called function.
const_iterator end() const
CallGraph & getCallGraph()
CallGraph Result
A formulaic typedef to inform clients of the result type.
Printer pass for the CallGraphAnalysis results.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
std::pair< WeakVH, CallGraphNode * > CallRecord
A pair of the calling instruction (a call or invoke) and the call graph node being called...
CallGraphPrinterPass(raw_ostream &OS)
std::vector< CallRecord >::const_iterator const_iterator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static CallGraphNode * CGGetValuePtr(const PairTy &P)
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
const CallGraph & getCallGraph() const
The internal CallGraph around which the rest of this interface is wrapped.
CallGraphNode * getOrInsertFunction(const Function *F)
Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist...
void removeCallEdgeFor(CallSite CS)
Removes the edge in the node for the specified call site.
This class implements an extremely fast bulk output stream that can only output to a stream...
A container for analyses that lazily runs them and caches their results.
std::vector< CallRecord > CalledFunctionsVector
This header defines various interfaces for pass management in LLVM.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
CallGraphNode * getExternalCallingNode() const
Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.
void print(raw_ostream &o, const Module *) const override
print - Print out the internal state of the pass.
A special type used by analysis passes to provide an address that identifies that particular analysis...
mapped_iterator< CallGraph::const_iterator, decltype(&CGGetValuePtr)> nodes_iterator
const CallGraphNode * operator[](const Function *F) const
Returns the call graph node for the provided function.
CallGraphNode * getCallsExternalNode() const