24 : M(M), Root(nullptr), ExternalCallingNode(getOrInsertFunction(nullptr)),
32 Root = ExternalCallingNode;
37 CallsExternalNode->allReferencesDropped();
38 delete CallsExternalNode;
43 for (
auto &
I : FunctionMap)
44 I.second->allReferencesDropped();
46 for (
auto &
I : FunctionMap)
50 void CallGraph::addToCallGraph(
Function *
F) {
60 Root = ExternalCallingNode;
81 const Function *Callee =
CS.getCalledFunction();
94 OS <<
"CallGraph Root is: ";
98 OS <<
"<<null function: 0x" << Root <<
">>\n";
105 Nodes.
reserve(FunctionMap.size());
110 std::sort(Nodes.
begin(), Nodes.
end(),
113 if (
Function *RF = RHS->getFunction())
114 return LF->getName() < RF->getName();
116 return RHS->getFunction() !=
nullptr;
123 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
134 assert(CGN->
empty() &&
"Cannot remove function from call "
135 "graph if it references other functions!");
138 FunctionMap.erase(F);
150 assert(FunctionMap.count(From) &&
"No CallGraphNode for function!");
151 assert(!FunctionMap.count(To) &&
152 "Pointing CallGraphNode at a function that already exists");
153 FunctionMapTy::iterator
I = FunctionMap.find(From);
154 I->second->F =
const_cast<Function*
>(To);
155 FunctionMap[To] = I->second;
156 FunctionMap.erase(I);
167 assert((!F || F->
getParent() == &M) &&
"Function not in current module!");
177 OS <<
"Call graph node for function: '" << F->
getName() <<
"'";
179 OS <<
"Call graph node <<null function>>";
184 OS <<
" CS<" << I->first <<
"> calls ";
185 if (
Function *FI = I->second->getFunction())
186 OS <<
"function '" << FI->getName() <<
"'\n";
188 OS <<
"external node\n";
193 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
201 for (CalledFunctionsVector::iterator I = CalledFunctions.begin(); ; ++
I) {
202 assert(I != CalledFunctions.end() &&
"Cannot find callsite to remove!");
204 I->second->DropRef();
205 *I = CalledFunctions.back();
206 CalledFunctions.pop_back();
216 for (
unsigned i = 0, e = CalledFunctions.size(); i != e; ++i)
217 if (CalledFunctions[i].second == Callee) {
219 CalledFunctions[i] = CalledFunctions.back();
220 CalledFunctions.pop_back();
228 for (CalledFunctionsVector::iterator I = CalledFunctions.begin(); ; ++
I) {
229 assert(I != CalledFunctions.end() &&
"Cannot find callee to remove!");
231 if (CR.second == Callee && CR.first ==
nullptr) {
233 *I = CalledFunctions.back();
234 CalledFunctions.pop_back();
245 for (CalledFunctionsVector::iterator I = CalledFunctions.begin(); ; ++
I) {
246 assert(I != CalledFunctions.end() &&
"Cannot find callsite to remove!");
248 I->second->DropRef();
261 char CallGraphAnalysis::PassID;
292 OS <<
"No call graph has been built!\n";
300 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void push_back(const T &Elt)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A Module instance is used to store all the information related to an LLVM module. ...
InstrTy * getInstruction() const
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on...
void reserve(size_type N)
A node in the call graph for a module.
void dump() const
Print out this call graph node.
StringRef getName() const
Return a constant reference to the value's name.
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...
void addCalledFunction(CallSite CS, CallGraphNode *M)
Adds a function to the list of functions called by this one.
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.
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
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.
void initializeCallGraphWrapperPassPass(PassRegistry &)
Represent the analysis usage information of a pass.
~CallGraphWrapperPass() override
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void setPreservesAll()
Set by analyses that do not transform their input at all.
void print(raw_ostream &OS) const
The basic data container for the call graph of a Module of IR.
bool hasAddressTaken(const User **=nullptr) const
hasAddressTaken - returns true if there are any uses of this function other than direct calls or invo...
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
bool hasLocalLinkage() const
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
Module * getParent()
Get the module that this global value is contained inside of...
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...
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.
NodeTy * remove(iterator &IT)