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 friend class GraphDBClient;
116
117public:
124
125 static inline bool classof(const IntraCFGEdge*)
126 {
127 return true;
128 }
129 static inline bool classof(const ICFGEdge* edge)
130 {
131 return edge->getEdgeKind() == IntraCF;
132 }
133 static inline bool classof(const GenericICFGEdgeTy* edge)
134 {
135 return edge->getEdgeKind() == IntraCF;
136 }
138
139 const SVFVar* getCondition() const
140 {
141 return conditionVar;
142 }
143
145 {
146 assert(getCondition() && "this is not a conditional branch edge");
147 return branchCondVal;
148 }
149
150 virtual const std::string toString() const;
151
152private:
164
165 inline void setConditionVar(const SVFVar* c)
166 {
167 conditionVar = c;
168 }
169
171 {
173 }
174};
175
179class CallCFGEdge : public ICFGEdge
180{
181
182private:
183 std::vector<const CallPE*> callPEs;
184
185public:
188 : ICFGEdge(s, d, CallCF)
189 {
190 }
192 inline void addCallPE(const CallPE* callPE)
193 {
194 callPEs.push_back(callPE);
195 }
197 inline const CallICFGNode* getCallSite() const
198 {
199 assert(SVFUtil::isa<CallICFGNode>(getSrcNode()) && "not a CallICFGNode?");
200 return SVFUtil::cast<CallICFGNode>(getSrcNode());
201 }
203 inline const std::vector<const CallPE*>& getCallPEs() const
204 {
205 return callPEs;
206 }
208
209 static inline bool classof(const CallCFGEdge*)
210 {
211 return true;
212 }
213 static inline bool classof(const ICFGEdge* edge)
214 {
215 return edge->getEdgeKind() == CallCF;
216 }
217 static inline bool classof(const GenericICFGEdgeTy* edge)
218 {
219 return edge->getEdgeKind() == CallCF;
220 }
222 virtual const std::string toString() const;
223};
224
228class RetCFGEdge : public ICFGEdge
229{
230
231private:
232 const RetPE* retPE;
233
234public:
241 inline void addRetPE(const RetPE* ret)
242 {
243 assert(!retPE && "we can only have one retPE for each RetCFGEdge");
244 retPE = ret;
245 }
247 inline const RetPE* getRetPE() const
248 {
249 return retPE;
250 }
252 const CallICFGNode* getCallSite() const;
253
255
256 static inline bool classof(const RetCFGEdge*)
257 {
258 return true;
259 }
260 static inline bool classof(const ICFGEdge* edge)
261 {
262 return edge->getEdgeKind() == RetCF;
263 }
264 static inline bool classof(const GenericICFGEdgeTy* edge)
265 {
266 return edge->getEdgeKind() == RetCF;
267 }
269 virtual const std::string toString() const;
270};
271
272} // End namespace SVF
273
274#endif /* ICFGEdge_H_ */
virtual const std::string toString() const
Definition ICFG.cpp:174
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:213
static bool classof(const CallCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:209
const CallICFGNode * getCallSite() const
Return call ICFGNode at the callsite.
Definition ICFGEdge.h:197
std::vector< const CallPE * > callPEs
Definition ICFGEdge.h:183
const std::vector< const CallPE * > & getCallPEs() const
Add get parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:203
void addCallPE(const CallPE *callPE)
Add call parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:192
CallCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:187
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:217
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:154
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:144
virtual const std::string toString() const
Definition ICFG.cpp:162
void setConditionVar(const SVFVar *c)
Definition ICFGEdge.h:165
const SVFVar * conditionVar
Definition ICFGEdge.h:162
static bool classof(const IntraCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:125
friend class GraphDBClient
Definition ICFGEdge.h:115
void setBranchCondVal(s64_t bVal)
Definition ICFGEdge.h:170
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:133
const SVFVar * getCondition() const
Definition ICFGEdge.h:139
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:129
IntraCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:119
const CallICFGNode * getCallSite() const
Return call ICFGNode at the callsite.
Definition ICFG.cpp:193
static bool classof(const GenericICFGEdgeTy *edge)
Definition ICFGEdge.h:264
void addRetPE(const RetPE *ret)
Add call parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:241
RetCFGEdge(ICFGNode *s, ICFGNode *d)
Constructor.
Definition ICFGEdge.h:236
static bool classof(const RetCFGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGEdge.h:256
const RetPE * getRetPE() const
Add get parameter edge to this CallCFGEdge.
Definition ICFGEdge.h:247
virtual const std::string toString() const
Definition ICFG.cpp:183
static bool classof(const ICFGEdge *edge)
Definition ICFGEdge.h:260
const RetPE * retPE
Definition ICFGEdge.h:232
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