Static Value-Flow Analysis
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"
31 #include "MemoryModel/PointsTo.h"
32 
33 using namespace SVF;
34 using namespace SVFUtil;
35 using namespace std;
36 
38 
43 {
45  setDetectPWC(true); // Standard wave propagation always collapses PWCs
46 }
47 
52 {
53  // Initialize the nodeStack via a whole SCC detection
54  // Nodes in nodeStack are in topological order by default.
55  NodeStack& nodeStack = SCCDetect();
56 
57  // Process nodeStack and put the changed nodes into workList.
58  while (!nodeStack.empty())
59  {
60  NodeID nodeId = nodeStack.top();
61  nodeStack.pop();
62  collapsePWCNode(nodeId);
63  // process nodes in nodeStack
64  processNode(nodeId);
65  collapseFields();
66  }
67 
68  // New nodes will be inserted into workList during processing.
69  while (!isWorklistEmpty())
70  {
71  NodeID nodeId = popFromWorklist();
72  // process nodes in worklist
73  postProcessNode(nodeId);
74  }
75 }
76 
81 {
82  // This node may be merged during collapseNodePts() which means it is no longer a rep node
83  // in the graph. Only rep node needs to be handled.
84  if (sccRepNode(nodeId) != nodeId)
85  return;
86 
87  double propStart = stat->getClk();
88  ConstraintNode* node = consCG->getConstraintNode(nodeId);
89  handleCopyGep(node);
90  double propEnd = stat->getClk();
91  timeOfProcessCopyGep += (propEnd - propStart) / TIMEINTERVAL;
92 }
93 
98 {
99  double insertStart = stat->getClk();
100 
101  ConstraintNode* node = consCG->getConstraintNode(nodeId);
102 
103  // handle load
104  for (ConstraintNode::const_iterator it = node->outgoingLoadsBegin(), eit = node->outgoingLoadsEnd();
105  it != eit; ++it)
106  {
107  if (handleLoad(nodeId, *it))
108  reanalyze = true;
109  }
110  // handle store
112  it != eit; ++it)
113  {
114  if (handleStore(nodeId, *it))
115  reanalyze = true;
116  }
117 
118  double insertEnd = stat->getClk();
119  timeOfProcessLoadStore += (insertEnd - insertStart) / TIMEINTERVAL;
120 }
121 
126 {
127  bool changed = false;
128  for (PointsTo::iterator piter = getPts(nodeId).begin(), epiter = getPts(nodeId).end();
129  piter != epiter; ++piter)
130  {
131  if (processLoad(*piter, edge))
132  {
133  changed = true;
134  }
135  }
136  return changed;
137 }
138 
143 {
144  bool changed = false;
145  for (PointsTo::iterator piter = getPts(nodeId).begin(), epiter = getPts(nodeId).end();
146  piter != epiter; ++piter)
147  {
148  if (processStore(*piter, edge))
149  {
150  changed = true;
151  }
152  }
153  return changed;
154 }
#define TIMEINTERVAL
Definition: SVFType.h:512
virtual void solveWorklist()
virtual bool handleStore(NodeID id, const ConstraintEdge *store)
virtual bool handleLoad(NodeID id, const ConstraintEdge *load)
virtual void postProcessNode(NodeID nodeId)
static AndersenWaveDiff * diffWave
Definition: Andersen.h:402
virtual void processNode(NodeID nodeId)
virtual void initialize()
Initialize analysis.
Definition: Andersen.cpp:418
const_iterator outgoingLoadsEnd() const
Definition: ConsGNode.h:194
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_iterator outgoingLoadsBegin() const
Definition: ConsGNode.h:190
for isBitcode
Definition: BasicTypes.h:68
std::stack< NodeID > NodeStack
Definition: GeneralType.h:118
u32_t NodeID
Definition: GeneralType.h:55