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 virtual void clear() = 0;
106
108 virtual const DataSet& getPts(const Key& var) = 0;
110 virtual const KeySet& getRevPts(const Data& datum) = 0;
111
113 virtual bool addPts(const Key& var, const Data& element) = 0;
114
116 virtual bool unionPts(const Key& dstVar, const Key& srcVar) = 0;
118 virtual bool unionPts(const Key& dstVar, const DataSet& srcDataSet) = 0;
119
121 virtual void clearPts(const Key& var, const Data& element) = 0;
123 virtual void clearFullPts(const Key& var) = 0;
124
126 virtual void remapAllPts(void) = 0;
127
129 virtual void dumpPTData() = 0;
130
136
137protected:
139 bool rev;
141};
142
146template <typename Key, typename KeySet, typename Data, typename DataSet>
147class DiffPTData : public PTData<Key, KeySet, Data, DataSet>
148{
149public:
152
153 DiffPTData(bool reversePT = true, PTDataTy ty = PTDataTy::Diff) : BasePTData(reversePT, ty) { }
154
155 virtual ~DiffPTData() { }
156
158 virtual const DataSet& getDiffPts(Key& var) = 0;
159
163 virtual bool computeDiffPts(Key& var, const DataSet& all) = 0;
164
167 virtual void updatePropaPtsMap(Key& src, Key& dst) = 0;
168
170 virtual void clearPropaPts(Key& var) = 0;
171
175 {
176 return true;
177 }
179 {
180 return ptd->getPTDTY() == PTDataTy::Diff
181 || ptd->getPTDTY() == PTDataTy::MutDiff
182 || ptd->getPTDTY() == PTDataTy::PersDiff;
183 }
185};
186
191template <typename Key, typename KeySet, typename Data, typename DataSet>
192class DFPTData : public PTData<Key, KeySet, Data, DataSet>
193{
194public:
197
198 typedef NodeID LocID;
199
202
203 virtual ~DFPTData() { }
204
207 virtual bool hasDFInSet(LocID loc) const = 0;
208 virtual bool hasDFOutSet(LocID loc) const = 0;
210
213 virtual bool hasDFOutSet(LocID loc, const Key& var) const = 0;
214 virtual bool hasDFInSet(LocID loc, const Key& var) const = 0;
215 virtual const DataSet& getDFInPtsSet(LocID loc, const Key& var) = 0;
216 virtual const DataSet& getDFOutPtsSet(LocID loc, const Key& var) = 0;
218
224 virtual bool updateDFInFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
226 virtual bool updateAllDFInFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
228 virtual bool updateDFInFromOut(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
230 virtual bool updateAllDFInFromOut(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
231
233 virtual bool updateDFOutFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
235 virtual bool updateAllDFOutFromIn(LocID loc, const Key& singleton, bool strongUpdates) = 0;
236
238
240 virtual bool updateTLVPts(LocID srcLoc, const Key& srcVar, const Key& dstVar) = 0;
242 virtual bool updateATVPts(const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
244
248 {
249 return true;
250 }
251
253 {
254 return ptd->getPTDTY() == BasePTData::DataFlow
255 || ptd->getPTDTY() == BasePTData::MutDataFlow
256 || ptd->getPTDTY() == BasePTData::MutIncDataFlow
257 || ptd->getPTDTY() == BasePTData::PersDataFlow
258 || ptd->getPTDTY() == BasePTData::PersIncDataFlow;
259 }
261};
262
266template <typename Key, typename KeySet, typename Data, typename DataSet, typename VersionedKey, typename VersionedKeySet>
267class VersionedPTData : public PTData<Key, KeySet, Data, DataSet>
268{
269public:
272
273 VersionedPTData(bool reversePT = true, PTDataTy ty = PTDataTy::Versioned) : BasePTData(reversePT, ty) { }
274
275 virtual ~VersionedPTData() { }
276
277 virtual const DataSet& getPts(const VersionedKey& vk) = 0;
279
280 virtual bool addPts(const VersionedKey& vk, const Data& element) = 0;
281
282 virtual bool unionPts(const VersionedKey& dstVar, const VersionedKey& srcVar) = 0;
283 virtual bool unionPts(const VersionedKey& dstVar, const Key& srcVar) = 0;
284 virtual bool unionPts(const Key& dstVar, const VersionedKey& srcVar) = 0;
285 virtual bool unionPts(const VersionedKey& dstVar, const DataSet& srcDataSet) = 0;
286
287 virtual void clearPts(const VersionedKey& vk, const Data& element) = 0;
288 virtual void clearFullPts(const VersionedKey& vk) = 0;
289
293 {
294 return true;
295 }
296
298 {
299 return ptd->getPTDTY() == PTDataTy::Versioned
300 || ptd->getPTDTY() == PTDataTy::MutVersioned
301 || ptd->getPTDTY() == PTDataTy::PersVersioned;
302 }
303private:
304 using BasePTData::getPts;
305 using BasePTData::addPts;
310};
311
312} // End namespace SVF
313
314#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.
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