Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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, 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
 

Public Member Functions

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 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 CFLGraphgetGraph () const
 Return CFL Graph.
 
const CFGrammargetGrammar () 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 CFLEdgepopFromWorklist ()
 Worklist operations.
 
bool isInWorklist (const CFLEdge *item)
 

Protected Attributes

DataMap succMap
 
DataMap predMap
 
const NodeBS emptyData
 
NodeBS diff
 
- Protected Attributes inherited from SVF::CFLSolver
CFLGraphgraph
 
CFGrammargrammar
 
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 116 of file CFLSolver.h.

Member Typedef Documentation

◆ const_iterator

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

Definition at line 122 of file CFLSolver.h.

◆ DataMap

Definition at line 120 of file CFLSolver.h.

◆ iterator

Definition at line 121 of file CFLSolver.h.

◆ TypeMap

Definition at line 119 of file CFLSolver.h.

Constructor & Destructor Documentation

◆ POCRSolver()

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

Definition at line 269 of file CFLSolver.h.

269 : CFLSolver(_graph, _grammar)
270 {
271 buildCFLData();
272 }
CFLSolver(CFLGraph *_graph, CFGrammar *_grammar)
Definition CFLSolver.h:54
virtual void buildCFLData()
Init CFLData.
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ ~POCRSolver()

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

Destructor.

Definition at line 274 of file CFLSolver.h.

275 {
276 }

Member Function Documentation

◆ addEdge()

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

Definition at line 215 of file CFLSolver.h.

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

◆ 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 235 of file CFLSolver.h.

236 {
238 if (addPreds(dst, srcData, ty))
239 {
240 for (const NodeID datum: srcData)
241 if (addSucc(datum, dst, ty))
243 }
244 return newSrcs;
245 }
set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) add_llvm_executable(wpa wpa.cpp) target_link_libraries(wpa PUBLIC $
Definition CMakeLists.txt:1
if(prebuffer< 0)
Definition cJSON.cpp:1269
bool addPreds(const NodeID key, const NodeBS &data, const Label ty)
Definition CFLSolver.h:141
u32_t NodeID
Definition GeneralType.h:55
SparseBitVector NodeBS
Definition GeneralType.h:62

◆ 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 222 of file CFLSolver.h.

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

◆ addPred()

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

Definition at line 131 of file CFLSolver.h.

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

◆ addPreds()

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

Definition at line 141 of file CFLSolver.h.

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

◆ addSucc()

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

Definition at line 136 of file CFLSolver.h.

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

◆ addSuccs()

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

Definition at line 148 of file CFLSolver.h.

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

◆ begin() [1/2]

iterator SVF::POCRSolver::begin ( )
inline

Definition at line 173 of file CFLSolver.h.

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

◆ begin() [2/2]

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

Definition at line 163 of file CFLSolver.h.

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

◆ 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:108
bool addEdge(const NodeID src, const NodeID dst, const Label ty)
Definition CFLSolver.h:215

◆ clear()

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

Definition at line 157 of file CFLSolver.h.

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

◆ clearEdges()

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

Definition at line 262 of file CFLSolver.h.

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

◆ end() [1/2]

iterator SVF::POCRSolver::end ( )
inline

Definition at line 178 of file CFLSolver.h.

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

◆ end() [2/2]

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

Definition at line 168 of file CFLSolver.h.

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

◆ getPredMap() [1/2]

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

Definition at line 188 of file CFLSolver.h.

189 {
190 return predMap;
191 }

◆ getPredMap() [2/2]

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

Definition at line 198 of file CFLSolver.h.

199 {
200 return predMap[key];
201 }

◆ getPreds()

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

Definition at line 208 of file CFLSolver.h.

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

◆ getSuccMap() [1/2]

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

Definition at line 183 of file CFLSolver.h.

184 {
185 return succMap;
186 }

◆ getSuccMap() [2/2]

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

Definition at line 193 of file CFLSolver.h.

194 {
195 return succMap[key];
196 }

◆ getSuccs()

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

Definition at line 203 of file CFLSolver.h.

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

◆ 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 248 of file CFLSolver.h.

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

◆ initialize()

void POCRSolver::initialize ( )
virtual

Initialize 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::CFLSolver.

Reimplemented in SVF::POCRHybridSolver.

Definition at line 192 of file CFLSolver.cpp.

193{
194 for(auto edge : graph->getCFLEdges())
195 {
197 }
198
201 for(const Production& prod : grammar->getEpsilonProds())
202 {
203 for(auto IDMap : getSuccMap())
204 {
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);
211 }
212 }
213 }
214}
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
CFGrammar * grammar
Definition CFLSolver.h:109
virtual bool pushIntoWorklist(const CFLEdge *item)
Definition CFLSolver.h:84
NodeType * getGNode(NodeID id) const
Get a node.
DataMap & getSuccMap()
Definition CFLSolver.h:183

◆ 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();
147 for(const Production& prod : grammar->getProdsFromSingleRHS(Y))
148 {
150 numOfChecks++;
151 if (addEdge(i->getId(), j->getId(), X))
152 {
153 const CFLEdge* newEdge = graph->addCFLEdge(Y_edge->getSrcNode(), Y_edge->getDstNode(), X);
155 }
156
157 }
158
163 for(const Production& prod : grammar->getProdsFromFirstRHS(Y))
164 {
167 numOfChecks += getSuccMap(j->getId())[grammar->getSecondRHSSymbol(prod)].count();
168 for (NodeID diffDst: diffDsts)
169 {
172 }
173 }
174
179 for(const Production& prod : grammar->getProdsFromSecondRHS(Y))
180 {
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 {
188 }
189 }
190}
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
static double numOfChecks
Definition CFLSolver.h:52
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

◆ diff

NodeBS SVF::POCRSolver::diff
protected

Definition at line 128 of file CFLSolver.h.

◆ emptyData

const NodeBS SVF::POCRSolver::emptyData
protected

Definition at line 127 of file CFLSolver.h.

◆ predMap

DataMap SVF::POCRSolver::predMap
protected

Definition at line 126 of file CFLSolver.h.

◆ succMap

DataMap SVF::POCRSolver::succMap
protected

Definition at line 125 of file CFLSolver.h.


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