SVF
AndersenLCD.cpp
Go to the documentation of this file.
1 //===- AndersenLCD.cpp -- LCD based field-sensitive Andersen's analysis-------//
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 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 General Public License for more details.
17 
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * AndersenLCD.cpp
25  *
26  * Created on: 13 Sep. 2018
27  * Author: Yuxiang Lei
28  */
29 
30 #include "WPA/Andersen.h"
31 
32 using namespace SVF;
33 using namespace SVFUtil;
34 
36 
37 
39 {
40  while (!isWorklistEmpty())
41  {
42  // Merge detected SCC cycles
43  mergeSCC();
44 
45  NodeID nodeId = popFromWorklist();
46  collapsePWCNode(nodeId);
47  // Keep solving until workList is empty.
48  processNode(nodeId);
49  collapseFields();
50  }
51 }
52 
57 {
58  double propStart = stat->getClk();
59 
60  NodeID nodeId = node->getId();
61  computeDiffPts(nodeId);
62 
63  for (ConstraintEdge* edge : node->getCopyOutEdges())
64  {
65  NodeID dstNodeId = edge->getDstID();
66  const PointsTo& srcPts = getPts(nodeId);
67  const PointsTo& dstPts = getPts(dstNodeId);
68  // In one edge, if the pts of src node equals to that of dst node, and the edge
69  // is never met, push it into 'metEdges' and push the dst node into 'lcdCandidates'
70  if (!srcPts.empty() && srcPts == dstPts && !isMetEdge(edge))
71  {
72  addMetEdge(edge);
73  addLCDCandidate((edge)->getDstID());
74  }
75  processCopy(nodeId, edge);
76  }
77  for (ConstraintEdge* edge : node->getGepOutEdges())
78  {
79  if (GepCGEdge* gepEdge = SVFUtil::dyn_cast<GepCGEdge>(edge))
80  processGep(nodeId, gepEdge);
81  }
82 
83  double propEnd = stat->getClk();
84  timeOfProcessCopyGep += (propEnd - propStart) / TIMEINTERVAL;
85 }
86 
91 {
92  if (hasLCDCandidate())
93  {
94  SCCDetect();
95  cleanLCDCandidate();
96  }
97 }
98 
103 {
104  numOfSCCDetection++;
105 
106  NodeSet sccCandidates;
107  sccCandidates.clear();
108  for (NodeSet::iterator it = lcdCandidates.begin(); it != lcdCandidates.end(); ++it)
109  if (sccRepNode(*it) == *it)
110  sccCandidates.insert(*it);
111 
112  double sccStart = stat->getClk();
114  getSCCDetector()->find(sccCandidates);
115  double sccEnd = stat->getClk();
116  timeOfSCCDetection += (sccEnd - sccStart) / TIMEINTERVAL;
117 
118  double mergeStart = stat->getClk();
120  mergeSccCycle();
121  double mergeEnd = stat->getClk();
122  timeOfSCCMerges += (mergeEnd - mergeStart) / TIMEINTERVAL;
123 
124  return getSCCDetector()->topoNodeStack();
125 }
126 
131 {
132 
133  if(nodeId==newRepId)
134  return false;
135 
137  updatePropaPts(newRepId, nodeId);
138  unionPts(newRepId,nodeId);
139  pushIntoWorklist(newRepId);
140 
142  ConstraintNode* node = consCG->getConstraintNode(nodeId);
143  bool gepInsideScc = consCG->moveEdgesToRepNode(node, consCG->getConstraintNode(newRepId));
144 
146  updateNodeRepAndSubs(node->getId(),newRepId);
147 
148  consCG->removeConstraintNode(node);
149 
150  return gepInsideScc;
151 }
Set< NodeID > NodeSet
u32_t NodeID
Definition: SVFBasicTypes.h:80
std::stack< NodeID > NodeStack
static AndersenLCD * lcdAndersen
Definition: Andersen.h:560
bool mergeSrcToTgt(NodeID nodeId, NodeID newRepId)
#define TIMEINTERVAL
const ConstraintEdge::ConstraintEdgeSetTy & getCopyOutEdges() const
Definition: ConsGNode.h:128
const ConstraintEdge::ConstraintEdgeSetTy & getGepOutEdges() const
Definition: ConsGNode.h:136
for isBitcode
Definition: ContextDDA.h:15
NodeID getId() const
Get ID.
Definition: GenericGraph.h:164
NodeStack & SCCDetect()
virtual void handleCopyGep(ConstraintNode *node)
Definition: AndersenLCD.cpp:56
NodeBS PointsTo
Definition: SVFBasicTypes.h:88
virtual void mergeSCC()
Definition: AndersenLCD.cpp:90