Static Value-Flow Analysis
Steensgaard.cpp
Go to the documentation of this file.
1 //===- Steensgaard.cpp -- Steensgaard's field-insensitive
2 // analysis--------------//
3 //
4 // SVF: Static Value-Flow Analysis
5 //
6 // Copyright (C) <2013-2017> <Yulei Sui>
7 //
8 
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU Affero General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Affero General Public License for more details.
18 
19 // You should have received a copy of the GNU Affero General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 //===----------------------------------------------------------------------===//
23 
24 /*
25  * Steensgaard.cpp
26  *
27  * Created on: 2 Feb. 2021
28  * Author: Yulei Sui
29  */
30 
31 #include "WPA/Steensgaard.h"
32 
33 using namespace SVF;
34 using namespace SVFUtil;
35 
37 
43 {
44 
45  processAllAddr();
46 
47  // Keep solving until workList is empty.
48  while (!isWorklistEmpty())
49  {
50  NodeID nodeId = popFromWorklist();
51  ConstraintNode* node = consCG->getConstraintNode(nodeId);
52 
54  for (NodeID o : getPts(nodeId))
55  {
56 
58  for (ConstraintEdge* edge : node->getStoreInEdges())
59  {
60  ecUnion(edge->getSrcID(), o);
61  }
62  // r = *p : EC(r) == EC(o)
63  for (ConstraintEdge* edge : node->getLoadOutEdges())
64  {
65  ecUnion(o, edge->getDstID());
66  }
67  }
68 
70  for (ConstraintEdge* edge : node->getCopyOutEdges())
71  {
72  ecUnion(edge->getSrcID(), edge->getDstID());
73  }
75  for (ConstraintEdge* edge : node->getGepOutEdges())
76  {
77  ecUnion(edge->getSrcID(), edge->getDstID());
78  }
79  }
80 }
81 
83 {
84  rep = getEC(rep);
85  Set<NodeID>& subNodes = getSubNodes(node);
86  for (NodeID sub : subNodes)
87  {
88  nodeToECMap[sub] = rep;
89  addSubNode(rep, sub);
90  }
91  subNodes.clear();
92 }
93 
96 {
97  if (unionPts(ec, node))
98  pushIntoWorklist(ec);
99  setEC(node, ec);
100 }
101 
106 {
107  for (ConstraintGraph::const_iterator nodeIt = consCG->begin(),
108  nodeEit = consCG->end();
109  nodeIt != nodeEit; nodeIt++)
110  {
111  ConstraintNode* cgNode = nodeIt->second;
113  eit = cgNode->incomingAddrsEnd();
114  it != eit; ++it)
115  {
116  numOfProcessedAddr++;
117 
118  const AddrCGEdge* addr = cast<AddrCGEdge>(*it);
119  NodeID dst = addr->getDstID();
120  NodeID src = addr->getSrcID();
121  if (addPts(dst, src))
122  pushIntoWorklist(dst);
123  }
124  }
125 }
const_iterator incomingAddrsBegin() const
Definition: ConsGNode.h:181
const ConstraintEdge::ConstraintEdgeSetTy & getGepOutEdges() const
Definition: ConsGNode.h:123
const ConstraintEdge::ConstraintEdgeSetTy & getLoadOutEdges() const
Definition: ConsGNode.h:131
ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator
Definition: ConsGNode.h:45
const ConstraintEdge::ConstraintEdgeSetTy & getCopyOutEdges() const
Definition: ConsGNode.h:115
const_iterator incomingAddrsEnd() const
Definition: ConsGNode.h:185
const ConstraintEdge::ConstraintEdgeSetTy & getStoreInEdges() const
Definition: ConsGNode.h:135
NodeID getDstID() const
Definition: GenericGraph.h:85
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:81
static Steensgaard * steens
Definition: Steensgaard.h:124
void ecUnion(NodeID id, NodeID ec)
merge node into equiv class and merge node's pts into ec's pts
Definition: Steensgaard.cpp:95
void setEC(NodeID node, NodeID rep)
Definition: Steensgaard.cpp:82
virtual void solveWorklist() override
Definition: Steensgaard.cpp:42
for isBitcode
Definition: BasicTypes.h:68
u32_t NodeID
Definition: GeneralType.h:55
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96