svf-lib 1.0.1391 → 1.0.1393
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.
- package/SVF-linux/Release-build/svf/libSvfCore.a +0 -0
- package/SVF-linux/Release-build/svf-llvm/libSvfLLVM.a +0 -0
- package/SVF-linux/svf/include/CFL/CFLAlias.h +0 -24
- package/SVF-linux/svf/include/CFL/CFLSolver.h +318 -15
- package/SVF-osx/Release-build/svf/libSvfCore.a +0 -0
- package/SVF-osx/Release-build/svf-llvm/libSvfLLVM.a +0 -0
- package/SVF-osx/svf/include/CFL/CFLSolver.h +146 -191
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
@@ -32,8 +32,6 @@
|
|
|
32
32
|
|
|
33
33
|
#include "CFL/CFLBase.h"
|
|
34
34
|
#include "CFL/CFLStat.h"
|
|
35
|
-
#include "CFL/CFLData.h"
|
|
36
|
-
#include "CFL/CFLDataBuilder.h"
|
|
37
35
|
|
|
38
36
|
namespace SVF
|
|
39
37
|
{
|
|
@@ -142,34 +140,12 @@ private:
|
|
|
142
140
|
class POCRAlias : public CFLAlias
|
|
143
141
|
{
|
|
144
142
|
public:
|
|
145
|
-
static double timeOfBuildCFLData; // Time of building CFLData from CFLGraph
|
|
146
|
-
|
|
147
143
|
POCRAlias(SVFIR* ir) : CFLAlias(ir)
|
|
148
144
|
{
|
|
149
|
-
if (!_cflData)
|
|
150
|
-
_cflData = new CFLData();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/// Destructor
|
|
154
|
-
virtual ~POCRAlias()
|
|
155
|
-
{
|
|
156
|
-
delete _cflData;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
CFLData* cflData()
|
|
160
|
-
{
|
|
161
|
-
return _cflData;
|
|
162
145
|
}
|
|
163
146
|
|
|
164
147
|
/// Initialize the grammar, graph, CFLData, solver
|
|
165
148
|
virtual void initialize();
|
|
166
|
-
|
|
167
|
-
/// Init CFLData
|
|
168
|
-
virtual void buildCFLData();
|
|
169
|
-
|
|
170
|
-
private:
|
|
171
|
-
/// Graph dataset
|
|
172
|
-
CFLData* _cflData;
|
|
173
149
|
};
|
|
174
150
|
} // End namespace SVF
|
|
175
151
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* CFLSolver.h
|
|
25
25
|
*
|
|
26
26
|
* Created on: March 5, 2022
|
|
27
|
-
* Author: Yulei Sui
|
|
27
|
+
* Author: Yulei Sui, Yuxiang Lei
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
#ifndef INCLUDE_CFL_CFLSolver_H_
|
|
@@ -33,12 +33,285 @@
|
|
|
33
33
|
#include "Graphs/CFLGraph.h"
|
|
34
34
|
#include "CFL/CFLGrammar.h"
|
|
35
35
|
#include "Util/WorkList.h"
|
|
36
|
-
#include "CFL/CFLData.h"
|
|
37
36
|
|
|
37
|
+
using namespace std;
|
|
38
38
|
|
|
39
39
|
namespace SVF
|
|
40
40
|
{
|
|
41
41
|
|
|
42
|
+
typedef GrammarBase::Symbol Label;
|
|
43
|
+
/*!
|
|
44
|
+
* Adjacency-list graph representation
|
|
45
|
+
*/
|
|
46
|
+
class CFLData
|
|
47
|
+
{
|
|
48
|
+
public:
|
|
49
|
+
typedef std::map<const Label, NodeBS> TypeMap; // Label with SparseBitVector of NodeID
|
|
50
|
+
typedef std::unordered_map<NodeID, TypeMap> DataMap; // Each Node has a TypeMap
|
|
51
|
+
typedef typename DataMap::iterator iterator; // iterator for each node
|
|
52
|
+
typedef typename DataMap::const_iterator const_iterator; // const iterator
|
|
53
|
+
|
|
54
|
+
protected:
|
|
55
|
+
DataMap succMap; // succ map for nodes contains Label: Edgeset
|
|
56
|
+
DataMap predMap; // pred map for nodes contains Label: edgeset
|
|
57
|
+
const NodeBS emptyData; // ??
|
|
58
|
+
NodeBS diff; // ??
|
|
59
|
+
|
|
60
|
+
// union/add data
|
|
61
|
+
//@{
|
|
62
|
+
inline bool addPred(const NodeID key, const NodeID src, const Label ty)
|
|
63
|
+
{
|
|
64
|
+
return predMap[key][ty].test_and_set(src);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
inline bool addSucc(const NodeID key, const NodeID dst, const Label ty)
|
|
68
|
+
{
|
|
69
|
+
return succMap[key][ty].test_and_set(dst);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
inline bool addPreds(const NodeID key, const NodeBS& data, const Label ty)
|
|
73
|
+
{
|
|
74
|
+
if (data.empty())
|
|
75
|
+
return false;
|
|
76
|
+
return predMap[key][ty] |= data; // union of sparsebitvector (add to LHS)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
inline bool addSuccs(const NodeID key, const NodeBS& data, const Label ty)
|
|
80
|
+
{
|
|
81
|
+
if (data.empty())
|
|
82
|
+
return false;
|
|
83
|
+
return succMap[key][ty] |= data; // // union of sparsebitvector (add to LHS)
|
|
84
|
+
}
|
|
85
|
+
//@}
|
|
86
|
+
|
|
87
|
+
public:
|
|
88
|
+
// Constructor
|
|
89
|
+
CFLData()
|
|
90
|
+
{}
|
|
91
|
+
|
|
92
|
+
// Destructor
|
|
93
|
+
virtual ~CFLData()
|
|
94
|
+
{}
|
|
95
|
+
|
|
96
|
+
virtual void clear()
|
|
97
|
+
{
|
|
98
|
+
succMap.clear();
|
|
99
|
+
predMap.clear();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
inline const_iterator begin() const
|
|
103
|
+
{
|
|
104
|
+
return succMap.begin();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
inline const_iterator end() const
|
|
108
|
+
{
|
|
109
|
+
return succMap.end();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
inline iterator begin()
|
|
113
|
+
{
|
|
114
|
+
return succMap.begin();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
inline iterator end()
|
|
118
|
+
{
|
|
119
|
+
return succMap.end();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
inline DataMap& getSuccMap()
|
|
123
|
+
{
|
|
124
|
+
return succMap;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
inline DataMap& getPredMap()
|
|
128
|
+
{
|
|
129
|
+
return predMap;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
inline TypeMap& getSuccMap(const NodeID key)
|
|
133
|
+
{
|
|
134
|
+
return succMap[key];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
inline TypeMap& getPredMap(const NodeID key)
|
|
138
|
+
{
|
|
139
|
+
return predMap[key];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
inline NodeBS& getSuccs(const NodeID key, const Label ty)
|
|
143
|
+
{
|
|
144
|
+
return succMap[key][ty];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
inline NodeBS& getPreds(const NodeID key, const Label ty)
|
|
148
|
+
{
|
|
149
|
+
return predMap[key][ty];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Alias data operations
|
|
153
|
+
//@{
|
|
154
|
+
inline bool addEdge(const NodeID src, const NodeID dst, const Label ty)
|
|
155
|
+
{
|
|
156
|
+
addSucc(src, dst, ty);
|
|
157
|
+
return addPred(dst, src, ty);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// add edges and return the set of added edges (dst) for src
|
|
161
|
+
inline NodeBS addEdges(const NodeID src, const NodeBS& dstData, const Label ty)
|
|
162
|
+
{
|
|
163
|
+
NodeBS newDsts;
|
|
164
|
+
if (addSuccs(src, dstData, ty))
|
|
165
|
+
{
|
|
166
|
+
for (const NodeID datum: dstData)
|
|
167
|
+
if (addPred(datum, src, ty))
|
|
168
|
+
newDsts.set(datum);
|
|
169
|
+
}
|
|
170
|
+
return newDsts;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/// add edges and return the set of added edges (src) for dst
|
|
174
|
+
inline NodeBS addEdges(const NodeBS& srcData, const NodeID dst, const Label ty)
|
|
175
|
+
{
|
|
176
|
+
NodeBS newSrcs;
|
|
177
|
+
if (addPreds(dst, srcData, ty))
|
|
178
|
+
{
|
|
179
|
+
for (const NodeID datum: srcData)
|
|
180
|
+
if (addSucc(datum, dst, ty))
|
|
181
|
+
newSrcs.set(datum);
|
|
182
|
+
}
|
|
183
|
+
return newSrcs;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/// find src -> find src[ty] -> find dst in set
|
|
187
|
+
inline bool hasEdge(const NodeID src, const NodeID dst, const Label ty)
|
|
188
|
+
{
|
|
189
|
+
const_iterator iter1 = succMap.find(src);
|
|
190
|
+
if (iter1 == succMap.end())
|
|
191
|
+
return false;
|
|
192
|
+
|
|
193
|
+
auto iter2 = iter1->second.find(ty);
|
|
194
|
+
if (iter2 == iter1->second.end())
|
|
195
|
+
return false;
|
|
196
|
+
|
|
197
|
+
return iter2->second.test(dst);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* This is a dataset version, to be modified to a cflData version */
|
|
201
|
+
inline void clearEdges(const NodeID key)
|
|
202
|
+
{
|
|
203
|
+
succMap[key].clear();
|
|
204
|
+
predMap[key].clear();
|
|
205
|
+
}
|
|
206
|
+
//@}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/*!
|
|
210
|
+
* Hybrid graph representation for transitive relations
|
|
211
|
+
* The implementation is based on
|
|
212
|
+
* Yuxiang Lei, Yulei Sui, Shuo Ding, and Qirun Zhang.
|
|
213
|
+
* Taming Transitive Redundancy for Context-Free Language Reachability.
|
|
214
|
+
* ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications
|
|
215
|
+
*/
|
|
216
|
+
class HybridData
|
|
217
|
+
{
|
|
218
|
+
public:
|
|
219
|
+
struct TreeNode
|
|
220
|
+
{
|
|
221
|
+
NodeID id;
|
|
222
|
+
std::unordered_set<TreeNode*> children;
|
|
223
|
+
|
|
224
|
+
TreeNode(NodeID nId) : id(nId)
|
|
225
|
+
{}
|
|
226
|
+
|
|
227
|
+
~TreeNode()
|
|
228
|
+
{
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
inline bool operator==(const TreeNode& rhs) const
|
|
232
|
+
{
|
|
233
|
+
return id == rhs.id;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
inline bool operator<(const TreeNode& rhs) const
|
|
237
|
+
{
|
|
238
|
+
return id < rhs.id;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
public:
|
|
244
|
+
Map<NodeID, std::unordered_map<NodeID, TreeNode*>> indMap; // indMap[v][u] points to node v in tree(u)
|
|
245
|
+
|
|
246
|
+
HybridData()
|
|
247
|
+
{}
|
|
248
|
+
|
|
249
|
+
~HybridData()
|
|
250
|
+
{
|
|
251
|
+
for (auto iter1: indMap)
|
|
252
|
+
{
|
|
253
|
+
for (auto iter2: iter1.second)
|
|
254
|
+
{
|
|
255
|
+
delete iter2.second;
|
|
256
|
+
iter2.second = NULL;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
bool hasInd(NodeID src, NodeID dst)
|
|
262
|
+
{
|
|
263
|
+
auto it = indMap.find(dst);
|
|
264
|
+
if (it == indMap.end())
|
|
265
|
+
return false;
|
|
266
|
+
return (it->second.find(src) != it->second.end());
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/// Add a node dst to tree(src)
|
|
270
|
+
TreeNode* addInd(NodeID src, NodeID dst)
|
|
271
|
+
{
|
|
272
|
+
auto resIns = indMap[dst].insert(std::make_pair(src, new TreeNode(dst)));
|
|
273
|
+
if (resIns.second)
|
|
274
|
+
return resIns.first->second;
|
|
275
|
+
return nullptr;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/// Get the node dst in tree(src)
|
|
279
|
+
TreeNode* getNode(NodeID src, NodeID dst)
|
|
280
|
+
{
|
|
281
|
+
return indMap[dst][src];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/// add v into desc(x) as a child of u
|
|
285
|
+
void insertEdge(TreeNode* u, TreeNode* v)
|
|
286
|
+
{
|
|
287
|
+
u->children.insert(v);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
void addArc(NodeID src, NodeID dst)
|
|
291
|
+
{
|
|
292
|
+
if (!hasInd(src, dst))
|
|
293
|
+
{
|
|
294
|
+
for (auto iter: indMap[src])
|
|
295
|
+
{
|
|
296
|
+
meld(iter.first, getNode(iter.first, src), getNode(dst, dst));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
void meld(NodeID x, TreeNode* uNode, TreeNode* vNode)
|
|
302
|
+
{
|
|
303
|
+
TreeNode* newVNode = addInd(x, vNode->id);
|
|
304
|
+
if (!newVNode)
|
|
305
|
+
return;
|
|
306
|
+
|
|
307
|
+
insertEdge(uNode, newVNode);
|
|
308
|
+
for (TreeNode* vChild: vNode->children)
|
|
309
|
+
{
|
|
310
|
+
meld(x, newVNode, vChild);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
42
315
|
class CFLSolver
|
|
43
316
|
{
|
|
44
317
|
|
|
@@ -54,20 +327,20 @@ public:
|
|
|
54
327
|
{
|
|
55
328
|
}
|
|
56
329
|
|
|
57
|
-
~CFLSolver()
|
|
330
|
+
virtual ~CFLSolver()
|
|
58
331
|
{
|
|
59
332
|
delete graph;
|
|
60
333
|
delete grammar;
|
|
61
334
|
}
|
|
62
335
|
|
|
63
336
|
/// Initialize worklist
|
|
64
|
-
void initialize();
|
|
337
|
+
virtual void initialize();
|
|
65
338
|
|
|
66
339
|
/// Process CFLEdge
|
|
67
|
-
void processCFLEdge(const CFLEdge* Y_edge);
|
|
340
|
+
virtual void processCFLEdge(const CFLEdge* Y_edge);
|
|
68
341
|
|
|
69
342
|
/// Start solving
|
|
70
|
-
void solve();
|
|
343
|
+
virtual void solve();
|
|
71
344
|
|
|
72
345
|
/// Return CFL Graph
|
|
73
346
|
inline const CFLGraph* getGraph() const
|
|
@@ -80,11 +353,11 @@ public:
|
|
|
80
353
|
{
|
|
81
354
|
return grammar;
|
|
82
355
|
}
|
|
83
|
-
inline bool pushIntoWorklist(const CFLEdge* item)
|
|
356
|
+
virtual inline bool pushIntoWorklist(const CFLEdge* item)
|
|
84
357
|
{
|
|
85
358
|
return worklist.push(item);
|
|
86
359
|
}
|
|
87
|
-
inline bool isWorklistEmpty()
|
|
360
|
+
virtual inline bool isWorklistEmpty()
|
|
88
361
|
{
|
|
89
362
|
return worklist.empty();
|
|
90
363
|
}
|
|
@@ -103,7 +376,7 @@ protected:
|
|
|
103
376
|
}
|
|
104
377
|
//@}
|
|
105
378
|
|
|
106
|
-
|
|
379
|
+
protected:
|
|
107
380
|
CFLGraph* graph;
|
|
108
381
|
CFLGrammar* grammar;
|
|
109
382
|
/// Worklist for resolution
|
|
@@ -114,22 +387,52 @@ private:
|
|
|
114
387
|
/// Solver Utilize CFLData
|
|
115
388
|
class POCRSolver : public CFLSolver
|
|
116
389
|
{
|
|
390
|
+
public:
|
|
391
|
+
POCRSolver(CFLGraph* _graph, CFLGrammar* _grammar) : CFLSolver(_graph, _grammar), cflData(NULL)
|
|
392
|
+
{
|
|
393
|
+
if (!cflData)
|
|
394
|
+
{
|
|
395
|
+
cflData = new CFLData();
|
|
396
|
+
// Build CFL Data
|
|
397
|
+
buildCFLData();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
117
400
|
/// Destructor
|
|
118
401
|
virtual ~POCRSolver()
|
|
119
402
|
{
|
|
120
|
-
delete
|
|
403
|
+
delete cflData;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/// Process CFLEdge
|
|
407
|
+
virtual void processCFLEdge(const CFLEdge* Y_edge);
|
|
408
|
+
|
|
409
|
+
/// Init CFLData
|
|
410
|
+
virtual void buildCFLData();
|
|
411
|
+
|
|
412
|
+
virtual bool addEdge(const CFLNode* src, const CFLNode* dst, const Label ty)
|
|
413
|
+
{
|
|
414
|
+
return cflData->addEdge(src->getId(), dst->getId(), ty);
|
|
121
415
|
}
|
|
122
416
|
|
|
123
|
-
|
|
417
|
+
virtual bool addEdge(const NodeID srcId, const NodeID dstId, const Label ty)
|
|
124
418
|
{
|
|
125
|
-
return
|
|
419
|
+
return cflData->addEdge(srcId, dstId, ty);
|
|
126
420
|
}
|
|
127
421
|
|
|
128
|
-
|
|
422
|
+
virtual void initialize();
|
|
129
423
|
|
|
130
|
-
|
|
131
|
-
|
|
424
|
+
virtual NodeBS addEdges(const NodeID srcId, const NodeBS& dstData, const Label ty)
|
|
425
|
+
{
|
|
426
|
+
return cflData->addEdges(srcId, dstData, ty);
|
|
427
|
+
}
|
|
132
428
|
|
|
429
|
+
|
|
430
|
+
virtual NodeBS addEdges(const NodeBS& srcData, const NodeID dstId, const Label ty)
|
|
431
|
+
{
|
|
432
|
+
return cflData->addEdges(srcData, dstId, ty);
|
|
433
|
+
}
|
|
434
|
+
private:
|
|
435
|
+
CFLData* cflData;
|
|
133
436
|
};
|
|
134
437
|
}
|
|
135
438
|
|
|
Binary file
|
|
Binary file
|
|
@@ -38,173 +38,7 @@ using namespace std;
|
|
|
38
38
|
|
|
39
39
|
namespace SVF
|
|
40
40
|
{
|
|
41
|
-
|
|
42
41
|
typedef GrammarBase::Symbol Label;
|
|
43
|
-
/*!
|
|
44
|
-
* Adjacency-list graph representation
|
|
45
|
-
*/
|
|
46
|
-
class CFLData
|
|
47
|
-
{
|
|
48
|
-
public:
|
|
49
|
-
typedef std::map<const Label, NodeBS> TypeMap; // Label with SparseBitVector of NodeID
|
|
50
|
-
typedef std::unordered_map<NodeID, TypeMap> DataMap; // Each Node has a TypeMap
|
|
51
|
-
typedef typename DataMap::iterator iterator; // iterator for each node
|
|
52
|
-
typedef typename DataMap::const_iterator const_iterator; // const iterator
|
|
53
|
-
|
|
54
|
-
protected:
|
|
55
|
-
DataMap succMap; // succ map for nodes contains Label: Edgeset
|
|
56
|
-
DataMap predMap; // pred map for nodes contains Label: edgeset
|
|
57
|
-
const NodeBS emptyData; // ??
|
|
58
|
-
NodeBS diff; // ??
|
|
59
|
-
|
|
60
|
-
// union/add data
|
|
61
|
-
//@{
|
|
62
|
-
inline bool addPred(const NodeID key, const NodeID src, const Label ty)
|
|
63
|
-
{
|
|
64
|
-
return predMap[key][ty].test_and_set(src);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
inline bool addSucc(const NodeID key, const NodeID dst, const Label ty)
|
|
68
|
-
{
|
|
69
|
-
return succMap[key][ty].test_and_set(dst);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
inline bool addPreds(const NodeID key, const NodeBS& data, const Label ty)
|
|
73
|
-
{
|
|
74
|
-
if (data.empty())
|
|
75
|
-
return false;
|
|
76
|
-
return predMap[key][ty] |= data; // union of sparsebitvector (add to LHS)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
inline bool addSuccs(const NodeID key, const NodeBS& data, const Label ty)
|
|
80
|
-
{
|
|
81
|
-
if (data.empty())
|
|
82
|
-
return false;
|
|
83
|
-
return succMap[key][ty] |= data; // // union of sparsebitvector (add to LHS)
|
|
84
|
-
}
|
|
85
|
-
//@}
|
|
86
|
-
|
|
87
|
-
public:
|
|
88
|
-
// Constructor
|
|
89
|
-
CFLData()
|
|
90
|
-
{}
|
|
91
|
-
|
|
92
|
-
// Destructor
|
|
93
|
-
virtual ~CFLData()
|
|
94
|
-
{}
|
|
95
|
-
|
|
96
|
-
virtual void clear()
|
|
97
|
-
{
|
|
98
|
-
succMap.clear();
|
|
99
|
-
predMap.clear();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
inline const_iterator begin() const
|
|
103
|
-
{
|
|
104
|
-
return succMap.begin();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
inline const_iterator end() const
|
|
108
|
-
{
|
|
109
|
-
return succMap.end();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
inline iterator begin()
|
|
113
|
-
{
|
|
114
|
-
return succMap.begin();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
inline iterator end()
|
|
118
|
-
{
|
|
119
|
-
return succMap.end();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
inline DataMap& getSuccMap()
|
|
123
|
-
{
|
|
124
|
-
return succMap;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
inline DataMap& getPredMap()
|
|
128
|
-
{
|
|
129
|
-
return predMap;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
inline TypeMap& getSuccMap(const NodeID key)
|
|
133
|
-
{
|
|
134
|
-
return succMap[key];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
inline TypeMap& getPredMap(const NodeID key)
|
|
138
|
-
{
|
|
139
|
-
return predMap[key];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
inline NodeBS& getSuccs(const NodeID key, const Label ty)
|
|
143
|
-
{
|
|
144
|
-
return succMap[key][ty];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
inline NodeBS& getPreds(const NodeID key, const Label ty)
|
|
148
|
-
{
|
|
149
|
-
return predMap[key][ty];
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Alias data operations
|
|
153
|
-
//@{
|
|
154
|
-
inline bool addEdge(const NodeID src, const NodeID dst, const Label ty)
|
|
155
|
-
{
|
|
156
|
-
addSucc(src, dst, ty);
|
|
157
|
-
return addPred(dst, src, ty);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/// add edges and return the set of added edges (dst) for src
|
|
161
|
-
inline NodeBS addEdges(const NodeID src, const NodeBS& dstData, const Label ty)
|
|
162
|
-
{
|
|
163
|
-
NodeBS newDsts;
|
|
164
|
-
if (addSuccs(src, dstData, ty))
|
|
165
|
-
{
|
|
166
|
-
for (const NodeID datum: dstData)
|
|
167
|
-
if (addPred(datum, src, ty))
|
|
168
|
-
newDsts.set(datum);
|
|
169
|
-
}
|
|
170
|
-
return newDsts;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/// add edges and return the set of added edges (src) for dst
|
|
174
|
-
inline NodeBS addEdges(const NodeBS& srcData, const NodeID dst, const Label ty)
|
|
175
|
-
{
|
|
176
|
-
NodeBS newSrcs;
|
|
177
|
-
if (addPreds(dst, srcData, ty))
|
|
178
|
-
{
|
|
179
|
-
for (const NodeID datum: srcData)
|
|
180
|
-
if (addSucc(datum, dst, ty))
|
|
181
|
-
newSrcs.set(datum);
|
|
182
|
-
}
|
|
183
|
-
return newSrcs;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/// find src -> find src[ty] -> find dst in set
|
|
187
|
-
inline bool hasEdge(const NodeID src, const NodeID dst, const Label ty)
|
|
188
|
-
{
|
|
189
|
-
const_iterator iter1 = succMap.find(src);
|
|
190
|
-
if (iter1 == succMap.end())
|
|
191
|
-
return false;
|
|
192
|
-
|
|
193
|
-
auto iter2 = iter1->second.find(ty);
|
|
194
|
-
if (iter2 == iter1->second.end())
|
|
195
|
-
return false;
|
|
196
|
-
|
|
197
|
-
return iter2->second.test(dst);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/* This is a dataset version, to be modified to a cflData version */
|
|
201
|
-
inline void clearEdges(const NodeID key)
|
|
202
|
-
{
|
|
203
|
-
succMap[key].clear();
|
|
204
|
-
predMap[key].clear();
|
|
205
|
-
}
|
|
206
|
-
//@}
|
|
207
|
-
};
|
|
208
42
|
|
|
209
43
|
/*!
|
|
210
44
|
* Hybrid graph representation for transitive relations
|
|
@@ -388,51 +222,172 @@ protected:
|
|
|
388
222
|
class POCRSolver : public CFLSolver
|
|
389
223
|
{
|
|
390
224
|
public:
|
|
391
|
-
|
|
225
|
+
typedef std::map<const Label, NodeBS> TypeMap; // Label with SparseBitVector of NodeID
|
|
226
|
+
typedef std::unordered_map<NodeID, TypeMap> DataMap; // Each Node has a TypeMap
|
|
227
|
+
typedef typename DataMap::iterator iterator; // iterator for each node
|
|
228
|
+
typedef typename DataMap::const_iterator const_iterator;
|
|
229
|
+
|
|
230
|
+
protected:
|
|
231
|
+
DataMap succMap; // succ map for nodes contains Label: Edgeset
|
|
232
|
+
DataMap predMap; // pred map for nodes contains Label: edgeset
|
|
233
|
+
const NodeBS emptyData; // ??
|
|
234
|
+
NodeBS diff;
|
|
235
|
+
// union/add data
|
|
236
|
+
//@{
|
|
237
|
+
inline bool addPred(const NodeID key, const NodeID src, const Label ty)
|
|
392
238
|
{
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
239
|
+
return predMap[key][ty].test_and_set(src);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
inline bool addSucc(const NodeID key, const NodeID dst, const Label ty)
|
|
243
|
+
{
|
|
244
|
+
return succMap[key][ty].test_and_set(dst);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
inline bool addPreds(const NodeID key, const NodeBS& data, const Label ty)
|
|
248
|
+
{
|
|
249
|
+
if (data.empty())
|
|
250
|
+
return false;
|
|
251
|
+
return predMap[key][ty] |= data; // union of sparsebitvector (add to LHS)
|
|
399
252
|
}
|
|
400
|
-
|
|
401
|
-
|
|
253
|
+
|
|
254
|
+
inline bool addSuccs(const NodeID key, const NodeBS& data, const Label ty)
|
|
402
255
|
{
|
|
403
|
-
|
|
256
|
+
if (data.empty())
|
|
257
|
+
return false;
|
|
258
|
+
return succMap[key][ty] |= data; // // union of sparsebitvector (add to LHS)
|
|
404
259
|
}
|
|
260
|
+
//@}
|
|
261
|
+
public:
|
|
405
262
|
|
|
406
|
-
|
|
407
|
-
|
|
263
|
+
virtual void clear()
|
|
264
|
+
{
|
|
265
|
+
succMap.clear();
|
|
266
|
+
predMap.clear();
|
|
267
|
+
}
|
|
408
268
|
|
|
409
|
-
|
|
410
|
-
|
|
269
|
+
inline const_iterator begin() const
|
|
270
|
+
{
|
|
271
|
+
return succMap.begin();
|
|
272
|
+
}
|
|
411
273
|
|
|
412
|
-
|
|
274
|
+
inline const_iterator end() const
|
|
413
275
|
{
|
|
414
|
-
return
|
|
276
|
+
return succMap.end();
|
|
415
277
|
}
|
|
416
278
|
|
|
417
|
-
|
|
279
|
+
inline iterator begin()
|
|
418
280
|
{
|
|
419
|
-
return
|
|
281
|
+
return succMap.begin();
|
|
420
282
|
}
|
|
421
283
|
|
|
422
|
-
|
|
284
|
+
inline iterator end()
|
|
285
|
+
{
|
|
286
|
+
return succMap.end();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
inline DataMap& getSuccMap()
|
|
290
|
+
{
|
|
291
|
+
return succMap;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
inline DataMap& getPredMap()
|
|
295
|
+
{
|
|
296
|
+
return predMap;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
inline TypeMap& getSuccMap(const NodeID key)
|
|
300
|
+
{
|
|
301
|
+
return succMap[key];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
inline TypeMap& getPredMap(const NodeID key)
|
|
305
|
+
{
|
|
306
|
+
return predMap[key];
|
|
307
|
+
}
|
|
423
308
|
|
|
424
|
-
|
|
309
|
+
inline NodeBS& getSuccs(const NodeID key, const Label ty)
|
|
425
310
|
{
|
|
426
|
-
return
|
|
311
|
+
return succMap[key][ty];
|
|
427
312
|
}
|
|
428
313
|
|
|
314
|
+
inline NodeBS& getPreds(const NodeID key, const Label ty)
|
|
315
|
+
{
|
|
316
|
+
return predMap[key][ty];
|
|
317
|
+
}
|
|
429
318
|
|
|
430
|
-
|
|
319
|
+
// Alias data operations
|
|
320
|
+
//@{
|
|
321
|
+
inline bool addEdge(const NodeID src, const NodeID dst, const Label ty)
|
|
431
322
|
{
|
|
432
|
-
|
|
323
|
+
addSucc(src, dst, ty);
|
|
324
|
+
return addPred(dst, src, ty);
|
|
433
325
|
}
|
|
434
|
-
|
|
435
|
-
|
|
326
|
+
|
|
327
|
+
/// add edges and return the set of added edges (dst) for src
|
|
328
|
+
inline NodeBS addEdges(const NodeID src, const NodeBS& dstData, const Label ty)
|
|
329
|
+
{
|
|
330
|
+
NodeBS newDsts;
|
|
331
|
+
if (addSuccs(src, dstData, ty))
|
|
332
|
+
{
|
|
333
|
+
for (const NodeID datum: dstData)
|
|
334
|
+
if (addPred(datum, src, ty))
|
|
335
|
+
newDsts.set(datum);
|
|
336
|
+
}
|
|
337
|
+
return newDsts;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/// add edges and return the set of added edges (src) for dst
|
|
341
|
+
inline NodeBS addEdges(const NodeBS& srcData, const NodeID dst, const Label ty)
|
|
342
|
+
{
|
|
343
|
+
NodeBS newSrcs;
|
|
344
|
+
if (addPreds(dst, srcData, ty))
|
|
345
|
+
{
|
|
346
|
+
for (const NodeID datum: srcData)
|
|
347
|
+
if (addSucc(datum, dst, ty))
|
|
348
|
+
newSrcs.set(datum);
|
|
349
|
+
}
|
|
350
|
+
return newSrcs;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/// find src -> find src[ty] -> find dst in set
|
|
354
|
+
inline bool hasEdge(const NodeID src, const NodeID dst, const Label ty)
|
|
355
|
+
{
|
|
356
|
+
const_iterator iter1 = succMap.find(src);
|
|
357
|
+
if (iter1 == succMap.end())
|
|
358
|
+
return false;
|
|
359
|
+
|
|
360
|
+
auto iter2 = iter1->second.find(ty);
|
|
361
|
+
if (iter2 == iter1->second.end())
|
|
362
|
+
return false;
|
|
363
|
+
|
|
364
|
+
return iter2->second.test(dst);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/* This is a dataset version, to be modified to a cflData version */
|
|
368
|
+
inline void clearEdges(const NodeID key)
|
|
369
|
+
{
|
|
370
|
+
succMap[key].clear();
|
|
371
|
+
predMap[key].clear();
|
|
372
|
+
}
|
|
373
|
+
//@}
|
|
374
|
+
|
|
375
|
+
POCRSolver(CFLGraph* _graph, CFLGrammar* _grammar) : CFLSolver(_graph, _grammar)
|
|
376
|
+
{
|
|
377
|
+
buildCFLData();
|
|
378
|
+
}
|
|
379
|
+
/// Destructor
|
|
380
|
+
virtual ~POCRSolver()
|
|
381
|
+
{
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/// Process CFLEdge
|
|
385
|
+
virtual void processCFLEdge(const CFLEdge* Y_edge);
|
|
386
|
+
|
|
387
|
+
/// Init CFLData
|
|
388
|
+
virtual void buildCFLData();
|
|
389
|
+
|
|
390
|
+
virtual void initialize();
|
|
436
391
|
};
|
|
437
392
|
}
|
|
438
393
|
|