svf-lib 1.0.1246 → 1.0.1248

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.
@@ -58,7 +58,7 @@ class List
58
58
  class ListNode
59
59
  {
60
60
  public:
61
- ListNode(const Data& d)
61
+ ListNode(const Data &d)
62
62
  {
63
63
  data = d;
64
64
  next = nullptr;
@@ -67,7 +67,7 @@ class List
67
67
  ~ListNode() {}
68
68
 
69
69
  Data data;
70
- ListNode* next;
70
+ ListNode *next;
71
71
  };
72
72
 
73
73
  typedef Set<Data> DataSet;
@@ -87,16 +87,16 @@ public:
87
87
  return (head == nullptr);
88
88
  }
89
89
 
90
- inline bool find(const Data& data) const
90
+ inline bool find(const Data &data) const
91
91
  {
92
- return (nodeSet.find(data) == nodeSet.end() ? false : true);
92
+ return nodeSet.find(data) != nodeSet.end();
93
93
  }
94
94
 
95
- void push(const Data& data)
95
+ void push(const Data &data)
96
96
  {
97
97
  if (nodeSet.find(data) == nodeSet.end())
98
98
  {
99
- Node* new_node = new Node(data);
99
+ Node *new_node = new Node(data);
100
100
  if (head == nullptr)
101
101
  head = new_node;// the list is empty
102
102
  else
@@ -109,12 +109,12 @@ public:
109
109
  {
110
110
  assert(head != nullptr && "list is empty");
111
111
  /// get node from list head
112
- Node* head_node = head;
112
+ Node *head_node = head;
113
113
 
114
114
  /// change list head to the next node
115
115
  head = head->next;
116
116
  if (head == nullptr)
117
- tail = nullptr; /// the last node is popped.
117
+ tail = nullptr; /// the last node is popped.
118
118
 
119
119
  Data data = head_node->data;
120
120
  nodeSet.erase(data);
@@ -124,8 +124,8 @@ public:
124
124
 
125
125
  private:
126
126
  DataSet nodeSet;
127
- Node* head;
128
- Node* tail;
127
+ Node *head;
128
+ Node *tail;
129
129
  };
130
130
 
131
131
  /**
@@ -136,6 +136,7 @@ private:
136
136
  template<class Data>
137
137
  class FIFOWorkList
138
138
  {
139
+ typedef Set<Data> DataSet;
139
140
  typedef std::deque<Data> DataDeque;
140
141
  public:
141
142
  FIFOWorkList() {}
@@ -147,28 +148,30 @@ public:
147
148
  return data_list.empty();
148
149
  }
149
150
 
150
- inline bool find(const Data& data) const
151
+ inline u32_t size() const
151
152
  {
152
- return std::find(data_list.begin(), data_list.end(), data) != data_list.end();
153
+ assert(data_list.size() == data_set.size() && "list and set must be the same size!");
154
+ return data_list.size();
153
155
  }
154
156
 
155
- /**
156
- * Push a data into the work list.
157
- */
158
- inline bool push(const Data& data)
157
+ inline bool find(const Data &data) const
159
158
  {
160
- data_list.push_back(data);
161
- return true;
159
+ return data_set.find(data) != data_set.end();
162
160
  }
163
161
 
164
162
  /**
165
- * Pop a data from the END of work list.
163
+ * Push a data into the work list.
166
164
  */
167
- inline Data pop()
165
+ inline bool push(const Data &data)
168
166
  {
169
- Data data = front();
170
- removeFront();
171
- return data;
167
+ if (!find(data))
168
+ {
169
+ data_list.push_back(data);
170
+ data_set.insert(data);
171
+ return true;
172
+ }
173
+ else
174
+ return false;
172
175
  }
173
176
 
174
177
  /**
@@ -177,16 +180,29 @@ public:
177
180
  inline void removeFront()
178
181
  {
179
182
  assert(!empty() && "work list is empty");
183
+ data_set.erase(front());
180
184
  data_list.pop_front();
181
185
  }
182
186
 
183
187
  /**
184
188
  * Get reference of top data from the END of work list.
185
189
  */
186
- inline Data& front()
190
+ inline Data &front()
191
+ {
192
+ assert(!empty() && "work list is empty");
193
+ Data &data = data_list.front();
194
+ return data;
195
+ }
196
+
197
+ /**
198
+ * Pop a data from the END of work list.
199
+ */
200
+ inline Data pop()
187
201
  {
188
202
  assert(!empty() && "work list is empty");
189
- Data& data = data_list.front();
203
+ Data data = data_list.front();
204
+ data_list.pop_front();
205
+ data_set.erase(data);
190
206
  return data;
191
207
  }
192
208
 
@@ -196,10 +212,12 @@ public:
196
212
  inline void clear()
197
213
  {
198
214
  data_list.clear();
215
+ data_set.clear();
199
216
  }
200
217
 
201
218
  private:
202
- DataDeque data_list; ///< work list using std::vector.
219
+ DataSet data_set; ///< store all data in the work list.
220
+ DataDeque data_list; ///< work list using std::vector.
203
221
  };
204
222
 
205
223
  /**
@@ -210,6 +228,7 @@ private:
210
228
  template<class Data>
211
229
  class FILOWorkList
212
230
  {
231
+ typedef Set<Data> DataSet;
213
232
  typedef std::vector<Data> DataVector;
214
233
  public:
215
234
  FILOWorkList() {}
@@ -221,18 +240,30 @@ public:
221
240
  return data_list.empty();
222
241
  }
223
242
 
224
- inline bool find(const Data& data) const
243
+ inline u32_t size() const
225
244
  {
226
- return std::find(data_list.begin(), data_list.end(), data) != data_list.end();
245
+ assert(data_list.size() == data_set.size() && "list and set must be the same size!");
246
+ return data_list.size();
247
+ }
248
+
249
+ inline bool find(const Data &data) const
250
+ {
251
+ return data_set.find(data) != data_set.end();;
227
252
  }
228
253
 
229
254
  /**
230
255
  * Push a data into the work list.
231
256
  */
232
- inline bool push(const Data& data)
257
+ inline bool push(const Data &data)
233
258
  {
234
- data_list.push_back(data);
235
- return true;
259
+ if (!find(data))
260
+ {
261
+ data_list.push_back(data);
262
+ data_set.insert(data);
263
+ return true;
264
+ }
265
+ else
266
+ return false;
236
267
  }
237
268
 
238
269
  /**
@@ -240,8 +271,10 @@ public:
240
271
  */
241
272
  inline Data pop()
242
273
  {
243
- Data data = back();
244
- removeBack();
274
+ assert(!empty() && "work list is empty");
275
+ Data data = data_list.back();
276
+ data_list.pop_back();
277
+ data_set.erase(data);
245
278
  return data;
246
279
  }
247
280
 
@@ -251,16 +284,17 @@ public:
251
284
  inline void removeBack()
252
285
  {
253
286
  assert(!empty() && "work list is empty");
287
+ data_set.erase(back());
254
288
  data_list.pop_back();
255
289
  }
256
290
 
257
291
  /**
258
292
  * Get reference of top data from the END of work list.
259
293
  */
260
- inline Data& back()
294
+ inline Data &back()
261
295
  {
262
296
  assert(!empty() && "work list is empty");
263
- Data& data = data_list.back();
297
+ Data &data = data_list.back();
264
298
  return data;
265
299
  }
266
300
 
@@ -270,10 +304,12 @@ public:
270
304
  inline void clear()
271
305
  {
272
306
  data_list.clear();
307
+ data_set.clear();
273
308
  }
274
309
 
275
310
  private:
276
- DataVector data_list; ///< work list using std::vector.
311
+ DataSet data_set; ///< store all data in the work list.
312
+ DataVector data_list; ///< work list using std::vector.
277
313
  };
278
314
 
279
315
  } // End namespace SVF
Binary file
@@ -162,13 +162,6 @@ public:
162
162
  return keyFunc->dominate(bbKey,bbValue);
163
163
  }
164
164
 
165
- /// Get LoopInfo
166
- inline LoopInfo* getLoopInfo(const Function* f)
167
- {
168
- return cfInfoBuilder.getLoopInfo(f);
169
- }
170
-
171
-
172
165
  /// Guard Computation for a value-flow (between two basic blocks)
173
166
  //@{
174
167
  virtual Condition ComputeIntraVFGGuard(const BasicBlock* src, const BasicBlock* dst);
@@ -26,6 +26,8 @@
26
26
 
27
27
  #include <llvm/Support/SourceMgr.h>
28
28
 
29
+ #include "llvm/Analysis/LoopInfo.h"
30
+
29
31
  namespace SVF
30
32
  {
31
33
 
@@ -73,6 +75,11 @@ typedef llvm::DominanceFrontier DominanceFrontier;
73
75
  typedef llvm::PostDominatorTree PostDominatorTree;
74
76
  typedef llvm::DominanceFrontierBase<llvm::BasicBlock, false> DominanceFrontierBase;
75
77
 
78
+ /// LLVM Loop
79
+ typedef llvm::Loop Loop;
80
+ typedef llvm::LoopInfo LoopInfo;
81
+ typedef llvm::User User;
82
+
76
83
  // LLVM Instructions
77
84
  typedef llvm::AllocaInst AllocaInst;
78
85
  typedef llvm::AtomicCmpXchgInst AtomicCmpXchgInst;
@@ -55,7 +55,6 @@
55
55
  #include <llvm/BinaryFormat/Dwarf.h>
56
56
  #endif
57
57
 
58
- #include "llvm/Analysis/LoopInfo.h"
59
58
  #include "llvm/IR/CFG.h"
60
59
  #include "llvm/BinaryFormat/Dwarf.h"
61
60
 
@@ -74,9 +73,6 @@ typedef llvm::Instruction Instruction;
74
73
  typedef llvm::CallBase CallBase;
75
74
  typedef llvm::GlobalValue GlobalValue;
76
75
  typedef llvm::GlobalVariable GlobalVariable;
77
- typedef llvm::User User;
78
- typedef llvm::Loop Loop;
79
- typedef llvm::LoopInfo LoopInfo;
80
76
 
81
77
  /// LLVM outputs
82
78
  typedef llvm::raw_string_ostream raw_string_ostream;
@@ -129,11 +125,8 @@ private:
129
125
  Map<const BasicBlock*,Set<const BasicBlock*>> dtBBsMap;
130
126
  Map<const BasicBlock*,Set<const BasicBlock*>> dfBBsMap;
131
127
  Map<const BasicBlock*,Set<const BasicBlock*>> pdtBBsMap;
128
+ Map<const BasicBlock*,std::vector<const BasicBlock*>> bb2LoopMap;
132
129
  public:
133
- SVFFunction(const std::string& val): SVFValue(val,SVFValue::SVFFunc),
134
- isDecl(false), isIntri(false), fun(nullptr), exitBB(nullptr), isUncalled(false), isNotRet(false)
135
- {
136
- }
137
130
 
138
131
  SVFFunction(Function* f): SVFValue(f->getName().str(),SVFValue::SVFFunc),
139
132
  isDecl(f->isDeclaration()), isIntri(f->isIntrinsic()), fun(f), exitBB(nullptr), isUncalled(false), isNotRet(false)
@@ -216,6 +209,28 @@ public:
216
209
  return dfBBsMap;
217
210
  }
218
211
 
212
+ inline bool hasLoopInfo(const BasicBlock* bb) const
213
+ {
214
+ return bb2LoopMap.find(bb)!=bb2LoopMap.end();
215
+ }
216
+
217
+ inline const std::vector<const BasicBlock*>& getLoopInfo(const BasicBlock* bb) const
218
+ {
219
+ Map<const BasicBlock*, std::vector<const BasicBlock*>>::const_iterator mapIter = bb2LoopMap.find(bb);
220
+ if(mapIter != bb2LoopMap.end())
221
+ return mapIter->second;
222
+ else
223
+ {
224
+ assert(hasLoopInfo(bb) && "loopinfo does not exit(bb not in a loop)");
225
+ abort();
226
+ }
227
+ }
228
+
229
+ inline void addToBB2LoopMap(const BasicBlock* bb, const BasicBlock* loopBB)
230
+ {
231
+ bb2LoopMap[bb].push_back(loopBB);
232
+ }
233
+
219
234
  inline const Map<const BasicBlock*,Set<const BasicBlock*>>& getPostDomTreeMap() const
220
235
  {
221
236
  return pdtBBsMap;
@@ -251,6 +266,35 @@ public:
251
266
  return this->exitBB;
252
267
  }
253
268
 
269
+ void getExitBlocksOfLoop(const BasicBlock* bb, Set<const BasicBlock*>& exitbbs) const
270
+ {
271
+ if (hasLoopInfo(bb))
272
+ {
273
+ const std::vector<const BasicBlock*>& blocks = getLoopInfo(bb);
274
+ assert(!blocks.empty() && "no available loop info?");
275
+ for (const BasicBlock* block : blocks)
276
+ {
277
+ for (succ_const_iterator succIt = succ_begin(block); succIt != succ_end(block); succIt++)
278
+ {
279
+ const BasicBlock* succ = *succIt;
280
+ if ((std::find(blocks.begin(), blocks.end(), succ)==blocks.end()))
281
+ exitbbs.insert(succ);
282
+ }
283
+ }
284
+ }
285
+ }
286
+
287
+ bool isLoopHeader(const BasicBlock* bb) const
288
+ {
289
+ if (hasLoopInfo(bb))
290
+ {
291
+ const std::vector<const BasicBlock*>& blocks = getLoopInfo(bb);
292
+ assert(!blocks.empty() && "no available loop info?");
293
+ return blocks.front() == bb;
294
+ }
295
+ return false;
296
+ }
297
+
254
298
  bool dominate(const BasicBlock* bbKey, const BasicBlock* bbValue) const
255
299
  {
256
300
  if (bbKey == bbValue)
@@ -352,7 +396,6 @@ public:
352
396
  {
353
397
  return CB;
354
398
  }
355
- using arg_iterator = User::const_op_iterator;
356
399
  Value *getArgument(unsigned ArgNo) const
357
400
  {
358
401
  return CB->getArgOperand(ArgNo);
@@ -361,14 +404,6 @@ public:
361
404
  {
362
405
  return CB->getType();
363
406
  }
364
- User::const_op_iterator arg_begin() const
365
- {
366
- return CB->arg_begin();
367
- }
368
- User::const_op_iterator arg_end() const
369
- {
370
- return CB->arg_end();
371
- }
372
407
  unsigned arg_size() const
373
408
  {
374
409
  return CB->arg_size();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1246",
3
+ "version": "1.0.1248",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {