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
47public:
57
59
60public:
67
69
70 inline bool isCFGEdge() const
71 {
72 return getEdgeKind() == IntraCF || getEdgeKind() == CallCF ||
73 getEdgeKind() == RetCF;
74 }
75 inline bool isCallCFGEdge() const
76 {
77 return getEdgeKind() == CallCF;
78 }
79 inline bool isRetCFGEdge() const
80 {
81 return getEdgeKind() == RetCF;
82 }
83 inline bool isIntraCFGEdge() const
84 {
85 return getEdgeKind() == IntraCF;
86 }
92 {
93 return (cs << EdgeKindMaskBits) | k;
94 }
95
97
99 {
100 o << edge.toString();
101 return o;
102 }
104
105 virtual const std::string toString() const;
106};
107
111class IntraCFGEdge : public ICFGEdge
112{
113 friend class ICFG;
114 friend class SVFIRBuilder;
115
116public:
123
124 static inline bool classof(const IntraCFGEdge*)
125 {
126 return true;
127 }
128 static inline bool classof(const ICFGEdge* edge)
129 {
130 return edge->getEdgeKind() == IntraCF;
131 }
132 static inline bool classof(const GenericICFGEdgeTy* edge)
133 {
134 return edge->getEdgeKind() == IntraCF;
135 }
137
138 const SVFVar* getCondition() const
139 {
140 return conditionVar;
141 }
142
144 {
145 assert(getCondition() && "this is not a conditional branch edge");
146 return branchCondVal;
147 }
148
149 virtual const std::string toString() const;
150
151private:
163
164 inline void setConditionVar(const SVFVar* c)
165 {
166 conditionVar = c;
167 }
168
170 {
172 }
173};
174
178class CallCFGEdge : public ICFGEdge
179{
180
181private:
182 std::vector<const CallPE*> callPEs;
183
184public:
187 : ICFGEdge(s, d, CallCF)
188 {
189 }
191 inline void addCallPE(const CallPE* callPE)
192 {
193 callPEs.push_back(callPE);
194 }
196 inline const CallICFGNode* getCallSite() const
197 {
198 assert(SVFUtil::isa<CallICFGNode>(getSrcNode()) && "not a CallICFGNode?");
199 return SVFUtil::cast<CallICFGNode>(getSrcNode());
200 }
202 inline const std::vector<const CallPE*>& getCallPEs() const
203 {
204 return callPEs;
205 }
207
208 static inline bool classof(const CallCFGEdge*)
209 {
210 return true;
211 }
212 static inline bool classof(const ICFGEdge* edge)
213 {
214 return edge->getEdgeKind() == CallCF;
215 }
216 static inline bool classof(const GenericICFGEdgeTy* edge)
217 {
218 return edge->getEdgeKind() == CallCF;
219 }
221 virtual const std::string toString() const;
222};
223
227class RetCFGEdge : public ICFGEdge
228{
229
230private:
231 const RetPE* retPE;
232
233public:
240 inline void addRetPE(const RetPE* ret)
241 {
242 assert(!retPE && "we can only have one retPE for each RetCFGEdge");
243 retPE = ret;
244 }
246 inline const RetPE* getRetPE() const
247 {
248 return retPE;
249 }
251 const CallICFGNode* getCallSite() const;
252
254
255 static inline bool classof(const RetCFGEdge*)
256 {
257 return true;
258 }
259 static inline bool classof(const ICFGEdge* edge)
260 {
261 return edge->getEdgeKind() == RetCF;
262 }
263 static inline bool classof(const GenericICFGEdgeTy* edge)
264 {
265 return edge->getEdgeKind() == RetCF;
266 }
268 virtual const std::string toString() const;
269};
270
271} // End namespace SVF
272
273#endif /* ICFGEdge_H_ */
virtual const std::string toString() const
Definition ICFG.cpp:185
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:212
static bool classof(const CallCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:208
const CallICFGNode * getCallSite() const
Return call ICFGNode at the callsite.
Definition ICFGEdge.h:196
std::vector< const CallPE * > callPEs
Definition ICFGEdge.h:182
const std::vector< const CallPE * > & getCallPEs() const
Add get parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:202
void addCallPE(const CallPE *callPE)
Add call parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:191
CallCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:186
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:216
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:91
ICFGEdgeK SVFGEdgeK
Definition ICFGEdge.h:58
bool isCallCFGEdge() const
Definition ICFGEdge.h:75
bool isCFGEdge() const
Get methods of the components.
Definition ICFGEdge.h:70
GenericNode< ICFGNode, ICFGEdge >::GEdgeSetTy ICFGEdgeSetTy
Definition ICFGEdge.h:88
bool isIntraCFGEdge() const
Definition ICFGEdge.h:83
~ICFGEdge()
Destructor.
Definition ICFGEdge.h:66
virtual const std::string toString() const
Definition ICFG.cpp:165
friend OutStream & operator<<(OutStream &o, const ICFGEdge &edge)
Overloading operator << for dumping ICFG node ID.
Definition ICFGEdge.h:98
ICFGEdge(ICFGNode *s, ICFGNode *d, GEdgeFlag k)
Constructor.
Definition ICFGEdge.h:62
ICFGEdgeSetTy SVFGEdgeSetTy
Definition ICFGEdge.h:89
bool isRetCFGEdge() const
Definition ICFGEdge.h:79
s64_t getSuccessorCondValue() const
Definition ICFGEdge.h:143
virtual const std::string toString() const
Definition ICFG.cpp:173
void setConditionVar(const SVFVar *c)
Definition ICFGEdge.h:164
const SVFVar * conditionVar
Definition ICFGEdge.h:161
static bool classof(const IntraCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:124
void setBranchCondVal(s64_t bVal)
Definition ICFGEdge.h:169
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:132
const SVFVar * getCondition() const
Definition ICFGEdge.h:138
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:128
IntraCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:118
const CallICFGNode * getCallSite() const
Return call ICFGNode at the callsite.
Definition ICFG.cpp:204
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:263
void addRetPE(const RetPE *ret)
Add call parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:240
RetCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:235
static bool classof(const RetCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:255
const RetPE * getRetPE() const
Add get parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:246
virtual const std::string toString() const
Definition ICFG.cpp:194
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:259
const RetPE * retPE
Definition ICFGEdge.h:231
for isBitcode
Definition BasicTypes.h:68
unsigned CallSiteID
Definition GeneralType.h:58
std::ostream OutStream
Definition GeneralType.h:46
GenericEdge< ICFGNode > GenericICFGEdgeTy
Definition ICFGEdge.h:43
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
signed long long s64_t
Definition GeneralType.h:50