Static Value-Flow Analysis
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | List of all members
SVF::POCRHybridSolver Class Reference

Solver Utilize Hybrid Representation of Graph. More...

#include <CFLSolver.h>

Inheritance diagram for SVF::POCRHybridSolver:
SVF::POCRSolver SVF::CFLSolver

Classes

struct  TreeNode
 

Public Member Functions

bool hasInd_h (NodeID src, NodeID dst)
 
TreeNodeaddInd_h (NodeID src, NodeID dst)
 Add a node dst to tree(src)
 
TreeNodegetNode_h (NodeID src, NodeID dst)
 Get the node dst in tree(src)
 
void insertEdge_h (TreeNode *u, TreeNode *v)
 add v into desc(x) as a child of u
 
void addArc_h (NodeID src, NodeID dst)
 
void meld_h (NodeID x, TreeNode *uNode, TreeNode *vNode)
 
 POCRHybridSolver (CFLGraph *_graph, CFGrammar *_grammar)
 
virtual ~POCRHybridSolver ()
 Destructor.
 
virtual void processCFLEdge (const CFLEdge *Y_edge)
 Process CFLEdge.
 
virtual void initialize ()
 Initialize worklist.
 
void addArc (NodeID src, NodeID dst)
 
void meld (NodeID x, TreeNode *uNode, TreeNode *vNode)
 
- Public Member Functions inherited from SVF::POCRSolver
virtual void clear ()
 
const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 
DataMapgetSuccMap ()
 
DataMapgetPredMap ()
 
TypeMapgetSuccMap (const NodeID key)
 
TypeMapgetPredMap (const NodeID key)
 
NodeBSgetSuccs (const NodeID key, const Label ty)
 
NodeBSgetPreds (const NodeID key, const Label ty)
 
bool addEdge (const NodeID src, const NodeID dst, const Label ty)
 
NodeBS addEdges (const NodeID src, const NodeBS &dstData, const Label ty)
 add edges and return the set of added edges (dst) for src
 
NodeBS addEdges (const NodeBS &srcData, const NodeID dst, const Label ty)
 add edges and return the set of added edges (src) for dst
 
bool hasEdge (const NodeID src, const NodeID dst, const Label ty)
 find src -> find src[ty] -> find dst in set
 
void clearEdges (const NodeID key)
 
 POCRSolver (CFLGraph *_graph, CFGrammar *_grammar)
 
virtual ~POCRSolver ()
 Destructor.
 
virtual void buildCFLData ()
 Init CFLData.
 
- Public Member Functions inherited from SVF::CFLSolver
 CFLSolver (CFLGraph *_graph, CFGrammar *_grammar)
 
virtual ~CFLSolver ()
 
virtual void solve ()
 Start solving.
 
const CFLGraphgetGraph () const
 Return CFL Graph.
 
const CFGrammargetGrammar () const
 Return CFL Grammar.
 
virtual bool pushIntoWorklist (const CFLEdge *item)
 
virtual bool isWorklistEmpty ()
 

Public Attributes

Map< NodeID, std::unordered_map< NodeID, TreeNode * > > indMap
 

Additional Inherited Members

- Public Types inherited from SVF::POCRSolver
typedef std::map< const Label, NodeBSTypeMap
 
typedef std::unordered_map< NodeID, TypeMapDataMap
 
typedef DataMap::iterator iterator
 
typedef DataMap::const_iterator const_iterator
 
- Public Types inherited from SVF::CFLSolver
typedef FIFOWorkList< const CFLEdge * > WorkList
 Define worklist.
 
typedef CFGrammar::Production Production
 
typedef CFGrammar::Symbol Symbol
 
- Static Public Attributes inherited from SVF::CFLSolver
static double numOfChecks = 0
 
- Protected Member Functions inherited from SVF::POCRSolver
bool addPred (const NodeID key, const NodeID src, const Label ty)
 
bool addSucc (const NodeID key, const NodeID dst, const Label ty)
 
bool addPreds (const NodeID key, const NodeBS &data, const Label ty)
 
bool addSuccs (const NodeID key, const NodeBS &data, const Label ty)
 
- Protected Member Functions inherited from SVF::CFLSolver
const CFLEdgepopFromWorklist ()
 Worklist operations.
 
bool isInWorklist (const CFLEdge *item)
 
- Protected Attributes inherited from SVF::POCRSolver
DataMap succMap
 
DataMap predMap
 
const NodeBS emptyData
 
NodeBS diff
 
- Protected Attributes inherited from SVF::CFLSolver
CFLGraphgraph
 
CFGrammargrammar
 
WorkList worklist
 Worklist for resolution.
 

Detailed Description

Solver Utilize Hybrid Representation of Graph.

Hybrid graph representation for transitive relations The implementation is based on Yuxiang Lei, Yulei Sui, Shuo Ding, and Qirun Zhang. Taming Transitive Redundancy for Context-Free Language Reachability. ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications

Definition at line 294 of file CFLSolver.h.

Constructor & Destructor Documentation

◆ POCRHybridSolver()

SVF::POCRHybridSolver::POCRHybridSolver ( CFLGraph _graph,
CFGrammar _grammar 
)
inline

Definition at line 347 of file CFLSolver.h.

347 : POCRSolver(_graph, _grammar)
348 {
349 }
POCRSolver(CFLGraph *_graph, CFGrammar *_grammar)
Definition CFLSolver.h:269
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ ~POCRHybridSolver()

virtual SVF::POCRHybridSolver::~POCRHybridSolver ( )
inlinevirtual

Destructor.

Definition at line 351 of file CFLSolver.h.

352 {
353 for (auto iter1: indMap)
354 {
355 for (auto iter2: iter1.second)
356 {
357 delete iter2.second;
358 iter2.second = NULL;
359 }
360 }
361 }
Map< NodeID, std::unordered_map< NodeID, TreeNode * > > indMap
Definition CFLSolver.h:323
#define NULL
Definition extapi.c:2

Member Function Documentation

◆ addArc()

void POCRHybridSolver::addArc ( NodeID  src,
NodeID  dst 
)

Definition at line 314 of file CFLSolver.cpp.

315{
316 if(hasEdge(src, dst, grammar->strToSymbol("F")))
317 return;
318
319 for (auto& iter: indMap[src])
320 {
321 meld(iter.first, getNode_h(iter.first, src), getNode_h(dst, dst));
322 }
323}
CFGrammar * grammar
Definition CFLSolver.h:109
Symbol strToSymbol(const std::string str) const
Definition CFGrammar.cpp:74
TreeNode * getNode_h(NodeID src, NodeID dst)
Get the node dst in tree(src)
Definition CFLSolver.h:331
void meld(NodeID x, TreeNode *uNode, TreeNode *vNode)
bool hasEdge(const NodeID src, const NodeID dst, const Label ty)
find src -> find src[ty] -> find dst in set
Definition CFLSolver.h:248

◆ addArc_h()

void POCRHybridSolver::addArc_h ( NodeID  src,
NodeID  dst 
)

Definition at line 359 of file CFLSolver.cpp.

360{
361 if (!hasInd_h(src, dst))
362 {
363 for (auto iter: indMap[src])
364 {
365 meld_h(iter.first, getNode_h(iter.first, src), getNode_h(dst, dst));
366 }
367 }
368}
void meld_h(NodeID x, TreeNode *uNode, TreeNode *vNode)
bool hasInd_h(NodeID src, NodeID dst)

◆ addInd_h()

POCRHybridSolver::TreeNode * POCRHybridSolver::addInd_h ( NodeID  src,
NodeID  dst 
)

Add a node dst to tree(src)

Definition at line 349 of file CFLSolver.cpp.

350{
351 TreeNode* newNode = new TreeNode(dst);
352 auto resIns = indMap[dst].insert(std::make_pair(src, newNode));
353 if (resIns.second)
354 return resIns.first->second;
355 delete newNode;
356 return nullptr;
357}

◆ getNode_h()

TreeNode * SVF::POCRHybridSolver::getNode_h ( NodeID  src,
NodeID  dst 
)
inline

Get the node dst in tree(src)

Definition at line 331 of file CFLSolver.h.

332 {
333 return indMap[dst][src];
334 }

◆ hasInd_h()

bool POCRHybridSolver::hasInd_h ( NodeID  src,
NodeID  dst 
)

Definition at line 341 of file CFLSolver.cpp.

342{
343 auto it = indMap.find(dst);
344 if (it == indMap.end())
345 return false;
346 return (it->second.find(src) != it->second.end());
347}

◆ initialize()

void POCRHybridSolver::initialize ( )
virtual

Initialize worklist.

add X(i,i) if not exist to E and to worklist

Foreach production X -> epsilon add X(i,i) if not exist to E and to worklist

Foreach production X -> epsilon add X(i,i) if not exist to E and to worklist

Reimplemented from SVF::POCRSolver.

Definition at line 284 of file CFLSolver.cpp.

285{
286 for(auto edge : graph->getCFLEdges())
287 {
289 }
290
291 // init hybrid dataset
292 for (auto it = graph->begin(); it != graph->end(); ++it)
293 {
294 NodeID nId = it->first;
295 addInd_h(nId, nId);
296 }
297
299 for(const Production& prod : grammar->getEpsilonProds())
300 {
301 for(auto IDMap : getSuccMap())
302 {
304 if (addEdge(IDMap.first, IDMap.first, X))
305 {
306 CFLNode* i = graph->getGNode(IDMap.first);
307 const CFLEdge* newEdge = graph->addCFLEdge(i, i, X);
309 }
310 }
311 }
312}
const Symbol & getLHSSymbol(const Production &prod) const
Definition CFGrammar.h:368
virtual const CFLEdge * addCFLEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
Definition CFLGraph.cpp:47
CFGrammar::Production Production
Definition CFLSolver.h:49
CFGrammar::Symbol Symbol
Definition CFLSolver.h:50
virtual bool pushIntoWorklist(const CFLEdge *item)
Definition CFLSolver.h:84
CFLGraph * graph
Definition CFLSolver.h:108
iterator begin()
Iterators.
NodeType * getGNode(NodeID id) const
Get a node.
TreeNode * addInd_h(NodeID src, NodeID dst)
Add a node dst to tree(src)
bool addEdge(const NodeID src, const NodeID dst, const Label ty)
Definition CFLSolver.h:215
DataMap & getSuccMap()
Definition CFLSolver.h:183
u32_t NodeID
Definition GeneralType.h:55

◆ insertEdge_h()

void SVF::POCRHybridSolver::insertEdge_h ( TreeNode u,
TreeNode v 
)
inline

add v into desc(x) as a child of u

Definition at line 337 of file CFLSolver.h.

338 {
339 u->children.insert(v);
340 }

◆ meld()

void POCRHybridSolver::meld ( NodeID  x,
TreeNode uNode,
TreeNode vNode 
)

Definition at line 326 of file CFLSolver.cpp.

327{
328 numOfChecks++;
329
330 TreeNode* newVNode = addInd_h(x, vNode->id);
331 if (!newVNode)
332 return;
333
335 for (TreeNode* vChild: vNode->children)
336 {
338 }
339}
static double numOfChecks
Definition CFLSolver.h:52
void insertEdge_h(TreeNode *u, TreeNode *v)
add v into desc(x) as a child of u
Definition CFLSolver.h:337
iter_range< typename GenericGraphTraits< GraphType >::ChildIteratorType > children(const typename GenericGraphTraits< GraphType >::NodeRef &G)

◆ meld_h()

void POCRHybridSolver::meld_h ( NodeID  x,
TreeNode uNode,
TreeNode vNode 
)

Definition at line 370 of file CFLSolver.cpp.

371{
372 TreeNode* newVNode = addInd_h(x, vNode->id);
373 if (!newVNode)
374 return;
375
377 for (TreeNode* vChild: vNode->children)
378 {
380 }
381}

◆ processCFLEdge()

void POCRHybridSolver::processCFLEdge ( const CFLEdge Y_edge)
virtual

Process CFLEdge.

For each production X -> Y add X(i,j) if not exist to E and to worklist

For each production X -> Y Z Foreach outgoing edge Z(j,k) from node j do add X(i,k) if not exist to E and to worklist

For each production X -> Z Y Foreach incoming edge Z(k,i) to node i do add X(k,j) if not exist to E and to worklist

Reimplemented from SVF::POCRSolver.

Definition at line 216 of file CFLSolver.cpp.

217{
218 CFLNode* i = Y_edge->getSrcNode();
219 CFLNode* j = Y_edge->getDstNode();
220
223 Symbol Y = Y_edge->getEdgeKind();
225 for(const Production& prod : grammar->getProdsFromSingleRHS(Y))
226 {
228 numOfChecks++;
229 if (addEdge(i->getId(), j->getId(), X))
230 {
231 const CFLEdge* newEdge = graph->addCFLEdge(Y_edge->getSrcNode(), Y_edge->getDstNode(), X);
233 }
234
235 }
236
241 for(const Production& prod : grammar->getProdsFromFirstRHS(Y))
242 {
244 {
245 addArc(i->getId(), j->getId());
246 }
247 else
248 {
251 numOfChecks += getSuccMap(j->getId())[grammar->getSecondRHSSymbol(prod)].count();
252 for (NodeID diffDst: diffDsts)
253 {
256 }
257 }
258 }
259
264 for(const Production& prod : grammar->getProdsFromSecondRHS(Y))
265 {
267 {
268 addArc(i->getId(), j->getId());
269 }
270 else
271 {
273 NodeBS diffSrcs = addEdges(getPredMap(i->getId())[grammar->getFirstRHSSymbol(prod)], j->getId(), X);
274 numOfChecks += getPredMap(i->getId())[grammar->getFirstRHSSymbol(prod)].count();
275 for (NodeID diffSrc: diffSrcs)
276 {
279 }
280 }
281 }
282}
const Symbol & getFirstRHSSymbol(const Production &prod) const
Definition CFGrammar.h:373
const Symbol & getSecondRHSSymbol(const Production &prod) const
Definition CFGrammar.h:378
const bool hasProdsFromFirstRHS(const Symbol sym) const
Definition CFGrammar.h:328
const bool hasProdsFromSecondRHS(const Symbol sym) const
Definition CFGrammar.h:340
const bool hasProdsFromSingleRHS(const Symbol sym) const
Definition CFGrammar.h:334
void addArc(NodeID src, NodeID dst)
DataMap & getPredMap()
Definition CFLSolver.h:188
NodeBS addEdges(const NodeID src, const NodeBS &dstData, const Label ty)
add edges and return the set of added edges (dst) for src
Definition CFLSolver.h:222

Member Data Documentation

◆ indMap

Map<NodeID, std::unordered_map<NodeID, TreeNode*> > SVF::POCRHybridSolver::indMap

Definition at line 323 of file CFLSolver.h.


The documentation for this class was generated from the following files: