Static Value-Flow Analysis
Loading...
Searching...
No Matches
AbstractPointsToDS.h
Go to the documentation of this file.
1//===- AbstractPointsToDS.h -- Abstract points-to data structure-------------//
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
41
42
43/*
44 * AbstractPointsToDS.h
45 *
46 * Authors: Mohamad Barbar and Yulei Sui
47 *
48 * The implementation is based on
49 * Mohamad Barbar and Yulei Sui. Hash Consed Points-To Sets.
50 * 28th Static Analysis Symposium (SAS'21)
51 */
52
53#ifndef ABSTRACT_POINTSTO_H_
54#define ABSTRACT_POINTSTO_H_
55
56namespace SVF
57{
71template <typename Key, typename KeySet, typename Data, typename DataSet>
72class PTData
73{
74public:
93
95
96 virtual ~PTData() { }
97
99 inline PTDataTy getPTDTY() const
100 {
101 return ptdTy;
102 }
103
105 inline bool hasReversePts() const
106 {
107 return rev;
108 }
109
111 virtual void clear() = 0;
112
114 virtual const DataSet& getPts(const Key& var) = 0;
116 virtual const KeySet& getRevPts(const Data& datum) = 0;
117
119 virtual bool addPts(const Key& var, const Data& element) = 0;
120
122 virtual bool unionPts(const Key& dstVar, const Key& srcVar) = 0;
124 virtual bool unionPts(const Key& dstVar, const DataSet& srcDataSet) = 0;
125
127 virtual void clearPts(const Key& var, const Data& element) = 0;
129 virtual void clearFullPts(const Key& var) = 0;
130
132 virtual void remapAllPts(void) = 0;
133
135 virtual void dumpPTData() = 0;
136
142
143protected:
145 bool rev;
147};
148
152template <typename Key, typename KeySet, typename Data, typename DataSet>
153class DiffPTData : public PTData<Key, KeySet, Data, DataSet>
154{
155public:
158
159 DiffPTData(bool reversePT = true, PTDataTy ty = PTDataTy::Diff) : BasePTData(reversePT, ty) { }
160
161 virtual ~DiffPTData() { }
162
164 virtual const DataSet& getDiffPts(Key& var) = 0;
165
169 virtual bool computeDiffPts(Key& var, const DataSet& all) = 0;
170
173 virtual void updatePropaPtsMap(Key& src, Key& dst) = 0;
174
176 virtual void clearPropaPts(Key& var) = 0;
177
181 {
182 return true;
183 }
185 {
186 return ptd->getPTDTY() == PTDataTy::Diff
187 || ptd->getPTDTY() == PTDataTy::MutDiff
188 || ptd->getPTDTY() == PTDataTy::PersDiff;
189 }
191};
192
197template <typename Key, typename KeySet, typename Data, typename DataSet>
198class DFPTData : public PTData<Key, KeySet, Data, DataSet>
199{
200public:
203
204 typedef NodeID LocID;
205
208
209 virtual ~DFPTData() { }
210
213 virtual bool hasDFInSet(LocID loc) const = 0;
214 virtual bool hasDFOutSet(LocID loc) const = 0;
216
219 virtual bool hasDFOutSet(LocID loc, const Key& var) const = 0;
220 virtual bool hasDFInSet(LocID loc, const Key& var) const = 0;
221 virtual const DataSet& getDFInPtsSet(LocID loc, const Key& var) = 0;
222 virtual const DataSet& getDFOutPtsSet(LocID loc, const Key& var) = 0;
224
230 virtual bool updateDFInFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
232 virtual bool updateAllDFInFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
234 virtual bool updateDFInFromOut(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
236 virtual bool updateAllDFInFromOut(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
237
239 virtual bool updateDFOutFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
241 virtual bool updateAllDFOutFromIn(LocID loc, const Key& singleton, bool strongUpdates) = 0;
242
244
246 virtual bool updateTLVPts(LocID srcLoc, const Key& srcVar, const Key& dstVar) = 0;
248 virtual bool updateATVPts(const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
250
254 {
255 return true;
256 }
257
259 {
260 return ptd->getPTDTY() == BasePTData::DataFlow
261 || ptd->getPTDTY() == BasePTData::MutDataFlow
262 || ptd->getPTDTY() == BasePTData::MutIncDataFlow
263 || ptd->getPTDTY() == BasePTData::PersDataFlow
264 || ptd->getPTDTY() == BasePTData::PersIncDataFlow;
265 }
267};
268
272template <typename Key, typename KeySet, typename Data, typename DataSet, typename VersionedKey, typename VersionedKeySet>
273class VersionedPTData : public PTData<Key, KeySet, Data, DataSet>
274{
275public:
278
279 VersionedPTData(bool reversePT = true, PTDataTy ty = PTDataTy::Versioned) : BasePTData(reversePT, ty) { }
280
281 virtual ~VersionedPTData() { }
282
283 virtual const DataSet& getPts(const VersionedKey& vk) = 0;
285
286 virtual bool addPts(const VersionedKey& vk, const Data& element) = 0;
287
288 virtual bool unionPts(const VersionedKey& dstVar, const VersionedKey& srcVar) = 0;
289 virtual bool unionPts(const VersionedKey& dstVar, const Key& srcVar) = 0;
290 virtual bool unionPts(const Key& dstVar, const VersionedKey& srcVar) = 0;
291 virtual bool unionPts(const VersionedKey& dstVar, const DataSet& srcDataSet) = 0;
292
293 virtual void clearPts(const VersionedKey& vk, const Data& element) = 0;
294 virtual void clearFullPts(const VersionedKey& vk) = 0;
295
299 {
300 return true;
301 }
302
304 {
305 return ptd->getPTDTY() == PTDataTy::Versioned
306 || ptd->getPTDTY() == PTDataTy::MutVersioned
307 || ptd->getPTDTY() == PTDataTy::PersVersioned;
308 }
309private:
310 using BasePTData::getPts;
311 using BasePTData::addPts;
316};
317
318} // End namespace SVF
319
320#endif // ABSTRACT_POINTSTO_H_
virtual bool updateATVPts(const Key &srcVar, LocID dstLoc, const Key &dstVar)=0
Update address-taken variables OUT[dstLoc:dstVar] with points-to of top-level pointers.
static bool classof(const DFPTData< Key, KeySet, Data, DataSet > *)
virtual bool hasDFOutSet(LocID loc, const Key &var) const =0
virtual bool updateDFInFromOut(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar)=0
Union (IN[dstLoc:dstVar], OUT[srcLoc:srcVar]).
virtual bool hasDFOutSet(LocID loc) const =0
virtual const DataSet & getDFInPtsSet(LocID loc, const Key &var)=0
DFPTData(bool reversePT=true, PTDataTy ty=BasePTData::DataFlow)
Constructor.
virtual bool updateAllDFInFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar)=0
Union (IN[dstLoc::dstVar], IN[srcLoc:srcVar]. There is no flag check, unlike the above.
PTData< Key, KeySet, Data, DataSet > BasePTData
virtual bool updateAllDFOutFromIn(LocID loc, const Key &singleton, bool strongUpdates)=0
For each variable var in IN at loc, do updateDFOutFromIn(loc, var, loc, var).
virtual bool updateDFInFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar)=0
virtual bool updateAllDFInFromOut(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar)=0
Union (IN[dstLoc::dstVar], OUT[srcLoc:srcVar]. There is no flag check, unlike the above.
virtual bool updateTLVPts(LocID srcLoc, const Key &srcVar, const Key &dstVar)=0
Update points-to set of top-level pointers with IN[srcLoc:srcVar].
BasePTData::PTDataTy PTDataTy
virtual bool hasDFInSet(LocID loc, const Key &var) const =0
static bool classof(const PTData< Key, KeySet, Data, DataSet > *ptd)
virtual bool hasDFInSet(LocID loc) const =0
virtual void clearAllDFOutUpdatedVar(LocID)=0
virtual bool updateDFOutFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar)=0
Union (OUT[dstLoc:dstVar], IN[srcLoc:srcVar]).
virtual const DataSet & getDFOutPtsSet(LocID loc, const Key &var)=0
virtual const DataSet & getDiffPts(Key &var)=0
Get diff points to.
static bool classof(const DiffPTData< Key, KeySet, Data, DataSet > *)
virtual void updatePropaPtsMap(Key &src, Key &dst)=0
virtual bool computeDiffPts(Key &var, const DataSet &all)=0
BasePTData::PTDataTy PTDataTy
virtual void clearPropaPts(Key &var)=0
Clear propagated points-to set of var.
DiffPTData(bool reversePT=true, PTDataTy ty=PTDataTy::Diff)
PTData< Key, KeySet, Data, DataSet > BasePTData
static bool classof(const PTData< Key, KeySet, Data, DataSet > *ptd)
virtual void clearPts(const Key &var, const Data &element)=0
Clears element from the points-to set of var.
PTData(bool reversePT=true, PTDataTy ty=PTDataTy::Base)
bool rev
Whether we maintain reverse points-to sets or not.
bool hasReversePts() const
Whether we maintain reverse points-to sets.
virtual Map< DataSet, unsigned > getAllPts(bool liveOnly) const =0
PTDataTy
Types of a points-to data structures.
virtual const DataSet & getPts(const Key &var)=0
Get points-to set of var.
virtual void clearFullPts(const Key &var)=0
Fully clears the points-to set of var.
virtual void dumpPTData()=0
Dump stored keys and points-to sets.
virtual bool unionPts(const Key &dstVar, const DataSet &srcDataSet)=0
Performs pts(dstVar) = pts(dstVar) U srcDataSet.
virtual const KeySet & getRevPts(const Data &datum)=0
Get reverse points-to set of a datum.
virtual bool addPts(const Key &var, const Data &element)=0
Adds element to the points-to set associated with var.
virtual void clear()=0
Clears all points-to sets as if nothing is stored.
PTDataTy getPTDTY() const
Get the type of points-to data structure that this is.
virtual void remapAllPts(void)=0
Remaps all points-to sets to use the current mapping.
virtual bool unionPts(const Key &dstVar, const Key &srcVar)=0
Performs pts(dstVar) = pts(dstVar) U pts(srcVar).
virtual void clearPts(const VersionedKey &vk, const Data &element)=0
VersionedPTData(bool reversePT=true, PTDataTy ty=PTDataTy::Versioned)
static bool classof(const VersionedPTData< Key, KeySet, Data, DataSet, VersionedKey, VersionedKeySet > *)
virtual void clearFullPts(const VersionedKey &vk)=0
virtual bool unionPts(const VersionedKey &dstVar, const Key &srcVar)=0
static bool classof(const PTData< Key, KeySet, Data, DataSet > *ptd)
virtual const DataSet & getPts(const VersionedKey &vk)=0
virtual bool unionPts(const VersionedKey &dstVar, const VersionedKey &srcVar)=0
virtual bool unionPts(const Key &dstVar, const VersionedKey &srcVar)=0
PTData< Key, KeySet, Data, DataSet > BasePTData
virtual const VersionedKeySet & getVersionedKeyRevPts(const Data &datum)=0
virtual bool unionPts(const VersionedKey &dstVar, const DataSet &srcDataSet)=0
virtual bool addPts(const VersionedKey &vk, const Data &element)=0
BasePTData::PTDataTy PTDataTy
for isBitcode
Definition BasicTypes.h:70
u32_t NodeID
Definition GeneralType.h:76
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76