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 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 GraphType & graph ()
 
void find (void)
 
void find (NodeSet &candidates)
 

Private Types

typedef SVF::GenericGraphTraits< GraphType > GTraits
 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 54 of file SCC.h.

Member Typedef Documentation

◆ child_iterator

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

Definition at line 62 of file SCC.h.

◆ GNODE

template<class GraphType >
typedef GTraits::NodeRef SVF::SCCDetection< GraphType >::GNODE
private

Definition at line 60 of file SCC.h.

◆ GNODESCCInfoMap

template<class GraphType >
typedef Map<NodeID,GNodeSCCInfo > SVF::SCCDetection< GraphType >::GNODESCCInfoMap

Definition at line 116 of file SCC.h.

◆ GNodeStack

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

Definition at line 66 of file SCC.h.

◆ GTraits

template<class GraphType >
typedef SVF::GenericGraphTraits<GraphType> SVF::SCCDetection< GraphType >::GTraits
private

Define the GTraits and node iterator for printing.

Definition at line 59 of file SCC.h.

◆ node_iterator

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

Definition at line 61 of file SCC.h.

◆ NodeID

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

Definition at line 63 of file SCC.h.

◆ NodeToNodeMap

template<class GraphType >
typedef Map<NodeID, NodeID> SVF::SCCDetection< GraphType >::NodeToNodeMap

Definition at line 117 of file SCC.h.

Constructor & Destructor Documentation

◆ SCCDetection()

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

Definition at line 119 of file SCC.h.

120 : _graph(GT),
121 _I(0)
122 {}
const GraphType & _graph
Definition SCC.h:194
NodeID _I
Definition SCC.h:195
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

Member Function Documentation

◆ clear()

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

Definition at line 295 of file SCC.h.

296 {
297 _NodeSCCAuxInfo.clear();
298 _I = 0;
299 _D.clear();
300 repNodes.clear();
301 while(!_SS.empty())
302 _SS.pop();
303 while(!_T.empty())
304 _T.pop();
305 }
GNodeStack _T
Definition SCC.h:198
GNodeStack _SS
Definition SCC.h:197
NodeBS repNodes
Definition SCC.h:199
GNODESCCInfoMap _NodeSCCAuxInfo
Definition SCC.h:192
NodeToNodeMap _D
Definition SCC.h:196

◆ find() [1/2]

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

Definition at line 334 of file SCC.h.

335 {
336 // This function is reloaded to only visit candidate NODES
337 clear();
338 for (NodeID node : candidates)
339 {
340 if (!this->visited(node))
341 {
342 if (this->rep(node) == UINT_MAX || this->rep(node) == node)
343 visit(node);
344 else
345 this->visited(node);
346 }
347 }
348 }
void rep(NodeID n, NodeID r)
Definition SCC.h:218
void clear()
Definition SCC.h:295
unsigned NodeID
Definition SCC.h:63
bool visited(NodeID n)
Definition SCC.h:201
void visit(NodeID v)
Definition SCC.h:249

◆ find() [2/2]

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

Definition at line 308 of file SCC.h.

309 {
310 // Visit each unvisited root node. A root node is defined
311 // to be a node that has no incoming copy/skew edges
312 clear();
313 node_iterator I = GTraits::nodes_begin(_graph);
314 node_iterator E = GTraits::nodes_end(_graph);
315 for (; I != E; ++I)
316 {
317 NodeID node = Node_Index(*I);
318 if (!this->visited(node))
319 {
320 // We skip any nodes that have a representative other than
321 // themselves. Such nodes occur as a result of merging
322 // nodes either through unifying an ACC or other node
323 // merging optimizations. Any such node should have no
324 // outgoing edges and therefore should no longer be a member
325 // of an SCC.
326 if (this->rep(node) == UINT_MAX || this->rep(node) == node)
327 visit(node);
328 else
329 this->visited(node);
330 }
331 }
332 }
NodeID Node_Index(GNODE node) const
Definition SCC.h:244
GTraits::nodes_iterator node_iterator
Definition SCC.h:61

◆ getRepNodes()

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

get all repNodeID

Definition at line 181 of file SCC.h.

182 {
183 return repNodes;
184 }

◆ GNodeSCCInfo()

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

Definition at line 133 of file SCC.h.

134 {
135 return _NodeSCCAuxInfo;
136 }

◆ graph()

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

Definition at line 186 of file SCC.h.

187 {
188 return _graph;
189 }

◆ inSCC()

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

Definition at line 205 of file SCC.h.

206 {
207 return _NodeSCCAuxInfo[n].inSCC();
208 }
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 149 of file SCC.h.

150 {
151 NodeID rep = repNode(n);
152 // multi-node cycle
153 if (subNodes(rep).count() > 1)
154 {
155 return true;
156 }
157 // self-cycle
158 else
159 {
160 child_iterator EI = GTraits::direct_child_begin(Node(rep));
161 child_iterator EE = GTraits::direct_child_end(Node(rep));
162 for (; EI != EE; ++EI)
163 {
164 NodeID w = Node_Index(*EI);
165 if(w==rep)
166 return true;
167 }
168 return false;
169 }
170 }
int count
Definition cJSON.h:216
NodeID repNode(NodeID n) const
get the rep node if not found return itself
Definition SCC.h:139
GNODE Node(NodeID id) const
Definition SCC.h:239
const NodeBS & subNodes(NodeID n) const
get all subnodes in one scc, if size is empty insert itself into the set
Definition SCC.h:173
GTraits::ChildIteratorType child_iterator
Definition SCC.h:62

◆ isInSCC()

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

Definition at line 234 of file SCC.h.

235 {
236 return _NodeSCCAuxInfo[n].inSCC();
237 }

◆ Node()

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

Definition at line 239 of file SCC.h.

240 {
241 return GTraits::getNode(_graph, id);
242 }

◆ Node_Index()

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

Definition at line 244 of file SCC.h.

245 {
246 return GTraits::getNodeID(node);
247 }

◆ rep() [1/2]

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

Definition at line 230 of file SCC.h.

231 {
232 return _NodeSCCAuxInfo[n].rep();
233 }

◆ rep() [2/2]

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

Definition at line 218 of file SCC.h.

219 {
220 _NodeSCCAuxInfo[n].rep(r);
221 _NodeSCCAuxInfo[r].addSubNodes(n);
222 if (n != r)
223 {
224 _NodeSCCAuxInfo[n].subNodes().clear();
226 repNodes.set(r);
227 }
228 }
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 139 of file SCC.h.

140 {
141 typename GNODESCCInfoMap::const_iterator it = _NodeSCCAuxInfo.find(n);
142 assert(it!=_NodeSCCAuxInfo.end() && "scc rep not found");
143 NodeID rep = it->second.rep();
144 return rep!= UINT_MAX ? rep : n ;
145 }

◆ setInSCC()

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

Definition at line 214 of file SCC.h.

215 {
216 _NodeSCCAuxInfo[n].inSCC(v);
217 }

◆ setVisited()

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

Definition at line 210 of file SCC.h.

211 {
212 _NodeSCCAuxInfo[n].visited(v);
213 }

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

174 {
175 typename GNODESCCInfoMap::const_iterator it = _NodeSCCAuxInfo.find(n);
176 assert(it!=_NodeSCCAuxInfo.end() && "scc rep not found");
177 return it->second.subNodes();
178 }

◆ topoNodeStack()

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

Definition at line 128 of file SCC.h.

129 {
130 return _T;
131 }

◆ visit()

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

Definition at line 249 of file SCC.h.

250 {
251 // SVFUtil::outs() << "visit GNODE: " << Node_Index(v)<< "\n";
252 _I += 1;
253 _D[v] = _I;
254 this->rep(v,v);
255 this->setVisited(v,true);
256
257 child_iterator EI = GTraits::direct_child_begin(Node(v));
258 child_iterator EE = GTraits::direct_child_end(Node(v));
259
260 for (; EI != EE; ++EI)
261 {
262 NodeID w = Node_Index(*EI);
263
264 if (!this->visited(w))
265 visit(w);
266 if (!this->inSCC(w))
267 {
268 NodeID rep;
269 rep = _D[this->rep(v)] < _D[this->rep(w)] ?
270 this->rep(v) : this->rep(w);
271 this->rep(v,rep);
272 }
273 }
274 if (this->rep(v) == v)
275 {
276 this->setInSCC(v,true);
277 while (!_SS.empty())
278 {
279 NodeID w = _SS.top();
280 if (_D[w] <= _D[v])
281 break;
282 else
283 {
284 _SS.pop();
285 this->setInSCC(w,true);
286 this->rep(w,v);
287 }
288 }
289 _T.push(v);
290 }
291 else
292 _SS.push(v);
293 }
bool inSCC(NodeID n)
Definition SCC.h:205
void setInSCC(NodeID n, bool v)
Definition SCC.h:214
void setVisited(NodeID n, bool v)
Definition SCC.h:210

◆ visited()

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

Definition at line 201 of file SCC.h.

202 {
203 return _NodeSCCAuxInfo[n].visited();
204 }

Member Data Documentation

◆ _D

template<class GraphType >
NodeToNodeMap SVF::SCCDetection< GraphType >::_D
private

Definition at line 196 of file SCC.h.

◆ _graph

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

Definition at line 194 of file SCC.h.

◆ _I

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

Definition at line 195 of file SCC.h.

◆ _NodeSCCAuxInfo

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

Definition at line 192 of file SCC.h.

◆ _SS

template<class GraphType >
GNodeStack SVF::SCCDetection< GraphType >::_SS
private

Definition at line 197 of file SCC.h.

◆ _T

template<class GraphType >
GNodeStack SVF::SCCDetection< GraphType >::_T
private

Definition at line 198 of file SCC.h.

◆ repNodes

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

Definition at line 199 of file SCC.h.


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