-
Notifications
You must be signed in to change notification settings - Fork 2
/
PointsTo.cpp
145 lines (130 loc) · 3.45 KB
/
PointsTo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "PointsTo.h"
#include "Utils.h"
#include <boost/range.hpp>
#define MEM_SSA true
using namespace llvm;
using namespace std;
ObjPto::ObjPto(ObjId srcObjId, offset_t srcOffset, ObjId dstObjId, offset_t dstOffset, InstLoc instLoc) : srcObjId(srcObjId), srcOffset(srcOffset), dstObjId(dstObjId), dstOffset(dstOffset), instLoc(instLoc)
{
}
bool ObjPto::operator<(const ObjPto &rhs) const
{
if (this->srcObjId != rhs.srcObjId)
{
return this->srcObjId < rhs.srcObjId;
}
else if (this->srcOffset != rhs.srcOffset)
{
return this->srcOffset < rhs.srcOffset;
}
else if (this->dstObjId != rhs.dstObjId)
{
return this->dstObjId < rhs.dstObjId;
}
else if (this->dstOffset != rhs.dstOffset)
{
return this->dstOffset < rhs.dstOffset;
}
return false;
}
set<ObjLoc> PointsToRecords::getPteesOfValPtr(Context context, Value *pointer)
{
auto &tmp = this->valueData[context];
if (tmp.find(pointer) != tmp.end())
{
return tmp.at(pointer);
}
else
{
return set<ObjLoc>();
}
}
void PointsToRecords::addPteesForValPtr(Context context, Value *pointer, set<ObjLoc> pointees)
{
if (pointees.empty())
{
return;
}
this->valueData[context][pointer].insert(pointees.begin(), pointees.end());
}
string PointsToRecords::toString()
{
string res;
res += "StackPtoRecords(\n";
for (auto &itCtx : this->valueData)
{
res += "context(";
res += itCtx.first.toString();
res += "\n";
for (auto &itVal : itCtx.second)
{
res += getName(itVal.first);
res += " -> [";
for (auto &itObjLoc : itVal.second)
{
res += "(";
res += ObjectManager::toString(itObjLoc.objId);
res += ", ";
res += to_string(itObjLoc.offset);
res += "), ";
}
res += "]\n";
}
res += ")\n";
}
res += ")\n";
res += "ObjPtoRecords(\n";
for (auto &objPto : this->objPtos)
{
res += "(";
res += ObjectManager::toString(objPto.srcObjId);
res += ", ";
res += to_string(objPto.srcOffset);
res += ") -> (";
res += "(";
res += ObjectManager::toString(objPto.dstObjId);
res += ", ";
res += to_string(objPto.dstOffset);
res += ")\n";
}
res += ")";
return res;
}
set<ObjLoc> PointsToRecords::getPteesOfObjPtr(ObjLoc pointer, InstLoc currLoc)
{
set<ObjLoc> res;
auto &srcView = this->objPtos.get<0>();
for (auto &objPto : boost::make_iterator_range(srcView.equal_range(boost::make_tuple(pointer.objId, pointer.offset))))
{
#if MEM_SSA
if (isReachable(objPto.instLoc, currLoc))
{
#endif
res.insert(ObjLoc(objPto.dstObjId, objPto.dstOffset));
#if MEM_SSA
}
#endif
}
return res;
}
void PointsToRecords::addPteesForObjPtr(ObjLoc pointer, set<ObjLoc> pointees, InstLoc updateLoc)
{
if (pointees.empty())
{
return;
}
for (auto &pointee : pointees)
{
this->objPtos.insert(ObjPto(pointer.objId, pointer.offset, pointee.objId, pointee.offset, updateLoc));
}
}
set<ObjPto> PointsToRecords::getRecordsOfObj(ObjId objId)
{
set<ObjPto> res;
auto &srcView = this->objPtos.get<0>();
for (auto &objPto : boost::make_iterator_range(srcView.equal_range(objId)))
{
res.insert(objPto);
}
return res;
}