SVF
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
SVF::LocationSet Class Reference

#include <LocationSet.h>

Public Types

enum  LSRelation {
  NonOverlap, Overlap, Subset, Superset,
  Same
}
 
typedef FieldInfo::ElemNumStridePairVec ElemNumStridePairVec
 

Public Member Functions

 LocationSet (Size_t o=0)
 Constructor. More...
 
 LocationSet (const LocationSet &ls)
 Copy Constructor. More...
 
 LocationSet (const FieldInfo &fi)
 Initialization from FieldInfo. More...
 
 ~LocationSet ()
 
void addElemNumStridePair (const NodePair &pair)
 
bool isConstantOffset () const
 Return TRUE if this is a constant location set. More...
 
bool intersects (const LocationSet &RHS) const
 Return TRUE if we share any location in common with RHS. More...
 
std::string dump () const
 Dump location set. More...
 
LocationSet operator+ (const LocationSet &rhs) const
 Overload operators. More...
 
const LocationSetoperator= (const LocationSet &rhs)
 
bool operator< (const LocationSet &rhs) const
 
bool operator== (const LocationSet &rhs) const
 
Size_t getOffset () const
 Get methods. More...
 
Size_t getByteOffset () const
 
void setFldIdx (Size_t idx)
 
void setByteOffset (Size_t os)
 
const ElemNumStridePairVecgetNumStridePair () const
 

Static Public Member Functions

static LSRelation checkRelation (const LocationSet &LHS, const LocationSet &RHS)
 Check relations of two location sets. More...
 

Private Member Functions

bool increaseIfNotReachUpperBound (std::vector< NodeID > &indices, const ElemNumStridePairVec &pairVec) const
 Return TRUE if successfully increased any index by 1. More...
 
PointsTo computeAllLocations () const
 Compute all possible locations according to offset and number-stride pairs. More...
 
unsigned gcd (unsigned n1, unsigned n2) const
 Return greatest common divisor. More...
 

Private Attributes

Size_t fldIdx
 offset relative to base More...
 
Size_t byteOffset
 offset relative to base More...
 
ElemNumStridePairVec numStridePair
 element number and stride pair More...
 

Friends

class SymbolTableInfo
 
class LocSymTableInfo
 

Detailed Description

Definition at line 93 of file LocationSet.h.

Member Typedef Documentation

◆ ElemNumStridePairVec

Definition at line 103 of file LocationSet.h.

Member Enumeration Documentation

◆ LSRelation

Enumerator
NonOverlap 
Overlap 
Subset 
Superset 
Same 

Definition at line 98 of file LocationSet.h.

Constructor & Destructor Documentation

◆ LocationSet() [1/3]

SVF::LocationSet::LocationSet ( Size_t  o = 0)
inline

Constructor.

Definition at line 106 of file LocationSet.h.

106  : fldIdx(o), byteOffset(o)
107  {}
Size_t byteOffset
offset relative to base
Definition: LocationSet.h:285
Size_t fldIdx
offset relative to base
Definition: LocationSet.h:284

◆ LocationSet() [2/3]

SVF::LocationSet::LocationSet ( const LocationSet ls)
inline

Copy Constructor.

Definition at line 110 of file LocationSet.h.

111  : fldIdx(ls.fldIdx), byteOffset(ls.byteOffset)
112  {
113  const ElemNumStridePairVec& vec = ls.getNumStridePair();
114  ElemNumStridePairVec::const_iterator it = vec.begin();
115  ElemNumStridePairVec::const_iterator eit = vec.end();
116  for (; it != eit; ++it)
118  }
FieldInfo::ElemNumStridePairVec ElemNumStridePairVec
Definition: LocationSet.h:103
void addElemNumStridePair(const NodePair &pair)
Definition: LocationSet.cpp:42
Size_t byteOffset
offset relative to base
Definition: LocationSet.h:285
Size_t fldIdx
offset relative to base
Definition: LocationSet.h:284

◆ LocationSet() [3/3]

SVF::LocationSet::LocationSet ( const FieldInfo fi)
inline

Initialization from FieldInfo.

Definition at line 121 of file LocationSet.h.

122  : fldIdx(fi.getFlattenFldIdx()), byteOffset(fi.getFlattenByteOffset())
123  {
124  const ElemNumStridePairVec& vec = fi.getElemNumStridePairVect();
125  ElemNumStridePairVec::const_iterator it = vec.begin();
126  ElemNumStridePairVec::const_iterator eit = vec.end();
127  for (; it != eit; ++it)
129  }
FieldInfo::ElemNumStridePairVec ElemNumStridePairVec
Definition: LocationSet.h:103
void addElemNumStridePair(const NodePair &pair)
Definition: LocationSet.cpp:42
Size_t byteOffset
offset relative to base
Definition: LocationSet.h:285
Size_t fldIdx
offset relative to base
Definition: LocationSet.h:284

◆ ~LocationSet()

SVF::LocationSet::~LocationSet ( )
inline

Definition at line 131 of file LocationSet.h.

131 {}

Member Function Documentation

◆ addElemNumStridePair()

void LocationSet::addElemNumStridePair ( const NodePair pair)

Add element num and stride pair

The pair will not be added if any number of a stride is zero, because they will not have effect on the locations represented by this LocationSet.

Find the GCD stride

Definition at line 42 of file LocationSet.cpp.

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 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
static const llvm::cl::opt< bool > SingleStride
Definition: Options.h:78
unsigned gcd(unsigned n1, unsigned n2) const
Return greatest common divisor.
Definition: LocationSet.h:279
static u32_t getMaxFieldLimit()
Definition: MemModel.h:88
ElemNumStridePairVec numStridePair
element number and stride pair
Definition: LocationSet.h:286

◆ checkRelation()

static LSRelation SVF::LocationSet::checkRelation ( const LocationSet LHS,
const LocationSet RHS 
)
inlinestatic

Check relations of two location sets.

Definition at line 231 of file LocationSet.h.

232  {
233  PointsTo lhsLocations = LHS.computeAllLocations();
234  PointsTo rhsLocations = RHS.computeAllLocations();
235  if (lhsLocations.intersects(rhsLocations))
236  {
237  if (lhsLocations == rhsLocations)
238  return Same;
239  else if (lhsLocations.contains(rhsLocations))
240  return Superset;
241  else if (rhsLocations.contains(lhsLocations))
242  return Subset;
243  else
244  return Overlap;
245  }
246  else
247  {
248  return NonOverlap;
249  }
250  }
NodeBS PointsTo
Definition: SVFBasicTypes.h:88

◆ computeAllLocations()

PointsTo LocationSet::computeAllLocations ( ) const
private

Compute all possible locations according to offset and number-stride pairs.

Compute all possible locations according to offset and number-stride pairs.

Definition at line 116 of file LocationSet.cpp.

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 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
FieldInfo::ElemNumStridePairVec ElemNumStridePairVec
Definition: LocationSet.h:103
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
Size_t getOffset() const
Get methods.
Definition: LocationSet.h:194
const ElemNumStridePairVec & getNumStridePair() const
Definition: LocationSet.h:210
static int result
Definition: cuddGenetic.c:121
NodeBS PointsTo
Definition: SVFBasicTypes.h:88

◆ dump()

std::string SVF::LocationSet::dump ( ) const
inline

Dump location set.

Definition at line 253 of file LocationSet.h.

254  {
255  std::string str;
256  raw_string_ostream rawstr(str);
257 
258  rawstr << "LocationSet\tField_Index: " << getOffset();
259  rawstr << "\tOffset: " << getByteOffset()
260  << ",\tNum-Stride: {";
261  const ElemNumStridePairVec& vec = getNumStridePair();
262  ElemNumStridePairVec::const_iterator it = vec.begin();
263  ElemNumStridePairVec::const_iterator eit = vec.end();
264  for (; it != eit; ++it)
265  {
266  rawstr << " (" << it->first << "," << it->second << ")";
267  }
268  rawstr << " }\n";
269  return rawstr.str();
270  }
Size_t getByteOffset() const
Definition: LocationSet.h:198
FieldInfo::ElemNumStridePairVec ElemNumStridePairVec
Definition: LocationSet.h:103
llvm::raw_string_ostream raw_string_ostream
Definition: BasicTypes.h:100
Size_t getOffset() const
Get methods.
Definition: LocationSet.h:194
const ElemNumStridePairVec & getNumStridePair() const
Definition: LocationSet.h:210

◆ gcd()

unsigned SVF::LocationSet::gcd ( unsigned  n1,
unsigned  n2 
) const
inlineprivate

Return greatest common divisor.

Definition at line 279 of file LocationSet.h.

280  {
281  return (n2 == 0) ? n1 : gcd (n2, n1 % n2);
282  }
unsigned gcd(unsigned n1, unsigned n2) const
Return greatest common divisor.
Definition: LocationSet.h:279

◆ getByteOffset()

Size_t SVF::LocationSet::getByteOffset ( ) const
inline

Definition at line 198 of file LocationSet.h.

199  {
200  return byteOffset;
201  }
Size_t byteOffset
offset relative to base
Definition: LocationSet.h:285

◆ getNumStridePair()

const ElemNumStridePairVec& SVF::LocationSet::getNumStridePair ( ) const
inline

Definition at line 210 of file LocationSet.h.

211  {
212  return numStridePair;
213  }
ElemNumStridePairVec numStridePair
element number and stride pair
Definition: LocationSet.h:286

◆ getOffset()

Size_t SVF::LocationSet::getOffset ( ) const
inline

Get methods.

Definition at line 194 of file LocationSet.h.

195  {
196  return fldIdx;
197  }
Size_t fldIdx
offset relative to base
Definition: LocationSet.h:284

◆ increaseIfNotReachUpperBound()

bool LocationSet::increaseIfNotReachUpperBound ( std::vector< NodeID > &  indices,
const ElemNumStridePairVec pairVec 
) const
private

Return TRUE if successfully increased any index by 1.

Return TRUE if it successfully increases any index by 1

Check if all indices reach upper bound

Increase index if not reach upper bound

Definition at line 75 of file LocationSet.cpp.

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 }
#define assert(ex)
Definition: util.h:141
unsigned u32_t
Definition: SVFBasicTypes.h:75

◆ intersects()

bool SVF::LocationSet::intersects ( const LocationSet RHS) const
inline

Return TRUE if we share any location in common with RHS.

Definition at line 225 of file LocationSet.h.

226  {
227  return computeAllLocations().intersects(RHS.computeAllLocations());
228  }
PointsTo computeAllLocations() const
Compute all possible locations according to offset and number-stride pairs.

◆ isConstantOffset()

bool SVF::LocationSet::isConstantOffset ( ) const
inline

Return TRUE if this is a constant location set.

Definition at line 219 of file LocationSet.h.

220  {
221  return (numStridePair.size() == 0);
222  }
ElemNumStridePairVec numStridePair
element number and stride pair
Definition: LocationSet.h:286

◆ operator+()

LocationSet SVF::LocationSet::operator+ ( const LocationSet rhs) const
inline

Overload operators.

Definition at line 136 of file LocationSet.h.

137  {
138  LocationSet ls(rhs);
139  ls.fldIdx += getOffset();
140  ls.byteOffset += getByteOffset();
141  ElemNumStridePairVec::const_iterator it = getNumStridePair().begin();
142  ElemNumStridePairVec::const_iterator eit = getNumStridePair().end();
143  for (; it != eit; ++it)
144  ls.addElemNumStridePair(*it);
145 
146  return ls;
147  }
Size_t getByteOffset() const
Definition: LocationSet.h:198
LocationSet(Size_t o=0)
Constructor.
Definition: LocationSet.h:106
Size_t getOffset() const
Get methods.
Definition: LocationSet.h:194
const ElemNumStridePairVec & getNumStridePair() const
Definition: LocationSet.h:210

◆ operator<()

bool SVF::LocationSet::operator< ( const LocationSet rhs) const
inline

Definition at line 155 of file LocationSet.h.

156  {
157  if (fldIdx != rhs.fldIdx)
158  return (fldIdx < rhs.fldIdx);
159 // else if (byteOffset != rhs.byteOffset)
160 // return (byteOffset < rhs.byteOffset);
161  else
162  {
163  const ElemNumStridePairVec& pairVec = getNumStridePair();
164  const ElemNumStridePairVec& rhsPairVec = rhs.getNumStridePair();
165  if (pairVec.size() != rhsPairVec.size())
166  return (pairVec.size() < rhsPairVec.size());
167  else
168  {
169  ElemNumStridePairVec::const_iterator it = pairVec.begin();
170  ElemNumStridePairVec::const_iterator rhsIt = rhsPairVec.begin();
171  for (; it != pairVec.end() && rhsIt != rhsPairVec.end(); ++it, ++rhsIt)
172  {
173  if ((*it).first != (*rhsIt).first)
174  return ((*it).first < (*rhsIt).first);
175  else if ((*it).second != (*rhsIt).second)
176  return ((*it).second < (*rhsIt).second);
177  }
178 
179  return false;
180  }
181  }
182  }
FieldInfo::ElemNumStridePairVec ElemNumStridePairVec
Definition: LocationSet.h:103
Size_t fldIdx
offset relative to base
Definition: LocationSet.h:284
const ElemNumStridePairVec & getNumStridePair() const
Definition: LocationSet.h:210

◆ operator=()

const LocationSet& SVF::LocationSet::operator= ( const LocationSet rhs)
inline

Definition at line 148 of file LocationSet.h.

149  {
150  fldIdx = rhs.fldIdx;
151  byteOffset = rhs.byteOffset;
152  numStridePair = rhs.getNumStridePair();
153  return *this;
154  }
Size_t byteOffset
offset relative to base
Definition: LocationSet.h:285
Size_t fldIdx
offset relative to base
Definition: LocationSet.h:284
ElemNumStridePairVec numStridePair
element number and stride pair
Definition: LocationSet.h:286

◆ operator==()

bool SVF::LocationSet::operator== ( const LocationSet rhs) const
inline

Definition at line 184 of file LocationSet.h.

185  {
186  return this->fldIdx == rhs.fldIdx
187  && this->byteOffset == rhs.byteOffset
188  && this->numStridePair == rhs.numStridePair;
189  }
Size_t byteOffset
offset relative to base
Definition: LocationSet.h:285
Size_t fldIdx
offset relative to base
Definition: LocationSet.h:284
ElemNumStridePairVec numStridePair
element number and stride pair
Definition: LocationSet.h:286

◆ setByteOffset()

void SVF::LocationSet::setByteOffset ( Size_t  os)
inline

Definition at line 206 of file LocationSet.h.

207  {
208  byteOffset = os;
209  }
Size_t byteOffset
offset relative to base
Definition: LocationSet.h:285

◆ setFldIdx()

void SVF::LocationSet::setFldIdx ( Size_t  idx)
inline

Definition at line 202 of file LocationSet.h.

203  {
204  fldIdx = idx;
205  }
Size_t fldIdx
offset relative to base
Definition: LocationSet.h:284

Friends And Related Function Documentation

◆ LocSymTableInfo

friend class LocSymTableInfo
friend

Definition at line 96 of file LocationSet.h.

◆ SymbolTableInfo

friend class SymbolTableInfo
friend

Definition at line 95 of file LocationSet.h.

Member Data Documentation

◆ byteOffset

Size_t SVF::LocationSet::byteOffset
private

offset relative to base

Definition at line 285 of file LocationSet.h.

◆ fldIdx

Size_t SVF::LocationSet::fldIdx
private

offset relative to base

Definition at line 284 of file LocationSet.h.

◆ numStridePair

ElemNumStridePairVec SVF::LocationSet::numStridePair
private

element number and stride pair

Definition at line 286 of file LocationSet.h.


The documentation for this class was generated from the following files: