Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
SVF::CDGBuilder Class Reference

#include <CDGBuilder.h>

Public Member Functions

 CDGBuilder ()
 constructor
 
 ~CDGBuilder ()
 destructor
 
void build ()
 start here
 
void buildControlDependence (const SVFModule *svfgModule)
 build control dependence for each function
 
void buildICFGNodeControlMap ()
 build map at icfg node level
 

Private Member Functions

void extractNodesBetweenPdomNodes (const SVFBasicBlock *succ, const SVFBasicBlock *LCA, std::vector< const SVFBasicBlock * > &tgtNodes)
 extract nodes between two nodes in pdom tree
 
void dfsNodesBetweenPdomNodes (const SVFBasicBlock *cur, const SVFBasicBlock *tgt, std::vector< const SVFBasicBlock * > &path, std::vector< const SVFBasicBlock * > &tgtNodes, SVFLoopAndDomInfo *ld)
 
s64_t getBBSuccessorBranchID (const SVFBasicBlock *BB, const SVFBasicBlock *Succ)
 
void updateMap (const SVFBasicBlock *pred, const SVFBasicBlock *bb, s32_t pos)
 update map
 

Static Private Member Functions

static void extractBBS (const SVFFunction *func, Map< const SVFBasicBlock *, std::vector< const SVFBasicBlock * > > &res)
 extract basic block edges to be processed
 

Private Attributes

CDG_controlDG
 
Map< const SVFBasicBlock *, Map< const SVFBasicBlock *, Set< s32_t > > > _svfcontrolMap
 map a basicblock to its controlling BBs (position, set of BBs)
 
Map< const SVFBasicBlock *, Map< const SVFBasicBlock *, Set< s32_t > > > _svfdependentOnMap
 map a basicblock to its dependent on BBs (position, set of BBs)
 
Map< const ICFGNode *, Map< const ICFGNode *, Set< s32_t > > > _nodeControlMap
 map an ICFG node to its controlling ICFG nodes (position, set of Nodes)
 
Map< const ICFGNode *, Map< const ICFGNode *, Set< s32_t > > > _nodeDependentOnMap
 map an ICFG node to its dependent on ICFG nodes (position, set of Nodes)
 

Detailed Description

Definition at line 38 of file CDGBuilder.h.

Constructor & Destructor Documentation

◆ CDGBuilder()

SVF::CDGBuilder::CDGBuilder ( )
inline

constructor

Definition at line 43 of file CDGBuilder.h.

44 {
45
46 }
static CDG * getCDG()
Singleton design here to make sure we only have one instance during any analysis.
Definition CDG.h:166

◆ ~CDGBuilder()

SVF::CDGBuilder::~CDGBuilder ( )
inline

destructor

Definition at line 49 of file CDGBuilder.h.

50 {
51
52 }

Member Function Documentation

◆ build()

void CDGBuilder::build ( )

start here

Start here

Definition at line 77 of file CDGBuilder.cpp.

78{
79 if (_controlDG->getTotalNodeNum() > 0)
80 return;
81 PAG *pag = PAG::getPAG();
84}
void buildControlDependence(const SVFModule *svfgModule)
build control dependence for each function
void buildICFGNodeControlMap()
build map at icfg node level
u32_t getTotalNodeNum() const
Get total number of node/edge.
SVFModule * getModule()
Definition SVFIR.h:162
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116

◆ buildControlDependence()

void CDGBuilder::buildControlDependence ( const SVFModule svfgModule)

build control dependence for each function

Build control dependence for each function

(1) construct CFG for each function (2) extract basic block edges (pred->succ) on the CFG to be processed succ does not post-dominates pred (!postDT->dominates(succ, pred)) (3) extract nodes from succ to the least common ancestor LCA of pred and succ including LCA if LCA is pred, excluding LCA if LCA is not pred

Parameters
svfgModule

Definition at line 124 of file CDGBuilder.cpp.

125{
127 for (const auto& item: *svfirCallGraph)
128 {
129 const SVFFunction *svfFun = (item.second)->getFunction();
130 if (SVFUtil::isExtCall(svfFun)) continue;
131 // extract basic block edges to be processed
134
135 for (const auto &item: BBS)
136 {
137 const SVFBasicBlock *pred = item.first;
138 // for each bb pair
139 for (const SVFBasicBlock *succ: item.second)
140 {
141 const SVFBasicBlock *SVFLCA = const_cast<SVFFunction *>(svfFun)->
142 getLoopAndDomInfo()->findNearestCommonPDominator(pred, succ);
143 std::vector<const SVFBasicBlock *> tgtNodes;
144 // no common ancestor, may be exit()
145 if (SVFLCA == NULL)
146 tgtNodes.push_back(succ);
147 else
148 {
149 if (SVFLCA == pred) tgtNodes.push_back(SVFLCA);
150 // from succ to LCA
152 }
153
155 for (const SVFBasicBlock *bb: tgtNodes)
156 {
157 updateMap(pred, bb, pos);
158 }
159 }
160 }
161 }
162}
cJSON * item
Definition cJSON.h:222
void updateMap(const SVFBasicBlock *pred, const SVFBasicBlock *bb, s32_t pos)
update map
Definition CDGBuilder.h:90
void extractNodesBetweenPdomNodes(const SVFBasicBlock *succ, const SVFBasicBlock *LCA, std::vector< const SVFBasicBlock * > &tgtNodes)
extract nodes between two nodes in pdom tree
static void extractBBS(const SVFFunction *func, Map< const SVFBasicBlock *, std::vector< const SVFBasicBlock * > > &res)
extract basic block edges to be processed
s64_t getBBSuccessorBranchID(const SVFBasicBlock *BB, const SVFBasicBlock *Succ)
CallGraph * getCallGraph()
Definition SVFIR.h:193
#define NULL
Definition extapi.c:2
const SVFFunction * getFunction(const std::string &name)
Get the corresponding Function based on its name.
Definition LLVMUtil.cpp:411
bool isExtCall(const SVFFunction *fun)
Definition SVFUtil.h:278
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
signed long long s64_t
Definition GeneralType.h:49

◆ buildICFGNodeControlMap()

void CDGBuilder::buildICFGNodeControlMap ( )

build map at icfg node level

Build map at ICFG node level

Definition at line 188 of file CDGBuilder.cpp.

189{
190 for (const auto &it: _svfcontrolMap)
191 {
192 for (const auto &it2: it.second)
193 {
194 const SVFBasicBlock *controllingBB = it2.first;
195 const ICFGNode *controlNode = it.first->getICFGNodeList().back();
196 if (const CallICFGNode* callNode =
197 SVFUtil::dyn_cast<CallICFGNode>(controlNode))
198 {
199 // not a branch statement:
200 // invoke void %3(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2)
201 // to label %invoke.cont1 unwind label %lpad
202 controlNode = callNode->getRetICFGNode();
203 }
204 if (!controlNode) continue;
205 // controlNode control at pos
206 for (const auto &controllee: controllingBB->getICFGNodeList())
207 {
208 _nodeControlMap[controlNode][controllee].insert(it2.second.begin(), it2.second.end());
209 _nodeDependentOnMap[controllee][controlNode].insert(it2.second.begin(), it2.second.end());
210 for (s32_t pos: it2.second)
211 {
212 if (const IntraICFGNode* intraNode =
214 {
215 assert(intraNode->getSVFStmts().size() == 1 &&
216 "not a branch stmt?");
217 const SVFVar* condition =
218 SVFUtil::cast<BranchStmt>(
219 intraNode->getSVFStmts().front())
220 ->getCondition();
222 condition,
223 pos);
224 }
225 else
226 {
227 // not a branch statement:
228 // invoke void %3(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2)
229 // to label %invoke.cont1 unwind label %lpad
230 SVFIR* pag = PAG::getPAG();
233 pag->getGNode(pag->getNullPtr()), pos);
234 }
235
236 }
237 }
238 }
239 }
240}
Map< const ICFGNode *, Map< const ICFGNode *, Set< s32_t > > > _nodeControlMap
map an ICFG node to its controlling ICFG nodes (position, set of Nodes)
Definition CDGBuilder.h:101
Map< const SVFBasicBlock *, Map< const SVFBasicBlock *, Set< s32_t > > > _svfcontrolMap
map a basicblock to its controlling BBs (position, set of BBs)
Definition CDGBuilder.h:99
Map< const ICFGNode *, Map< const ICFGNode *, Set< s32_t > > > _nodeDependentOnMap
map an ICFG node to its dependent on ICFG nodes (position, set of Nodes)
Definition CDGBuilder.h:102
void addCDGEdgeFromSrcDst(const ICFGNode *src, const ICFGNode *dst, const SVFVar *pNode, s32_t branchID)
Add CDG edges from nodeid pair.
Definition CDG.cpp:35
NodeType * getGNode(NodeID id) const
Get a node.
NodeID getNullPtr() const
Definition IRGraph.h:173
signed s32_t
Definition GeneralType.h:47

◆ dfsNodesBetweenPdomNodes()

void CDGBuilder::dfsNodesBetweenPdomNodes ( const SVFBasicBlock cur,
const SVFBasicBlock tgt,
std::vector< const SVFBasicBlock * > &  path,
std::vector< const SVFBasicBlock * > &  tgtNodes,
SVFLoopAndDomInfo ld 
)
private

Definition at line 35 of file CDGBuilder.cpp.

40{
41 path.push_back(cur);
42 if (cur == tgt)
43 {
44 tgtNodes.insert(tgtNodes.end(), path.begin() + 1, path.end());
45 }
46 else
47 {
48 auto it = ld->getPostDomTreeMap().find(cur);
49 for (const auto &nxt: it->second)
50 {
52 }
53 }
54 path.pop_back();
55}
void dfsNodesBetweenPdomNodes(const SVFBasicBlock *cur, const SVFBasicBlock *tgt, std::vector< const SVFBasicBlock * > &path, std::vector< const SVFBasicBlock * > &tgtNodes, SVFLoopAndDomInfo *ld)

◆ extractBBS()

void CDGBuilder::extractBBS ( const SVFFunction func,
Map< const SVFBasicBlock *, std::vector< const SVFBasicBlock * > > &  res 
)
staticprivate

extract basic block edges to be processed

(2) extract basic block edges on the CFG (pred->succ) to be processed succ does not post-dominates pred (!postDT->dominates(succ, pred))

Parameters
func
res

Definition at line 171 of file CDGBuilder.cpp.

173{
174 for (const auto &bb: *func)
175 {
176 for (const auto &succ: bb->getSuccessors())
177 {
178 if (func->postDominate(succ, bb))
179 continue;
180 res[bb].push_back(succ);
181 }
182 }
183}
bool postDominate(const SVFBasicBlock *bbKey, const SVFBasicBlock *bbValue) const
Definition SVFValue.h:521

◆ extractNodesBetweenPdomNodes()

void CDGBuilder::extractNodesBetweenPdomNodes ( const SVFBasicBlock succ,
const SVFBasicBlock LCA,
std::vector< const SVFBasicBlock * > &  tgtNodes 
)
private

extract nodes between two nodes in pdom tree

(3) extract nodes from succ to the least common ancestor LCA of pred and succ including LCA if LCA is pred, excluding LCA if LCA is not pred

Parameters
succ
LCA
tgtNodes

Definition at line 65 of file CDGBuilder.cpp.

67{
68 if (succ == LCA) return;
69 std::vector<const SVFBasicBlock *> path;
70 SVFLoopAndDomInfo *ld = const_cast<SVFFunction *>(LCA->getFunction())->getLoopAndDomInfo();
72}

◆ getBBSuccessorBranchID()

s64_t CDGBuilder::getBBSuccessorBranchID ( const SVFBasicBlock BB,
const SVFBasicBlock Succ 
)
private

Definition at line 87 of file CDGBuilder.cpp.

88{
89 ICFG *icfg = PAG::getPAG()->getICFG();
90 assert(!BB->getICFGNodeList().empty() && "empty bb?");
91 const ICFGNode *pred = BB->back();
93 {
94 // not a branch statement:
95 // invoke void %3(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2)
96 // to label %invoke.cont1 unwind label %lpad
97 pred = callNode->getRetICFGNode();
98 }
100 if (const IntraCFGEdge *intraEdge = SVFUtil::dyn_cast<IntraCFGEdge>(edge))
101 {
102 if(intraEdge->getCondition())
103 return intraEdge->getSuccessorCondValue();
104 else
105 return 0;
106 }
107 else
108 {
109 assert(false && "not intra edge?");
110 abort();
111 }
112}
ICFGEdge * getICFGEdge(const ICFGNode *src, const ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
Get a SVFG edge according to src and dst.
Definition ICFG.cpp:303
ICFG * getICFG() const
Definition SVFIR.h:172

◆ updateMap()

void SVF::CDGBuilder::updateMap ( const SVFBasicBlock pred,
const SVFBasicBlock bb,
s32_t  pos 
)
inlineprivate

update map

Definition at line 90 of file CDGBuilder.h.

91 {
92 _svfcontrolMap[pred][bb].insert(pos);
93 _svfdependentOnMap[bb][pred].insert(pos);
94 }
Map< const SVFBasicBlock *, Map< const SVFBasicBlock *, Set< s32_t > > > _svfdependentOnMap
map a basicblock to its dependent on BBs (position, set of BBs)
Definition CDGBuilder.h:100

Member Data Documentation

◆ _controlDG

CDG* SVF::CDGBuilder::_controlDG
private

Definition at line 98 of file CDGBuilder.h.

◆ _nodeControlMap

Map<const ICFGNode *, Map<const ICFGNode *, Set<s32_t> > > SVF::CDGBuilder::_nodeControlMap
private

map an ICFG node to its controlling ICFG nodes (position, set of Nodes)

Definition at line 101 of file CDGBuilder.h.

◆ _nodeDependentOnMap

Map<const ICFGNode *, Map<const ICFGNode *, Set<s32_t> > > SVF::CDGBuilder::_nodeDependentOnMap
private

map an ICFG node to its dependent on ICFG nodes (position, set of Nodes)

Definition at line 102 of file CDGBuilder.h.

◆ _svfcontrolMap

Map<const SVFBasicBlock *, Map<const SVFBasicBlock *, Set<s32_t> > > SVF::CDGBuilder::_svfcontrolMap
private

map a basicblock to its controlling BBs (position, set of BBs)

Definition at line 99 of file CDGBuilder.h.

◆ _svfdependentOnMap

Map<const SVFBasicBlock *, Map<const SVFBasicBlock *, Set<s32_t> > > SVF::CDGBuilder::_svfdependentOnMap
private

map a basicblock to its dependent on BBs (position, set of BBs)

Definition at line 100 of file CDGBuilder.h.


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