SVF
LocationSet.cpp
Go to the documentation of this file.
1 //===- LocationSet.cpp -- Location set for modeling abstract memory object----//
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  * @file: LocationSet.cpp
25  * @author: yesen
26  * @date: 26 Sep 2014
27  *
28  * LICENSE
29  *
30  */
31 
32 #include "Util/Options.h"
34 #include "MemoryModel/MemModel.h"
35 
36 using namespace SVF;
37 
38 
43 {
46  if (pair.first == 0 || pair.second == 0)
47  return;
48 
50  {
51  if (numStridePair.empty())
52  numStridePair.push_back(std::make_pair(StInfo::getMaxFieldLimit(),pair.second));
53  else
54  {
56  NodeID existStride = (*numStridePair.begin()).second;
57  NodeID newStride = gcd(pair.second, existStride);
58  if (newStride != existStride)
59  {
60  numStridePair.pop_back();
61  numStridePair.push_back(std::make_pair(StInfo::getMaxFieldLimit(),newStride));
62  }
63  }
64  }
65  else
66  {
67  numStridePair.push_back(pair);
68  }
69 }
70 
71 
75 bool LocationSet::increaseIfNotReachUpperBound(std::vector<NodeID>& indices,
76  const ElemNumStridePairVec& pairVec) const
77 {
78  assert(indices.size() == pairVec.size() && "vector size not match");
79 
81  bool reachUpperBound = true;
82  for (u32_t i = 0; i < indices.size(); i++)
83  {
84  assert(pairVec[i].first > 0 && "number must be greater than 0");
85  if (indices[i] < (pairVec[i].first - 1))
86  reachUpperBound = false;
87  }
88 
90  bool increased = false;
91  if (reachUpperBound == false)
92  {
93  u32_t i = 0;
94  while (increased == false)
95  {
96  if (indices[i] < (pairVec[i].first - 1))
97  {
98  indices[i] += 1;
99  increased = true;
100  }
101  else
102  {
103  indices[i] = 0;
104  i++;
105  }
106  }
107  }
108 
109  return increased;
110 }
111 
112 
117 {
118 
120  result.set(getOffset());
121 
122  if (isConstantOffset() == false)
123  {
124  const ElemNumStridePairVec& lhsVec = getNumStridePair();
125  std::vector<NodeID> indices;
126  u32_t size = lhsVec.size();
127  while (size)
128  {
129  indices.push_back(0);
130  size--;
131  }
132 
133  do
134  {
135  u32_t i = 0;
136  NodeID ofst = getOffset();
137  while (i < lhsVec.size())
138  {
139  ofst += (lhsVec[i].second * indices[i]);
140  i++;
141  }
142 
143  result.set(ofst);
144 
145  }
146  while (increaseIfNotReachUpperBound(indices, lhsVec));
147  }
148 
149  return result;
150 }
151 
152 
153 
PointsTo computeAllLocations() const
Compute all possible locations according to offset and number-stride pairs.
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
FieldInfo::ElemNumStridePairVec ElemNumStridePairVec
Definition: LocationSet.h:103
static const llvm::cl::opt< bool > SingleStride
Definition: Options.h:78
bool isConstantOffset() const
Return TRUE if this is a constant location set.
Definition: LocationSet.h:219
unsigned u32_t
Definition: SVFBasicTypes.h:75
bool increaseIfNotReachUpperBound(std::vector< NodeID > &indices, const ElemNumStridePairVec &pairVec) const
Return TRUE if successfully increased any index by 1.
Definition: LocationSet.cpp:75
void addElemNumStridePair(const NodePair &pair)
Definition: LocationSet.cpp:42
unsigned gcd(unsigned n1, unsigned n2) const
Return greatest common divisor.
Definition: LocationSet.h:279
static u32_t getMaxFieldLimit()
Definition: MemModel.h:88
Size_t getOffset() const
Get methods.
Definition: LocationSet.h:194
for isBitcode
Definition: ContextDDA.h:15
const ElemNumStridePairVec & getNumStridePair() const
Definition: LocationSet.h:210
std::pair< NodeID, NodeID > NodePair
static int result
Definition: cuddGenetic.c:121
ElemNumStridePairVec numStridePair
element number and stride pair
Definition: LocationSet.h:286
NodeBS PointsTo
Definition: SVFBasicTypes.h:88