Static Value-Flow Analysis
Loading...
Searching...
No Matches
ICFGEdge.h
Go to the documentation of this file.
1//===- ICFGEdge.h -- ICFG edge------------------------------------------------//
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 * ICFGEdge.h
25 *
26 * Created on: Sep 11, 2018
27 * Author: Yulei Sui
28 */
29
30#ifndef ICFGEdge_H_
31#define ICFGEdge_H_
32
33namespace SVF
34{
35
36class ICFGNode;
37class CallPE;
38class RetPE;
39
45{
46 friend class SVFIRWriter;
47 friend class SVFIRReader;
48
49public:
59
61
62public:
69
71
72 inline bool isCFGEdge() const
73 {
74 return getEdgeKind() == IntraCF || getEdgeKind() == CallCF ||
75 getEdgeKind() == RetCF;
76 }
77 inline bool isCallCFGEdge() const
78 {
79 return getEdgeKind() == CallCF;
80 }
81 inline bool isRetCFGEdge() const
82 {
83 return getEdgeKind() == RetCF;
84 }
85 inline bool isIntraCFGEdge() const
86 {
87 return getEdgeKind() == IntraCF;
88 }
94 {
95 return (cs << EdgeKindMaskBits) | k;
96 }
97
99
101 {
102 o << edge.toString();
103 return o;
104 }
106
107 virtual const std::string toString() const;
108};
109
113class IntraCFGEdge : public ICFGEdge
114{
115 friend class SVFIRWriter;
116 friend class SVFIRReader;
117 friend class ICFG;
118 friend class SVFIRBuilder;
119
120public:
127
128 static inline bool classof(const IntraCFGEdge*)
129 {
130 return true;
131 }
132 static inline bool classof(const ICFGEdge* edge)
133 {
134 return edge->getEdgeKind() == IntraCF;
135 }
136 static inline bool classof(const GenericICFGEdgeTy* edge)
137 {
138 return edge->getEdgeKind() == IntraCF;
139 }
141
142 const SVFVar* getCondition() const
143 {
144 return conditionVar;
145 }
146
148 {
149 assert(getCondition() && "this is not a conditional branch edge");
150 return branchCondVal;
151 }
152
153 virtual const std::string toString() const;
154
155private:
167
168 inline void setConditionVar(const SVFVar* c)
169 {
170 conditionVar = c;
171 }
172
174 {
176 }
177};
178
182class CallCFGEdge : public ICFGEdge
183{
184 friend class SVFIRWriter;
185 friend class SVFIRReader;
186
187private:
188 std::vector<const CallPE*> callPEs;
189
190public:
193 : ICFGEdge(s, d, CallCF)
194 {
195 }
197 inline void addCallPE(const CallPE* callPE)
198 {
199 callPEs.push_back(callPE);
200 }
202 inline const CallICFGNode* getCallSite() const
203 {
204 assert(SVFUtil::isa<CallICFGNode>(getSrcNode()) && "not a CallICFGNode?");
205 return SVFUtil::cast<CallICFGNode>(getSrcNode());
206 }
208 inline const std::vector<const CallPE*>& getCallPEs() const
209 {
210 return callPEs;
211 }
213
214 static inline bool classof(const CallCFGEdge*)
215 {
216 return true;
217 }
218 static inline bool classof(const ICFGEdge* edge)
219 {
220 return edge->getEdgeKind() == CallCF;
221 }
222 static inline bool classof(const GenericICFGEdgeTy* edge)
223 {
224 return edge->getEdgeKind() == CallCF;
225 }
227 virtual const std::string toString() const;
228};
229
233class RetCFGEdge : public ICFGEdge
234{
235 friend class SVFIRWriter;
236 friend class SVFIRReader;
237
238private:
239 const RetPE* retPE;
240
241public:
248 inline void addRetPE(const RetPE* ret)
249 {
250 assert(!retPE && "we can only have one retPE for each RetCFGEdge");
251 retPE = ret;
252 }
254 inline const RetPE* getRetPE() const
255 {
256 return retPE;
257 }
259 const CallICFGNode* getCallSite() const;
260
262
263 static inline bool classof(const RetCFGEdge*)
264 {
265 return true;
266 }
267 static inline bool classof(const ICFGEdge* edge)
268 {
269 return edge->getEdgeKind() == RetCF;
270 }
271 static inline bool classof(const GenericICFGEdgeTy* edge)
272 {
273 return edge->getEdgeKind() == RetCF;
274 }
276 virtual const std::string toString() const;
277};
278
279} // End namespace SVF
280
281#endif /* ICFGEdge_H_ */
virtual const std::string toString() const
Definition ICFG.cpp:177
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:218
static bool classof(const CallCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:214
const CallICFGNode * getCallSite() const
Return call ICFGNode at the callsite.
Definition ICFGEdge.h:202
std::vector< const CallPE * > callPEs
Definition ICFGEdge.h:188
const std::vector< const CallPE * > & getCallPEs() const
Add get parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:208
void addCallPE(const CallPE *callPE)
Add call parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:197
CallCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:192
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:222
NodeType * getSrcNode() const
GEdgeKind getEdgeKind() const
static constexpr unsigned char EdgeKindMaskBits
We use the lower 8 bits to denote edge kind.
OrderedSet< EdgeType *, typename EdgeType::equalGEdge > GEdgeSetTy
Edge kind.
static GEdgeFlag makeEdgeFlagWithInvokeID(GEdgeKind k, CallSiteID cs)
Compute the unique edgeFlag value from edge kind and CallSiteID.
Definition ICFGEdge.h:93
ICFGEdgeK SVFGEdgeK
Definition ICFGEdge.h:60
bool isCallCFGEdge() const
Definition ICFGEdge.h:77
bool isCFGEdge() const
Get methods of the components.
Definition ICFGEdge.h:72
GenericNode< ICFGNode, ICFGEdge >::GEdgeSetTy ICFGEdgeSetTy
Definition ICFGEdge.h:90
bool isIntraCFGEdge() const
Definition ICFGEdge.h:85
~ICFGEdge()
Destructor.
Definition ICFGEdge.h:68
virtual const std::string toString() const
Definition ICFG.cpp:157
friend OutStream & operator<<(OutStream &o, const ICFGEdge &edge)
Overloading operator << for dumping ICFG node ID.
Definition ICFGEdge.h:100
ICFGEdge(ICFGNode *s, ICFGNode *d, GEdgeFlag k)
Constructor.
Definition ICFGEdge.h:64
ICFGEdgeSetTy SVFGEdgeSetTy
Definition ICFGEdge.h:91
bool isRetCFGEdge() const
Definition ICFGEdge.h:81
s64_t getSuccessorCondValue() const
Definition ICFGEdge.h:147
virtual const std::string toString() const
Definition ICFG.cpp:165
void setConditionVar(const SVFVar *c)
Definition ICFGEdge.h:168
const SVFVar * conditionVar
Definition ICFGEdge.h:165
static bool classof(const IntraCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:128
void setBranchCondVal(s64_t bVal)
Definition ICFGEdge.h:173
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:136
const SVFVar * getCondition() const
Definition ICFGEdge.h:142
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:132
IntraCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:122
const CallICFGNode * getCallSite() const
Return call ICFGNode at the callsite.
Definition ICFG.cpp:196
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:271
void addRetPE(const RetPE *ret)
Add call parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:248
RetCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:243
static bool classof(const RetCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:263
const RetPE * getRetPE() const
Add get parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:254
virtual const std::string toString() const
Definition ICFG.cpp:186
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:267
const RetPE * retPE
Definition ICFGEdge.h:239
for isBitcode
Definition BasicTypes.h:68
unsigned CallSiteID
Definition GeneralType.h:58
std::ostream OutStream
Definition GeneralType.h:45
GenericEdge< ICFGNode > GenericICFGEdgeTy
Definition ICFGEdge.h:43
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
signed long long s64_t
Definition GeneralType.h:49