SVF
AndersenHCD.cpp
Go to the documentation of this file.
1 //===- AndersenHCD.cpp -- HCD 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  * AndersenHCD.cpp
25  *
26  * Created on: 09 Oct. 2018
27  * Author: Yuxiang Lei
28  */
29 
30 #include "WPA/Andersen.h"
31 
32 using namespace SVF;
33 using namespace SVFUtil;
34 
36 
37 
38 // --- Methods of AndersenHCD ---
39 
45 {
47  // Build offline constraint graph and solve its constraints
48  oCG = new OfflineConsG(pag);
49  OSCC* oscc = new OSCC(oCG);
50  oscc->find();
51  oCG->solveOfflineSCC(oscc);
52  delete oscc;
53 }
54 
59 {
60  while (!isWorklistEmpty())
61  {
62  NodeID nodeId = popFromWorklist();
63  collapsePWCNode(nodeId);
64 
65  //Merge detected offline SCC cycles
66  mergeSCC(nodeId);
67 
68  // Keep solving until workList is empty.
69  processNode(nodeId);
70  collapseFields();
71  }
72 }
73 
78 {
79  if (hasOfflineRep(nodeId))
80  {
81  // get offline rep node
82  NodeID oRep = getOfflineRep(nodeId);
83  // get online rep node
84  NodeID rep = consCG->sccRepNode(oRep);
85  const PointsTo &pts = getPts(nodeId);
86  for (PointsTo::iterator ptIt = pts.begin(), ptEit = pts.end(); ptIt != ptEit; ++ptIt)
87  {
88  NodeID tgt = *ptIt;
89  ConstraintNode* tgtNode = consCG->getConstraintNode(tgt);
90  if (!tgtNode->getDirectInEdges().empty())
91  continue;
92  if (tgtNode->getAddrOutEdges().size() > 1)
93  continue;
94  assert(!oCG->isaRef(tgt) && "Point-to target should not be a ref node!");
95  mergeNodeAndPts(tgt, rep);
96  }
97  }
98 }
99 
104 {
105  node = sccRepNode(node);
106  rep = sccRepNode(rep);
107  if (!isaMergedNode(node))
108  {
109  if (unionPts(rep, node))
110  pushIntoWorklist(rep);
111  // Once a 'Node' is merged to its rep, it is collapsed,
112  // only its 'NodeID' remaining in the set 'subNodes' of its rep node.
113  mergeNodeToRep(node, rep);
114  setMergedNode(node);
115  }
116 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
virtual void initialize()
Definition: AndersenHCD.cpp:44
void find(void)
Definition: SCC.h:308
static AndersenHCD * hcdAndersen
Definition: Andersen.h:642
virtual void mergeSCC(NodeID nodeId)
Definition: AndersenHCD.cpp:77
const ConstraintEdge::ConstraintEdgeSetTy & getAddrOutEdges() const
Definition: ConsGNode.h:160
virtual void initialize()
Initialize analysis.
Definition: Andersen.cpp:167
virtual void solveWorklist()
Definition: AndersenHCD.cpp:58
void mergeNodeAndPts(NodeID node, NodeID tgt)
for isBitcode
Definition: ContextDDA.h:15
NodeBS PointsTo
Definition: SVFBasicTypes.h:88
const ConstraintEdge::ConstraintEdgeSetTy & getDirectInEdges() const
Return constraint edges.
Definition: ConsGNode.h:116