llvm.org GIT mirror llvm / 04ab82a
Implemented optimization for BatchEmitOwnedPtrs that we only emit one complete SerializedPtrID, followed by the *differences* in IDs. The big idea is that most IDs will be just be 1 off from the previous (either that or NULL, which we encode as a difference if 0), so this will greatly reduce the encoding space for extra IDs to just 1 bit per pointer. So far this optimization reduces serialization of Carbon.h by only 1%, but we aren't using any abbreviations now in the Bitcode file to properly take advantage of this optimization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44199 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 12 years ago
2 changed file(s) with 114 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
136136
137137 uint64_t ReadInt();
138138 int64_t ReadSInt();
139
139140 SerializedPtrID ReadPtrID() { return (SerializedPtrID) ReadInt(); }
141
142 SerializedPtrID ReadDiffPtrID(SerializedPtrID& PrevID) {
143 unsigned x = ReadInt();
144 return (SerializedPtrID) (x ? (PrevID+x) : 0);
145 }
140146
141147
142148 bool ReadBool() {
182188 bool A1=true, bool A2=true) {
183189
184190 SerializedPtrID ID1 = ReadPtrID();
185 SerializedPtrID ID2 = ReadPtrID();
191 SerializedPtrID ID2 = ReadDiffPtrID(ID2);
186192
187193 P1 = (ID1) ? SerializeTrait::Create(*this) : NULL;
188194 if (ID1 && A1) RegisterPtr(ID1,P1);
196202 bool A1=true, bool A2=true, bool A3=true) {
197203
198204 SerializedPtrID ID1 = ReadPtrID();
199 SerializedPtrID ID2 = ReadPtrID();
200 SerializedPtrID ID3 = ReadPtrID();
205 SerializedPtrID ID2 = ReadDiffPtrID(ID1);
206 SerializedPtrID ID3 = ReadDiffPtrID(ID2);
201207
202208 P1 = (ID1) ? SerializeTrait::Create(*this) : NULL;
203209 if (ID1 && A1) RegisterPtr(ID1,P1);
205211 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
206212 if (ID2 && A2) RegisterPtr(ID2,P2);
207213
208 P3 = (ID3) ? SerializeTrait2>::Create(*this) : NULL;
214 P3 = (ID3) ? SerializeTrait3>::Create(*this) : NULL;
209215 if (ID3 && A3) RegisterPtr(ID3,P3);
216 }
217
218 template
219 void BatchReadOwnedPtrs(T1*& P1, T2*& P2, T3*& P3, T4*& P4,
220 bool A1=true, bool A2=true, bool A3=true, bool A4=true) {
221
222 SerializedPtrID ID1 = ReadPtrID();
223 SerializedPtrID ID2 = ReadDiffPtrID(ID1);
224 SerializedPtrID ID3 = ReadDiffPtrID(ID2);
225 SerializedPtrID ID4 = ReadDiffPtrID(ID3);
226
227 P1 = (ID1) ? SerializeTrait::Create(*this) : NULL;
228 if (ID1 && A1) RegisterPtr(ID1,P1);
229
230 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
231 if (ID2 && A2) RegisterPtr(ID2,P2);
232
233 P3 = (ID3) ? SerializeTrait::Create(*this) : NULL;
234 if (ID3 && A3) RegisterPtr(ID3,P3);
235
236 P4 = (ID4) ? SerializeTrait::Create(*this) : NULL;
237 if (ID4 && A4) RegisterPtr(ID4,P4);
210238 }
211239
212240 template
213241 void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, bool AutoRegister=true) {
214242 llvm::SmallVector BatchIDVec;
215
216 for (unsigned i = 0; i < NumPtrs; ++i)
217 BatchIDVec.push_back(ReadPtrID());
243 SerializedPtrID TempPtrID;
244
245 for (unsigned i = 0; i < NumPtrs; ++i) {
246 TempPtrID = i ? ReadDiffPtrID(TempPtrID) : ReadPtrID();
247 BatchIDVec.push_back(TempPtrID);
248 }
218249
219250 for (unsigned i = 0; i < NumPtrs; ++i) {
220251 SerializedPtrID& PtrID = BatchIDVec[i];
231262 template
232263 void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2,
233264 bool A1=true, bool A2=true) {
234
265
266 SerializedPtrID ID2 = ReadPtrID();
267 SerializedPtrID TempID = ID2;
268
235269 llvm::SmallVector BatchIDVec;
236
237 for (unsigned i = 0; i < NumT1Ptrs; ++i)
238 BatchIDVec.push_back(ReadPtrID());
239
240 SerializedPtrID ID2 = ReadPtrID();
270
271 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
272 TempID = ReadDiffPtrID(TempID);
273 BatchIDVec.push_back(TempID);
274 }
275
276 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
277 if (ID2 && A2) RegisterPtr(ID2,P2);
241278
242279 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
243280 SerializedPtrID& PtrID = BatchIDVec[i];
248285 RegisterPtr(PtrID,p);
249286
250287 Ptrs[i] = p;
251 }
252
253 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
254 if (ID2 && A2) RegisterPtr(ID2,P2);
288 }
255289 }
256290
257291 template
258292 void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs,
259293 T2*& P2, T3*& P3,
260294 bool A1=true, bool A2=true, bool A3=true) {
295
296 SerializedPtrID ID2 = ReadPtrID();
297 SerializedPtrID ID3 = ReadDiffPtrID(ID2);
298
299 SerializedPtrID TempID = ID3;
261300
262301 llvm::SmallVector BatchIDVec;
263302
264 for (unsigned i = 0; i < NumT1Ptrs; ++i)
265 BatchIDVec.push_back(ReadPtrID());
266
267 SerializedPtrID ID2 = ReadPtrID();
268 SerializedPtrID ID3 = ReadPtrID();
303 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
304 TempID = ReadDiffPtrID(TempID);
305 BatchIDVec.push_back(TempID);
306 }
307
308 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
309 if (ID2 && A2) RegisterPtr(ID2,P2);
310
311 P3 = (ID3) ? SerializeTrait::Create(*this) : NULL;
312 if (ID3 && A3) RegisterPtr(ID3,P3);
269313
270314 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
271315 SerializedPtrID& PtrID = BatchIDVec[i];
277321
278322 Ptrs[i] = p;
279323 }
280
281 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
282 if (ID2 && A2) RegisterPtr(ID2,P2);
283
284 P3 = (ID3) ? SerializeTrait::Create(*this) : NULL;
285 if (ID3 && A3) RegisterPtr(ID3,P3);
286324 }
287325
288326 template
4444 void EmitCStr(const char* cstr);
4545
4646 void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
47
48 SerializedPtrID EmitPtr(const void* ptr,bool) {
49 SerializedPtrID ptr_id = getPtrId(ptr);
50 EmitInt(ptr_id);
51 return ptr_id;
52 }
53
54 SerializedPtrID EmitDiffPtrID(const void* ptr, SerializedPtrID PrevID) {
55 assert (!isRegistered(ptr));
56 SerializedPtrID ptr_id = getPtrId(ptr);
57
58 if (ptr_id == 0)
59 EmitInt(0);
60 else {
61 assert (ptr_id > PrevID);
62 EmitInt(ptr_id-PrevID);
63 }
64
65 return ptr_id;
66 }
67
4768
4869 template
4970 void EmitRef(const T& ref) { EmitPtr(&ref); }
5677
5778 template
5879 void BatchEmitOwnedPtrs(T1* p1, T2* p2) {
59 EmitPtr(p1);
60 EmitPtr(p2);
80 // Optimization: Only emit the differences between the IDs. Most of
81 // the time this difference will be "1", thus resulting in fewer bits.
82 assert (!isRegistered(p1));
83 assert (!isRegistered(p2));
84
85 EmitDiffPtrID(p2,EmitPtr(p1,true));
86
6187 if (p1) SerializeTrait::Emit(*this,*p1);
6288 if (p2) SerializeTrait::Emit(*this,*p2);
6389 }
6490
6591 template
6692 void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3) {
67 EmitPtr(p1);
68 EmitPtr(p2);
69 EmitPtr(p3);
93 EmitDiffPtrID(p3,EmitDiffPtrID(p2,EmitPtr(p1)));
94
7095 if (p1) SerializeTrait::Emit(*this,*p1);
7196 if (p2) SerializeTrait::Emit(*this,*p2);
7297 if (p3) SerializeTrait::Emit(*this,*p3);
7499
75100 template
76101 void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3, T4& p4) {
77 EmitPtr(p1);
78 EmitPtr(p2);
79 EmitPtr(p3);
80 EmitPtr(p4);
102 EmitDiffPtrID(p4,EmitDiffPtrID(p3,EmitDiffPtrID(p2,EmitPtr(p1))));
103
81104 if (p1) SerializeTrait::Emit(*this,*p1);
82105 if (p2) SerializeTrait::Emit(*this,*p2);
83106 if (p3) SerializeTrait::Emit(*this,*p3);
86109
87110 template
88111 void BatchEmitOwnedPtrs(unsigned NumPtrs, T* const * Ptrs) {
89 for (unsigned i = 0; i < NumPtrs; ++i)
90 EmitPtr(Ptrs[i]);
112 SerializedPtrID ID;
113
114 for (unsigned i = 0; i < NumPtrs; ++i) {
115 if (i == 0) ID = EmitPtr(Ptrs[i],true);
116 else ID = EmitDiffPtrID(Ptrs[i],ID);
117 }
91118
92119 for (unsigned i = 0; i < NumPtrs; ++i)
93120 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
96123 template
97124 void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, T2* p2) {
98125
126 SerializedPtrID ID = EmitPtr(p2,true);
127
99128 for (unsigned i = 0; i < NumT1Ptrs; ++i)
100 EmitPtr(Ptrs[i]);
129 ID = EmitDiffPtrID(Ptrs[i],ID);
101130
102 EmitPtr(p2);
131 if (p2) SerializeTrait::Emit(*this,*p2);
103132
104133 for (unsigned i = 0; i < NumT1Ptrs; ++i)
105 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
106
107 if (p2) SerializeTrait::Emit(*this,*p2);
134 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
108135 }
109136
110137 template
111138 void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs,
112139 T2* p2, T3* p3) {
113140
141 SerializedPtrID TempID = EmitDiffPtrID(p3,EmitPtr(p2,true));
142
114143 for (unsigned i = 0; i < NumT1Ptrs; ++i)
115 EmitPtr(Ptrs[i]);
144 TempID = EmitDiffPtrID(Ptrs[i],TempID);
116145
117 EmitPtr(p2);
118 EmitPtr(p3);
146 if (p2) SerializeTrait::Emit(*this,*p2);
147 if (p3) SerializeTrait::Emit(*this,*p3);
119148
120149 for (unsigned i = 0; i < NumT1Ptrs; ++i)
121150 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
122151
123 if (p2) SerializeTrait::Emit(*this,*p2);
124 if (p3) SerializeTrait::Emit(*this,*p3);
125152 }
126153
127154 bool isRegistered(const void* p) const;