46 #ifndef LLVM_ANALYSIS_CALLGRAPH_H
47 #define LLVM_ANALYSIS_CALLGRAPH_H
73 typedef std::map<const Function *, std::unique_ptr<CallGraphNode>>
77 FunctionMapTy FunctionMap;
85 std::unique_ptr<CallGraphNode> CallsExternalNode;
120 assert(I != FunctionMap.end() &&
"Function not in callgraph!");
121 return I->second.get();
127 assert(I != FunctionMap.end() &&
"Function not in callgraph!");
128 return I->second.get();
136 return CallsExternalNode.get();
165 typedef std::pair<WeakTrackingVH, CallGraphNode *>
CallRecord;
174 assert(NumReferences == 0 &&
"Node deleted while references remain");
177 typedef std::vector<CallRecord>::iterator
iterator;
187 inline bool empty()
const {
return CalledFunctions.empty(); }
188 inline unsigned size()
const {
return (
unsigned)CalledFunctions.size(); }
196 assert(i < CalledFunctions.size() &&
"Invalid index");
197 return CalledFunctions[i].second;
212 while (!CalledFunctions.empty()) {
213 CalledFunctions.back().second->DropRef();
214 CalledFunctions.pop_back();
220 assert(CalledFunctions.empty() &&
221 "Cannot steal callsite information if I already have some");
222 std::swap(CalledFunctions, N->CalledFunctions);
235 I->second->DropRef();
236 *I = CalledFunctions.back();
237 CalledFunctions.pop_back();
267 std::vector<CallRecord> CalledFunctions;
271 unsigned NumReferences;
276 void DropRef() { --NumReferences; }
277 void AddRef() { ++NumReferences; }
280 void allReferencesDropped() { NumReferences = 0; }
319 std::unique_ptr<CallGraph> G;
354 return G->getExternalCallingNode();
358 return G->getCallsExternalNode();
373 return G->removeFunctionFromModule(CGN);
379 return G->getOrInsertFunction(F);
446 typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
449 return P.second.get();
469 typedef std::pair<const Function *const, std::unique_ptr<CallGraphNode>>
472 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::pair< WeakTrackingVH, CallGraphNode * > CallRecord
A pair of the calling instruction (a call or invoke) and the call graph node being called...
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.
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...
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
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
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