Static Value-Flow Analysis
Loading...
Searching...
No Matches
CallGraphBuilder.cpp
Go to the documentation of this file.
1//===- CallGraphBuilder.cpp ----------------------------------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23
24/*
25 * CallGraphBuilder.cpp
26 *
27 * Created on:
28 * Author: Yulei
29 */
30
31#include "Util/SVFUtil.h"
33#include "Graphs/ICFG.h"
34#include "SVFIR/SVFIR.h"
35#include "Graphs/CallGraph.h"
37
38using namespace SVF;
39using namespace SVFUtil;
40
42{
43 CallGraph* callgraph = new CallGraph();
44 for (const SVFFunction* svfFunc: svfModule->getFunctionSet())
45 {
46 callgraph->addCallGraphNode(svfFunc);
47 }
48
49 for (const auto& item : *callgraph)
50 {
51 for (const SVFBasicBlock* svfbb : (item.second)->getFunction()->getBasicBlockList())
52 {
53 for (const ICFGNode* inst : svfbb->getICFGNodeList())
54 {
56 {
57 const CallICFGNode* callBlockNode = cast<CallICFGNode>(inst);
58 if(const SVFFunction* callee = callBlockNode->getCalledFunction())
59 {
60 callgraph->addDirectCallGraphEdge(callBlockNode,(item.second)->getFunction(),callee);
61 }
62 }
63 }
64 }
65 }
66 return callgraph;
67}
68
74
76{
79
81 for (const auto& item: *svfirCallGraph)
82 {
83 for (const SVFBasicBlock* svfbb : (item.second)->getFunction()->getBasicBlockList())
84 {
85 for (const ICFGNode* inst : svfbb->getICFGNodeList())
86 {
87 if (SVFUtil::isa<CallICFGNode>(inst) && tdAPI->isTDFork(SVFUtil::cast<CallICFGNode>(inst)))
88 {
89 const CallICFGNode* cs = cast<CallICFGNode>(inst);
90 cg->addForksite(cs);
91 const ValVar* svfVar = tdAPI->getForkedFun(cs);
92 if (SVFUtil::isa<FunValVar>(svfVar))
93 {
94 cg->addDirectForkEdge(cs);
95 }
96 // indirect call to the start routine function
97 else
98 {
99 cg->addThreadForkEdgeSetMap(cs, nullptr);
100 }
101 }
102 }
103 }
104 }
105 // record join sites
106 for (const auto& item: *svfirCallGraph)
107 {
108 for (const SVFBasicBlock* svfbb : (item.second)->getFunction()->getBasicBlockList())
109 {
110 for (const ICFGNode* node : svfbb->getICFGNodeList())
111 {
112 if (SVFUtil::isa<CallICFGNode>(node) && tdAPI->isTDJoin(SVFUtil::cast<CallICFGNode>(node)))
113 {
114 const CallICFGNode* cs = SVFUtil::cast<CallICFGNode>(node);
115 cg->addJoinsite(cs);
116 }
117 }
118 }
119 }
120
121 return cg;
122}
cJSON * item
Definition cJSON.h:222
CallGraph * buildSVFIRCallGraph(SVFModule *svfModule)
Buidl SVFIR callgraoh.
ThreadCallGraph * buildThreadCallGraph()
Build thread-aware callgraph.
PTACallGraph * buildPTACallGraph()
Buidl PTA callgraoh.
void addCallGraphNode(const SVFFunction *fun)
Definition CallGraph.cpp:86
void addDirectCallGraphEdge(const CallICFGNode *call, const SVFFunction *callerFun, const SVFFunction *calleeFun)
Add direct call edges.
const SVFFunction * getCalledFunction() const
Definition ICFGNode.h:518
const std::vector< const SVFBasicBlock * > & getBasicBlockList() const
Definition SVFValue.h:456
CallGraph * getCallGraph()
Definition SVFIR.h:193
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
const FunctionSetType & getFunctionSet() const
Definition SVFModule.h:199
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:107
bool isNonInstricCallSite(const ICFGNode *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
Definition SVFUtil.h:189
for isBitcode
Definition BasicTypes.h:68
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74