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 55 of file SCC.h.

Member Typedef Documentation

◆ child_iterator

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

Definition at line 63 of file SCC.h.

◆ GNODE

Definition at line 61 of file SCC.h.

◆ GNODESCCInfoMap

Definition at line 117 of file SCC.h.

◆ GNodeStack

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

Definition at line 67 of file SCC.h.

◆ GTraits

Define the GTraits and node iterator for printing.

Definition at line 60 of file SCC.h.

◆ node_iterator

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

Definition at line 62 of file SCC.h.

◆ NodeID

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

Definition at line 64 of file SCC.h.

◆ NodeToNodeMap

Definition at line 118 of file SCC.h.

Constructor & Destructor Documentation

◆ SCCDetection()

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

Definition at line 120 of file SCC.h.

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

Member Function Documentation

◆ clear()

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

Definition at line 317 of file SCC.h.

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

◆ find() [1/2]

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

Definition at line 356 of file SCC.h.

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

◆ find() [2/2]

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

Definition at line 330 of file SCC.h.

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

◆ getRepNodes()

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

get all repNodeID

Definition at line 203 of file SCC.h.

204 {
205 return repNodes;
206 }

◆ GNodeSCCInfo()

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

Definition at line 155 of file SCC.h.

156 {
157 return _NodeSCCAuxInfo;
158 }

◆ graph()

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

Definition at line 208 of file SCC.h.

209 {
210 return _graph;
211 }

◆ inSCC()

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

Definition at line 227 of file SCC.h.

228 {
229 return _NodeSCCAuxInfo[n].inSCC();
230 }
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 171 of file SCC.h.

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

◆ isInSCC()

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

Definition at line 256 of file SCC.h.

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

◆ Node()

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

Definition at line 261 of file SCC.h.

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

◆ Node_Index()

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

Definition at line 266 of file SCC.h.

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

◆ rep() [1/2]

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

Definition at line 252 of file SCC.h.

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

◆ rep() [2/2]

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

Definition at line 240 of file SCC.h.

241 {
242 _NodeSCCAuxInfo[n].rep(r);
243 _NodeSCCAuxInfo[r].addSubNodes(n);
244 if (n != r)
245 {
246 _NodeSCCAuxInfo[n].subNodes().clear();
248 repNodes.set(r);
249 }
250 }
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 161 of file SCC.h.

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

◆ 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 142 of file SCC.h.

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

◆ setInSCC()

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

Definition at line 236 of file SCC.h.

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

◆ setVisited()

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

Definition at line 232 of file SCC.h.

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

◆ 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 195 of file SCC.h.

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

◆ topoNodeStack() [1/2]

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

Definition at line 129 of file SCC.h.

130 {
131 return _T;
132 }

◆ topoNodeStack() [2/2]

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

Definition at line 134 of file SCC.h.

135 {
136 return _T;
137 }

◆ visit()

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

Definition at line 271 of file SCC.h.

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

◆ visited()

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

Definition at line 223 of file SCC.h.

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

Member Data Documentation

◆ _D

Definition at line 218 of file SCC.h.

◆ _graph

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

Definition at line 216 of file SCC.h.

◆ _I

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

Definition at line 217 of file SCC.h.

◆ _NodeSCCAuxInfo

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

Definition at line 214 of file SCC.h.

◆ _SS

Definition at line 219 of file SCC.h.

◆ _T

Definition at line 220 of file SCC.h.

◆ repNodes

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

Definition at line 221 of file SCC.h.


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