Static Value-Flow Analysis
Loading...
Searching...
No Matches
AccessPath.h
Go to the documentation of this file.
1//===- AccessPath.h -- Location set of abstract object-----------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <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 Affero 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 Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * @file: AccessPath.h
25 * @author: yesen
26 * @date: 26 Sep 2014
27 *
28 * LICENSE
29 *
30 */
31
32
33#ifndef AccessPath_H_
34#define AccessPath_H_
35
36
37#include "SVFIR/SVFValue.h"
38
39
40namespace SVF
41{
42
43class SVFVar;
44
45
46/*
47* Location set represents a set of locations in a memory block with following offsets:
48* { offset + \sum_{i=0}^N (stride_i * j_i) | 0 \leq j_i < M_i }
49* where N is the size of number-stride pair vector, M_i (stride_i) is i-th number (stride)
50* in the number-stride pair vector.
51*/
53{
54 friend class SymbolTableInfo;
55 friend class SVFIRWriter;
56 friend class SVFIRReader;
57
58public:
63
64 typedef std::pair<const SVFVar*, const SVFType*> IdxOperandPair;
65 typedef std::vector<IdxOperandPair> IdxOperandPairs;
66
68 AccessPath(APOffset o = 0, const SVFType* srcTy = nullptr) : fldIdx(o), gepPointeeType(srcTy) {}
69
77
79
81
82 AccessPath operator+(const AccessPath& rhs) const;
83 bool operator<(const AccessPath& rhs) const;
84 inline const AccessPath& operator=(const AccessPath& rhs)
85 {
87 idxOperandPairs = rhs.getIdxOperandPairVec();
88 gepPointeeType = rhs.gepPointeeType;
89 return *this;
90 }
91 inline bool operator==(const AccessPath& rhs) const
92 {
93 return this->fldIdx == rhs.fldIdx &&
95 }
97
99
101 {
102 return fldIdx;
103 }
104 inline void setFldIdx(APOffset idx)
105 {
106 fldIdx = idx;
107 }
109 {
110 return idxOperandPairs;
111 }
112 inline const SVFType* gepSrcPointeeType() const
113 {
114 return gepPointeeType;
115 }
117
138
145
147 u32_t getElementNum(const SVFType* type) const;
148
149
151
153 bool isConstantOffset() const;
154
156 inline bool intersects(const AccessPath& RHS) const
157 {
158 return computeAllLocations().intersects(RHS.computeAllLocations());
159 }
160
163
165 std::string dump() const;
166
167private:
168
171
174
180};
181
182} // End namespace SVF
183
184template <> struct std::hash<SVF::AccessPath>
185{
186 size_t operator()(const SVF::AccessPath &ap) const
187 {
189 std::hash<SVF::AccessPath::IdxOperandPairs> v;
190 return h(std::make_pair(ap.getConstantStructFldIdx(),
191 v(ap.getIdxOperandPairVec())));
192 }
193};
194
195#endif /* AccessPath_H_ */
newitem type
Definition cJSON.cpp:2739
std::vector< IdxOperandPair > IdxOperandPairs
Definition AccessPath.h:65
const SVFType * gepPointeeType
Definition AccessPath.h:177
u32_t getStructFieldOffset(const SVFVar *idxOperandVar, const SVFStructType *idxOperandType) const
Return byte offset from the beginning of the structure to the field where it is located for struct ty...
bool addOffsetVarAndGepTypePair(const SVFVar *var, const SVFType *gepIterType)
u32_t getElementNum(const SVFType *type) const
Return element number of a type.
bool isConstantOffset() const
Return TRUE if this is a constant location set.
APOffset computeConstantByteOffset() const
std::string dump() const
Dump location set.
bool intersects(const AccessPath &RHS) const
Return TRUE if we share any location in common with RHS.
Definition AccessPath.h:156
IdxOperandPairs idxOperandPairs
a vector of actual offset in the form of <SVF Var, iterator type>
Definition AccessPath.h:176
const AccessPath & operator=(const AccessPath &rhs)
Definition AccessPath.h:84
std::pair< const SVFVar *, const SVFType * > IdxOperandPair
Definition AccessPath.h:64
APOffset getConstantStructFldIdx() const
Get methods.
Definition AccessPath.h:100
AccessPath operator+(const AccessPath &rhs) const
Overload operators.
const SVFType * gepSrcPointeeType() const
Definition AccessPath.h:112
NodeBS computeAllLocations() const
Compute all possible locations according to offset and number-stride pairs.
LSRelation checkRelation(const AccessPath &LHS, const AccessPath &RHS)
Check relations of two location sets.
bool operator==(const AccessPath &rhs) const
Definition AccessPath.h:91
APOffset fldIdx
Accumulated Constant Offsets.
Definition AccessPath.h:175
const IdxOperandPairs & getIdxOperandPairVec() const
Definition AccessPath.h:108
void setFldIdx(APOffset idx)
Definition AccessPath.h:104
AccessPath(APOffset o=0, const SVFType *srcTy=nullptr)
Constructor.
Definition AccessPath.h:68
bool operator<(const AccessPath &rhs) const
APOffset computeConstantOffset() const
For example,.
AccessPath(const AccessPath &ap)
Copy Constructor.
Definition AccessPath.h:71
bool intersects(const SparseBitVector< ElementSize > *RHS) const
for isBitcode
Definition BasicTypes.h:68
s64_t APOffset
Definition GeneralType.h:60
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:46
size_t operator()(const SVF::AccessPath &ap) const
Definition AccessPath.h:186