Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFGNode.h
Go to the documentation of this file.
1//===- SVFGNode.h -- Sparse value-flow graph node-------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2018> <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 * SVFGNode.h
25 *
26 * Created on: 13 Sep. 2018
27 * Author: Yulei Sui
28 */
29
30#ifndef INCLUDE_MSSA_SVFGNODE_H_
31#define INCLUDE_MSSA_SVFGNODE_H_
32
33#include "Graphs/VFGNode.h"
34#include "Graphs/SVFGEdge.h"
35
36namespace SVF
37{
38
42class MRSVFGNode : public VFGNode
43{
44protected:
46
47 // This constructor can only be used by derived classes
49
50public:
52 inline const NodeBS& getPointsTo() const
53 {
54 return cpts;
55 }
56
57 inline const NodeBS getDefSVFVars() const override;
58
60
61 static inline bool classof(const MRSVFGNode *)
62 {
63 return true;
64 }
65 static inline bool classof(const VFGNode *node)
66 {
67 return isMRSVFGNodeKinds(node->getNodeKind());
68 }
69 static inline bool classof(const GenericVFGNodeTy *node)
70 {
71 return isMRSVFGNodeKinds(node->getNodeKind());
72 }
74
75 virtual const std::string toString() const override;
76};
77
78/*
79 * SVFG Node stands for entry chi node (address-taken variables)
80 */
82{
83private:
84 const MRVer* ver;
86
87public:
90 {
91 cpts = resVer->getMR()->getPointsTo();
92 ver = resVer;
94 }
95 inline const MRVer* getMRVer() const
96 {
97 return ver;
98 }
99 inline const FunEntryICFGNode* getFunEntryNode() const
100 {
101 return funEntryNode;
102 }
104
105 static inline bool classof(const FormalINSVFGNode *)
106 {
107 return true;
108 }
109 static inline bool classof(const VFGNode *node)
110 {
111 return node->getNodeKind() == FPIN;
112 }
113 static inline bool classof(const GenericVFGNodeTy *node)
114 {
115 return node->getNodeKind() == FPIN;
116 }
118
119 virtual const std::string toString() const;
120};
121
122
123/*
124 * SVFG Node stands for return mu node (address-taken variables)
125 */
127{
128private:
129 const MRVer* ver;
131
132public:
135
136 inline const FunExitICFGNode* getFunExitNode() const
137 {
138 return funExitNode;
139 }
140
141 inline const MRVer* getMRVer() const
142 {
143 return ver;
144 }
146
147 static inline bool classof(const FormalOUTSVFGNode *)
148 {
149 return true;
150 }
151 static inline bool classof(const VFGNode *node)
152 {
153 return node->getNodeKind() == FPOUT;
154 }
155 static inline bool classof(const GenericVFGNodeTy *node)
156 {
157 return node->getNodeKind() == FPOUT;
158 }
160
161 virtual const std::string toString() const;
162};
163
164
165/*
166 * SVFG Node stands for callsite mu node (address-taken variables)
167 */
169{
170private:
172 const MRVer* ver;
173public:
176 MRSVFGNode(id, APIN), cs(c)
177 {
178 cpts = mrver->getMR()->getPointsTo();
179 ver = mrver;
180 }
182 inline const CallICFGNode* getCallSite() const
183 {
184 return cs;
185 }
186
188 inline const MRVer* getMRVer() const
189 {
190 return ver;
191 }
192
193
195
196 static inline bool classof(const ActualINSVFGNode *)
197 {
198 return true;
199 }
200 static inline bool classof(const VFGNode *node)
201 {
202 return node->getNodeKind() == APIN;
203 }
204 static inline bool classof(const GenericVFGNodeTy *node)
205 {
206 return node->getNodeKind() == APIN;
207 }
209
210 virtual const std::string toString() const;
211};
212
213
214/*
215 * SVFG Node stands for callsite chi node (address-taken variables)
216 */
218{
219private:
221 const MRVer* ver;
222
223public:
225 ActualOUTSVFGNode(NodeID id, const CallICFGNode* cal, const MRVer* resVer):
227 {
228 cpts = resVer->getMR()->getPointsTo();
229 ver = resVer;
230 }
232 inline const CallICFGNode* getCallSite() const
233 {
234 return cs;
235 }
237 inline const MRVer* getMRVer() const
238 {
239 return ver;
240 }
242
243 static inline bool classof(const ActualOUTSVFGNode *)
244 {
245 return true;
246 }
247 static inline bool classof(const VFGNode *node)
248 {
249 return node->getNodeKind() == APOUT;
250 }
251 static inline bool classof(const GenericVFGNodeTy *node)
252 {
253 return node->getNodeKind() == APOUT;
254 }
256
257 virtual const std::string toString() const;
258};
259
260
261/*
262 * SVFG Node stands for a memory ssa phi node or formalIn or ActualOut
263 */
265{
266public:
268
269protected:
270 const MRVer* ver;
272
273public:
276 {
277 cpts = resVer->getMR()->getPointsTo();
278 ver = resVer;
279 }
281 inline const MRVer* getResVer() const
282 {
283 return ver;
284 }
286
287 inline const MRVer* getOpVer(u32_t pos) const
288 {
289 OPVers::const_iterator it = opVers.find(pos);
290 assert(it!=opVers.end() && "version is nullptr, did not rename?");
291 return it->second;
292 }
293 inline void setOpVer(u32_t pos, const MRVer* node)
294 {
295 opVers[pos] = node;
296 }
297 inline u32_t getOpVerNum() const
298 {
299 return opVers.size();
300 }
301 inline OPVers::const_iterator opVerBegin() const
302 {
303 return opVers.begin();
304 }
305 inline OPVers::const_iterator opVerEnd() const
306 {
307 return opVers.end();
308 }
310
312
313 static inline bool classof(const MSSAPHISVFGNode *)
314 {
315 return true;
316 }
317 static inline bool classof(const MRSVFGNode *node)
318 {
319 return isMSSAPHISVFGNodeKinds(node->getNodeKind());
320 }
321 static inline bool classof(const VFGNode *node)
322 {
323 return isMSSAPHISVFGNodeKinds(node->getNodeKind());
324 }
325 static inline bool classof(const GenericVFGNodeTy *node)
326 {
327 return isMSSAPHISVFGNodeKinds(node->getNodeKind());
328 }
330
331 virtual const std::string toString() const;
332};
333
334/*
335 * Intra MSSA PHI
336 */
338{
339
340public:
343 {
344 }
345
346 inline const MRVer* getMRVer() const
347 {
348 return getResVer();
349 }
350
351 inline OPVers::const_iterator opVerBegin() const
352 {
353 return opVers.begin();
354 }
355
356 inline OPVers::const_iterator opVerEnd() const
357 {
358 return opVers.end();
359 }
360
362
363 static inline bool classof(const IntraMSSAPHISVFGNode *)
364 {
365 return true;
366 }
367 static inline bool classof(const MSSAPHISVFGNode * node)
368 {
369 return node->getNodeKind() == MIntraPhi;
370 }
371 static inline bool classof(const MRSVFGNode *node)
372 {
373 return node->getNodeKind() == MIntraPhi;
374 }
375 static inline bool classof(const VFGNode *node)
376 {
377 return node->getNodeKind() == MIntraPhi;
378 }
379 static inline bool classof(const GenericVFGNodeTy *node)
380 {
381 return node->getNodeKind() == MIntraPhi;
382 }
384
385 virtual const std::string toString() const;
386};
387
388
389/*
390 * Inter MSSA PHI (formalIN/ActualOUT)
391 */
393{
394
395public:
400
401 inline bool isFormalINPHI() const
402 {
403 return (fun!=nullptr) && (callInst == nullptr);
404 }
405
406 inline bool isActualOUTPHI() const
407 {
408 return (fun==nullptr) && (callInst != nullptr);
409 }
410
411 inline const SVFFunction* getFun() const
412 {
413 assert(isFormalINPHI() && "expect a formal parameter phi");
414 return fun;
415 }
416
417 inline const CallICFGNode* getCallSite() const
418 {
419 assert(isActualOUTPHI() && "expect a actual return phi");
420 return callInst;
421 }
422
424
425 static inline bool classof(const InterMSSAPHISVFGNode *)
426 {
427 return true;
428 }
429 static inline bool classof(const MSSAPHISVFGNode * node)
430 {
431 return node->getNodeKind() == MInterPhi;
432 }
433 static inline bool classof(const MRSVFGNode *node)
434 {
435 return node->getNodeKind() == MInterPhi;
436 }
437 static inline bool classof(const VFGNode *node)
438 {
439 return node->getNodeKind() == MInterPhi;
440 }
441 static inline bool classof(const GenericVFGNodeTy *node)
442 {
443 return node->getNodeKind() == MInterPhi;
444 }
446
447 virtual const std::string toString() const;
448
449private:
452};
453
454/*
455 * Dummy node which encodes propagation of an object/version pair.
456 */
458{
459public:
463
464 NodeID getObject(void) const
465 {
466 return object;
467 }
468 Version getVersion(void) const
469 {
470 return version;
471 }
472
474
475 static inline bool classof(const DummyVersionPropSVFGNode *)
476 {
477 return true;
478 }
479
480 static inline bool classof(const VFGNode *node)
481 {
482 return node->getNodeKind() == DummyVProp;
483 }
484
485 static inline bool classof(const GenericVFGNodeTy *node)
486 {
487 return node->getNodeKind() == DummyVProp;
488 }
490
491 const NodeBS getDefSVFVars() const override;
492
493private:
496};
497
498
499} // End namespace SVF
500
501#endif /* INCLUDE_MSSA_SVFGNODE_H_ */
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:204
const MRVer * getMRVer() const
Ver.
Definition SVFGNode.h:188
virtual const std::string toString() const
Definition SVFG.cpp:78
const CallICFGNode * getCallSite() const
Callsite.
Definition SVFGNode.h:182
const CallICFGNode * cs
Definition SVFGNode.h:171
static bool classof(const ActualINSVFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:196
ActualINSVFGNode(NodeID id, const CallICFGNode *c, const MRVer *mrver)
Constructor.
Definition SVFGNode.h:175
const MRVer * ver
Definition SVFGNode.h:172
static bool classof(const VFGNode *node)
Definition SVFGNode.h:200
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:251
const CallICFGNode * cs
Definition SVFGNode.h:220
static bool classof(const VFGNode *node)
Definition SVFGNode.h:247
const CallICFGNode * getCallSite() const
Callsite.
Definition SVFGNode.h:232
virtual const std::string toString() const
Definition SVFG.cpp:89
static bool classof(const ActualOUTSVFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:243
const MRVer * ver
Definition SVFGNode.h:221
const MRVer * getMRVer() const
Ver.
Definition SVFGNode.h:237
ActualOUTSVFGNode(NodeID id, const CallICFGNode *cal, const MRVer *resVer)
Constructor.
Definition SVFGNode.h:225
static bool classof(const VFGNode *node)
Definition SVFGNode.h:480
DummyVersionPropSVFGNode(NodeID id, NodeID object, Version version)
Definition SVFGNode.h:460
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:485
const NodeBS getDefSVFVars() const override
Return the left hand side SVF Vars.
Definition SVFG.cpp:131
NodeID getObject(void) const
Definition SVFGNode.h:464
static bool classof(const DummyVersionPropSVFGNode *)
Methods to support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:475
Version getVersion(void) const
Definition SVFGNode.h:468
static bool classof(const FormalINSVFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:105
const MRVer * ver
Definition SVFGNode.h:84
FormalINSVFGNode(NodeID id, const MRVer *resVer, const FunEntryICFGNode *funEntry)
Constructor.
Definition SVFGNode.h:89
const MRVer * getMRVer() const
Definition SVFGNode.h:95
const FunEntryICFGNode * getFunEntryNode() const
Definition SVFGNode.h:99
virtual const std::string toString() const
Definition SVFG.cpp:57
const FunEntryICFGNode * funEntryNode
Definition SVFGNode.h:85
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:113
static bool classof(const VFGNode *node)
Definition SVFGNode.h:109
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:155
virtual const std::string toString() const
Definition SVFG.cpp:68
static bool classof(const VFGNode *node)
Definition SVFGNode.h:151
const MRVer * getMRVer() const
Definition SVFGNode.h:141
static bool classof(const FormalOUTSVFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:147
const FunExitICFGNode * getFunExitNode() const
Definition SVFGNode.h:136
const MRVer * ver
Definition SVFGNode.h:129
const FunExitICFGNode * funExitNode
Definition SVFGNode.h:130
static bool classof(const MSSAPHISVFGNode *node)
Definition SVFGNode.h:429
static bool classof(const MRSVFGNode *node)
Definition SVFGNode.h:433
virtual const std::string toString() const
Definition SVFG.cpp:138
bool isFormalINPHI() const
Definition SVFGNode.h:401
bool isActualOUTPHI() const
Definition SVFGNode.h:406
const CallICFGNode * getCallSite() const
Definition SVFGNode.h:417
static bool classof(const InterMSSAPHISVFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:425
InterMSSAPHISVFGNode(NodeID id, const FormalINSVFGNode *fi)
Constructor interPHI for formal parameter.
Definition SVFGNode.h:397
static bool classof(const VFGNode *node)
Definition SVFGNode.h:437
const SVFFunction * fun
Definition SVFGNode.h:450
const CallICFGNode * callInst
Definition SVFGNode.h:451
const SVFFunction * getFun() const
Get the function of this SVFGNode.
Definition SVFGNode.h:411
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:441
InterMSSAPHISVFGNode(NodeID id, const ActualOUTSVFGNode *ao)
Constructor interPHI for actual return.
Definition SVFGNode.h:399
static bool classof(const MRSVFGNode *node)
Definition SVFGNode.h:371
static bool classof(const VFGNode *node)
Definition SVFGNode.h:375
OPVers::const_iterator opVerEnd() const
Definition SVFGNode.h:356
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:379
IntraMSSAPHISVFGNode(NodeID id, const MRVer *resVer)
Constructor.
Definition SVFGNode.h:342
virtual const std::string toString() const
Definition SVFG.cpp:122
static bool classof(const MSSAPHISVFGNode *node)
Definition SVFGNode.h:367
static bool classof(const IntraMSSAPHISVFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:363
const MRVer * getMRVer() const
Definition SVFGNode.h:346
OPVers::const_iterator opVerBegin() const
Definition SVFGNode.h:351
static bool classof(const MRSVFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:61
virtual const std::string toString() const override
Definition SVFG.cpp:49
MRSVFGNode(NodeID id, VFGNodeK k)
Definition SVFGNode.h:48
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:69
static bool classof(const VFGNode *node)
Definition SVFGNode.h:65
const NodeBS & getPointsTo() const
Return points-to of the MR.
Definition SVFGNode.h:52
const NodeBS getDefSVFVars() const override
Return the left hand side SVF Vars.
Definition SVFG.cpp:44
const MemRegion * getMR() const
Return the memory region.
Definition MSSAMuChi.h:63
virtual const std::string toString() const
Definition SVFG.cpp:101
const MRVer * getOpVer(u32_t pos) const
MSSA phi operands.
Definition SVFGNode.h:287
Map< u32_t, const MRVer * > OPVers
Definition SVFGNode.h:267
OPVers::const_iterator opVerEnd() const
Definition SVFGNode.h:305
static bool classof(const MRSVFGNode *node)
Definition SVFGNode.h:317
const MRVer * ver
Definition SVFGNode.h:270
void setOpVer(u32_t pos, const MRVer *node)
Definition SVFGNode.h:293
const MRVer * getResVer() const
Ver.
Definition SVFGNode.h:281
static bool classof(const GenericVFGNodeTy *node)
Definition SVFGNode.h:325
static bool classof(const VFGNode *node)
Definition SVFGNode.h:321
static bool classof(const MSSAPHISVFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition SVFGNode.h:313
OPVers::const_iterator opVerBegin() const
Definition SVFGNode.h:301
MSSAPHISVFGNode(NodeID id, const MRVer *resVer, VFGNodeK k=MPhi)
Constructor.
Definition SVFGNode.h:275
u32_t getOpVerNum() const
Definition SVFGNode.h:297
const NodeBS & getPointsTo() const
Return points-to.
Definition MemRegion.h:83
NodeID id
Node ID.
static bool isMRSVFGNodeKinds(GNodeK n)
GNodeK getNodeKind() const
Get node kind.
static bool isMSSAPHISVFGNodeKinds(GNodeK n)
for isBitcode
Definition BasicTypes.h:68
u32_t NodeID
Definition GeneralType.h:55
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned Version
unsigned u32_t
Definition GeneralType.h:46