49 return fun->getName();
64 "not an indirect callsite??");
72 std::stringstream rawstr(str);
75 rawstr <<
"direct call";
77 rawstr <<
"indirect call";
85 std::stringstream rawstr(str);
86 rawstr <<
"CallGraphNode ID: " <<
getId() <<
" {fun: " <<
fun->getName() <<
"}";
98 [&reachableFromEntry, &visitedNodes, &dfs](
const CallGraphNode *v)
102 return reachableFromEntry[
id];
105 return reachableFromEntry[
id] =
true;
108 for (
const_iterator it = v->InEdgeBegin(), eit = v->InEdgeEnd(); it != eit; ++it)
115 return reachableFromEntry[
id] = result;
137 for (
const auto&
item : other)
166 csToIdMap.insert(std::make_pair(newCS, csid));
167 idToCSMap.insert(std::make_pair(csid, newCS));
193 if (outEdge && inEdge)
195 assert(outEdge == inEdge &&
"edges not match");
209 for (CallGraphEdge::CallGraphEdgeSet::iterator iter = src->
OutEdgeBegin();
251 for(CallGraphEdge::CallInstSet::const_iterator cit = (*it)->directCallsBegin(),
252 ecit = (*it)->directCallsEnd(); cit!=ecit; ++cit)
254 csSet.insert((*cit));
256 for(CallGraphEdge::CallInstSet::const_iterator cit = (*it)->indirectCallsBegin(),
257 ecit = (*it)->indirectCallsEnd(); cit!=ecit; ++cit)
259 csSet.insert((*cit));
273 for(CallGraphEdge::CallInstSet::const_iterator cit = (*it)->directCallsBegin(),
274 ecit = (*it)->directCallsEnd(); cit!=ecit; ++cit)
276 csSet.insert((*cit));
290 for(CallGraphEdge::CallInstSet::const_iterator cit = (*it)->indirectCallsBegin(),
291 ecit = (*it)->indirectCallsEnd(); cit!=ecit; ++cit)
293 csSet.insert((*cit));
310 for (; it != eit; ++it)
313 if (targets.empty() ==
false)
318 isReachableFromProgEntry(reachableFromEntry, visitedNodes) ==
false)
331 std::stack<const CallGraphNode*> nodeStack;
333 nodeStack.push(dstNode);
336 while (nodeStack.empty() ==
false)
388 for (
const auto&
item : *
this)
453 return "shape=record";
456 return "shape=Mrecord";
459 template<
class EdgeIter>
466 assert(edge &&
"No edge found!!");
472 color =
"color=green";
476 color =
"color=blue";
480 color =
"color=black";
489 template<
class EdgeIter>
493 assert(edge &&
"No edge found!!");
496 std::stringstream rawstr(str);
void addInDirectCallSite(const CallICFGNode *call)
void addDirectCallSite(const CallICFGNode *call)
Add direct and indirect callsite.
CallInstSet & getIndirectCalls()
CallInstSet indirectCalls
virtual const std::string toString() const
bool isDirectCallEdge() const
Set< const CallICFGNode * > CallInstSet
CallSiteID getCallSiteID() const
Get direct and indirect calls.
CallGraphNode(NodeID i, const FunObjVar *f)
Constructor.
const FunObjVar * getFunction() const
Get function of this call node.
const std::string & getName() const
virtual const std::string toString() const
bool isReachableFromProgEntry(Map< NodeID, bool > &reachableFromEntry, NodeBS &visitedNodes) const
Return TRUE if this function can be reached from main.
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
Map a call instruction to its corresponding call edges.
void getAllCallSitesInvokingCallee(const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
Get callsites invoking the callee.
void addIndirectCallGraphEdge(const CallICFGNode *cs, const FunObjVar *callerFun, const FunObjVar *calleeFun)
Add indirect call edges.
CallGraphEdge * hasGraphEdge(CallGraphEdge *cgEdge) const
Whether we have already created this call graph edge.
CallEdgeMap indirectCallMap
Indirect call map.
void addCallGraphNode(CallGraphNode *cgNode)
add call graph node from database [only used this function when loading cgNodes from db results]
void addEdge(CallGraphEdge *edge)
Add call graph edge.
const FunObjVar * getCallerOfCallSite(CallSiteID id) const
void getIndCallSitesInvokingCallee(const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
static IdToCallSiteMap idToCSMap
Map a callsite ID to a pair of call instruction and callee.
static CallSiteID totalCallSiteNum
CallSiteIDs, start from 1;.
Map< CallSiteID, CallSitePair > IdToCallSiteMap
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
void destroy()
Clean up memory.
CallSiteID addCallSite(const CallICFGNode *cs, const FunObjVar *callee)
Add CallSiteID.
FunToCallGraphNodeMap funToCallGraphNodeMap
Call Graph node map.
CallGraphEdgeSet::const_iterator CallGraphEdgeConstIter
CallGraph(CGEK k=NormCallGraph)
Constructor.
static CallSiteToIdMap csToIdMap
Call site information.
const CallICFGNode * getCallSite(CallSiteID id) const
bool isReachableBetweenFunctions(const FunObjVar *srcFn, const FunObjVar *dstFn) const
Whether its reachable between two functions.
void view()
View the graph from the debugger.
void dump(const std::string &filename)
Dump the graph.
void getDirCallSitesInvokingCallee(const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
void verifyCallGraph()
Issue a warning if the function which has indirect call sites can not be reached from program entry.
u32_t numOfResolvedIndCallEdge
CallGraphEdge * getGraphEdge(CallGraphNode *src, CallGraphNode *dst, CallGraphEdge::CEDGEK kind, CallSiteID csId)
Get call graph edge via nodes.
Map< CallSitePair, CallSiteID > CallSiteToIdMap
void addDirectCallGraphEdge(CallGraphEdge *cgEdge)
add direct call graph edge from database [only used this function when loading cgEdges from db result...
Set< const FunObjVar * > FunctionSet
const FunObjVar * getCalledFunction() const
const FunObjVar * getCaller() const
Return callsite.
NodeType * getSrcNode() const
NodeType * getDstNode() const
GEdgeKind getEdgeKind() const
void addGNode(NodeID id, NodeType *node)
u32_t getTotalNodeNum() const
Get total number of node/edge.
bool hasIncomingEdge() const
Has incoming/outgoing edge set.
bool hasOutgoingEdge() const
GEdgeSetTy::iterator iterator
iterator OutEdgeBegin()
iterators
GEdgeSetTy::const_iterator const_iterator
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType >, bool simple=false)
static const Option< bool > DisableWarn
NodeID getId() const
Get ID.
virtual const std::string & getName() const
bool test_and_set(unsigned Idx)
bool isProgEntryFunction(const FunObjVar *)
Program entry function e.g. main.
LLVM_NODISCARD bool isa(const Y &Val)
bool isExtCall(const FunObjVar *fun)
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
const ValVar * getForkedFun(const CallICFGNode *inst)
Return thread fork function.
std::ostream & outs()
Overwrite llvm::outs().
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
DOTGraphTraits(bool isSimple=false)
static std::string getNodeAttributes(CallGraphNode *node, CallGraph *)
static std::string getGraphName(CallGraph *)
Return name of the graph.
static std::string getNodeLabel(CallGraphNode *node, CallGraph *)
Return function name;.
static std::string getEdgeSourceLabel(NodeType *, EdgeIter EI)
static std::string getEdgeAttributes(CallGraphNode *, EdgeIter EI, CallGraph *)
NodeType::iterator ChildIteratorType
DefaultDOTGraphTraits(bool simple=false)