14 #ifndef PERSISTENT_POINTS_TO_H_
15 #define PERSISTENT_POINTS_TO_H_
31 template <
typename Data>
36 typedef std::function<Data(
const Data &,
const Data &)>
DataOp;
48 idToPts.push_back(std::make_unique<Data>());
72 idToPts.push_back(std::make_unique<Data>());
82 for (
auto &d :
idToPts) d->checkAndRemap();
94 typename PTSToIDMap::const_iterator foundId =
ptsToId.find(pts);
95 if (foundId !=
ptsToId.end())
return foundId->second;
99 idToPts.push_back(std::make_unique<Data>(pts));
109 assert(
idToPts.size() >
id &&
"PPTC::getActualPts: points-to set not stored!");
116 static const DataOp unionOp = [](
const Data &lhs,
const Data &rhs)
124 std::pair<PointsToID, PointsToID> operands = std::minmax(lhs, rhs);
131 return operands.second;
135 if (operands.first == operands.second)
138 return operands.first;
141 bool opPerformed =
false;
154 unionCache[std::minmax(lhs, result)] = result;
162 unionCache[std::minmax(rhs, result)] = result;
175 static const DataOp complementOp = [](
const Data &lhs,
const Data &rhs)
204 bool opPerformed =
false;
238 static const DataOp intersectionOp = [](
const Data &lhs,
const Data &rhs)
246 std::pair<PointsToID, PointsToID> operands = std::minmax(lhs, rhs);
257 if (operands.first == operands.second)
260 return operands.first;
263 bool opPerformed =
false;
315 static const unsigned fieldWidth = 25;
348 for (
const auto &d :
idToPts) allPts[*d] = 1;
366 bool commutative,
bool &opPerformed)
368 std::pair<PointsToID, PointsToID> operands;
371 if (commutative) operands = std::minmax(lhs, rhs);
372 else operands = std::make_pair(lhs, rhs);
375 OpCache::const_iterator foundResult = opCache.find(operands);
376 if (foundResult != opCache.end())
return foundResult->second;
383 Data result = dataOp(lhsPts, rhsPts);
387 typename PTSToIDMap::const_iterator foundId =
ptsToId.find(result);
388 if (foundId !=
ptsToId.end()) resultId = foundId->second;
392 idToPts.push_back(std::make_unique<Data>(result));
397 opCache[operands] = resultId;
u64_t lookupIntersections
PointsToID unionPts(PointsToID lhs, PointsToID rhs)
Unions lhs and rhs and returns their union's ID.
PointsToID intersectPts(PointsToID lhs, PointsToID rhs)
Intersects lhs and rhs (lhs AND rhs) and returns the intersection's ID.
std::vector< std::unique_ptr< Data > > idToPts
u64_t uniqueIntersections
u64_t propertyIntersections
OpCache intersectionCache
Maps two IDs to their intersection. Keys must be sorted.
PointsToID newPointsToId(void)
std::function< Data(const Data &, const Data &)> DataOp
PTSToIDMap ptsToId
Maps points-to sets to their corresponding ID.
OpCache unionCache
Maps two IDs to their union. Keys must be sorted.
u64_t propertyComplements
void printStats(const std::string subtitle) const
Print statistics on operations and points-to set numbers.
PointsToID complementPts(PointsToID lhs, PointsToID rhs)
Relatively complements lhs and rhs (lhs \ rhs) and returns it's ID.
Map< std::pair< PointsToID, PointsToID >, PointsToID > OpCache
void remapAllPts(void)
Remaps all points-to sets stored in the cache to the current mapping.
static PointsToID emptyPointsToId(void)
PointsToID emplacePts(const Data &pts)
Map< Data, PointsToID > PTSToIDMap
void initStats(void)
Initialises statistics variables to 0.
const Data & getActualPts(PointsToID id) const
Returns the points-to set which id represents. id must be stored in the cache.
Map< Data, unsigned > getAllPts(void)
PointsToID opPts(PointsToID lhs, PointsToID rhs, const DataOp &dataOp, OpCache &opCache, bool commutative, bool &opPerformed)
PersistentPointsToCache(void)
PointsToID idCounter
Used to generate new PointsToIDs. Any non-zero is valid.
u64_t preemptiveComplements
OpCache complementCache
Maps two IDs to their relative complement.
u64_t preemptiveIntersections
void clear()
Clear the cache.
void reset(void)
Resets the cache removing everything except the emptyData it was initialised with.
std::ostream & outs()
Overwrite llvm::outs()
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map