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 "Graphs/ConsG.h"
31#include "WPA/CSC.h"
32#include "Util/SVFUtil.h"
33
34using namespace SVF;
35using namespace SVFUtil;
36
37
42{
43 _I = 0;
44 _D.clear();
45}
46
47
51void CSC::find(NodeStack& candidates)
52{
53 clear();
54
56 while (!candidates.empty())
57 {
58 NodeID nId = candidates.top();
59 revCandidates.push(nId);
60 candidates.pop();
61
62 if (_scc->subNodes(nId).count()>1 && !isVisited(nId)) // node is actually in a cycle
63 visit(nId, 0);
64 }
65
66 while (!revCandidates.empty())
67 {
68 NodeID nId = revCandidates.top();
69 candidates.push(nId);
70 revCandidates.pop();
71 }
72}
73
74
79{
80// pwcReps[nodeId] = _scc->repNode(nodeId);
82
83 _I += _w;
84 _D[nodeId] = _I;
85 _S.push(nodeId);
86
89 {
91 if (NormalGepCGEdge* gepCGEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(*eit))
92 offset = gepCGEdge->getConstantFieldIdx();
93 else
94 offset = 0;
95 NodeID dstId = (*eit)->getDstID();
96 if (_scc->repNode(nodeId) == _scc->repNode(dstId) && !isVisited(dstId))
98 }
99
101 NodeSet _C;
102
103 while (!_S.empty())
104 {
105 NodeID backNodeId = _S.top();
106 _S.pop();
107 _revS.push(backNodeId);
110 {
111 NormalGepCGEdge* normalGep = SVFUtil::dyn_cast<NormalGepCGEdge>(_consG->getEdge(node, backNode, ConstraintEdge::NormalGep));
112 s32_t _w = normalGep->getConstantFieldIdx();
114 backNode->strides.set(_l);
115 for (auto cNodeId : _C)
117 }
120 {
122 backNode->strides.set(_l);
123 for (auto cNodeId : _C)
125 }
126 _C.insert(backNodeId);
127 }
128
129 while (!_revS.empty())
130 {
131 NodeID backedId = _revS.top();
132 _S.push(backedId);
133 _revS.pop();
134 }
135
136 _S.pop(); // after checking all the edges of the top node of _S, remove the node
137}
buffer offset
Definition cJSON.cpp:1113
void find(NodeStack &candidates)
Definition CSC.cpp:51
IdToIdMap _D
Definition CSC.h:61
void visit(NodeID nodeId, s32_t _w)
Definition CSC.cpp:78
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:41
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:125
ConstraintNode * getConstraintNode(NodeID id) const
Get/add/remove constraint node.
Definition ConsG.h:104
ConstraintEdge * getEdge(ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
Get an edge via its src and dst nodes and kind.
Definition ConsG.h:143
NodeBS strides
For stride-based field representation.
Definition ConsGNode.h:71
iterator directOutEdgeEnd()
Definition ConsG.cpp:678
ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator
Definition ConsGNode.h:45
iterator directOutEdgeBegin()
Iterators.
Definition ConsG.cpp:670
void set(unsigned Idx)
for isBitcode
Definition BasicTypes.h:70
std::stack< NodeID > NodeStack
Definition GeneralType.h:92
Set< NodeID > NodeSet
Definition GeneralType.h:87
u32_t NodeID
Definition GeneralType.h:76
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
signed s32_t
Definition GeneralType.h:68