svf-lib 1.0.1825 → 1.0.1827

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/SVF-linux/Release-build/svf/libSvfCore.a +0 -0
  2. package/{SVF-osx → SVF-linux}/Release-build/svf-llvm/extapi.bc +459 -460
  3. package/SVF-linux/Release-build/svf-llvm/libSvfLLVM.a +0 -0
  4. package/SVF-osx/svf/include/Util/WorkList.h +0 -0
  5. package/SVF-osx/svf-llvm/include/SVF-LLVM/CPPUtil.h +37 -12
  6. package/SVF-osx/svf-llvm/include/SVF-LLVM/DCHG.h +1 -9
  7. package/SVF-osx/svf-llvm/include/SVF-LLVM/ICFGBuilder.h +1 -0
  8. package/SVF-osx/svf-llvm/include/SVF-LLVM/LLVMModule.h +0 -1
  9. package/SVF-osx/svf-llvm/include/SVF-LLVM/LLVMUtil.h +4 -108
  10. package/package.json +1 -1
  11. package/SVF-osx/Release-build/svf/libSvfCore.a +0 -0
  12. package/SVF-osx/Release-build/svf-llvm/libSvfLLVM.a +0 -0
  13. package/SVF-osx/svf/include/AbstractExecution/WTO.h +0 -892
  14. package/SVF-osx/svf/include/CFL/CFLData.h +0 -316
  15. package/SVF-osx/svf/include/CFL/CFLDataBuilder.h +0 -91
  16. package/SVF-osx/svf/include/CFL/CFLGrammar.h +0 -468
  17. package/SVF-osx/svf/include/CFL/CFLGrammar.txt +0 -15
  18. package/SVF-osx/svf/include/CFL/CFLGrammarDev.txt +0 -16
  19. package/SVF-osx/svf/include/CFL/PEGGrammar.txt +0 -11
  20. package/SVF-osx/svf/include/CFL/VFG.txt +0 -7
  21. package/SVF-osx/svf/include/CUDD/cudd.h +0 -688
  22. package/SVF-osx/svf/include/CUDD/cuddInt.h +0 -1145
  23. package/SVF-osx/svf/include/CUDD/epd.h +0 -192
  24. package/SVF-osx/svf/include/CUDD/mtr.h +0 -180
  25. package/SVF-osx/svf/include/CUDD/mtrInt.h +0 -92
  26. package/SVF-osx/svf/include/CUDD/st.h +0 -230
  27. package/SVF-osx/svf/include/CUDD/util.h +0 -196
  28. package/SVF-osx/svf/include/Graphs/ExternalPAG.h +0 -147
  29. package/SVF-osx/svf/include/Graphs/ICFGWrapper.h +0 -726
  30. package/SVF-osx/svf/include/Graphs/OfflineConsG.h +0 -151
  31. package/SVF-osx/svf/include/Graphs/PAG.h +0 -932
  32. package/SVF-osx/svf/include/Graphs/PAGEdge.h +0 -738
  33. package/SVF-osx/svf/include/Graphs/PAGNode.h +0 -843
  34. package/SVF-osx/svf/include/MTA/LockResultValidator.h +0 -118
  35. package/SVF-osx/svf/include/MTA/MTAAnnotator.h +0 -118
  36. package/SVF-osx/svf/include/MemoryModel/LocationSet.h +0 -157
  37. package/SVF-osx/svf/include/MemoryModel/MemModel.h +0 -414
  38. package/SVF-osx/svf/include/MemoryModel/PAGBuilderFromFile.h +0 -80
  39. package/SVF-osx/svf/include/MemoryModel/PTAStat.h +0 -174
  40. package/SVF-osx/svf/include/MemoryModel/PTAType.h +0 -368
  41. package/SVF-osx/svf/include/MemoryModel/PointsToDFDS.h +0 -514
  42. package/SVF-osx/svf/include/MemoryModel/PointsToDS.h +0 -289
  43. package/SVF-osx/svf/include/MemoryModel/SVFIR.h +0 -650
  44. package/SVF-osx/svf/include/MemoryModel/SVFStatements.h +0 -1101
  45. package/SVF-osx/svf/include/MemoryModel/SVFSymbols.h +0 -648
  46. package/SVF-osx/svf/include/MemoryModel/SVFVariables.h +0 -721
  47. package/SVF-osx/svf/include/MemoryModel/SymbolTableInfo.h +0 -713
  48. package/SVF-osx/svf/include/SABER/PathCondAllocator.h +0 -303
  49. package/SVF-osx/svf/include/SABER/SaberAnnotator.h +0 -72
  50. package/SVF-osx/svf/include/SVFIR/SVFIRRW.h +0 -1302
  51. package/SVF-osx/svf/include/SVFIR/SVFModuleRW.h +0 -197
  52. package/SVF-osx/svf/include/Util/BDDExpr.h +0 -198
  53. package/SVF-osx/svf/include/Util/BasicTypes.h +0 -768
  54. package/SVF-osx/svf/include/Util/CFLSolver.h +0 -186
  55. package/SVF-osx/svf/include/Util/Conditions.h +0 -421
  56. package/SVF-osx/svf/include/Util/CppUtil.h +0 -81
  57. package/SVF-osx/svf/include/Util/ExeState.h +0 -197
  58. package/SVF-osx/svf/include/Util/ExtAPI.json +0 -5853
  59. package/SVF-osx/svf/include/Util/IRAnnotator.h +0 -321
  60. package/SVF-osx/svf/include/Util/PathCondAllocator.h +0 -286
  61. package/SVF-osx/svf/include/Util/PathDPItem.h +0 -310
  62. package/SVF-osx/svf/include/Util/SCC.h +0 -352
  63. package/SVF-osx/svf/include/Util/SVFBasicTypes.h +0 -245
  64. package/SVF-osx/svf/include/Util/SVFInstruction.h +0 -40
  65. package/SVF-osx/svf/include/Util/SVFModule.h +0 -278
  66. package/SVF-osx/svf/include/Util/SymState.h +0 -118
  67. package/SVF-osx/svf/include/Util/TypeBasedHeapCloning.h +0 -188
  68. package/SVF-osx/svf/include/WPA/AndersenSFR.h +0 -160
  69. package/SVF-osx/svf/include/WPA/FlowSensitiveTBHC.h +0 -122
  70. package/SVF-osx/svf/include/WPA/TypeBasedHeapCloning.h +0 -188
  71. package/SVF-osx/svf-llvm/include/SVF-LLVM/IRAnnotator.h +0 -324
@@ -1,892 +0,0 @@
1
- //===- WTO.h -- Weakest Topological Order Analysis-------------------------//
2
- //
3
- // SVF: Static Value-Flow Analysis
4
- //
5
- // Copyright (C) <2013-> <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 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 General Public License for more details.
17
-
18
- // You should have received a copy of the GNU General Public License
19
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
- //
21
- //===----------------------------------------------------------------------===//
22
-
23
- /*
24
- * WTO.h
25
- *
26
- * The implementation is based on F. Bourdoncle's paper:
27
- * "Efficient chaotic iteration strategies with widenings", Formal
28
- * Methods in Programming and Their Applications, 1993, pages 128-141.
29
- *
30
- * Created on: Jul 3, 2022
31
- * Author: Xiao Cheng, Jiawei Wang
32
- *
33
- */
34
-
35
- #ifndef WTO_H_
36
- #define WTO_H_
37
-
38
- #include "SVFIR/SVFType.h"
39
- #include "SVFIR/SVFValue.h"
40
- #include "Graphs/CFBasicBlockG.h"
41
-
42
- namespace SVF
43
- {
44
-
45
- class CFBasicBlockGWTO;
46
-
47
- class CFBasicBlockGWTONode;
48
-
49
- class CFBasicBlockGWTOCycle;
50
-
51
- /*!
52
- * Cycle depth of a WTO Component
53
- *
54
- * The cycle depth is represented as **a list of cycle's heads**,
55
- * **from the outermost to the innermost**.
56
- *
57
- * e.g., consider the following nested cycle:
58
- *
59
- * -->1 --> 2 --> 3 --> 4
60
- * \ /
61
- * <-- 6 <-- 5 <--
62
- * \ /
63
- * >7>
64
- *
65
- * where C1: (1 2 3 4 5 6 7) is the outer cycle, where 1 is the head,
66
- * and C2: (5 6 7) is the inner cycle, where 5 is the head.
67
- *
68
- * The cycle depth is as following:
69
- * ---------------------------------
70
- * | Node NO. | Cycle Depth |
71
- * --------------------------------
72
- * | 1 (head of C1) | [ ] |
73
- * --------------------------------
74
- * | 2, 3, 4 | [1] |
75
- * --------------------------------
76
- * | 5 (head of C2) | [1] |
77
- * --------------------------------
78
- * | 6, 7 | [1, 5] |
79
- * --------------------------------
80
- */
81
- template <typename NodeRef>
82
- class WTOCycleDepth
83
- {
84
- public:
85
- typedef std::vector<NodeRef> NodeRefList;
86
- typedef typename NodeRefList::const_iterator Iterator;
87
-
88
- private:
89
- NodeRefList _heads;
90
-
91
- public:
92
- /// Default Constructor
93
- WTOCycleDepth() = default;
94
-
95
- /// Default Copy Constructor
96
- WTOCycleDepth(const WTOCycleDepth &) = default;
97
-
98
- /// Default Move Constructor
99
- WTOCycleDepth(WTOCycleDepth &&) = default;
100
-
101
- /// Default Copy Operator=
102
- WTOCycleDepth &operator=(const WTOCycleDepth &) = default;
103
-
104
- /// Default Move Operator=
105
- WTOCycleDepth &operator=(WTOCycleDepth &&) = default;
106
-
107
- /// Default Destructor
108
- ~WTOCycleDepth() = default;
109
-
110
- /// Add a cycle head to the end of the head list
111
- void push_back(NodeRef head)
112
- {
113
- _heads.push_back(head);
114
- }
115
-
116
- Iterator begin() const
117
- {
118
- return _heads.cbegin();
119
- }
120
-
121
- Iterator end() const
122
- {
123
- return _heads.cend();
124
- }
125
-
126
- /// Convert the wto-cycle-depth to a string
127
- std::string toString() const
128
- {
129
- std::string str;
130
- std::stringstream rawstr(str);
131
- rawstr << "[";
132
- for (auto it = begin(), et = end(); it != et;)
133
- {
134
- rawstr << (*it)->getName().data();
135
- ++it;
136
- if (it != et)
137
- {
138
- rawstr << ", ";
139
- }
140
- }
141
- rawstr << "]";
142
- return rawstr.str();
143
- }
144
-
145
- private:
146
- /// Compare the given wto-cycle-depth
147
- int compare(const WTOCycleDepth &other) const
148
- {
149
- if (this == &other)
150
- {
151
- return 0; // 0 - equals
152
- }
153
-
154
- auto this_it = begin();
155
- auto other_it = other.begin();
156
- while (this_it != end())
157
- {
158
- if (other_it == other.end())
159
- {
160
- return 1; // `this` is inside `other`
161
- }
162
- else if (*this_it == *other_it)
163
- {
164
- ++this_it;
165
- ++other_it;
166
- }
167
- else
168
- {
169
- return 2; // not comparable
170
- }
171
- }
172
- if (other_it == other.end())
173
- {
174
- return 0; // equals
175
- }
176
- else
177
- {
178
- return -1; // `other` is inside `this`
179
- }
180
- }
181
-
182
- public:
183
-
184
- /// Overloading operators
185
- //@{
186
- /// Return the common prefix of the given wto-cycle-depth
187
- WTOCycleDepth operator^(const WTOCycleDepth &other) const
188
- {
189
- WTOCycleDepth res;
190
- for (auto this_it = begin(), other_it = other.begin();
191
- this_it != end() && other_it != other.end();
192
- ++this_it, ++other_it)
193
- {
194
- if (*this_it == *other_it)
195
- {
196
- res.push_back(*this_it);
197
- }
198
- else
199
- {
200
- break;
201
- }
202
- }
203
- return res;
204
- }
205
-
206
- /// Less than other's depth - `other` is inside `this`
207
- bool operator<(const WTOCycleDepth &other) const
208
- {
209
- return compare(other) == -1;
210
- }
211
-
212
- /// Less than or Equal with other's depth
213
- bool operator<=(const WTOCycleDepth &other) const
214
- {
215
- return compare(other) <= 0;
216
- }
217
-
218
- /// Equal with other's depth
219
- bool operator==(const WTOCycleDepth &other) const
220
- {
221
- return compare(other) == 0;
222
- }
223
-
224
- /// Greater than other's depth - `this` is inside `other`
225
- bool operator>(const WTOCycleDepth &other) const
226
- {
227
- return compare(other) == 1;
228
- }
229
-
230
- /// Greater than or Equal with other's depth
231
- bool operator>=(const WTOCycleDepth &other) const
232
- {
233
- return operator<=(other);
234
- }
235
-
236
- /// Dump into CMD
237
- friend std::ostream &operator<<(std::ostream &o, const WTOCycleDepth &CFBasicBlockGWTO)
238
- {
239
- o << CFBasicBlockGWTO.toString();
240
- return o;
241
- }
242
- //@}
243
-
244
- }; // end class WTOCycleDepth
245
-
246
- /*!
247
- * Weak topological order (WTO) visitor
248
- */
249
- class WTOVisitor
250
- {
251
-
252
- public:
253
- /// Default Constructor
254
- WTOVisitor() = default;
255
-
256
- /// Default Copy Constructor
257
- WTOVisitor(const WTOVisitor &) noexcept = default;
258
-
259
- /// Default Move Constructor
260
- WTOVisitor(WTOVisitor &&) noexcept = default;
261
-
262
- /// Default Copy Operator=
263
- WTOVisitor &operator=(const WTOVisitor &) noexcept = default;
264
-
265
- /// Default Move Operator=
266
- WTOVisitor &operator=(WTOVisitor &&) noexcept = default;
267
-
268
- /// Default Destructor
269
- virtual ~WTOVisitor() = default;
270
-
271
- /// Visit WTO Node
272
- virtual void visit(const CFBasicBlockGWTONode &) = 0;
273
-
274
- /// Visit WTO Cycle
275
- virtual void visit(const CFBasicBlockGWTOCycle &) = 0;
276
-
277
- }; // end class WTOVisitor
278
-
279
- /*!
280
- * Base class for a WTO component for CFBasicBlockG
281
- *
282
- * A WTO component can be either a node or cycle
283
- */
284
- class CFBasicBlockGWTOComp
285
- {
286
-
287
- public:
288
- enum WtoCT
289
- {
290
- Node, Cycle
291
- };
292
-
293
- public:
294
- /// Default Constructor
295
- CFBasicBlockGWTOComp(WtoCT k) : _type(k) {};
296
-
297
- /// Copy Constructor
298
- CFBasicBlockGWTOComp(const CFBasicBlockGWTOComp &) noexcept = default;
299
-
300
- /// Move Constructor
301
- CFBasicBlockGWTOComp(CFBasicBlockGWTOComp &&) noexcept = default;
302
-
303
- /// Copy Operator=
304
- CFBasicBlockGWTOComp &operator=(const CFBasicBlockGWTOComp &) noexcept = default;
305
-
306
- /// Move Operator=
307
- CFBasicBlockGWTOComp &operator=(CFBasicBlockGWTOComp &&) noexcept = default;
308
-
309
- /// Default Destructor
310
- virtual ~CFBasicBlockGWTOComp() = default;
311
-
312
- /// Accept a visitor
313
- virtual void accept(WTOVisitor *) const = 0;
314
-
315
- /// Return the WTO Kind (node or cycle)
316
- inline WtoCT getKind() const
317
- {
318
- return _type;
319
- }
320
-
321
- virtual std::string toString() const = 0;
322
-
323
- friend std::ostream &operator<<(std::ostream &o, const CFBasicBlockGWTOComp &CFBasicBlockGWTO)
324
- {
325
- o << CFBasicBlockGWTO.toString();
326
- return o;
327
- }
328
-
329
- private:
330
-
331
- WtoCT _type;
332
-
333
- }; // end class CFBasicBlockGWTOComp
334
-
335
- /*!
336
- * WTO node for CFBasicBlockG
337
- */
338
- class CFBasicBlockGWTONode final : public CFBasicBlockGWTOComp
339
- {
340
- private:
341
- const CFBasicBlockNode *_node;
342
-
343
- public:
344
- /// Constructor
345
- explicit CFBasicBlockGWTONode(const CFBasicBlockNode *node) : CFBasicBlockGWTOComp(CFBasicBlockGWTOComp::Node), _node(node) {}
346
-
347
- /// Return the graph node
348
- const CFBasicBlockNode *node() const
349
- {
350
- return _node;
351
- }
352
-
353
- /// Accept a visitor
354
- void accept(WTOVisitor *v) const override
355
- {
356
- v->visit(*this);
357
- }
358
-
359
- /// Convert the node to string
360
- std::string toString() const override
361
- {
362
- return std::string(_node->getName().data());
363
- }
364
-
365
- /// ClassOf
366
- //@{
367
- static inline bool classof(const CFBasicBlockGWTONode *)
368
- {
369
- return true;
370
- }
371
-
372
- static inline bool classof(const CFBasicBlockGWTOComp *c)
373
- {
374
- return c->getKind() == CFBasicBlockGWTOComp::Node;
375
- }
376
- ///@}
377
-
378
- }; // end class CFBasicBlockGWTONode
379
-
380
- /*!
381
- * WTO cycle for CFBasicBlockG
382
- */
383
- class CFBasicBlockGWTOCycle final : public CFBasicBlockGWTOComp
384
- {
385
- private:
386
- typedef std::list<const CFBasicBlockGWTOComp *> WtoComponentRefList;
387
- typedef WtoComponentRefList::const_iterator Iterator;
388
-
389
- private:
390
- /// Head of the cycle
391
- const CFBasicBlockNode *_head;
392
-
393
- /// List of components
394
- WtoComponentRefList _components;
395
-
396
- public:
397
- /// Constructor
398
- CFBasicBlockGWTOCycle(const CFBasicBlockNode *head, WtoComponentRefList components)
399
- : CFBasicBlockGWTOComp(CFBasicBlockGWTOComp::Cycle), _head(head), _components(std::move(components)) {}
400
-
401
- /// Return the head of the cycle
402
- const CFBasicBlockNode *head() const
403
- {
404
- return _head;
405
- }
406
-
407
- Iterator begin() const
408
- {
409
- return _components.cbegin();
410
- }
411
-
412
- Iterator end() const
413
- {
414
- return _components.cend();
415
- }
416
-
417
- /// Accept a visitor
418
- void accept(WTOVisitor *v) const override
419
- {
420
- v->visit(*this);
421
- }
422
-
423
- /// ClassOf
424
- //@{
425
- static inline bool classof(const CFBasicBlockGWTOCycle *)
426
- {
427
- return true;
428
- }
429
-
430
- static inline bool classof(const CFBasicBlockGWTOComp *c)
431
- {
432
- return c->getKind() == CFBasicBlockGWTOComp::Cycle;
433
- }
434
- ///@}
435
-
436
- std::string toString() const override
437
- {
438
- std::string str;
439
- std::stringstream rawstr(str);
440
- rawstr << "(";
441
- rawstr << _head->getName().data() << ", ";
442
- for (auto it = begin(), et = end(); it != et;)
443
- {
444
- rawstr << (*it)->toString();
445
- ++it;
446
- if (it != et)
447
- {
448
- rawstr << ", ";
449
- }
450
- }
451
- rawstr << ")";
452
- return rawstr.str();
453
- }
454
-
455
- }; // end class CFBasicBlockGWTOCycle
456
-
457
- /*!
458
- * Weak topological order for CFBasicBlockG
459
- */
460
- class CFBasicBlockGWTO
461
- {
462
-
463
- public:
464
- typedef WTOCycleDepth<const CFBasicBlockNode*> CFBasicBlockGWTOCycleDepth;
465
- typedef Set<const CFBasicBlockNode *> NodeRefSet;
466
-
467
- protected:
468
- typedef std::list<const CFBasicBlockGWTOComp *> WTOCompRefList;
469
- typedef Set <const CFBasicBlockGWTOComp *> WTOCompRefSet;
470
- typedef Map<const CFBasicBlockNode *, const CFBasicBlockGWTOCycle *> NodeRefToWTOCycleMap;
471
- typedef Map<const CFBasicBlockNode *, NodeRefSet> NodeRefToNodeRefSetMap;
472
-
473
- typedef u32_t CycleDepthNumber;
474
- typedef Map<const CFBasicBlockNode *, CycleDepthNumber> NodeRefToCycleDepthNumber;
475
- typedef std::vector<const CFBasicBlockNode *> CFBasicBlockNodes;
476
- typedef std::shared_ptr<CFBasicBlockGWTOCycleDepth> CFBasicBlockGWTOCycleDepthPtr;
477
- typedef Map<const CFBasicBlockNode *, CFBasicBlockGWTOCycleDepthPtr> NodeRefToWTOCycleDepthPtr;
478
-
479
- public:
480
- typedef typename WTOCompRefList::const_iterator Iterator;
481
-
482
- protected:
483
- WTOCompRefList _components;
484
- WTOCompRefSet _allComponents;
485
- NodeRefToWTOCycleMap _headToCycle;
486
- NodeRefToNodeRefSetMap _headToTails;
487
- NodeRefToWTOCycleDepthPtr _nodeToDepth;
488
- NodeRefToCycleDepthNumber _nodeToCDN;
489
- CycleDepthNumber _num;
490
- CFBasicBlockNodes _stack;
491
- CFBasicBlockGraph* _graph;
492
-
493
- public:
494
- explicit CFBasicBlockGWTO() : _num(0) {}
495
-
496
- explicit CFBasicBlockGWTO(CFBasicBlockGraph* graph, const CFBasicBlockNode *entry) : _num(0), _graph(graph)
497
- {
498
- build(entry);
499
- }
500
-
501
- CFBasicBlockGWTO(const CFBasicBlockGWTO &other) = default;
502
-
503
- CFBasicBlockGWTO(CFBasicBlockGWTO &&other) = default;
504
-
505
- CFBasicBlockGWTO &operator=(const CFBasicBlockGWTO &other) = default;
506
-
507
- CFBasicBlockGWTO &operator=(CFBasicBlockGWTO &&other) = default;
508
-
509
- ~CFBasicBlockGWTO()
510
- {
511
- for (const auto &component: _allComponents)
512
- {
513
- delete component;
514
- }
515
- }
516
-
517
- Iterator begin() const
518
- {
519
- return _components.cbegin();
520
- }
521
-
522
- Iterator end() const
523
- {
524
- return _components.cend();
525
- }
526
-
527
- bool isHead(const CFBasicBlockNode *node) const
528
- {
529
- return _headToCycle.find(node) != _headToCycle.end();
530
- }
531
-
532
- typename NodeRefToWTOCycleMap::const_iterator headBegin() const
533
- {
534
- return _headToCycle.cbegin();
535
- }
536
-
537
- typename NodeRefToWTOCycleMap::const_iterator headEnd() const
538
- {
539
- return _headToCycle.cend();
540
- }
541
-
542
- const NodeRefSet &getTails(const CFBasicBlockNode *node) const
543
- {
544
- auto it = _headToTails.find(node);
545
- assert(it != _headToTails.end() && "node not found");
546
- return it->second;
547
- }
548
-
549
- /// Get the wto-cycle-depth of the given node
550
- const CFBasicBlockGWTOCycleDepth &getWTOCycleDepth(const CFBasicBlockNode *n) const
551
- {
552
- auto it = _nodeToDepth.find(n);
553
- assert(it != _nodeToDepth.end() && "node not found");
554
- return *(it->second);
555
- }
556
-
557
- /// Whether the given node is in the node to cycle getCDN
558
- inline bool inNodeToCycleDepth(const CFBasicBlockNode *n) const
559
- {
560
- auto it = _nodeToDepth.find(n);
561
- return it != _nodeToDepth.end();
562
- }
563
-
564
- /// Accept the given visitor
565
- void accept(WTOVisitor* v)
566
- {
567
- for (const auto &c: _components)
568
- {
569
- c->accept(v);
570
- }
571
- }
572
-
573
- std::string toString() const
574
- {
575
- std::string str;
576
- std::stringstream rawstr(str);
577
- rawstr << "[";
578
- for (auto it = begin(), et = end(); it != et;)
579
- {
580
- rawstr << (*it)->toString();
581
- ++it;
582
- if (it != et)
583
- {
584
- rawstr << ", ";
585
- }
586
- }
587
- rawstr << "]";
588
- return rawstr.str();
589
- }
590
-
591
- friend std::ostream &operator<<(std::ostream &o, const CFBasicBlockGWTO &CFBasicBlockGWTO)
592
- {
593
- o << CFBasicBlockGWTO.toString();
594
- return o;
595
- }
596
-
597
- protected:
598
-
599
- inline void build(const CFBasicBlockNode *entry)
600
- {
601
- visit(entry, _components);
602
- _nodeToCDN.clear();
603
- _stack.clear();
604
- buildNodeToWTOCycleDepth();
605
- build_tails();
606
- }
607
-
608
- /// Visitor to build the WTO cycle getCDN of each node
609
- class WTOCycleDepthBuilder final
610
- : public WTOVisitor
611
- {
612
- private:
613
- CFBasicBlockGWTOCycleDepthPtr _wtoCycleDepth;
614
- NodeRefToWTOCycleDepthPtr &_nodeToWTOCycleDepth;
615
-
616
- public:
617
- explicit WTOCycleDepthBuilder(NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth)
618
- : _wtoCycleDepth(std::make_shared<CFBasicBlockGWTOCycleDepth>()),
619
- _nodeToWTOCycleDepth(nodeToWTOCycleDepth) {}
620
-
621
- void visit(const CFBasicBlockGWTOCycle &cycle) override
622
- {
623
- const CFBasicBlockNode *head = cycle.head();
624
- CFBasicBlockGWTOCycleDepthPtr previous_nesting = _wtoCycleDepth;
625
- _nodeToWTOCycleDepth.insert(std::make_pair(head, _wtoCycleDepth));
626
- _wtoCycleDepth = std::make_shared<CFBasicBlockGWTOCycleDepth>(*_wtoCycleDepth);
627
- _wtoCycleDepth->push_back(head);
628
- for (auto it = cycle.begin(), et = cycle.end(); it != et; ++it)
629
- {
630
- (*it)->accept(this);
631
- }
632
- _wtoCycleDepth = previous_nesting;
633
- }
634
-
635
- void visit(const CFBasicBlockGWTONode &node) override
636
- {
637
- _nodeToWTOCycleDepth.insert(
638
- std::make_pair(node.node(), _wtoCycleDepth));
639
- }
640
-
641
- }; // end class WTOCycleDepthBuilder
642
-
643
- /// Visitor to build the tails of each head/loop
644
- class TailBuilder : public WTOVisitor
645
- {
646
- protected:
647
- NodeRefSet &_tails;
648
- const CFBasicBlockGWTOCycleDepth &_headWTOCycleDepth;
649
- const CFBasicBlockNode *_head;
650
- NodeRefToWTOCycleDepthPtr &_nodeToWTOCycleDepth;
651
- CFBasicBlockGraph* _graph;
652
-
653
- public:
654
-
655
- explicit TailBuilder(CFBasicBlockGraph* graph, NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
656
- const CFBasicBlockGWTOCycleDepth &headWTOCycleDepth) : _tails(tails), _headWTOCycleDepth(headWTOCycleDepth), _head(head), _nodeToWTOCycleDepth(
657
- nodeToWTOCycleDepth), _graph(graph)
658
- {
659
- }
660
-
661
- void visit(const CFBasicBlockGWTOCycle &cycle) override
662
- {
663
- for (auto it = cycle.begin(), et = cycle.end(); it != et; ++it)
664
- {
665
- (*it)->accept(this);
666
- }
667
- }
668
-
669
- virtual void visit(const CFBasicBlockGWTONode &node) override
670
- {
671
- if(const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node.node()->getICFGNodes().front()))
672
- {
673
- const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
674
- const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
675
- if (succ != _head && succNesting <= _headWTOCycleDepth)
676
- {
677
- _tails.insert(node.node());
678
- }
679
- }
680
- else
681
- {
682
- for (const auto &edge: node.node()->getOutEdges())
683
- {
684
- if(edge->getICFGEdge() && !edge->getICFGEdge()->isIntraCFGEdge()) continue;
685
- const CFBasicBlockNode *succ = edge->getDstNode();
686
- const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
687
- if (succ != _head && succNesting <= _headWTOCycleDepth)
688
- {
689
- _tails.insert(node.node());
690
- }
691
- }
692
- }
693
- }
694
-
695
- protected:
696
- /// Get the wto-cycle-depth of the given node
697
- const CFBasicBlockGWTOCycleDepth &getWTOCycleDepth(const CFBasicBlockNode *n) const
698
- {
699
- auto it = _nodeToWTOCycleDepth.find(n);
700
- assert(it != _nodeToWTOCycleDepth.end() && "node not found");
701
- return *(it->second);
702
- }
703
-
704
- };
705
-
706
- protected:
707
- /// Get the cycle depth number of the given node
708
- CycleDepthNumber getCDN(const CFBasicBlockNode *n) const
709
- {
710
- auto it = _nodeToCDN.find(n);
711
- if (it != _nodeToCDN.end())
712
- {
713
- return it->second;
714
- }
715
- else
716
- {
717
- return 0;
718
- }
719
- }
720
-
721
- /// Set the cycle depth number of the given node
722
- void setCDN(const CFBasicBlockNode *n, const CycleDepthNumber &Depth)
723
- {
724
- auto res = _nodeToCDN.insert(std::make_pair(n, Depth));
725
- if (!res.second)
726
- {
727
- (res.first)->second = Depth;
728
- }
729
- }
730
-
731
- /// Pop a node from the stack
732
- const CFBasicBlockNode *pop()
733
- {
734
- assert(!_stack.empty() && "empty stack");
735
- const CFBasicBlockNode *top = _stack.back();
736
- _stack.pop_back();
737
- return top;
738
- }
739
-
740
- /// Push a node on the stack
741
- void push(const CFBasicBlockNode *n)
742
- {
743
- _stack.push_back(n);
744
- }
745
-
746
- const CFBasicBlockGWTONode *newNode(const CFBasicBlockNode *node)
747
- {
748
- const CFBasicBlockGWTONode *ptr = new CFBasicBlockGWTONode(node);
749
- _allComponents.insert(ptr);
750
- return ptr;
751
- }
752
-
753
- const CFBasicBlockGWTOCycle *newCycle(const CFBasicBlockNode *node, const WTOCompRefList &partition)
754
- {
755
- const CFBasicBlockGWTOCycle *ptr = new CFBasicBlockGWTOCycle(node, std::move(partition));
756
- _allComponents.insert(ptr);
757
- return ptr;
758
- }
759
-
760
- /// Create the cycle component for the given node
761
- const CFBasicBlockGWTOCycle *component(const CFBasicBlockNode *node)
762
- {
763
- WTOCompRefList partition;
764
- if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
765
- {
766
- const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
767
- if (getCDN(succ) == 0)
768
- {
769
- visit(succ, partition);
770
- }
771
- }
772
- else
773
- {
774
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
775
- {
776
- if((*it)->getICFGEdge() && !(*it)->getICFGEdge()->isIntraCFGEdge()) continue;
777
- const CFBasicBlockNode *succ = (*it)->getDstNode();
778
- if (getCDN(succ) == 0)
779
- {
780
- visit(succ, partition);
781
- }
782
- }
783
- }
784
- const CFBasicBlockGWTOCycle *ptr = newCycle(node, partition);
785
- _headToCycle.emplace(node, ptr);
786
- return ptr;
787
- }
788
-
789
- /// Main algorithm to build WTO
790
- virtual CycleDepthNumber visit(const CFBasicBlockNode *node, WTOCompRefList &partition)
791
- {
792
- CycleDepthNumber head(0);
793
- CycleDepthNumber min(0);
794
- bool loop;
795
-
796
- push(node);
797
- _num += CycleDepthNumber(1);
798
- head = _num;
799
- setCDN(node, head);
800
- loop = false;
801
- if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
802
- {
803
- const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
804
- CycleDepthNumber succ_dfn = getCDN(succ);
805
- if (succ_dfn == CycleDepthNumber(0))
806
- {
807
- min = visit(succ, partition);
808
- }
809
- else
810
- {
811
- min = succ_dfn;
812
- }
813
- if (min <= head)
814
- {
815
- head = min;
816
- loop = true;
817
- }
818
- }
819
- else
820
- {
821
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
822
- {
823
- if((*it)->getICFGEdge() && !(*it)->getICFGEdge()->isIntraCFGEdge()) continue;
824
- const CFBasicBlockNode *succ = (*it)->getDstNode();
825
- if (succ->getFunction() != node->getFunction())
826
- continue;
827
- CycleDepthNumber succ_dfn = getCDN(succ);
828
- if (succ_dfn == CycleDepthNumber(0))
829
- {
830
- min = visit(succ, partition);
831
- }
832
- else
833
- {
834
- min = succ_dfn;
835
- }
836
- if (min <= head)
837
- {
838
- head = min;
839
- loop = true;
840
- }
841
- }
842
- }
843
- if (head == getCDN(node))
844
- {
845
- setCDN(node, UINT_MAX);
846
- const CFBasicBlockNode *element = pop();
847
- if (loop)
848
- {
849
- while (element != node)
850
- {
851
- setCDN(element, 0);
852
- element = pop();
853
- }
854
- partition.push_front(component(node));
855
- }
856
- else
857
- {
858
- partition.push_front(newNode(node));
859
- }
860
- }
861
- return head;
862
- }
863
-
864
- /// Build the node to WTO cycle depth table
865
- void buildNodeToWTOCycleDepth()
866
- {
867
- WTOCycleDepthBuilder builder(_nodeToDepth);
868
- for (auto it = begin(), et = end(); it != et; ++it)
869
- {
870
- (*it)->accept(&builder);
871
- }
872
- }
873
-
874
- /// Build the tails for each cycle
875
- virtual void build_tails()
876
- {
877
- for (const auto &head: _headToCycle)
878
- {
879
- NodeRefSet tails;
880
- TailBuilder builder(_graph, _nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
881
- for (auto it = head.second->begin(), eit = head.second->end(); it != eit; ++it)
882
- {
883
- (*it)->accept(&builder);
884
- }
885
- _headToTails.emplace(head.first, tails);
886
- }
887
- }
888
-
889
- }; // end class CFBasicBlockGWTO
890
-
891
- } // end namespace SVF
892
- #endif /* WTO_H_ */