Static Value-Flow Analysis
Public Types | Public Member Functions | Private Attributes | List of all members
SVF::CSC Class Reference

#include <CSC.h>

Public Types

typedef Map< NodeID, NodeIDIdToIdMap
 
typedef FILOWorkList< NodeIDWorkStack
 
typedef IdToIdMap::iterator iterator
 

Public Member Functions

 CSC (ConstraintGraph *g, CGSCC *c)
 
void find (NodeStack &candidates)
 
void visit (NodeID nodeId, s32_t _w)
 
void clear ()
 
bool isVisited (NodeID nId)
 
void setVisited (NodeID nId)
 

Private Attributes

ConstraintGraph_consG
 
CGSCC_scc
 
NodeID _I
 
IdToIdMap _D
 
NodeStack _S
 
NodeSet _visited
 

Detailed Description

class CSC: cycle stride calculation

Definition at line 49 of file CSC.h.

Member Typedef Documentation

◆ IdToIdMap

Definition at line 52 of file CSC.h.

◆ iterator

typedef IdToIdMap::iterator SVF::CSC::iterator

Definition at line 54 of file CSC.h.

◆ WorkStack

Definition at line 53 of file CSC.h.

Constructor & Destructor Documentation

◆ CSC()

SVF::CSC::CSC ( ConstraintGraph g,
CGSCC c 
)
inline

Definition at line 68 of file CSC.h.

69  : _consG(g), _scc(c), _I(0) {}
ConstraintGraph * _consG
Definition: CSC.h:57
CGSCC * _scc
Definition: CSC.h:58
NodeID _I
Definition: CSC.h:60

Member Function Documentation

◆ clear()

void CSC::clear ( void  )

Definition at line 39 of file CSC.cpp.

40 {
41  _I = 0;
42  _D.clear();
43 }
IdToIdMap _D
Definition: CSC.h:61

◆ find()

void CSC::find ( NodeStack candidates)

Definition at line 49 of file CSC.cpp.

50 {
51  clear();
52 
53  NodeStack revCandidates;
54  while (!candidates.empty())
55  {
56  NodeID nId = candidates.top();
57  revCandidates.push(nId);
58  candidates.pop();
59 
60  if (_scc->subNodes(nId).count()>1 && !isVisited(nId)) // node is actually in a cycle
61  visit(nId, 0);
62  }
63 
64  while (!revCandidates.empty())
65  {
66  NodeID nId = revCandidates.top();
67  candidates.push(nId);
68  revCandidates.pop();
69  }
70 }
void visit(NodeID nodeId, s32_t _w)
Definition: CSC.cpp:76
bool isVisited(NodeID nId)
Definition: CSC.h:75
void clear()
Definition: CSC.cpp:39
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
unsigned count() const
std::stack< NodeID > NodeStack
Definition: GeneralType.h:118
u32_t NodeID
Definition: GeneralType.h:55

◆ isVisited()

bool SVF::CSC::isVisited ( NodeID  nId)
inline

Definition at line 75 of file CSC.h.

76  {
77  return _visited.find(nId) != _visited.end();
78  }
NodeSet _visited
Definition: CSC.h:63

◆ setVisited()

void SVF::CSC::setVisited ( NodeID  nId)
inline

Definition at line 80 of file CSC.h.

81  {
82  _visited.insert(nId);
83  }

◆ visit()

void CSC::visit ( NodeID  nodeId,
s32_t  _w 
)

Definition at line 76 of file CSC.cpp.

77 {
78 // pwcReps[nodeId] = _scc->repNode(nodeId);
79  setVisited(nodeId);
80 
81  _I += _w;
82  _D[nodeId] = _I;
83  _S.push(nodeId);
84 
85  ConstraintNode* node = _consG->getConstraintNode(nodeId);
86  for (ConstraintNode::const_iterator eit = node->directOutEdgeBegin(); eit != node->directOutEdgeEnd(); ++eit)
87  {
88  s32_t offset;
89  if (NormalGepCGEdge* gepCGEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(*eit))
90  offset = gepCGEdge->getConstantFieldIdx();
91  else
92  offset = 0;
93  NodeID dstId = (*eit)->getDstID();
94  if (_scc->repNode(nodeId) == _scc->repNode(dstId) && !isVisited(dstId))
95  visit(dstId, offset);
96  }
97 
98  NodeStack _revS;
99  NodeSet _C;
100 
101  while (!_S.empty())
102  {
103  NodeID backNodeId = _S.top();
104  _S.pop();
105  _revS.push(backNodeId);
106  ConstraintNode* backNode = _consG->getConstraintNode(backNodeId);
107  if (_consG->hasEdge(node, backNode, ConstraintEdge::NormalGep))
108  {
109  NormalGepCGEdge* normalGep = SVFUtil::dyn_cast<NormalGepCGEdge>(_consG->getEdge(node, backNode, ConstraintEdge::NormalGep));
110  s32_t _w = normalGep->getConstantFieldIdx();
111  s32_t _l = _D[nodeId] +_w - _D[backNodeId];
112  backNode->strides.set(_l);
113  for (auto cNodeId : _C)
114  _consG->getConstraintNode(cNodeId)->strides.set(_l);
115  }
116  else if (_consG->hasEdge(node, backNode, ConstraintEdge::VariantGep) ||
117  _consG->hasEdge(node, backNode, ConstraintEdge::Copy))
118  {
119  s32_t _l = _D[nodeId] - _D[backNodeId];
120  backNode->strides.set(_l);
121  for (auto cNodeId : _C)
122  _consG->getConstraintNode(cNodeId)->strides.set(_l);
123  }
124  _C.insert(backNodeId);
125  }
126 
127  while (!_revS.empty())
128  {
129  NodeID backedId = _revS.top();
130  _S.push(backedId);
131  _revS.pop();
132  }
133 
134  _S.pop(); // after checking all the edges of the top node of _S, remove the node
135 }
buffer offset
Definition: cJSON.cpp:1113
NodeStack _S
Definition: CSC.h:62
void setVisited(NodeID nId)
Definition: CSC.h:80
ConstraintEdge * getEdge(ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
Get an edge via its src and dst nodes and kind.
Definition: ConsG.h:148
ConstraintNode * getConstraintNode(NodeID id) const
Get/add/remove constraint node.
Definition: ConsG.h:109
bool hasEdge(ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
Definition: ConsG.h:130
NodeBS strides
For stride-based field representation.
Definition: ConsGNode.h:71
iterator directOutEdgeEnd()
Definition: ConsG.cpp:674
ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator
Definition: ConsGNode.h:45
iterator directOutEdgeBegin()
Iterators.
Definition: ConsG.cpp:666
APOffset getConstantFieldIdx() const
Get location set of the gep edge.
Definition: ConsGEdge.h:309
NodeID repNode(NodeID n) const
get the rep node if not found return itself
Definition: SCC.h:139
void set(unsigned Idx)
Set< NodeID > NodeSet
Definition: GeneralType.h:113
signed s32_t
Definition: GeneralType.h:47

Member Data Documentation

◆ _consG

ConstraintGraph* SVF::CSC::_consG
private

Definition at line 57 of file CSC.h.

◆ _D

IdToIdMap SVF::CSC::_D
private

Definition at line 61 of file CSC.h.

◆ _I

NodeID SVF::CSC::_I
private

Definition at line 60 of file CSC.h.

◆ _S

NodeStack SVF::CSC::_S
private

Definition at line 62 of file CSC.h.

◆ _scc

CGSCC* SVF::CSC::_scc
private

Definition at line 58 of file CSC.h.

◆ _visited

NodeSet SVF::CSC::_visited
private

Definition at line 63 of file CSC.h.


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