Static Value-Flow Analysis
ConsGNode.h
Go to the documentation of this file.
1 //===- ConsGNode.h -- Constraint graph node-----------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2017> <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  * ConsGNode.h
25  *
26  * Created on: Mar 19, 2014
27  * Author: Yulei Sui
28  */
29 
30 #ifndef CONSGNODE_H_
31 #define CONSGNODE_H_
32 
33 namespace SVF
34 {
35 
41 {
42 
43 public:
44  typedef ConstraintEdge::ConstraintEdgeSetTy::iterator iterator;
45  typedef ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator;
46  bool _isPWCNode;
47 
48 private:
51 
54 
59 
62 
65 
68 
69 public:
73 
75  {
76 
77  }
78 
80 
81  inline bool isPWCNode() const
82  {
83  return _isPWCNode;
84  }
85  inline void setPWCNode()
86  {
87  _isPWCNode = true;
88  }
90 
93  {
94  return (kind == ConstraintEdge::Copy || kind == ConstraintEdge::NormalGep || kind == ConstraintEdge::VariantGep );
95  }
97  {
98  return (kind == ConstraintEdge::Load || kind == ConstraintEdge::Store);
99  }
100 
102 
104  {
105  return directInEdges;
106  }
108  {
109  return directOutEdges;
110  }
112  {
113  return copyInEdges;
114  }
116  {
117  return copyOutEdges;
118  }
120  {
121  return gepInEdges;
122  }
124  {
125  return gepOutEdges;
126  }
128  {
129  return loadInEdges;
130  }
132  {
133  return loadOutEdges;
134  }
136  {
137  return storeInEdges;
138  }
140  {
141  return storeOutEdges;
142  }
144  {
145  return addressInEdges;
146  }
148  {
149  return addressOutEdges;
150  }
152 
154 
163 
165  {
166  return addressInEdges;
167  }
169  {
170  return addressOutEdges;
171  }
172 
174  {
175  return addressOutEdges.begin();
176  }
178  {
179  return addressOutEdges.end();
180  }
182  {
183  return addressInEdges.begin();
184  }
186  {
187  return addressInEdges.end();
188  }
189 
191  {
192  return loadOutEdges.begin();
193  }
195  {
196  return loadOutEdges.end();
197  }
199  {
200  return loadInEdges.begin();
201  }
203  {
204  return loadInEdges.end();
205  }
206 
208  {
209  return storeOutEdges.begin();
210  }
212  {
213  return storeOutEdges.end();
214  }
216  {
217  return storeInEdges.begin();
218  }
220  {
221  return storeInEdges.end();
222  }
224 
226 
227  inline void addIncomingCopyEdge(CopyCGEdge *inEdge)
228  {
229  addIncomingDirectEdge(inEdge);
230  copyInEdges.insert(inEdge);
231  }
232  inline void addIncomingGepEdge(GepCGEdge* inEdge)
233  {
234  addIncomingDirectEdge(inEdge);
235  gepInEdges.insert(inEdge);
236  }
237  inline void addOutgoingCopyEdge(CopyCGEdge *outEdge)
238  {
239  addOutgoingDirectEdge(outEdge);
240  copyOutEdges.insert(outEdge);
241  }
242  inline void addOutgoingGepEdge(GepCGEdge* outEdge)
243  {
244  addOutgoingDirectEdge(outEdge);
245  gepOutEdges.insert(outEdge);
246  }
247  inline void addIncomingAddrEdge(AddrCGEdge* inEdge)
248  {
249  addressInEdges.insert(inEdge);
250  addIncomingEdge(inEdge);
251  }
252  inline void addIncomingLoadEdge(LoadCGEdge* inEdge)
253  {
254  loadInEdges.insert(inEdge);
255  addIncomingEdge(inEdge);
256  }
257  inline void addIncomingStoreEdge(StoreCGEdge* inEdge)
258  {
259  storeInEdges.insert(inEdge);
260  addIncomingEdge(inEdge);
261  }
263  {
264  assert(inEdge->getDstID() == this->getId());
265  bool added1 = directInEdges.insert(inEdge).second;
266  bool added2 = addIncomingEdge(inEdge);
267  bool both_added = added1 & added2;
268  assert(both_added && "edge not added, duplicated adding!!");
269  return both_added;
270  }
271  inline void addOutgoingAddrEdge(AddrCGEdge* outEdge)
272  {
273  addressOutEdges.insert(outEdge);
274  addOutgoingEdge(outEdge);
275  }
276  inline bool addOutgoingLoadEdge(LoadCGEdge* outEdge)
277  {
278  bool added1 = loadOutEdges.insert(outEdge).second;
279  bool added2 = addOutgoingEdge(outEdge);
280  bool both_added = added1 & added2;
281  assert(both_added && "edge not added, duplicated adding!!");
282  return both_added;
283  }
284  inline bool addOutgoingStoreEdge(StoreCGEdge* outEdge)
285  {
286  bool added1 = storeOutEdges.insert(outEdge).second;
287  bool added2 = addOutgoingEdge(outEdge);
288  bool both_added = added1 & added2;
289  assert(both_added && "edge not added, duplicated adding!!");
290  return both_added;
291  }
292  inline bool addOutgoingDirectEdge(ConstraintEdge* outEdge)
293  {
294  assert(outEdge->getSrcID() == this->getId());
295  bool added1 = directOutEdges.insert(outEdge).second;
296  bool added2 = addOutgoingEdge(outEdge);
297  bool both_added = added1 & added2;
298  assert(both_added && "edge not added, duplicated adding!!");
299  return both_added;
300  }
302 
304  //{@
305  inline bool removeOutgoingAddrEdge(AddrCGEdge* outEdge)
306  {
307  u32_t num1 = addressOutEdges.erase(outEdge);
308  u32_t num2 = removeOutgoingEdge(outEdge);
309  bool removed = (num1 > 0) & (num2 > 0);
310  assert(removed && "edge not in the set, can not remove!!!");
311  return removed;
312  }
313 
314  inline bool removeIncomingAddrEdge(AddrCGEdge* inEdge)
315  {
316  u32_t num1 = addressInEdges.erase(inEdge);
317  u32_t num2 = removeIncomingEdge(inEdge);
318  bool removed = (num1 > 0) & (num2 > 0);
319  assert(removed && "edge not in the set, can not remove!!!");
320  return removed;
321  }
322 
324  {
325  if (SVFUtil::isa<GepCGEdge>(outEdge))
326  gepOutEdges.erase(outEdge);
327  else
328  copyOutEdges.erase(outEdge);
329  u32_t num1 = directOutEdges.erase(outEdge);
330  u32_t num2 = removeOutgoingEdge(outEdge);
331  bool removed = (num1 > 0) & (num2 > 0);
332  assert(removed && "edge not in the set, can not remove!!!");
333  return removed;
334  }
335 
337  {
338  if (SVFUtil::isa<GepCGEdge>(inEdge))
339  gepInEdges.erase(inEdge);
340  else
341  copyInEdges.erase(inEdge);
342  u32_t num1 = directInEdges.erase(inEdge);
343  u32_t num2 = removeIncomingEdge(inEdge);
344  bool removed = (num1 > 0) & (num2 > 0);
345  assert(removed && "edge not in the set, can not remove!!!");
346  return removed;
347  }
348 
349  inline bool removeOutgoingLoadEdge(LoadCGEdge* outEdge)
350  {
351  u32_t num1 = loadOutEdges.erase(outEdge);
352  u32_t num2 = removeOutgoingEdge(outEdge);
353  bool removed = (num1 > 0) & (num2 > 0);
354  assert(removed && "edge not in the set, can not remove!!!");
355  return removed;
356  }
357 
358  inline bool removeIncomingLoadEdge(LoadCGEdge* inEdge)
359  {
360  u32_t num1 = loadInEdges.erase(inEdge);
361  u32_t num2 = removeIncomingEdge(inEdge);
362  bool removed = (num1 > 0) & (num2 > 0);
363  assert(removed && "edge not in the set, can not remove!!!");
364  return removed;
365  }
366 
367  inline bool removeOutgoingStoreEdge(StoreCGEdge* outEdge)
368  {
369  u32_t num1 = storeOutEdges.erase(outEdge);
370  u32_t num2 = removeOutgoingEdge(outEdge);
371  bool removed = (num1 > 0) & (num2 > 0);
372  assert(removed && "edge not in the set, can not remove!!!");
373  return removed;
374  }
375 
377  {
378  u32_t num1 = storeInEdges.erase(inEdge);
379  u32_t num2 = removeIncomingEdge(inEdge);
380  bool removed = (num1 > 0) & (num2 > 0);
381  assert(removed && "edge not in the set, can not remove!!!");
382  return removed;
383  }
385 
386  virtual const std::string toString() const;
387 
389 
390  friend OutStream &operator<<(OutStream &o, const ConstraintNode &node)
391  {
392  o << node.toString();
393  return o;
394  }
396 
398 
399  static inline bool classof(const ConstraintNode *)
400  {
401  return true;
402  }
403 
404  static inline bool classof(const GenericICFGNodeTy* node)
405  {
406  return node->getNodeKind() == ConstraintNodeKd;
407  }
408 
409  static inline bool classof(const SVFBaseNode* node)
410  {
411  return node->getNodeKind() == ConstraintNodeKd;
412  }
414 };
415 
416 } // End namespace SVF
417 
418 #endif /* CONSGNODE_H_ */
#define false
Definition: cJSON.cpp:70
const char *const string
Definition: cJSON.h:172
GenericNode< ConstraintNode, ConstraintEdge >::GEdgeSetTy ConstraintEdgeSetTy
Constraint edge type.
Definition: ConsGEdge.h:85
const ConstraintEdge::ConstraintEdgeSetTy & getDirectOutEdges() const
Definition: ConsGNode.h:107
const_iterator incomingLoadsEnd() const
Definition: ConsGNode.h:202
bool isPWCNode() const
Whether a node involves in PWC, if so, all its points-to elements should become field-insensitive.
Definition: ConsGNode.h:81
ConstraintEdge::ConstraintEdgeSetTy copyOutEdges
Definition: ConsGNode.h:61
const_iterator outgoingLoadsEnd() const
Definition: ConsGNode.h:194
bool isdirectEdge(ConstraintEdge::ConstraintEdgeK kind)
Direct and Indirect SVFIR edges.
Definition: ConsGNode.h:92
bool addOutgoingStoreEdge(StoreCGEdge *outEdge)
Definition: ConsGNode.h:284
const_iterator incomingAddrsBegin() const
Definition: ConsGNode.h:181
const ConstraintEdge::ConstraintEdgeSetTy & getGepOutEdges() const
Definition: ConsGNode.h:123
ConstraintEdge::ConstraintEdgeSetTy::iterator iterator
Definition: ConsGNode.h:44
iterator directInEdgeEnd()
Definition: ConsG.cpp:690
void addIncomingStoreEdge(StoreCGEdge *inEdge)
Definition: ConsGNode.h:257
ConstraintEdge::ConstraintEdgeSetTy addressInEdges
all incoming address edge of this node
Definition: ConsGNode.h:66
void addOutgoingCopyEdge(CopyCGEdge *outEdge)
Definition: ConsGNode.h:237
bool removeOutgoingStoreEdge(StoreCGEdge *outEdge)
Definition: ConsGNode.h:367
bool removeIncomingStoreEdge(StoreCGEdge *inEdge)
Definition: ConsGNode.h:376
const ConstraintEdge::ConstraintEdgeSetTy & getDirectInEdges() const
Return constraint edges.
Definition: ConsGNode.h:103
bool addOutgoingDirectEdge(ConstraintEdge *outEdge)
Definition: ConsGNode.h:292
bool addIncomingDirectEdge(ConstraintEdge *inEdge)
Definition: ConsGNode.h:262
static bool classof(const ConstraintNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: ConsGNode.h:399
ConstraintEdge::ConstraintEdgeSetTy gepInEdges
Definition: ConsGNode.h:63
ConstraintEdge::ConstraintEdgeSetTy copyInEdges
Definition: ConsGNode.h:60
ConstraintEdge::ConstraintEdgeSetTy directInEdges
Definition: ConsGNode.h:57
ConstraintEdge::ConstraintEdgeSetTy gepOutEdges
Definition: ConsGNode.h:64
const ConstraintEdge::ConstraintEdgeSetTy & getLoadOutEdges() const
Definition: ConsGNode.h:131
const_iterator incomingStoresBegin() const
Definition: ConsGNode.h:215
bool removeIncomingAddrEdge(AddrCGEdge *inEdge)
Definition: ConsGNode.h:314
friend OutStream & operator<<(OutStream &o, const ConstraintNode &node)
Overloading operator << for dumping node.
Definition: ConsGNode.h:390
virtual const std::string toString() const
Definition: ConsG.cpp:731
const_iterator outgoingStoresEnd() const
Definition: ConsGNode.h:211
bool removeOutgoingDirectEdge(ConstraintEdge *outEdge)
Definition: ConsGNode.h:323
bool removeIncomingDirectEdge(ConstraintEdge *inEdge)
Definition: ConsGNode.h:336
bool removeOutgoingLoadEdge(LoadCGEdge *outEdge)
Definition: ConsGNode.h:349
const_iterator incomingLoadsBegin() const
Definition: ConsGNode.h:198
static bool classof(const GenericICFGNodeTy *node)
Definition: ConsGNode.h:404
const_iterator outgoingAddrsBegin() const
Definition: ConsGNode.h:173
ConstraintEdge::ConstraintEdgeSetTy loadOutEdges
all outgoing load edge of this node
Definition: ConsGNode.h:50
const ConstraintEdge::ConstraintEdgeSetTy & getStoreOutEdges() const
Definition: ConsGNode.h:139
NodeBS strides
For stride-based field representation.
Definition: ConsGNode.h:71
bool isIndirectEdge(ConstraintEdge::ConstraintEdgeK kind)
Definition: ConsGNode.h:96
ConstraintEdge::ConstraintEdgeSetTy storeOutEdges
all outgoing store edge of this node
Definition: ConsGNode.h:53
const_iterator incomingStoresEnd() const
Definition: ConsGNode.h:219
const ConstraintEdge::ConstraintEdgeSetTy & getAddrOutEdges() const
Definition: ConsGNode.h:147
iterator directInEdgeBegin()
Definition: ConsG.cpp:682
const_iterator outgoingStoresBegin() const
Definition: ConsGNode.h:207
void addIncomingLoadEdge(LoadCGEdge *inEdge)
Definition: ConsGNode.h:252
bool removeIncomingLoadEdge(LoadCGEdge *inEdge)
Definition: ConsGNode.h:358
ConstraintEdge::ConstraintEdgeSetTy storeInEdges
all incoming store edge of this node
Definition: ConsGNode.h:52
iterator directOutEdgeEnd()
Definition: ConsG.cpp:674
const ConstraintEdge::ConstraintEdgeSetTy & getCopyInEdges() const
Definition: ConsGNode.h:111
bool addOutgoingLoadEdge(LoadCGEdge *outEdge)
Definition: ConsGNode.h:276
void addIncomingGepEdge(GepCGEdge *inEdge)
Definition: ConsGNode.h:232
ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator
Definition: ConsGNode.h:45
const ConstraintEdge::ConstraintEdgeSetTy & getCopyOutEdges() const
Definition: ConsGNode.h:115
bool removeOutgoingAddrEdge(AddrCGEdge *outEdge)
Remove constraint graph edges.
Definition: ConsGNode.h:305
void addOutgoingGepEdge(GepCGEdge *outEdge)
Definition: ConsGNode.h:242
const ConstraintEdge::ConstraintEdgeSetTy & getLoadInEdges() const
Definition: ConsGNode.h:127
const ConstraintEdge::ConstraintEdgeSetTy & getGepInEdges() const
Definition: ConsGNode.h:119
ConstraintEdge::ConstraintEdgeSetTy & incomingAddrEdges()
Definition: ConsGNode.h:164
static bool classof(const SVFBaseNode *node)
Definition: ConsGNode.h:409
const_iterator outgoingAddrsEnd() const
Definition: ConsGNode.h:177
void addIncomingCopyEdge(CopyCGEdge *inEdge)
Add constraint graph edges.
Definition: ConsGNode.h:227
iterator directOutEdgeBegin()
Iterators.
Definition: ConsG.cpp:666
ConstraintEdge::ConstraintEdgeSetTy & outgoingAddrEdges()
Definition: ConsGNode.h:168
const ConstraintEdge::ConstraintEdgeSetTy & getAddrInEdges() const
Definition: ConsGNode.h:143
const_iterator incomingAddrsEnd() const
Definition: ConsGNode.h:185
const ConstraintEdge::ConstraintEdgeSetTy & getStoreInEdges() const
Definition: ConsGNode.h:135
void addIncomingAddrEdge(AddrCGEdge *inEdge)
Definition: ConsGNode.h:247
ConstraintEdge::ConstraintEdgeSetTy addressOutEdges
all outgoing address edge of this node
Definition: ConsGNode.h:67
void addOutgoingAddrEdge(AddrCGEdge *outEdge)
Definition: ConsGNode.h:271
const_iterator outgoingLoadsBegin() const
Definition: ConsGNode.h:190
ConstraintEdge::ConstraintEdgeSetTy loadInEdges
all incoming load edge of this node
Definition: ConsGNode.h:49
ConstraintNode(NodeID i)
Definition: ConsGNode.h:74
ConstraintEdge::ConstraintEdgeSetTy directOutEdges
Definition: ConsGNode.h:58
NodeID getDstID() const
Definition: GenericGraph.h:85
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:81
bool addIncomingEdge(EdgeType *inEdge)
Add incoming and outgoing edges.
Definition: GenericGraph.h:527
GNodeK getNodeKind() const
Get node kind.
Definition: GenericGraph.h:266
for isBitcode
Definition: BasicTypes.h:68
u32_t NodeID
Definition: GeneralType.h:55
GenericNode< ConstraintNode, ConstraintEdge > GenericConsNodeTy
Definition: ConsGNode.h:39
std::ostream OutStream
Definition: GeneralType.h:45
unsigned u32_t
Definition: GeneralType.h:46