Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::POCRSolver Class Reference

Solver Utilize CFLData. More...

#include <CFLSolver.h>

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

Public Types

typedef std::map< const Label, NodeBS > TypeMap
typedef std::unordered_map< NodeID, TypeMap > DataMap
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

Public Member Functions

virtual void clear ()
const_iterator begin () const
const_iterator end () const
iterator begin ()
iterator end ()
DataMap & getSuccMap ()
DataMap & getPredMap ()
TypeMap & getSuccMap (const NodeID key)
TypeMap & getPredMap (const NodeID key)
NodeBS & getSuccs (const NodeID key, const Label ty)
NodeBS & getPreds (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 processCFLEdge (const CFLEdge *Y_edge)
 Process CFLEdge.
virtual void buildCFLData ()
 Init CFLData.
virtual void initialize ()
 Initialize worklist.
Public Member Functions inherited from SVF::CFLSolver
 CFLSolver (CFLGraph *_graph, CFGrammar *_grammar)
virtual ~CFLSolver ()
virtual void solve ()
 Start solving.
const CFLGraph * getGraph () const
 Return CFL Graph.
const CFGrammar * getGrammar () const
 Return CFL Grammar.
virtual bool pushIntoWorklist (const CFLEdge *item)
virtual bool isWorklistEmpty ()

Protected Member Functions

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 CFLEdge * popFromWorklist ()
 Worklist operations.
bool isInWorklist (const CFLEdge *item)

Protected Attributes

DataMap succMap
DataMap predMap
const NodeBS emptyData
NodeBS diff
Protected Attributes inherited from SVF::CFLSolver
CFLGraph * graph
CFGrammar * grammar
WorkList worklist
 Worklist for resolution.

Additional Inherited Members

Static Public Attributes inherited from SVF::CFLSolver
static double numOfChecks = 0

Detailed Description

Solver Utilize CFLData.

Definition at line 117 of file CFLSolver.h.

Member Typedef Documentation

◆ const_iterator

typedef DataMap::const_iterator SVF::POCRSolver::const_iterator

Definition at line 123 of file CFLSolver.h.

◆ DataMap

typedef std::unordered_map<NodeID, TypeMap> SVF::POCRSolver::DataMap

Definition at line 121 of file CFLSolver.h.

◆ iterator

typedef DataMap::iterator SVF::POCRSolver::iterator

Definition at line 122 of file CFLSolver.h.

◆ TypeMap

typedef std::map<const Label, NodeBS> SVF::POCRSolver::TypeMap

Definition at line 120 of file CFLSolver.h.

Constructor & Destructor Documentation

◆ POCRSolver()

SVF::POCRSolver::POCRSolver ( CFLGraph * _graph,
CFGrammar * _grammar )
inline

Definition at line 270 of file CFLSolver.h.

270 : CFLSolver(_graph, _grammar)
271 {
272 buildCFLData();
273 }
CFLSolver(CFLGraph *_graph, CFGrammar *_grammar)
Definition CFLSolver.h:55
virtual void buildCFLData()
Init CFLData.

◆ ~POCRSolver()

virtual SVF::POCRSolver::~POCRSolver ( )
inlinevirtual

Destructor.

Definition at line 275 of file CFLSolver.h.

276 {
277 }

Member Function Documentation

◆ addEdge()

bool SVF::POCRSolver::addEdge ( const NodeID src,
const NodeID dst,
const Label ty )
inline

Definition at line 216 of file CFLSolver.h.

217 {
218 addSucc(src, dst, ty);
219 return addPred(dst, src, ty);
220 }
bool addPred(const NodeID key, const NodeID src, const Label ty)
Definition CFLSolver.h:132
bool addSucc(const NodeID key, const NodeID dst, const Label ty)
Definition CFLSolver.h:137

◆ addEdges() [1/2]

NodeBS SVF::POCRSolver::addEdges ( const NodeBS & srcData,
const NodeID dst,
const Label ty )
inline

add edges and return the set of added edges (src) for dst

Definition at line 236 of file CFLSolver.h.

237 {
238 NodeBS newSrcs;
239 if (addPreds(dst, srcData, ty))
240 {
241 for (const NodeID datum: srcData)
242 if (addSucc(datum, dst, ty))
243 newSrcs.set(datum);
244 }
245 return newSrcs;
246 }
bool addPreds(const NodeID key, const NodeBS &data, const Label ty)
Definition CFLSolver.h:142
u32_t NodeID
Definition GeneralType.h:76
SparseBitVector NodeBS
Definition GeneralType.h:82

◆ addEdges() [2/2]

NodeBS SVF::POCRSolver::addEdges ( const NodeID src,
const NodeBS & dstData,
const Label ty )
inline

add edges and return the set of added edges (dst) for src

Definition at line 223 of file CFLSolver.h.

224 {
225 NodeBS newDsts;
226 if (addSuccs(src, dstData, ty))
227 {
228 for (const NodeID datum: dstData)
229 if (addPred(datum, src, ty))
230 newDsts.set(datum);
231 }
232 return newDsts;
233 }
bool addSuccs(const NodeID key, const NodeBS &data, const Label ty)
Definition CFLSolver.h:149

◆ addPred()

bool SVF::POCRSolver::addPred ( const NodeID key,
const NodeID src,
const Label ty )
inlineprotected

Definition at line 132 of file CFLSolver.h.

133 {
134 return predMap[key][ty].test_and_set(src);
135 };
DataMap predMap
Definition CFLSolver.h:127

◆ addPreds()

bool SVF::POCRSolver::addPreds ( const NodeID key,
const NodeBS & data,
const Label ty )
inlineprotected

Definition at line 142 of file CFLSolver.h.

143 {
144 if (data.empty())
145 return false;
146 return predMap[key][ty] |= data; // union of sparsebitvector (add to LHS)
147 }

◆ addSucc()

bool SVF::POCRSolver::addSucc ( const NodeID key,
const NodeID dst,
const Label ty )
inlineprotected

Definition at line 137 of file CFLSolver.h.

138 {
139 return succMap[key][ty].test_and_set(dst);
140 };
DataMap succMap
Definition CFLSolver.h:126

◆ addSuccs()

bool SVF::POCRSolver::addSuccs ( const NodeID key,
const NodeBS & data,
const Label ty )
inlineprotected

Definition at line 149 of file CFLSolver.h.

150 {
151 if (data.empty())
152 return false;
153 return succMap[key][ty] |= data; // // union of sparsebitvector (add to LHS)
154 }

◆ begin() [1/2]

iterator SVF::POCRSolver::begin ( )
inline

Definition at line 174 of file CFLSolver.h.

175 {
176 return succMap.begin();
177 }

◆ begin() [2/2]

const_iterator SVF::POCRSolver::begin ( ) const
inline

Definition at line 164 of file CFLSolver.h.

165 {
166 return succMap.begin();
167 }

◆ buildCFLData()

void POCRSolver::buildCFLData ( )
virtual

Init CFLData.

Definition at line 132 of file CFLSolver.cpp.

133{
134 for (CFLEdge* edge: graph->getCFLEdges())
135 addEdge(edge->getSrcID(), edge->getDstID(), edge->getEdgeKind());
136}
CFLGraph * graph
Definition CFLSolver.h:109
bool addEdge(const NodeID src, const NodeID dst, const Label ty)
Definition CFLSolver.h:216

◆ clear()

virtual void SVF::POCRSolver::clear ( )
inlinevirtual

Definition at line 158 of file CFLSolver.h.

159 {
160 succMap.clear();
161 predMap.clear();
162 }

◆ clearEdges()

void SVF::POCRSolver::clearEdges ( const NodeID key)
inline

Definition at line 263 of file CFLSolver.h.

264 {
265 succMap[key].clear();
266 predMap[key].clear();
267 }

◆ end() [1/2]

iterator SVF::POCRSolver::end ( )
inline

Definition at line 179 of file CFLSolver.h.

180 {
181 return succMap.end();
182 }

◆ end() [2/2]

const_iterator SVF::POCRSolver::end ( ) const
inline

Definition at line 169 of file CFLSolver.h.

170 {
171 return succMap.end();
172 }

◆ getPredMap() [1/2]

DataMap & SVF::POCRSolver::getPredMap ( )
inline

Definition at line 189 of file CFLSolver.h.

190 {
191 return predMap;
192 }

◆ getPredMap() [2/2]

TypeMap & SVF::POCRSolver::getPredMap ( const NodeID key)
inline

Definition at line 199 of file CFLSolver.h.

200 {
201 return predMap[key];
202 }

◆ getPreds()

NodeBS & SVF::POCRSolver::getPreds ( const NodeID key,
const Label ty )
inline

Definition at line 209 of file CFLSolver.h.

210 {
211 return predMap[key][ty];
212 }

◆ getSuccMap() [1/2]

DataMap & SVF::POCRSolver::getSuccMap ( )
inline

Definition at line 184 of file CFLSolver.h.

185 {
186 return succMap;
187 }

◆ getSuccMap() [2/2]

TypeMap & SVF::POCRSolver::getSuccMap ( const NodeID key)
inline

Definition at line 194 of file CFLSolver.h.

195 {
196 return succMap[key];
197 }

◆ getSuccs()

NodeBS & SVF::POCRSolver::getSuccs ( const NodeID key,
const Label ty )
inline

Definition at line 204 of file CFLSolver.h.

205 {
206 return succMap[key][ty];
207 }

◆ hasEdge()

bool SVF::POCRSolver::hasEdge ( const NodeID src,
const NodeID dst,
const Label ty )
inline

find src -> find src[ty] -> find dst in set

Definition at line 249 of file CFLSolver.h.

250 {
251 const_iterator iter1 = succMap.find(src);
252 if (iter1 == succMap.end())
253 return false;
254
255 auto iter2 = iter1->second.find(ty);
256 if (iter2 == iter1->second.end())
257 return false;
258
259 return iter2->second.test(dst);
260 }
DataMap::const_iterator const_iterator
Definition CFLSolver.h:123

◆ initialize()

void POCRSolver::initialize ( )
virtual

Initialize worklist.

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

Reimplemented from SVF::CFLSolver.

Reimplemented in SVF::POCRHybridSolver.

Definition at line 192 of file CFLSolver.cpp.

193{
194 for(auto edge : graph->getCFLEdges())
195 {
196 pushIntoWorklist(edge);
197 }
198
201 for(const Production& prod : grammar->getEpsilonProds())
202 {
203 for(auto IDMap : getSuccMap())
204 {
205 Symbol X = grammar->getLHSSymbol(prod);
206 if (addEdge(IDMap.first, IDMap.first, X))
207 {
208 CFLNode* i = graph->getGNode(IDMap.first);
209 const CFLEdge* newEdge = graph->addCFLEdge(i, i, X);
210 pushIntoWorklist(newEdge);
211 }
212 }
213 }
214}
CFGrammar::Production Production
Definition CFLSolver.h:50
CFGrammar::Symbol Symbol
Definition CFLSolver.h:51
CFGrammar * grammar
Definition CFLSolver.h:110
virtual bool pushIntoWorklist(const CFLEdge *item)
Definition CFLSolver.h:85
DataMap & getSuccMap()
Definition CFLSolver.h:184

◆ processCFLEdge()

void POCRSolver::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::CFLSolver.

Reimplemented in SVF::POCRHybridSolver.

Definition at line 138 of file CFLSolver.cpp.

139{
140 CFLNode* i = Y_edge->getSrcNode();
141 CFLNode* j = Y_edge->getDstNode();
142
145 Symbol Y = Y_edge->getEdgeKind();
146 if (grammar->hasProdsFromSingleRHS(Y))
147 for(const Production& prod : grammar->getProdsFromSingleRHS(Y))
148 {
149 Symbol X = grammar->getLHSSymbol(prod);
150 numOfChecks++;
151 if (addEdge(i->getId(), j->getId(), X))
152 {
153 const CFLEdge* newEdge = graph->addCFLEdge(Y_edge->getSrcNode(), Y_edge->getDstNode(), X);
154 pushIntoWorklist(newEdge);
155 }
156
157 }
158
162 if (grammar->hasProdsFromFirstRHS(Y))
163 for(const Production& prod : grammar->getProdsFromFirstRHS(Y))
164 {
165 Symbol X = grammar->getLHSSymbol(prod);
166 NodeBS diffDsts = addEdges(i->getId(), getSuccMap(j->getId())[grammar->getSecondRHSSymbol(prod)], X);
167 numOfChecks += getSuccMap(j->getId())[grammar->getSecondRHSSymbol(prod)].count();
168 for (NodeID diffDst: diffDsts)
169 {
170 const CFLEdge* newEdge = graph->addCFLEdge(i, graph->getGNode(diffDst), X);
171 pushIntoWorklist(newEdge);
172 }
173 }
174
178 if(grammar->hasProdsFromSecondRHS(Y))
179 for(const Production& prod : grammar->getProdsFromSecondRHS(Y))
180 {
181 Symbol X = grammar->getLHSSymbol(prod);
182 NodeBS diffSrcs = addEdges(getPredMap(i->getId())[grammar->getFirstRHSSymbol(prod)], j->getId(), X);
183 numOfChecks += getPredMap(i->getId())[grammar->getFirstRHSSymbol(prod)].count();
184 for (NodeID diffSrc: diffSrcs)
185 {
186 const CFLEdge* newEdge = graph->addCFLEdge(graph->getGNode(diffSrc), j, X);
187 pushIntoWorklist(newEdge);
188 }
189 }
190}
GEdgeKind getEdgeKind() const
Definition CFLGraph.h:57
static double numOfChecks
Definition CFLSolver.h:53
NodeType * getSrcNode() const
NodeType * getDstNode() const
DataMap & getPredMap()
Definition CFLSolver.h:189
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:223
NodeID getId() const
Get ID.
Definition SVFValue.h:158

Member Data Documentation

◆ diff

NodeBS SVF::POCRSolver::diff
protected

Definition at line 129 of file CFLSolver.h.

◆ emptyData

const NodeBS SVF::POCRSolver::emptyData
protected

Definition at line 128 of file CFLSolver.h.

◆ predMap

DataMap SVF::POCRSolver::predMap
protected

Definition at line 127 of file CFLSolver.h.

◆ succMap

DataMap SVF::POCRSolver::succMap
protected

Definition at line 126 of file CFLSolver.h.


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