46 #ifndef LLVM_ANALYSIS_CALLGRAPH_H 47 #define LLVM_ANALYSIS_CALLGRAPH_H 78 std::map<const Function *, std::unique_ptr<CallGraphNode>>;
81 FunctionMapTy FunctionMap;
89 std::unique_ptr<CallGraphNode> CallsExternalNode;
124 assert(I != FunctionMap.end() &&
"Function not in callgraph!");
125 return I->second.get();
131 assert(I != FunctionMap.end() &&
"Function not in callgraph!");
132 return I->second.get();
140 return CallsExternalNode.get();
169 using CallRecord = std::pair<WeakTrackingVH, CallGraphNode *>;
181 assert(NumReferences == 0 &&
"Node deleted while references remain");
184 using iterator = std::vector<CallRecord>::iterator;
194 inline bool empty()
const {
return CalledFunctions.empty(); }
195 inline unsigned size()
const {
return (
unsigned)CalledFunctions.size(); }
203 assert(i < CalledFunctions.size() &&
"Invalid index");
204 return CalledFunctions[i].second;
219 while (!CalledFunctions.empty()) {
220 CalledFunctions.back().second->DropRef();
221 CalledFunctions.pop_back();
227 assert(CalledFunctions.empty() &&
228 "Cannot steal callsite information if I already have some");
229 std::swap(CalledFunctions, N->CalledFunctions);
242 I->second->DropRef();
243 *I = CalledFunctions.back();
244 CalledFunctions.pop_back();
250 void removeCallEdgeFor(
CallSite CS);
274 std::vector<CallRecord> CalledFunctions;
278 unsigned NumReferences = 0;
280 void DropRef() { --NumReferences; }
281 void AddRef() { ++NumReferences; }
284 void allReferencesDropped() { NumReferences = 0; }
325 std::unique_ptr<CallGraph>
G;
360 return G->getExternalCallingNode();
364 return G->getCallsExternalNode();
379 return G->removeFunctionFromModule(CGN);
385 return G->getOrInsertFunction(F);
393 bool runOnModule(
Module &M)
override;
394 void releaseMemory()
override;
457 std::pair<const Function *const, std::unique_ptr<CallGraphNode>>;
464 return P.second.get();
484 std::pair<const Function *const, std::unique_ptr<CallGraphNode>>;
491 return P.second.get();
509 #endif // LLVM_ANALYSIS_CALLGRAPH_H static const CallGraphNode * CGNGetValue(CGNPairTy P)
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
static CallGraphNode * CGNGetValue(CGNPairTy P)
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
FunctionMapTy::iterator iterator
const CallGraphNode::CallRecord & EdgeRef
A node in the call graph for a module.
Module & getModule() const
Returns the module the call graph corresponds to.
unsigned getNumReferences() const
Returns the number of other CallGraphNodes in this CallGraph that reference this node in their callee...
static ChildIteratorType child_end(NodeRef N)
void addCalledFunction(CallSite CS, CallGraphNode *M)
Adds a function to the list of functions called by this one.
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...
CallGraph::const_iterator const_iterator
Function * removeFunctionFromModule(CallGraphNode *CGN)
Unlink the function from this module, returning it.
InstrTy * getInstruction() const
CallGraphNode * getCallsExternalNode() const
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)
Module & getModule() const
Returns the module the call graph corresponds to.
CallGraphNode * operator[](unsigned i) const
Returns the i'th called function.
std::vector< CallRecord > CalledFunctionsVector
static ChildIteratorType child_begin(NodeRef N)
static NodeRef getEntryNode(CallGraph *CGN)
A CRTP mix-in to automatically provide informational APIs needed for passes.
static NodeRef getEntryNode(CallGraphNode *CGN)
amdgpu Simplify well known AMD library false Value * Callee
const CallGraphNode * operator[](const Function *F) const
Returns the call graph node for the provided function.
std::pair< const Function *const, std::unique_ptr< CallGraphNode > > PairTy
typename CallGraphNode *::UnknownGraphTypeError NodeRef
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 * getCallsExternalNode() const
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)
FunctionMapTy::const_iterator const_iterator
void stealCalledFunctionsFrom(CallGraphNode *N)
Moves all the callee information from N to this node.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const_iterator begin() const
A CRTP mix-in that provides informational APIs needed for analysis passes.
const_iterator begin() const
Represent the analysis usage information of a pass.
CallGraph run(Module &M, ModuleAnalysisManager &)
Compute the CallGraph for the module M.
static ChildIteratorType child_begin(NodeRef N)
std::pair< const Function *const, std::unique_ptr< CallGraphNode > > PairTy
static ChildIteratorType child_end(NodeRef N)
const CallGraph & getCallGraph() const
The internal CallGraph around which the rest of this interface is wrapped.
static NodeRef getEntryNode(const CallGraph *CGN)
Function * getFunction() const
Returns the function that this call graph node represents.
BlockVerifier::State From
CallGraphNode(Function *F)
Creates a node for the specified function.
CallGraphNode::const_iterator ChildEdgeIteratorType
static NodeRef getEntryNode(const CallGraphNode *CGN)
const_iterator begin() const
Function * removeFunctionFromModule(CallGraphNode *CGN)
Unlink the function from this module, returning it.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
static ChildEdgeIteratorType child_edge_end(NodeRef N)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
CallGraph::iterator iterator
amdgpu Simplify well known AMD library false Value Value * Arg
void removeCallEdge(iterator I)
An analysis pass to compute the CallGraph for a Module.
static NodeRef edge_dest(EdgeRef E)
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.
const_iterator end() const
CallGraph & getCallGraph()
std::pair< 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.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
CallGraphNode * getExternalCallingNode() const
Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.
CallGraphNode::CallRecord CGNPairTy
const_iterator end() const
std::vector< CallRecord >::iterator iterator
std::vector< CallRecord >::const_iterator const_iterator
CallGraphNode * getExternalCallingNode() const
Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
CallGraphPrinterPass(raw_ostream &OS)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static CallGraphNode * CGGetValuePtr(const PairTy &P)
CallGraphNode::CallRecord CGNPairTy
CallGraphNode * getOrInsertFunction(const Function *F)
Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist...
This class implements an extremely fast bulk output stream that can only output to a stream...
const_iterator end() const
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
A special type used by analysis passes to provide an address that identifies that particular analysis...
void print(raw_ostream &OS) const
static ChildEdgeIteratorType child_edge_begin(NodeRef N)
const CallGraphNode * operator[](const Function *F) const
Returns the call graph node for the provided function.