20 :
ModulePass(
ID), Root(0), ExternalCallingNode(0), CallsExternalNode(0) {
24 void CallGraph::addToCallGraph(
Function *
F) {
34 Root = ExternalCallingNode;
55 const Function *Callee = CS.getCalledFunction();
73 assert(!CallsExternalNode);
83 Root = ExternalCallingNode;
94 if (CallsExternalNode) {
95 CallsExternalNode->allReferencesDropped();
96 delete CallsExternalNode;
97 CallsExternalNode = 0;
100 if (FunctionMap.empty())
106 for (FunctionMapTy::iterator
I = FunctionMap.begin(), E = FunctionMap.end();
108 I->second->allReferencesDropped();
111 for (FunctionMapTy::iterator
I = FunctionMap.begin(), E = FunctionMap.end();
118 OS <<
"CallGraph Root is: ";
122 OS <<
"<<null function: 0x" << Root <<
">>\n";
126 I->second->print(OS);
128 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
145 assert(CGN->
empty() &&
"Cannot remove function from call "
146 "graph if it references other functions!");
149 FunctionMap.erase(F);
161 assert(FunctionMap.count(From) &&
"No CallGraphNode for function!");
162 assert(!FunctionMap.count(To) &&
163 "Pointing CallGraphNode at a function that already exists");
164 FunctionMapTy::iterator
I = FunctionMap.find(From);
165 I->second->F =
const_cast<Function*
>(To);
166 FunctionMap[To] = I->second;
167 FunctionMap.erase(I);
177 assert((!F || F->
getParent() == Mod) &&
"Function not in current module!");
183 OS <<
"Call graph node for function: '" << F->
getName() <<
"'";
185 OS <<
"Call graph node <<null function>>";
190 OS <<
" CS<" << I->first <<
"> calls ";
191 if (
Function *FI = I->second->getFunction())
192 OS <<
"function '" << FI->getName() <<
"'\n";
194 OS <<
"external node\n";
199 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
207 for (CalledFunctionsVector::iterator I = CalledFunctions.begin(); ; ++
I) {
208 assert(I != CalledFunctions.end() &&
"Cannot find callsite to remove!");
210 I->second->DropRef();
211 *I = CalledFunctions.back();
212 CalledFunctions.pop_back();
222 for (
unsigned i = 0, e = CalledFunctions.size(); i != e; ++i)
223 if (CalledFunctions[i].second == Callee) {
225 CalledFunctions[i] = CalledFunctions.back();
226 CalledFunctions.pop_back();
234 for (CalledFunctionsVector::iterator I = CalledFunctions.begin(); ; ++
I) {
235 assert(I != CalledFunctions.end() &&
"Cannot find callee to remove!");
237 if (CR.second == Callee && CR.first == 0) {
239 *I = CalledFunctions.back();
240 CalledFunctions.pop_back();
251 for (CalledFunctionsVector::iterator I = CalledFunctions.begin(); ; ++
I) {
252 assert(I != CalledFunctions.end() &&
"Cannot find callsite to remove!");
254 I->second->DropRef();
static PassRegistry * getPassRegistry()
The main container class for the LLVM Intermediate Representation.
StringRef getName() const
Function * getFunction() const
unsigned getNumReferences() const
void removeOneAbstractEdgeTo(CallGraphNode *Callee)
void addCalledFunction(CallSite CS, CallGraphNode *M)
void replaceCallEdge(CallSite CS, CallSite NewCS, CallGraphNode *NewNode)
Function * removeFunctionFromModule(CallGraphNode *CGN)
ID
LLVM Calling Convention Representation.
FunctionMapTy::const_iterator const_iterator
bool hasAddressTaken(const User **=0) const
void removeAnyCallEdgeTo(CallGraphNode *Callee)
InstrTy * getInstruction() const
virtual void getAnalysisUsage(AnalysisUsage &AU) const
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
void initializeCallGraphPass(PassRegistry &)
void print(raw_ostream &OS) const
bool isDeclaration() const
bool hasLocalLinkage() const
virtual bool runOnModule(Module &M)
std::vector< CallRecord >::const_iterator const_iterator
#define DEFINING_FILE_FOR(name)
CallGraphNode * getOrInsertFunction(const Function *F)
void removeCallEdgeFor(CallSite CS)
std::pair< WeakVH, CallGraphNode * > CallRecord
void print(raw_ostream &o, const Module *) const
NodeTy * remove(iterator &IT)