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;
44class ValVar;
45
46
47/*
48* Location set represents a set of locations in a memory block with following offsets:
49* { offset + \sum_{i=0}^N (stride_i * j_i) | 0 \leq j_i < M_i }
50* where N is the size of number-stride pair vector, M_i (stride_i) is i-th number (stride)
51* in the number-stride pair vector.
52*/
54{
55 friend class GraphDBClient;
56public:
61
62 typedef std::pair<const ValVar*, const SVFType*> IdxOperandPair;
63 typedef std::vector<IdxOperandPair> IdxOperandPairs;
64
66 AccessPath(APOffset o = 0, const SVFType* srcTy = nullptr) : fldIdx(o), gepPointeeType(srcTy) {}
67
75
77
79
80 AccessPath operator+(const AccessPath& rhs) const;
81 bool operator<(const AccessPath& rhs) const;
82 inline const AccessPath& operator=(const AccessPath& rhs)
83 {
85 idxOperandPairs = rhs.getIdxOperandPairVec();
86 gepPointeeType = rhs.gepPointeeType;
87 return *this;
88 }
89 inline bool operator==(const AccessPath& rhs) const
90 {
91 return this->fldIdx == rhs.fldIdx &&
93 }
95
97
99 {
100 return fldIdx;
101 }
102 inline void setFldIdx(APOffset idx)
103 {
104 fldIdx = idx;
105 }
107 {
108 return idxOperandPairs;
109 }
110 inline const SVFType* gepSrcPointeeType() const
111 {
112 return gepPointeeType;
113 }
115
136
143
145 u32_t getElementNum(const SVFType* type) const;
146
147
149
151 bool isConstantOffset() const;
152
154 inline bool intersects(const AccessPath& RHS) const
155 {
156 return computeAllLocations().intersects(RHS.computeAllLocations());
157 }
158
161
163 std::string dump() const;
164
165protected:
166 inline void addIdxOperandPair(std::pair<const ValVar*, const SVFType*> pair)
167 {
168 idxOperandPairs.push_back(pair);
169 }
170
171private:
172
175
178
184};
185
186} // End namespace SVF
187
188template <> struct std::hash<SVF::AccessPath>
189{
190 size_t operator()(const SVF::AccessPath &ap) const
191 {
193 std::hash<SVF::AccessPath::IdxOperandPairs> v;
194 return h(std::make_pair(ap.getConstantStructFldIdx(),
195 v(ap.getIdxOperandPairVec())));
196 }
197};
198
199#endif /* AccessPath_H_ */
newitem type
Definition cJSON.cpp:2739
std::vector< IdxOperandPair > IdxOperandPairs
Definition AccessPath.h:63
const SVFType * gepPointeeType
Definition AccessPath.h:181
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:154
IdxOperandPairs idxOperandPairs
a vector of actual offset in the form of <SVF Var, iterator type>
Definition AccessPath.h:180
const AccessPath & operator=(const AccessPath &rhs)
Definition AccessPath.h:82
APOffset getConstantStructFldIdx() const
Get methods.
Definition AccessPath.h:98
AccessPath operator+(const AccessPath &rhs) const
Overload operators.
void addIdxOperandPair(std::pair< const ValVar *, const SVFType * > pair)
Definition AccessPath.h:166
const SVFType * gepSrcPointeeType() const
Definition AccessPath.h:110
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:89
APOffset fldIdx
Accumulated Constant Offsets.
Definition AccessPath.h:179
u32_t getStructFieldOffset(const ValVar *idxOperandVar, const SVFStructType *idxOperandType) const
Return byte offset from the beginning of the structure to the field where it is located for struct ty...
const IdxOperandPairs & getIdxOperandPairVec() const
Definition AccessPath.h:106
friend class GraphDBClient
Definition AccessPath.h:55
void setFldIdx(APOffset idx)
Definition AccessPath.h:102
AccessPath(APOffset o=0, const SVFType *srcTy=nullptr)
Constructor.
Definition AccessPath.h:66
bool addOffsetVarAndGepTypePair(const ValVar *var, const SVFType *gepIterType)
bool operator<(const AccessPath &rhs) const
std::pair< const ValVar *, const SVFType * > IdxOperandPair
Definition AccessPath.h:62
APOffset computeConstantOffset() const
For example,.
AccessPath(const AccessPath &ap)
Copy Constructor.
Definition AccessPath.h:69
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:47
size_t operator()(const SVF::AccessPath &ap) const
Definition AccessPath.h:190