Static Value-Flow Analysis
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) More...
 
TreeNodegetNode_h (NodeID src, NodeID dst)
 Get the node dst in tree(src) More...
 
void insertEdge_h (TreeNode *u, TreeNode *v)
 add v into desc(x) as a child of u More...
 
void addArc_h (NodeID src, NodeID dst)
 
void meld_h (NodeID x, TreeNode *uNode, TreeNode *vNode)
 
 POCRHybridSolver (CFLGraph *_graph, CFGrammar *_grammar)
 
virtual ~POCRHybridSolver ()
 Destructor. More...
 
virtual void processCFLEdge (const CFLEdge *Y_edge)
 Process CFLEdge. More...
 
virtual void initialize ()
 Initialize worklist. More...
 
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 More...
 
NodeBS addEdges (const NodeBS &srcData, const NodeID dst, const Label ty)
 add edges and return the set of added edges (src) for dst More...
 
bool hasEdge (const NodeID src, const NodeID dst, const Label ty)
 find src -> find src[ty] -> find dst in set More...
 
void clearEdges (const NodeID key)
 
 POCRSolver (CFLGraph *_graph, CFGrammar *_grammar)
 
virtual ~POCRSolver ()
 Destructor. More...
 
virtual void buildCFLData ()
 Init CFLData. More...
 
- Public Member Functions inherited from SVF::CFLSolver
 CFLSolver (CFLGraph *_graph, CFGrammar *_grammar)
 
virtual ~CFLSolver ()
 
virtual void solve ()
 Start solving. More...
 
const CFLGraphgetGraph () const
 Return CFL Graph. More...
 
const CFGrammargetGrammar () const
 Return CFL Grammar. More...
 
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. More...
 
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. More...
 
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. More...
 

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

◆ ~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  }
return NULL
Definition: cJSON.cpp:1173
Map< NodeID, std::unordered_map< NodeID, TreeNode * > > indMap
Definition: CFLSolver.h:323

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
void meld(NodeID x, TreeNode *uNode, TreeNode *vNode)
Definition: CFLSolver.cpp:326
TreeNode * getNode_h(NodeID src, NodeID dst)
Get the node dst in tree(src)
Definition: CFLSolver.h:331
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)
Definition: CFLSolver.cpp:370
bool hasInd_h(NodeID src, NodeID dst)
Definition: CFLSolver.cpp:341

◆ 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  {
288  pushIntoWorklist(edge);
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  {
303  Symbol X = grammar->getLHSSymbol(prod);
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);
308  pushIntoWorklist(newEdge);
309  }
310  }
311  }
312 }
const Symbol & getLHSSymbol(const Production &prod) const
Definition: CFGrammar.h:368
Productions & getEpsilonProds()
Definition: CFGrammar.h:308
virtual const CFLEdge * addCFLEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
Definition: CFLGraph.cpp:47
const CFLEdgeSet & getCFLEdges() const
Definition: CFLGraph.h:199
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.
Definition: GenericGraph.h:627
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
TreeNode * addInd_h(NodeID src, NodeID dst)
Add a node dst to tree(src)
Definition: CFLSolver.cpp:349
DataMap & getSuccMap()
Definition: CFLSolver.h:183
bool addEdge(const NodeID src, const NodeID dst, const Label ty)
Definition: CFLSolver.h:215
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 
334  insertEdge_h(uNode, newVNode);
335  for (TreeNode* vChild: vNode->children)
336  {
337  meld_h(x, newVNode, vChild);
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

◆ 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 
376  insertEdge_h(uNode, newVNode);
377  for (TreeNode* vChild: vNode->children)
378  {
379  meld_h(x, newVNode, vChild);
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  {
227  Symbol X = grammar->getLHSSymbol(prod);
228  numOfChecks++;
229  if (addEdge(i->getId(), j->getId(), X))
230  {
231  const CFLEdge* newEdge = graph->addCFLEdge(Y_edge->getSrcNode(), Y_edge->getDstNode(), X);
232  pushIntoWorklist(newEdge);
233  }
234 
235  }
236 
241  for(const Production& prod : grammar->getProdsFromFirstRHS(Y))
242  {
243  if ((grammar->getLHSSymbol(prod) == grammar->strToSymbol("F")) && (Y == grammar->strToSymbol("F")) && (grammar->getSecondRHSSymbol(prod) == grammar->strToSymbol("F")))
244  {
245  addArc(i->getId(), j->getId());
246  }
247  else
248  {
249  Symbol X = grammar->getLHSSymbol(prod);
250  NodeBS diffDsts = addEdges(i->getId(), getSuccMap(j->getId())[grammar->getSecondRHSSymbol(prod)], X);
251  numOfChecks += getSuccMap(j->getId())[grammar->getSecondRHSSymbol(prod)].count();
252  for (NodeID diffDst: diffDsts)
253  {
254  const CFLEdge* newEdge = graph->addCFLEdge(i, graph->getGNode(diffDst), X);
255  pushIntoWorklist(newEdge);
256  }
257  }
258  }
259 
264  for(const Production& prod : grammar->getProdsFromSecondRHS(Y))
265  {
266  if ((grammar->getLHSSymbol(prod) == grammar->strToSymbol("F")) && (Y == grammar->strToSymbol("F")) && (grammar->getFirstRHSSymbol(prod) == grammar->strToSymbol("F")))
267  {
268  addArc(i->getId(), j->getId());
269  }
270  else
271  {
272  Symbol X = grammar->getLHSSymbol(prod);
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  {
277  const CFLEdge* newEdge = graph->addCFLEdge(graph->getGNode(diffSrc), j, X);
278  pushIntoWorklist(newEdge);
279  }
280  }
281  }
282 }
const Productions & getProdsFromSingleRHS(const Symbol sym) const
Definition: CFGrammar.h:346
const Productions & getProdsFromFirstRHS(const Symbol sym) const
Definition: CFGrammar.h:353
const Productions & getProdsFromSecondRHS(const Symbol sym) const
Definition: CFGrammar.h:360
const Symbol & getFirstRHSSymbol(const Production &prod) const
Definition: CFGrammar.h:373
const bool hasProdsFromFirstRHS(const Symbol sym) const
Definition: CFGrammar.h:328
const bool hasProdsFromSecondRHS(const Symbol sym) const
Definition: CFGrammar.h:340
const Symbol & getSecondRHSSymbol(const Production &prod) const
Definition: CFGrammar.h:378
const bool hasProdsFromSingleRHS(const Symbol sym) const
Definition: CFGrammar.h:334
GEdgeKind getEdgeKind() const
Definition: CFLGraph.h:58
NodeType * getSrcNode() const
Definition: GenericGraph.h:97
NodeType * getDstNode() const
Definition: GenericGraph.h:101
void addArc(NodeID src, NodeID dst)
Definition: CFLSolver.cpp:314
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
DataMap & getPredMap()
Definition: CFLSolver.h:188
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260

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: