Static Value-Flow Analysis
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 
56 #include "SVFIR/SVFType.h"
57 
58 namespace SVF
59 {
73 template <typename Key, typename KeySet, typename Data, typename DataSet>
74 class PTData
75 {
76 public:
78  enum PTDataTy
79  {
94  };
95 
96  PTData(bool reversePT = true, PTDataTy ty = PTDataTy::Base) : rev(reversePT), ptdTy(ty) { }
97 
98  virtual ~PTData() { }
99 
101  inline PTDataTy getPTDTY() const
102  {
103  return ptdTy;
104  }
105 
107  virtual void clear() = 0;
108 
110  virtual const DataSet& getPts(const Key& var) = 0;
112  virtual const KeySet& getRevPts(const Data& datum) = 0;
113 
115  virtual bool addPts(const Key& var, const Data& element) = 0;
116 
118  virtual bool unionPts(const Key& dstVar, const Key& srcVar) = 0;
120  virtual bool unionPts(const Key& dstVar, const DataSet& srcDataSet) = 0;
121 
123  virtual void clearPts(const Key& var, const Data& element) = 0;
125  virtual void clearFullPts(const Key& var) = 0;
126 
128  virtual void remapAllPts(void) = 0;
129 
131  virtual void dumpPTData() = 0;
132 
137  virtual Map<DataSet, unsigned> getAllPts(bool liveOnly) const = 0;
138 
139 protected:
141  bool rev;
143 };
144 
148 template <typename Key, typename KeySet, typename Data, typename DataSet>
149 class DiffPTData : public PTData<Key, KeySet, Data, DataSet>
150 {
151 public:
153  typedef typename BasePTData::PTDataTy PTDataTy;
154 
155  DiffPTData(bool reversePT = true, PTDataTy ty = PTDataTy::Diff) : BasePTData(reversePT, ty) { }
156 
157  virtual ~DiffPTData() { }
158 
160  virtual const DataSet& getDiffPts(Key& var) = 0;
161 
165  virtual bool computeDiffPts(Key& var, const DataSet& all) = 0;
166 
169  virtual void updatePropaPtsMap(Key& src, Key& dst) = 0;
170 
172  virtual void clearPropaPts(Key& var) = 0;
173 
177  {
178  return true;
179  }
180  static inline bool classof(const PTData<Key, KeySet, Data, DataSet>* ptd)
181  {
182  return ptd->getPTDTY() == PTDataTy::Diff
183  || ptd->getPTDTY() == PTDataTy::MutDiff
184  || ptd->getPTDTY() == PTDataTy::PersDiff;
185  }
187 };
188 
193 template <typename Key, typename KeySet, typename Data, typename DataSet>
194 class DFPTData : public PTData<Key, KeySet, Data, DataSet>
195 {
196 public:
198  typedef typename BasePTData::PTDataTy PTDataTy;
199 
200  typedef NodeID LocID;
201 
203  DFPTData(bool reversePT = true, PTDataTy ty = BasePTData::DataFlow) : BasePTData(reversePT, ty) { }
204 
205  virtual ~DFPTData() { }
206 
209  virtual bool hasDFInSet(LocID loc) const = 0;
210  virtual bool hasDFOutSet(LocID loc) const = 0;
212 
215  virtual bool hasDFOutSet(LocID loc, const Key& var) const = 0;
216  virtual bool hasDFInSet(LocID loc, const Key& var) const = 0;
217  virtual const DataSet& getDFInPtsSet(LocID loc, const Key& var) = 0;
218  virtual const DataSet& getDFOutPtsSet(LocID loc, const Key& var) = 0;
220 
226  virtual bool updateDFInFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
228  virtual bool updateAllDFInFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
230  virtual bool updateDFInFromOut(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
232  virtual bool updateAllDFInFromOut(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
233 
235  virtual bool updateDFOutFromIn(LocID srcLoc, const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
237  virtual bool updateAllDFOutFromIn(LocID loc, const Key& singleton, bool strongUpdates) = 0;
238 
239  virtual void clearAllDFOutUpdatedVar(LocID) = 0;
240 
242  virtual bool updateTLVPts(LocID srcLoc, const Key& srcVar, const Key& dstVar) = 0;
244  virtual bool updateATVPts(const Key& srcVar, LocID dstLoc, const Key& dstVar) = 0;
246 
249  static inline bool classof(const DFPTData<Key, KeySet, Data, DataSet> *)
250  {
251  return true;
252  }
253 
254  static inline bool classof(const PTData<Key, KeySet, Data, DataSet>* ptd)
255  {
256  return ptd->getPTDTY() == BasePTData::DataFlow
257  || ptd->getPTDTY() == BasePTData::MutDataFlow
261  }
263 };
264 
268 template <typename Key, typename KeySet, typename Data, typename DataSet, typename VersionedKey, typename VersionedKeySet>
269 class VersionedPTData : public PTData<Key, KeySet, Data, DataSet>
270 {
271 public:
273  typedef typename BasePTData::PTDataTy PTDataTy;
274 
275  VersionedPTData(bool reversePT = true, PTDataTy ty = PTDataTy::Versioned) : BasePTData(reversePT, ty) { }
276 
277  virtual ~VersionedPTData() { }
278 
279  virtual const DataSet& getPts(const VersionedKey& vk) = 0;
280  virtual const VersionedKeySet& getVersionedKeyRevPts(const Data& datum) = 0;
281 
282  virtual bool addPts(const VersionedKey& vk, const Data& element) = 0;
283 
284  virtual bool unionPts(const VersionedKey& dstVar, const VersionedKey& srcVar) = 0;
285  virtual bool unionPts(const VersionedKey& dstVar, const Key& srcVar) = 0;
286  virtual bool unionPts(const Key& dstVar, const VersionedKey& srcVar) = 0;
287  virtual bool unionPts(const VersionedKey& dstVar, const DataSet& srcDataSet) = 0;
288 
289  virtual void clearPts(const VersionedKey& vk, const Data& element) = 0;
290  virtual void clearFullPts(const VersionedKey& vk) = 0;
291 
295  {
296  return true;
297  }
298 
299  static inline bool classof(const PTData<Key, KeySet, Data, DataSet>* ptd)
300  {
301  return ptd->getPTDTY() == PTDataTy::Versioned
302  || ptd->getPTDTY() == PTDataTy::MutVersioned
303  || ptd->getPTDTY() == PTDataTy::PersVersioned;
304  }
305 private:
306  using BasePTData::getPts;
307  using BasePTData::addPts;
308  using BasePTData::unionPts;
309  using BasePTData::clearPts;
312 };
313 
314 } // End namespace SVF
315 
316 #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 const DataSet & getDFInPtsSet(LocID loc, const Key &var)=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
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
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.
virtual const DataSet & getDiffPts(Key &var)=0
Get diff points to.
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 ~PTData()
PTDataTy
Types of a points-to data structures.
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 const DataSet & getPts(const Key &var)=0
Get points-to set of var.
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.
virtual Map< DataSet, unsigned > getAllPts(bool liveOnly) const =0
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 VersionedKeySet & getVersionedKeyRevPts(const Data &datum)=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 bool unionPts(const VersionedKey &dstVar, const DataSet &srcDataSet)=0
virtual const DataSet & getPts(const VersionedKey &vk)=0
virtual bool addPts(const VersionedKey &vk, const Data &element)=0
BasePTData::PTDataTy PTDataTy
for isBitcode
Definition: BasicTypes.h:68
u32_t NodeID
Definition: GeneralType.h:55
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101