Static Value-Flow Analysis
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SVF::SCCDetection< GraphType > Class Template Reference

#include <SCC.h>

Classes

class  GNodeSCCInfo
 

Public Types

typedef std::stack< NodeIDGNodeStack
 
typedef Map< NodeID, GNodeSCCInfoGNODESCCInfoMap
 
typedef Map< NodeID, NodeIDNodeToNodeMap
 

Public Member Functions

 SCCDetection (const GraphType &GT)
 
GNodeStacktopoNodeStack ()
 
const GNodeStacktopoNodeStack () const
 
FIFOWorkList< NodeIDrevTopoNodeStack () const
 
const GNODESCCInfoMapGNodeSCCInfo () const
 
NodeID repNode (NodeID n) const
 get the rep node if not found return itself
 
bool isInCycle (NodeID n) const
 whether the node is in a cycle
 
const NodeBSsubNodes (NodeID n) const
 get all subnodes in one scc, if size is empty insert itself into the set
 
const NodeBSgetRepNodes () const
 get all repNodeID
 
const GraphTypegraph ()
 
void find (void)
 
void find (NodeSet &candidates)
 

Private Types

typedef SVF::GenericGraphTraits< GraphTypeGTraits
 Define the GTraits and node iterator for printing.
 
typedef GTraits::NodeRef GNODE
 
typedef GTraits::nodes_iterator node_iterator
 
typedef GTraits::ChildIteratorType child_iterator
 
typedef unsigned NodeID
 

Private Member Functions

bool visited (NodeID n)
 
bool inSCC (NodeID n)
 
void setVisited (NodeID n, bool v)
 
void setInSCC (NodeID n, bool v)
 
void rep (NodeID n, NodeID r)
 
NodeID rep (NodeID n)
 
bool isInSCC (NodeID n)
 
GNODE Node (NodeID id) const
 
NodeID Node_Index (GNODE node) const
 
void visit (NodeID v)
 
void clear ()
 

Private Attributes

GNODESCCInfoMap _NodeSCCAuxInfo
 
const GraphType_graph
 
NodeID _I
 
NodeToNodeMap _D
 
GNodeStack _SS
 
GNodeStack _T
 
NodeBS repNodes
 

Detailed Description

template<class GraphType>
class SVF::SCCDetection< GraphType >

Definition at line 56 of file SCC.h.

Member Typedef Documentation

◆ child_iterator

template<class GraphType >
typedef GTraits::ChildIteratorType SVF::SCCDetection< GraphType >::child_iterator
private

Definition at line 64 of file SCC.h.

◆ GNODE

Definition at line 62 of file SCC.h.

◆ GNODESCCInfoMap

Definition at line 118 of file SCC.h.

◆ GNodeStack

template<class GraphType >
typedef std::stack<NodeID> SVF::SCCDetection< GraphType >::GNodeStack

Definition at line 68 of file SCC.h.

◆ GTraits

Define the GTraits and node iterator for printing.

Definition at line 61 of file SCC.h.

◆ node_iterator

template<class GraphType >
typedef GTraits::nodes_iterator SVF::SCCDetection< GraphType >::node_iterator
private

Definition at line 63 of file SCC.h.

◆ NodeID

template<class GraphType >
typedef unsigned SVF::SCCDetection< GraphType >::NodeID
private

Definition at line 65 of file SCC.h.

◆ NodeToNodeMap

Definition at line 119 of file SCC.h.

Constructor & Destructor Documentation

◆ SCCDetection()

template<class GraphType >
SVF::SCCDetection< GraphType >::SCCDetection ( const GraphType GT)
inline

Definition at line 121 of file SCC.h.

122 : _graph(GT),
123 _I(0)
124 {}
const GraphType & _graph
Definition SCC.h:217
NodeID _I
Definition SCC.h:218
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

Member Function Documentation

◆ clear()

template<class GraphType >
void SVF::SCCDetection< GraphType >::clear ( )
inlineprivate

Definition at line 318 of file SCC.h.

319 {
320 _NodeSCCAuxInfo.clear();
321 _I = 0;
322 _D.clear();
323 repNodes.clear();
324 while(!_SS.empty())
325 _SS.pop();
326 while(!_T.empty())
327 _T.pop();
328 }
GNodeStack _T
Definition SCC.h:221
GNodeStack _SS
Definition SCC.h:220
NodeBS repNodes
Definition SCC.h:222
GNODESCCInfoMap _NodeSCCAuxInfo
Definition SCC.h:215
NodeToNodeMap _D
Definition SCC.h:219

◆ find() [1/2]

template<class GraphType >
void SVF::SCCDetection< GraphType >::find ( NodeSet candidates)
inline

Definition at line 357 of file SCC.h.

358 {
359 // This function is reloaded to only visit candidate NODES
360 clear();
361 for (NodeID node : candidates)
362 {
363 if (!this->visited(node))
364 {
365 if (this->rep(node) == UINT_MAX || this->rep(node) == node)
366 visit(node);
367 else
368 this->visited(node);
369 }
370 }
371 }
void rep(NodeID n, NodeID r)
Definition SCC.h:241
void clear()
Definition SCC.h:318
unsigned NodeID
Definition SCC.h:65
bool visited(NodeID n)
Definition SCC.h:224
void visit(NodeID v)
Definition SCC.h:272

◆ find() [2/2]

template<class GraphType >
void SVF::SCCDetection< GraphType >::find ( void  )
inline

Definition at line 331 of file SCC.h.

332 {
333 // Visit each unvisited root node. A root node is defined
334 // to be a node that has no incoming copy/skew edges
335 clear();
336 node_iterator I = GTraits::nodes_begin(_graph);
337 node_iterator E = GTraits::nodes_end(_graph);
338 for (; I != E; ++I)
339 {
340 NodeID node = Node_Index(*I);
341 if (!this->visited(node))
342 {
343 // We skip any nodes that have a representative other than
344 // themselves. Such nodes occur as a result of merging
345 // nodes either through unifying an ACC or other node
346 // merging optimizations. Any such node should have no
347 // outgoing edges and therefore should no longer be a member
348 // of an SCC.
349 if (this->rep(node) == UINT_MAX || this->rep(node) == node)
350 visit(node);
351 else
352 this->visited(node);
353 }
354 }
355 }
NodeID Node_Index(GNODE node) const
Definition SCC.h:267
GTraits::nodes_iterator node_iterator
Definition SCC.h:63

◆ getRepNodes()

template<class GraphType >
const NodeBS & SVF::SCCDetection< GraphType >::getRepNodes ( ) const
inline

get all repNodeID

Definition at line 204 of file SCC.h.

205 {
206 return repNodes;
207 }

◆ GNodeSCCInfo()

template<class GraphType >
const GNODESCCInfoMap & SVF::SCCDetection< GraphType >::GNodeSCCInfo ( ) const
inline

Definition at line 156 of file SCC.h.

157 {
158 return _NodeSCCAuxInfo;
159 }

◆ graph()

template<class GraphType >
const GraphType & SVF::SCCDetection< GraphType >::graph ( )
inline

Definition at line 209 of file SCC.h.

210 {
211 return _graph;
212 }

◆ inSCC()

template<class GraphType >
bool SVF::SCCDetection< GraphType >::inSCC ( NodeID  n)
inlineprivate

Definition at line 228 of file SCC.h.

229 {
230 return _NodeSCCAuxInfo[n].inSCC();
231 }
cJSON * n
Definition cJSON.cpp:2558

◆ isInCycle()

template<class GraphType >
bool SVF::SCCDetection< GraphType >::isInCycle ( NodeID  n) const
inline

whether the node is in a cycle

Definition at line 172 of file SCC.h.

173 {
174 NodeID rep = repNode(n);
175 // multi-node cycle
176 if (subNodes(rep).count() > 1)
177 {
178 return true;
179 }
180 // self-cycle
181 else
182 {
183 child_iterator EI = GTraits::direct_child_begin(Node(rep));
184 child_iterator EE = GTraits::direct_child_end(Node(rep));
185 for (; EI != EE; ++EI)
186 {
187 NodeID w = Node_Index(*EI);
188 if(w==rep)
189 return true;
190 }
191 return false;
192 }
193 }
int count
Definition cJSON.h:216
NodeID repNode(NodeID n) const
get the rep node if not found return itself
Definition SCC.h:162
GNODE Node(NodeID id) const
Definition SCC.h:262
const NodeBS & subNodes(NodeID n) const
get all subnodes in one scc, if size is empty insert itself into the set
Definition SCC.h:196
GTraits::ChildIteratorType child_iterator
Definition SCC.h:64

◆ isInSCC()

template<class GraphType >
bool SVF::SCCDetection< GraphType >::isInSCC ( NodeID  n)
inlineprivate

Definition at line 257 of file SCC.h.

258 {
259 return _NodeSCCAuxInfo[n].inSCC();
260 }

◆ Node()

template<class GraphType >
GNODE SVF::SCCDetection< GraphType >::Node ( NodeID  id) const
inlineprivate

Definition at line 262 of file SCC.h.

263 {
264 return GTraits::getNode(_graph, id);
265 }

◆ Node_Index()

template<class GraphType >
NodeID SVF::SCCDetection< GraphType >::Node_Index ( GNODE  node) const
inlineprivate

Definition at line 267 of file SCC.h.

268 {
269 return GTraits::getNodeID(node);
270 }

◆ rep() [1/2]

template<class GraphType >
NodeID SVF::SCCDetection< GraphType >::rep ( NodeID  n)
inlineprivate

Definition at line 253 of file SCC.h.

254 {
255 return _NodeSCCAuxInfo[n].rep();
256 }

◆ rep() [2/2]

template<class GraphType >
void SVF::SCCDetection< GraphType >::rep ( NodeID  n,
NodeID  r 
)
inlineprivate

Definition at line 241 of file SCC.h.

242 {
243 _NodeSCCAuxInfo[n].rep(r);
244 _NodeSCCAuxInfo[r].addSubNodes(n);
245 if (n != r)
246 {
247 _NodeSCCAuxInfo[n].subNodes().clear();
249 repNodes.set(r);
250 }
251 }
void set(unsigned Idx)
void reset(unsigned Idx)

◆ repNode()

template<class GraphType >
NodeID SVF::SCCDetection< GraphType >::repNode ( NodeID  n) const
inline

get the rep node if not found return itself

Definition at line 162 of file SCC.h.

163 {
164 typename GNODESCCInfoMap::const_iterator it = _NodeSCCAuxInfo.find(n);
165 assert(it!=_NodeSCCAuxInfo.end() && "scc rep not found");
166 NodeID rep = it->second.rep();
167 return rep!= UINT_MAX ? rep : n ;
168 }

◆ revTopoNodeStack()

template<class GraphType >
FIFOWorkList< NodeID > SVF::SCCDetection< GraphType >::revTopoNodeStack ( ) const
inline

Return a handle to the stack of nodes in reverse topological order. This will be used to seed the initial solution and improve efficiency.

Definition at line 143 of file SCC.h.

144 {
145 FIFOWorkList<NodeID> revTopoOrder;
147 while(!topoOrder.empty())
148 {
149 NodeID nodeID = topoOrder.top();
150 topoOrder.pop();
151 revTopoOrder.push(nodeID);
152 }
153 return revTopoOrder;
154 }
GNodeStack & topoNodeStack()
Definition SCC.h:130
std::stack< NodeID > GNodeStack
Definition SCC.h:68

◆ setInSCC()

template<class GraphType >
void SVF::SCCDetection< GraphType >::setInSCC ( NodeID  n,
bool  v 
)
inlineprivate

Definition at line 237 of file SCC.h.

238 {
239 _NodeSCCAuxInfo[n].inSCC(v);
240 }

◆ setVisited()

template<class GraphType >
void SVF::SCCDetection< GraphType >::setVisited ( NodeID  n,
bool  v 
)
inlineprivate

Definition at line 233 of file SCC.h.

234 {
235 _NodeSCCAuxInfo[n].visited(v);
236 }

◆ subNodes()

template<class GraphType >
const NodeBS & SVF::SCCDetection< GraphType >::subNodes ( NodeID  n) const
inline

get all subnodes in one scc, if size is empty insert itself into the set

Definition at line 196 of file SCC.h.

197 {
198 typename GNODESCCInfoMap::const_iterator it = _NodeSCCAuxInfo.find(n);
199 assert(it!=_NodeSCCAuxInfo.end() && "scc rep not found");
200 return it->second.subNodes();
201 }

◆ topoNodeStack() [1/2]

template<class GraphType >
GNodeStack & SVF::SCCDetection< GraphType >::topoNodeStack ( )
inline

Definition at line 130 of file SCC.h.

131 {
132 return _T;
133 }

◆ topoNodeStack() [2/2]

template<class GraphType >
const GNodeStack & SVF::SCCDetection< GraphType >::topoNodeStack ( ) const
inline

Definition at line 135 of file SCC.h.

136 {
137 return _T;
138 }

◆ visit()

template<class GraphType >
void SVF::SCCDetection< GraphType >::visit ( NodeID  v)
inlineprivate

Definition at line 272 of file SCC.h.

273 {
274 // SVFUtil::outs() << "visit GNODE: " << Node_Index(v)<< "\n";
275 _I += 1;
276 _D[v] = _I;
277 this->rep(v,v);
278 this->setVisited(v,true);
279
280 child_iterator EI = GTraits::direct_child_begin(Node(v));
281 child_iterator EE = GTraits::direct_child_end(Node(v));
282
283 for (; EI != EE; ++EI)
284 {
285 NodeID w = Node_Index(*EI);
286
287 if (!this->visited(w))
288 visit(w);
289 if (!this->inSCC(w))
290 {
291 NodeID rep;
292 rep = _D[this->rep(v)] < _D[this->rep(w)] ?
293 this->rep(v) : this->rep(w);
294 this->rep(v,rep);
295 }
296 }
297 if (this->rep(v) == v)
298 {
299 this->setInSCC(v,true);
300 while (!_SS.empty())
301 {
302 NodeID w = _SS.top();
303 if (_D[w] <= _D[v])
304 break;
305 else
306 {
307 _SS.pop();
308 this->setInSCC(w,true);
309 this->rep(w,v);
310 }
311 }
312 _T.push(v);
313 }
314 else
315 _SS.push(v);
316 }
bool inSCC(NodeID n)
Definition SCC.h:228
void setInSCC(NodeID n, bool v)
Definition SCC.h:237
void setVisited(NodeID n, bool v)
Definition SCC.h:233

◆ visited()

template<class GraphType >
bool SVF::SCCDetection< GraphType >::visited ( NodeID  n)
inlineprivate

Definition at line 224 of file SCC.h.

225 {
226 return _NodeSCCAuxInfo[n].visited();
227 }

Member Data Documentation

◆ _D

Definition at line 219 of file SCC.h.

◆ _graph

template<class GraphType >
const GraphType& SVF::SCCDetection< GraphType >::_graph
private

Definition at line 217 of file SCC.h.

◆ _I

template<class GraphType >
NodeID SVF::SCCDetection< GraphType >::_I
private

Definition at line 218 of file SCC.h.

◆ _NodeSCCAuxInfo

template<class GraphType >
GNODESCCInfoMap SVF::SCCDetection< GraphType >::_NodeSCCAuxInfo
private

Definition at line 215 of file SCC.h.

◆ _SS

Definition at line 220 of file SCC.h.

◆ _T

Definition at line 221 of file SCC.h.

◆ repNodes

template<class GraphType >
NodeBS SVF::SCCDetection< GraphType >::repNodes
private

Definition at line 222 of file SCC.h.


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