Static Value-Flow Analysis
Loading...
Searching...
No Matches
CSC.cpp
Go to the documentation of this file.
1//===- CSC.cpp -- Cycle Stride Calculation algorithm---------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * CSC.cpp
25 *
26 * Created on: 09, Feb, 2019
27 * Author: Yuxiang Lei
28 */
29
30#include "WPA/CSC.h"
31
32using namespace SVF;
33using namespace SVFUtil;
34
35
40{
41 _I = 0;
42 _D.clear();
43}
44
45
49void CSC::find(NodeStack& candidates)
50{
51 clear();
52
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}
71
72
77{
78// pwcReps[nodeId] = _scc->repNode(nodeId);
80
81 _I += _w;
82 _D[nodeId] = _I;
83 _S.push(nodeId);
84
87 {
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))
96 }
97
99 NodeSet _C;
100
101 while (!_S.empty())
102 {
103 NodeID backNodeId = _S.top();
104 _S.pop();
105 _revS.push(backNodeId);
108 {
109 NormalGepCGEdge* normalGep = SVFUtil::dyn_cast<NormalGepCGEdge>(_consG->getEdge(node, backNode, ConstraintEdge::NormalGep));
110 s32_t _w = normalGep->getConstantFieldIdx();
112 backNode->strides.set(_l);
113 for (auto cNodeId : _C)
115 }
118 {
120 backNode->strides.set(_l);
121 for (auto cNodeId : _C)
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
void find(NodeStack &candidates)
Definition CSC.cpp:49
IdToIdMap _D
Definition CSC.h:61
void visit(NodeID nodeId, s32_t _w)
Definition CSC.cpp:76
bool isVisited(NodeID nId)
Definition CSC.h:75
NodeStack _S
Definition CSC.h:62
ConstraintGraph * _consG
Definition CSC.h:57
void clear()
Definition CSC.cpp:39
CGSCC * _scc
Definition CSC.h:58
void setVisited(NodeID nId)
Definition CSC.h:80
NodeID _I
Definition CSC.h:60
bool hasEdge(ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
Definition ConsG.h:130
ConstraintNode * getConstraintNode(NodeID id) const
Get/add/remove constraint node.
Definition ConsG.h:109
ConstraintEdge * getEdge(ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
Get an edge via its src and dst nodes and kind.
Definition ConsG.h:148
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
void set(unsigned Idx)
for isBitcode
Definition BasicTypes.h:68
std::stack< NodeID > NodeStack
Set< NodeID > NodeSet
u32_t NodeID
Definition GeneralType.h:55
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
signed s32_t
Definition GeneralType.h:47