Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::CallGraphBuilder Class Reference

#include <CallGraphBuilder.h>

Public Member Functions

 CallGraphBuilder ()=default
CallGraph * buildPAGCallGraph (const std::vector< const FunObjVar * > &funset)
 Buidl PAG callgraoh.
CallGraph * buildPTACallGraph ()
 Buidl PTA callgraoh.
ThreadCallGraph * buildThreadCallGraph ()
 Build thread-aware callgraph.

Detailed Description

Definition at line 41 of file CallGraphBuilder.h.

Constructor & Destructor Documentation

◆ CallGraphBuilder()

SVF::CallGraphBuilder::CallGraphBuilder ( )
default

Member Function Documentation

◆ buildPAGCallGraph()

CallGraph * CallGraphBuilder::buildPAGCallGraph ( const std::vector< const FunObjVar * > & funset)

Buidl PAG callgraoh.

Definition at line 41 of file CallGraphBuilder.cpp.

42{
43 CallGraph* callgraph = new CallGraph();
44 for (const FunObjVar* svfFunc: funset)
45 {
46 callgraph->addCallGraphNode(svfFunc);
47 }
48
49 for (const auto& item : *callgraph)
50 {
51 for (auto it : *(item.second)->getFunction())
52 {
53 const SVFBasicBlock* svfbb = it.second;
54 for (const ICFGNode* inst : svfbb->getICFGNodeList())
55 {
57 {
58 const CallICFGNode* callBlockNode = cast<CallICFGNode>(inst);
59 if(const FunObjVar* callee = callBlockNode->getCalledFunction())
60 {
61 callgraph->addDirectCallGraphEdge(callBlockNode,(item.second)->getFunction(),callee);
62 }
63 }
64 }
65 }
66 }
67 return callgraph;
68}
cJSON * item
Definition cJSON.h:222
void addCallGraphNode(CallGraphNode *cgNode)
add call graph node from database [only used this function when loading cgNodes from db results]
const FunObjVar * getCalledFunction() const
Definition ICFGNode.h:501
const std::vector< const ICFGNode * > & getICFGNodeList() const
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition Casting.h:360
bool isNonInstricCallSite(const ICFGNode *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
Definition SVFUtil.h:190

◆ buildPTACallGraph()

CallGraph * CallGraphBuilder::buildPTACallGraph ( )

Buidl PTA callgraoh.

Definition at line 70 of file CallGraphBuilder.cpp.

71{
72 return new CallGraph(*(PAG::getPAG()->getCallGraph()));
73}
static PAG * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition PAG.h:121

◆ buildThreadCallGraph()

ThreadCallGraph * CallGraphBuilder::buildThreadCallGraph ( )

Build thread-aware callgraph.

Definition at line 75 of file CallGraphBuilder.cpp.

76{
77 const CallGraph* pagCallGraph = PAG::getPAG()->getCallGraph();
78 ThreadCallGraph* cg = new ThreadCallGraph(*pagCallGraph);
79
80 ThreadAPI* tdAPI = ThreadAPI::getThreadAPI();
81 for (const auto& item: *pagCallGraph)
82 {
83 for (auto it : *(item.second)->getFunction())
84 {
85 const SVFBasicBlock* svfbb = it.second;
86 for (const ICFGNode* inst : svfbb->getICFGNodeList())
87 {
89 {
90 const CallICFGNode* cs = cast<CallICFGNode>(inst);
91 cg->addForksite(cs);
92 const ValVar* svfVar = tdAPI->getForkedFun(cs);
93 if (SVFUtil::isa<FunValVar>(svfVar))
94 {
95 cg->addDirectForkEdge(cs);
96 }
97 // indirect call to the start routine function
98 else
99 {
100 cg->addThreadForkEdgeSetMap(cs, nullptr);
101 }
102 }
103 }
104 }
105 }
106 // record join sites
107 for (const auto& item: *pagCallGraph)
108 {
109 for (auto it : *(item.second)->getFunction())
110 {
111 const SVFBasicBlock* svfbb = it.second;
112 for (const ICFGNode* node : svfbb->getICFGNodeList())
113 {
115 {
116 const CallICFGNode* cs = SVFUtil::cast<CallICFGNode>(node);
117 cg->addJoinsite(cs);
118 }
119 }
120 }
121 }
122
123 return cg;
124}
const CallGraph * getCallGraph()
Get CG.
Definition PAG.h:249
const ValVar * getForkedFun(const CallICFGNode *inst) const
bool isTDFork(const CallICFGNode *inst) const
Return true if this call create a new thread.
bool isTDJoin(const CallICFGNode *inst) const
Return true if this call wait for a worker thread.
static ThreadAPI * getThreadAPI()
Return a static reference.
Definition ThreadAPI.h:99
bool addDirectForkEdge(const CallICFGNode *cs)
Add direct/indirect thread fork edges.
bool addForksite(const CallICFGNode *cs)
Add fork sites which directly or indirectly create a thread.
bool addJoinsite(const CallICFGNode *cs)
void addThreadForkEdgeSetMap(const CallICFGNode *cs, ThreadForkEdge *edge)
map call instruction to its PTACallGraphEdge map
LLVM_NODISCARD bool isa(const Y &Val)
Definition Casting.h:241

The documentation for this class was generated from the following files: