52 #ifndef LLVM_ANALYSIS_CALLGRAPH_H
53 #define LLVM_ANALYSIS_CALLGRAPH_H
78 typedef std::map<const Function *, CallGraphNode *> FunctionMapTy;
81 FunctionMapTy FunctionMap;
127 assert(I != FunctionMap.end() &&
"Function not in callgraph!");
134 assert(I != FunctionMap.end() &&
"Function not in callgraph!");
179 assert(NumReferences == 0 &&
"Node deleted while references remain");
182 typedef std::vector<CallRecord>::iterator
iterator;
192 inline bool empty()
const {
return CalledFunctions.empty(); }
193 inline unsigned size()
const {
return (
unsigned)CalledFunctions.size(); }
201 assert(i < CalledFunctions.size() &&
"Invalid index");
202 return CalledFunctions[i].second;
217 while (!CalledFunctions.empty()) {
218 CalledFunctions.back().second->DropRef();
219 CalledFunctions.pop_back();
225 assert(CalledFunctions.empty() &&
226 "Cannot steal callsite information if I already have some");
227 std::swap(CalledFunctions, N->CalledFunctions);
240 I->second->DropRef();
241 *I = CalledFunctions.back();
242 CalledFunctions.pop_back();
272 std::vector<CallRecord> CalledFunctions;
276 unsigned NumReferences;
281 void DropRef() { --NumReferences; }
282 void AddRef() { ++NumReferences; }
285 void allReferencesDropped() { NumReferences = 0; }
298 static void *
ID() {
return (
void *)&PassID; }
317 std::unique_ptr<CallGraph> G;
352 return G->getExternalCallingNode();
356 return G->getCallsExternalNode();
371 return G->removeFunctionFromModule(CGN);
377 return G->getOrInsertFunction(F);
403 typedef std::pointer_to_unary_function<CGNPairTy, CallGraphNode *>
424 typedef std::pointer_to_unary_function<CGNPairTy, const CallGraphNode *>
447 typedef std::pair<const Function *, CallGraphNode *>
PairTy;
448 typedef std::pointer_to_unary_function<PairTy, CallGraphNode &>
DerefFun;
468 typedef std::pair<const Function *, const CallGraphNode *>
PairTy;
469 typedef std::pointer_to_unary_function<PairTy, const CallGraphNode &>
mapped_iterator< NodeType::iterator, CGNDerefFun > ChildIteratorType
const_iterator begin() const
mapped_iterator< CallGraph::const_iterator, DerefFun > nodes_iterator
const CallGraphNode * operator[](const Function *F) const
Returns the call graph node for the provided function.
const_iterator begin() const
A Module instance is used to store all the information related to an LLVM module. ...
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
InstrTy * getInstruction() const
mapped_iterator< NodeType::const_iterator, CGNDerefFun > ChildIteratorType
FunctionMapTy::iterator iterator
static const CallGraphNode & CGdereference(PairTy P)
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.
void dump() const
Print out this call graph node.
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
void addCalledFunction(CallSite CS, CallGraphNode *M)
Adds a function to the list of functions called by this one.
static NodeType * getEntryNode(CallGraphNode *CGN)
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
std::pointer_to_unary_function< CGNPairTy, CallGraphNode * > CGNDerefFun
void print(raw_ostream &OS) const
CallGraph run(Module *M)
Compute the CallGraph for the module M.
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.
std::pointer_to_unary_function< CGNPairTy, const CallGraphNode * > CGNDerefFun
CallGraphNode * operator[](const Function *F)
Returns the call graph node for the provided function.
static nodes_iterator nodes_begin(const CallGraph *CG)
mapped_iterator< ItTy, FuncTy > map_iterator(const ItTy &I, FuncTy F)
FunctionMapTy::const_iterator const_iterator
mapped_iterator< CallGraph::iterator, DerefFun > nodes_iterator
CallGraph::iterator iterator
const_iterator end() const
static NodeType * getEntryNode(const CallGraphNode *CGN)
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.
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)
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
CallGraphNode * getCallsExternalNode() const
void stealCalledFunctionsFrom(CallGraphNode *N)
Moves all the callee information from N to this node.
static NodeType * getEntryNode(const CallGraph *CGN)
Represent the analysis usage information of a pass.
~CallGraphWrapperPass() override
std::pointer_to_unary_function< PairTy, CallGraphNode & > DerefFun
Module & getModule() const
Returns the module the call graph corresponds to.
std::pair< const Function *, CallGraphNode * > PairTy
static ChildIteratorType child_end(NodeType *N)
CallGraph::const_iterator const_iterator
static CallGraphNode & CGdereference(PairTy P)
CallGraphNode(Function *F)
Creates a node for the specified function.
CallGraphNode::CallRecord CGNPairTy
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.
static ChildIteratorType child_end(NodeType *N)
std::pair< const Function *, const CallGraphNode * > PairTy
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
static CallGraphNode * CGNDeref(CGNPairTy P)
static ChildIteratorType child_begin(NodeType *N)
CallGraph & getCallGraph()
static ChildIteratorType child_begin(NodeType *N)
static NodeType * getEntryNode(CallGraph *CGN)
CallGraph Result
A formulaic typedef to inform clients of the result type.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
const CallGraphNode NodeType
std::pair< WeakVH, CallGraphNode * > CallRecord
A pair of the calling instruction (a call or invoke) and the call graph node being called...
std::vector< CallRecord >::const_iterator const_iterator
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...
std::vector< CallRecord > CalledFunctionsVector
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
std::pointer_to_unary_function< PairTy, const CallGraphNode & > DerefFun
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.
static const CallGraphNode * CGNDeref(CGNPairTy P)
const CallGraphNode * operator[](const Function *F) const
Returns the call graph node for the provided function.
CallGraphNode * getCallsExternalNode() const