14#ifndef PERSISTENT_POINTSTO_H_
15#define PERSISTENT_POINTSTO_H_
24template <
typename Key,
typename KeySet,
typename Data,
typename DataSet>
26template <
typename Key,
typename KeySet,
typename Data,
typename DataSet>
28template <
typename Key,
typename KeySet,
typename Data,
typename DataSet,
typename VersionedKey,
typename VersionedKeySet>
32template <
typename Key,
typename KeySet,
typename Data,
typename DataSet>
35 template <
typename K,
typename KS,
typename D,
typename DS,
typename VK,
typename VKS>
58 inline const DataSet&
getPts(
const Key &var)
override
61 return ptCache.getActualPts(
id);
64 inline const KeySet&
getRevPts(
const Data &data)
override
66 assert(this->
rev &&
"PersistentPTData::getRevPts: constructed without reverse PT support!");
70 inline bool addPts(
const Key &dstKey,
const Data &element)
override
78 inline bool unionPts(
const Key& dstKey,
const Key& srcKey)
override
84 inline bool unionPts(
const Key& dstKey,
const DataSet& srcData)
override
94 void clearPts(
const Key &var,
const Data &element)
override
97 toRemoveData.set(element);
101 if (varId != complementId)
103 ptsMap[var] = complementId;
124 for (
const typename KeyToIDMap::value_type &ki :
ptsMap)
126 ++allPts[
ptCache.getActualPts(ki.second)];
146 return ptd->
getPTDTY() == PTDataTy::PersBase;
158 bool changed = newDstId != dstId;
161 ptsMap[dstKey] = newDstId;
167 const DataSet &srcPts =
ptCache.getActualPts(srcId);
198template <
typename Key,
typename KeySet,
typename Data,
typename DataSet>
223 inline const DataSet &
getPts(
const Key& var)
override
228 inline const KeySet&
getRevPts(
const Data &data)
override
230 assert(this->
rev &&
"PersistentDiffPTData::getRevPts: constructed without reverse PT support!");
234 inline bool addPts(
const Key &dstKey,
const Data &element)
override
239 inline bool unionPts(
const Key& dstKey,
const Key& srcKey)
override
244 inline bool unionPts(
const Key &dstKey,
const DataSet &srcDataSet)
override
246 return persPTData.unionPts(dstKey, srcDataSet);
249 void clearPts(
const Key &var,
const Data &element)
override
272 return ptCache.getActualPts(
id);
288 return diffId !=
ptCache.emptyPointsToId();
317 return ptd->
getPTDTY() == PTDataTy::PersDiff;
332template <
typename Key,
typename KeySet,
typename Data,
typename DataSet>
357 inline const DataSet &
getPts(
const Key& var)
override
364 assert(
false &&
"PersistentDFPTData::getRevPts: not supported yet!");
368 inline bool unionPts(
const Key& dstKey,
const Key& srcKey)
override
373 inline bool unionPts(
const Key& dstKey,
const DataSet &srcDataSet)
override
375 return persPTData.unionPts(dstKey, srcDataSet);
378 inline bool addPts(
const Key &dstKey,
const Data &element)
override
383 void clearPts(
const Key& var,
const Data &element)
override
415 typename DFKeyToIDMap::const_iterator foundInKeyToId =
dfInPtsMap.find(loc);
416 if (foundInKeyToId ==
dfInPtsMap.end())
return false;
417 const KeyToIDMap &inKeyToId = foundInKeyToId->second;
418 return (inKeyToId.find(var) != inKeyToId.end());
423 typename DFKeyToIDMap::const_iterator foundOutKeyToId =
dfOutPtsMap.find(loc);
424 if (foundOutKeyToId ==
dfOutPtsMap.end())
return false;
425 const KeyToIDMap &outKeyToId = foundOutKeyToId->second;
426 return (outKeyToId.find(var) != outKeyToId.end());
432 return ptCache.getActualPts(
id);
438 return ptCache.getActualPts(
id);
468 bool changed =
false;
472 for (
const typename KeyToIDMap::value_type &ki : inKeyToId)
474 const Key var = ki.first;
476 if (strongUpdates && var == singleton)
continue;
503 for (
const typename DFKeyToIDMap::value_type &lki :
dfInPtsMap)
505 for (
const typename KeyToIDMap::value_type &ki : lki.second)
507 ++allPts[
ptCache.getActualPts(ki.second)];
511 for (
const typename DFKeyToIDMap::value_type &lki :
dfOutPtsMap)
513 for (
const typename KeyToIDMap::value_type &ki : lki.second)
515 ++allPts[
ptCache.getActualPts(ki.second)];
542 return ptd->
getPTDTY() == PTDataTy::PersDataFlow
543 || ptd->
getPTDTY() == PTDataTy::PersIncDataFlow;
551 dst =
ptCache.unionPts(dst, src);
552 return oldDst != dst;
578template <
typename Key,
typename KeySet,
typename Data,
typename DataSet>
661 bool changed =
false;
666 for (
const Key &var : vars)
669 if (strongUpdates && var == singleton)
continue;
704 for (
const Key &var : vars)
752 if (it !=
inUpdatedVarMap.end())
return it->second.find(var) != it->second.end();
782 if (it !=
outUpdatedVarMap.end())
return it->second.find(var) != it->second.end();
803template <
typename Key,
typename KeySet,
typename Data,
typename DataSet,
typename VersionedKey,
typename VersionedKeySet>
825 const DataSet &
getPts(
const Key& vk)
override
829 const DataSet &
getPts(
const VersionedKey& vk)
override
836 assert(this->
rev &&
"PersistentVersionedPTData::getRevPts: constructed without reverse PT support!");
841 assert(this->
rev &&
"PersistentVersionedPTData::getVersionedKeyRevPts: constructed without reverse PT support!");
845 bool addPts(
const Key& k,
const Data &element)
override
849 bool addPts(
const VersionedKey& vk,
const Data &element)
override
851 return atPTData.addPts(vk, element);
854 bool unionPts(
const Key& dstVar,
const Key& srcVar)
override
856 return tlPTData.unionPts(dstVar, srcVar);
858 bool unionPts(
const VersionedKey& dstVar,
const VersionedKey& srcVar)
override
860 return atPTData.unionPts(dstVar, srcVar);
862 bool unionPts(
const VersionedKey& dstVar,
const Key& srcVar)
override
866 bool unionPts(
const Key& dstVar,
const VersionedKey& srcVar)
override
870 bool unionPts(
const Key &dstVar,
const DataSet &srcDataSet)
override
872 return tlPTData.unionPts(dstVar, srcDataSet);
874 bool unionPts(
const VersionedKey &dstVar,
const DataSet &srcDataSet)
override
876 return atPTData.unionPts(dstVar, srcDataSet);
879 void clearPts(
const Key& k,
const Data &element)
override
883 void clearPts(
const VersionedKey& vk,
const Data &element)
override
929 SVFUtil::outs() <<
"== Address-taken points-to information\n";
942 return ptd->
getPTDTY() == PTDataTy::PersVersioned;
DFPTData(bool reversePT=true, PTDataTy ty=BasePTData::DataFlow)
Constructor.
DiffPTData(bool reversePT=true, PTDataTy ty=PTDataTy::Diff)
PTData(bool reversePT=true, PTDataTy ty=PTDataTy::Base)
bool rev
Whether we maintain reverse points-to sets or not.
PTDataTy
Types of a points-to data structures.
PTDataTy getPTDTY() const
Get the type of points-to data structure that this is.
DFPTData backed by a PersistentPointsToCache.
void clearFullPts(const Key &var) override
Fully clears the points-to set of var.
Map< LocID, KeyToIDMap > DFKeyToIDMap
bool updateATVPts(const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Update address-taken variables OUT[dstLoc:dstVar] with points-to of top-level pointers.
bool hasDFInSet(LocID loc) const override
bool updateDFInFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
bool updateDFInFromOut(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Union (IN[dstLoc:dstVar], OUT[srcLoc:srcVar]).
bool updateAllDFInFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Union (IN[dstLoc::dstVar], IN[srcLoc:srcVar]. There is no flag check, unlike the above.
bool unionPts(const Key &dstKey, const DataSet &srcDataSet) override
Performs pts(dstVar) = pts(dstVar) U srcDataSet.
bool unionPtsThroughIds(PointsToID &dst, PointsToID &src)
bool unionPts(const Key &dstKey, const Key &srcKey) override
Performs pts(dstVar) = pts(dstVar) U pts(srcVar).
PersistentPTData< NodeID, NodeSet, NodeID, PointsTo > persPTData
bool hasDFOutSet(LocID loc, const Key &var) const override
PTData< Key, KeySet, Data, DataSet > BasePTData
static bool classof(const PTData< Key, KeySet, Data, DataSet > *ptd)
bool updateAllDFInFromOut(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Union (IN[dstLoc::dstVar], OUT[srcLoc:srcVar]. There is no flag check, unlike the above.
Map< DataSet, unsigned > getAllPts(bool liveOnly) const override
void clearPts(const Key &var, const Data &element) override
Clears element from the points-to set of var.
~PersistentDFPTData() override=default
void clearAllDFOutUpdatedVar(LocID) override
BaseDFPTData::LocID LocID
PersistentDFPTData(PersistentPointsToCache< DataSet > &cache, bool reversePT=true, PTDataTy ty=PTDataTy::PersDataFlow)
bool addPts(const Key &dstKey, const Data &element) override
Adds element to the points-to set associated with var.
bool updateAllDFOutFromIn(LocID loc, const Key &singleton, bool strongUpdates) override
For each variable var in IN at loc, do updateDFOutFromIn(loc, var, loc, var).
bool updateDFOutFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Union (OUT[dstLoc:dstVar], IN[srcLoc:srcVar]).
void clear() override
Clears all points-to sets as if nothing is stored.
void dumpPTData() override
Dump stored keys and points-to sets.
BasePTData::PTDataTy PTDataTy
const DataSet & getDFInPtsSet(LocID loc, const Key &var) override
const KeySet & getRevPts(const Data &) override
Get reverse points-to set of a datum.
static bool classof(const PersistentDFPTData< Key, KeySet, Data, DataSet > *)
bool hasDFInSet(LocID loc, const Key &var) const override
PointsToID & getDFInPtIdRef(LocID loc, const Key &var)
bool updateTLVPts(LocID srcLoc, const Key &srcVar, const Key &dstVar) override
Update points-to set of top-level pointers with IN[srcLoc:srcVar].
PointsToID & getDFOutPtIdRef(LocID loc, const Key &var)
const DataSet & getDFOutPtsSet(LocID loc, const Key &var) override
BasePersPTData::KeyToIDMap KeyToIDMap
void remapAllPts() override
Remaps all points-to sets to use the current mapping.
PersistentPointsToCache< PointsTo > & ptCache
bool hasDFOutSet(LocID loc) const override
DFPTData< Key, KeySet, Data, DataSet > BaseDFPTData
const DataSet & getPts(const Key &var) override
Get points-to set of var.
PersistentPTData< Key, KeySet, Data, DataSet > BasePersPTData
bool computeDiffPts(Key &var, const DataSet &all) override
PersistentPTData< NodeID, NodeSet, NodeID, PointsTo > persPTData
PersistentDiffPTData(PersistentPointsToCache< DataSet > &cache, bool reversePT=true, PTDataTy ty=PTDataTy::PersDiff)
Constructor.
Map< DataSet, unsigned > getAllPts(bool liveOnly) const override
~PersistentDiffPTData() override=default
void dumpPTData() override
Dump stored keys and points-to sets.
DiffPTData< Key, KeySet, Data, DataSet > BaseDiffPTData
PersistentPointsToCache< PointsTo > & ptCache
void clearPts(const Key &var, const Data &element) override
Clears element from the points-to set of var.
const DataSet & getPts(const Key &var) override
Get points-to set of var.
BasePersPTData::KeyToIDMap KeyToIDMap
static bool classof(const PTData< Key, KeySet, Data, DataSet > *ptd)
void clearPropaPts(Key &var) override
Clear propagated points-to set of var.
const DataSet & getDiffPts(Key &var) override
Get diff points to.
bool addPts(const Key &dstKey, const Data &element) override
Adds element to the points-to set associated with var.
BasePTData::PTDataTy PTDataTy
PTData< Key, KeySet, Data, DataSet > BasePTData
PersistentPTData< Key, KeySet, Data, DataSet > BasePersPTData
void updatePropaPtsMap(Key &src, Key &dst) override
BasePersPTData::RevPtsMap RevPtsMap
void remapAllPts() override
Remaps all points-to sets to use the current mapping.
const KeySet & getRevPts(const Data &data) override
Get reverse points-to set of a datum.
bool unionPts(const Key &dstKey, const Key &srcKey) override
Performs pts(dstVar) = pts(dstVar) U pts(srcVar).
void clear() override
Clears all points-to sets as if nothing is stored.
void clearFullPts(const Key &var) override
Fully clears the points-to set of var.
bool unionPts(const Key &dstKey, const DataSet &srcDataSet) override
Performs pts(dstVar) = pts(dstVar) U srcDataSet.
static bool classof(const PersistentDiffPTData< Key, KeySet, Data, DataSet > *)
Incremental version of the persistent data-flow points-to data structure.
UpdatedVarMap outUpdatedVarMap
UpdatedVarMap inUpdatedVarMap
const KeySet & getDFOutUpdatedVar(LocID loc)
Get all variables which have new pts info in loc's OUT set.
bool updateATVPts(const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Update address-taken variables OUT[dstLoc:dstVar] with points-to of top-level pointers.
void setVarDFInSetUpdated(LocID loc, const Key &var)
Handle address-taken variables whose IN pts changed.
bool updateTLVPts(LocID srcLoc, const Key &srcVar, const Key &dstVar) override
Update points-to set of top-level pointers with IN[srcLoc:srcVar].
BasePTData::PTDataTy PTDataTy
bool updateAllDFOutFromIn(LocID loc, const Key &singleton, bool strongUpdates) override
For each variable var in IN at loc, do updateDFOutFromIn(loc, var, loc, var).
static bool classof(const PTData< Key, KeySet, Data, DataSet > *ptd)
PersistentIncDFPTData(PersistentPointsToCache< DataSet > &cache, bool reversePT=true, PTDataTy ty=BasePTData::PersIncDataFlow)
Constructor.
bool updateAllDFInFromOut(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Union (IN[dstLoc::dstVar], OUT[srcLoc:srcVar]. There is no flag check, unlike the above.
bool varHasNewDFInPts(LocID loc, const Key &var)
Return TRUE if var has a new pts in loc's IN set.
bool updateDFInFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
static bool classof(const PersistentIncDFPTData< Key, KeySet, Data, DataSet > *)
PTData< Key, KeySet, Data, DataSet > BasePTData
BaseDFPTData::LocID LocID
const KeySet & getDFInUpdatedVar(LocID loc)
Get all variables which have new pts information in loc's IN set.
bool updateAllDFInFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Union (IN[dstLoc::dstVar], IN[srcLoc:srcVar]. There is no flag check, unlike the above.
void setVarDFOutSetUpdated(LocID loc, const Key &var)
bool updateDFOutFromIn(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Union (OUT[dstLoc:dstVar], IN[srcLoc:srcVar]).
void clearAllDFOutUpdatedVar(LocID loc) override
Map< LocID, KeySet > UpdatedVarMap
PersistentDFPTData< Key, KeySet, Data, DataSet > BasePersDFPTData
PersistentPTData< Key, KeySet, Data, DataSet > BasePersPTData
void removeVarFromDFOutUpdatedSet(LocID loc, const Key &var)
Remove var from loc's OUT updated set.
void removeVarFromDFInUpdatedSet(LocID loc, const Key &var)
Remove var from loc's IN updated set.
void clear() override
Clears all points-to sets as if nothing is stored.
~PersistentIncDFPTData() override=default
bool varHasNewDFOutPts(LocID loc, const Key &var)
Return TRUE if var has a new pts in loc's OUT set.
DFPTData< Key, KeySet, Data, DataSet > BaseDFPTData
bool updateDFInFromOut(LocID srcLoc, const Key &srcVar, LocID dstLoc, const Key &dstVar) override
Union (IN[dstLoc:dstVar], OUT[srcLoc:srcVar]).
PTData backed by a PersistentPointsToCache.
const DataSet & getPts(const Key &var) override
Get points-to set of var.
bool unionPtsFromId(const Key &dstKey, PointsToID srcId)
PersistentPointsToCache< DataSet > & ptCache
static bool classof(const PersistentPTData< Key, KeySet, Data, DataSet > *)
void clearRevPts(const DataSet &pts, const Key &k)
void clearSingleRevPts(KeySet &revSet, const Key &k)
bool addPts(const Key &dstKey, const Data &element) override
Adds element to the points-to set associated with var.
void clear() override
Clears all points-to sets as if nothing is stored.
static bool classof(const PTData< Key, KeySet, Data, DataSet > *ptd)
bool unionPts(const Key &dstKey, const Key &srcKey) override
Performs pts(dstVar) = pts(dstVar) U pts(srcVar).
Map< DataSet, unsigned > getAllPts(bool liveOnly) const override
friend class PersistentVersionedPTData
PersistentPTData(PersistentPointsToCache< DataSet > &cache, bool reversePT=true, PTDataTy ty=PTDataTy::PersBase)
Constructor.
~PersistentPTData() override=default
BasePTData::PTDataTy PTDataTy
void remapAllPts() override
Remaps all points-to sets to use the current mapping.
PTData< Key, KeySet, Data, DataSet > BasePTData
void clearPts(const Key &var, const Data &element) override
Clears element from the points-to set of var.
void dumpPTData() override
Dump stored keys and points-to sets.
bool unionPts(const Key &dstKey, const DataSet &srcData) override
Performs pts(dstVar) = pts(dstVar) U srcDataSet.
const KeySet & getRevPts(const Data &data) override
Get reverse points-to set of a datum.
Map< Key, PointsToID > KeyToIDMap
Map< Data, KeySet > RevPtsMap
void clearFullPts(const Key &var) override
Fully clears the points-to set of var.
static PointsToID emptyPointsToId(void)
void clearFullPts(const Key &k) override
Fully clears the points-to set of var.
bool unionPts(const Key &dstVar, const Key &srcVar) override
Performs pts(dstVar) = pts(dstVar) U pts(srcVar).
static bool classof(const PTData< Key, KeySet, Data, DataSet > *ptd)
PersistentPTData< VersionedKey, VersionedKeySet, Data, DataSet >::KeyToIDMap VersionedKeyToIDMap
static bool classof(const PersistentVersionedPTData< Key, KeySet, Data, DataSet, VersionedKey, VersionedKeySet > *)
PersistentPTData< NodeID, NodeSet, NodeID, PointsTo > tlPTData
const DataSet & getPts(const VersionedKey &vk) override
PersistentPTData< Key, KeySet, Data, DataSet >::KeyToIDMap KeyToIDMap
bool addPts(const VersionedKey &vk, const Data &element) override
void clearPts(const Key &k, const Data &element) override
Clears element from the points-to set of var.
const KeySet & getRevPts(const Data &data) override
Get reverse points-to set of a datum.
void remapAllPts() override
Remaps all points-to sets to use the current mapping.
PersistentVersionedPTData(PersistentPointsToCache< DataSet > &cache, bool reversePT=true, PTDataTy ty=PTDataTy::PersVersioned)
bool unionPts(const VersionedKey &dstVar, const Key &srcVar) override
BasePTData::PTDataTy PTDataTy
PersistentPTData< VersionedVar, Set< VersionedVar >, NodeID, PointsTo > atPTData
void clearPts(const VersionedKey &vk, const Data &element) override
~PersistentVersionedPTData() override=default
void clearFullPts(const VersionedKey &vk) override
const DataSet & getPts(const Key &vk) override
Get points-to set of var.
bool unionPts(const Key &dstVar, const DataSet &srcDataSet) override
Performs pts(dstVar) = pts(dstVar) U srcDataSet.
void dumpPTData() override
Dump stored keys and points-to sets.
bool unionPts(const VersionedKey &dstVar, const DataSet &srcDataSet) override
VersionedPTData< Key, KeySet, Data, DataSet, VersionedKey, VersionedKeySet > BaseVersionedPTData
bool addPts(const Key &k, const Data &element) override
Adds element to the points-to set associated with var.
PTData< Key, KeySet, Data, DataSet > BasePTData
bool unionPts(const Key &dstVar, const VersionedKey &srcVar) override
bool unionPts(const VersionedKey &dstVar, const VersionedKey &srcVar) override
const VersionedKeySet & getVersionedKeyRevPts(const Data &data) override
void clear() override
Clears all points-to sets as if nothing is stored.
Map< DataSet, unsigned > getAllPts(bool liveOnly) const override
VersionedPTData(bool reversePT=true, PTDataTy ty=PTDataTy::Versioned)
void mergePtsOccMaps(Map< Data, unsigned > &to, const Map< Data, unsigned > from)
Given a map mapping points-to sets to a count, adds from into to.
std::ostream & outs()
Overwrite llvm::outs().
void removeKey(const Key &key, KeySet &keySet)
Removes an element from a Set/CondSet (or anything implementing erase).
void insertKey(const Key &key, KeySet &keySet)
Inserts an element into a Set/CondSet (with insert).
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map