Static Value-Flow Analysis
Loading...
Searching...
No Matches
AndersenWaveDiff.cpp
Go to the documentation of this file.
1//===- AndersenWaveDiff.cpp -- Wave propagation based Andersen's analysis with caching--//
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 * AndersenWaveDiff.cpp
25 *
26 * Created on: 23/11/2013
27 * Author: yesen
28 */
29
30#include "WPA/Andersen.h"
32#include "Util/PTAStat.h"
33#include "Util/GeneralType.h"
34#include "Util/SVFUtil.h"
35
36using namespace SVF;
37using namespace SVFUtil;
38using namespace std;
39
41
46{
47 loadStoreStates.clear();
49 setDetectPWC(true); // Standard wave propagation always collapses PWCs
50}
51
60
65{
66 // Initialize the nodeStack via a whole SCC detection
67 // Nodes in nodeStack are in topological order by default.
68 NodeStack& nodeStack = SCCDetect();
69
70 // Process nodeStack and put the changed nodes into workList.
71 while (!nodeStack.empty())
72 {
73 NodeID nodeId = nodeStack.top();
74 nodeStack.pop();
76 // process nodes in nodeStack
79 }
80
81 // New nodes will be inserted into workList during processing.
82 while (!isWorklistEmpty())
83 {
85 // process nodes in worklist
87 }
88}
89
94{
95 // This node may be merged during collapseNodePts() which means it is no longer a rep node
96 // in the graph. Only rep node needs to be handled.
97 if (sccRepNode(nodeId) != nodeId)
98 return;
99
100 double propStart = stat->getClk();
102 handleCopyGep(node);
103 double propEnd = stat->getClk();
105}
106
115{
116 double insertStart = stat->getClk();
117
119 if (node->getLoadOutEdges().empty() && node->getStoreInEdges().empty())
120 return;
122 // Adding copy edges below does not change points-to sets until the next wave.
123 const PointsTo& all = getPts(nodeId);
125 added -= handled.pts;
126
127 // handle load
129 it != eit; ++it)
130 {
131 // A new destination means this load has not seen this node's old objects,
132 // e.g. when the edge was moved here by an SCC merge.
133 const bool isNewLoad = handled.loadDsts.test_and_set((*it)->getDstID());
134 const PointsTo& objs = isNewLoad ? all : added;
135 if (handleLoad(objs, *it))
136 reanalyze = true;
137 }
138 // handle store
140 it != eit; ++it)
141 {
142 // Likewise, a new store source needs all objects; an existing one needs
143 // only the objects added since this node was last handled.
144 const bool isNewStore = handled.storeSrcs.test_and_set((*it)->getSrcID());
145 const PointsTo& objs = isNewStore ? all : added;
146 if (handleStore(objs, *it))
147 reanalyze = true;
148 }
149 handled.pts = all;
150
151 double insertEnd = stat->getClk();
153}
154
159{
160 bool changed = false;
161 for (PointsTo::iterator piter = objs.begin(), epiter = objs.end();
162 piter != epiter; ++piter)
163 {
164 if (processLoad(*piter, edge))
165 {
166 changed = true;
167 }
168 }
169 return changed;
170}
171
176{
177 bool changed = false;
178 for (PointsTo::iterator piter = objs.begin(), epiter = objs.end();
179 piter != epiter; ++piter)
180 {
181 if (processStore(*piter, edge))
182 {
183 changed = true;
184 }
185 }
186 return changed;
187}
#define TIMEINTERVAL
Definition SVFType.h:604
static double timeOfProcessLoadStore
Definition Andersen.h:175
static double timeOfProcessCopyGep
Definition Andersen.h:174
ConstraintGraph * consCG
Constraint Graph.
Definition Andersen.h:181
NodeID sccRepNode(NodeID id) const override
SCC methods.
Definition Andersen.h:132
virtual bool handleLoad(const PointsTo &objs, const ConstraintEdge *load)
virtual bool handleStore(const PointsTo &objs, const ConstraintEdge *store)
Map< NodeID, LoadStoreState > loadStoreStates
Per node, the objects and load/store endpoints already handled.
Definition Andersen.h:463
virtual void postProcessNode(NodeID nodeId)
static AndersenWaveDiff * diffWave
Definition Andersen.h:424
virtual void processNode(NodeID nodeId)
void setDetectPWC(bool flag)
Definition Andersen.h:273
virtual void initialize()
Initialize analysis.
Definition Andersen.cpp:438
virtual NodeStack & SCCDetect()
SCC detection.
Definition Andersen.cpp:852
virtual void handleCopyGep(ConstraintNode *node)
Definition Andersen.cpp:498
virtual bool processLoad(NodeID node, const ConstraintEdge *load)
Definition Andersen.cpp:575
virtual const PointsTo & getPts(NodeID id)
Operation of points-to set.
Definition Andersen.h:242
void collapseFields()
collapse positive weight cycles of a graph
Definition Andersen.cpp:717
virtual bool processStore(NodeID node, const ConstraintEdge *load)
Definition Andersen.cpp:595
virtual void finalize()
Finalize analysis.
Definition Andersen.cpp:452
virtual void collapsePWCNode(NodeID nodeId)
Collapse a field object into its base for field insensitive analysis.
Definition Andersen.cpp:708
ConstraintNode * getConstraintNode(NodeID id) const
Get/add/remove constraint node.
Definition ConsG.h:104
const_iterator outgoingLoadsEnd() const
Definition ConsGNode.h:194
const ConstraintEdge::ConstraintEdgeSetTy & getStoreInEdges() const
Definition ConsGNode.h:135
const_iterator incomingStoresBegin() const
Definition ConsGNode.h:215
const_iterator incomingStoresEnd() const
Definition ConsGNode.h:219
ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator
Definition ConsGNode.h:45
const ConstraintEdge::ConstraintEdgeSetTy & getLoadOutEdges() const
Definition ConsGNode.h:131
const_iterator outgoingLoadsBegin() const
Definition ConsGNode.h:190
PTAStat * stat
Statistics.
bool test_and_set(u32_t n)
Definition PointsTo.cpp:156
static double getClk(bool mark=false)
Definition SVFStat.cpp:52
NodeID popFromWorklist()
Worklist operations.
Definition WPASolver.h:152
bool isWorklistEmpty()
Definition WPASolver.h:161
bool reanalyze
Reanalyze if any constraint value changed.
Definition WPASolver.h:172
for isBitcode
Definition BasicTypes.h:70
std::stack< NodeID > NodeStack
Definition GeneralType.h:92
u32_t NodeID
Definition GeneralType.h:76
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76