llvm.org GIT mirror llvm / 247fdca
Reverted patch 44199: http://llvm.org/viewvc/llvm-project?rev=44199&view=rev This patch completely broke serialization due to an invariant I assumed but did not hold. The assumed invariant was that all pointer IDs emitted by a call to BatchEmitOwnedPtrs would be consecutive. This is only the case if there has been no forward references to an owned pointer (and hence already registered with the Serializer object). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44203 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 12 years ago
2 changed file(s) with 59 addition(s) and 125 deletion(s). Raw diff Collapse all Expand all
136136
137137 uint64_t ReadInt();
138138 int64_t ReadSInt();
139
140139 SerializedPtrID ReadPtrID() { return (SerializedPtrID) ReadInt(); }
141
142 SerializedPtrID ReadDiffPtrID(SerializedPtrID& PrevID) {
143 bool x = ReadBool();
144 return (SerializedPtrID) (x ? (PrevID+1) : 0);
145 }
146140
147141
148142 bool ReadBool() {
188182 bool A1=true, bool A2=true) {
189183
190184 SerializedPtrID ID1 = ReadPtrID();
191 SerializedPtrID ID2 = ReadDiffPtrID(ID2);
185 SerializedPtrID ID2 = ReadPtrID();
192186
193187 P1 = (ID1) ? SerializeTrait::Create(*this) : NULL;
194188 if (ID1 && A1) RegisterPtr(ID1,P1);
202196 bool A1=true, bool A2=true, bool A3=true) {
203197
204198 SerializedPtrID ID1 = ReadPtrID();
205 SerializedPtrID ID2 = ReadDiffPtrID(ID1);
206 SerializedPtrID ID3 = ReadDiffPtrID(ID2);
199 SerializedPtrID ID2 = ReadPtrID();
200 SerializedPtrID ID3 = ReadPtrID();
207201
208202 P1 = (ID1) ? SerializeTrait::Create(*this) : NULL;
209203 if (ID1 && A1) RegisterPtr(ID1,P1);
215209 if (ID3 && A3) RegisterPtr(ID3,P3);
216210 }
217211
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);
238 }
239
240212 template
241213 void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, bool AutoRegister=true) {
242214 llvm::SmallVector BatchIDVec;
243 SerializedPtrID TempPtrID;
244
245 for (unsigned i = 0; i < NumPtrs; ++i) {
246 TempPtrID = i ? ReadDiffPtrID(TempPtrID) : ReadPtrID();
247 BatchIDVec.push_back(TempPtrID);
248 }
215
216 for (unsigned i = 0; i < NumPtrs; ++i)
217 BatchIDVec.push_back(ReadPtrID());
249218
250219 for (unsigned i = 0; i < NumPtrs; ++i) {
251220 SerializedPtrID& PtrID = BatchIDVec[i];
262231 template
263232 void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2,
264233 bool A1=true, bool A2=true) {
265
234
235 llvm::SmallVector BatchIDVec;
236
237 for (unsigned i = 0; i < NumT1Ptrs; ++i)
238 BatchIDVec.push_back(ReadPtrID());
239
266240 SerializedPtrID ID2 = ReadPtrID();
267 SerializedPtrID TempID = ID2;
268
269 llvm::SmallVector BatchIDVec;
270241
271242 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
272 TempID = ReadDiffPtrID(TempID);
273 BatchIDVec.push_back(TempID);
243 SerializedPtrID& PtrID = BatchIDVec[i];
244
245 T1* p = PtrID ? SerializeTrait::Create(*this) : NULL;
246
247 if (PtrID && A1)
248 RegisterPtr(PtrID,p);
249
250 Ptrs[i] = p;
274251 }
275252
276253 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
277254 if (ID2 && A2) RegisterPtr(ID2,P2);
278
279 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
280 SerializedPtrID& PtrID = BatchIDVec[i];
281
282 T1* p = PtrID ? SerializeTrait::Create(*this) : NULL;
283
284 if (PtrID && A1)
285 RegisterPtr(PtrID,p);
286
287 Ptrs[i] = p;
288 }
289255 }
290256
291257 template
292258 void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs,
293259 T2*& P2, T3*& P3,
294260 bool A1=true, bool A2=true, bool A3=true) {
295
261
262 llvm::SmallVector BatchIDVec;
263
264 for (unsigned i = 0; i < NumT1Ptrs; ++i)
265 BatchIDVec.push_back(ReadPtrID());
266
296267 SerializedPtrID ID2 = ReadPtrID();
297 SerializedPtrID ID3 = ReadDiffPtrID(ID2);
298
299 SerializedPtrID TempID = ID3;
300
301 llvm::SmallVector BatchIDVec;
268 SerializedPtrID ID3 = ReadPtrID();
302269
303270 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
304 TempID = ReadDiffPtrID(TempID);
305 BatchIDVec.push_back(TempID);
271 SerializedPtrID& PtrID = BatchIDVec[i];
272
273 T1* p = PtrID ? SerializeTrait::Create(*this) : NULL;
274
275 if (PtrID && A1)
276 RegisterPtr(PtrID,p);
277
278 Ptrs[i] = p;
306279 }
307280
308281 P2 = (ID2) ? SerializeTrait::Create(*this) : NULL;
309282 if (ID2 && A2) RegisterPtr(ID2,P2);
310283
311284 P3 = (ID3) ? SerializeTrait::Create(*this) : NULL;
312 if (ID3 && A3) RegisterPtr(ID3,P3);
313
314 for (unsigned i = 0; i < NumT1Ptrs; ++i) {
315 SerializedPtrID& PtrID = BatchIDVec[i];
316
317 T1* p = PtrID ? SerializeTrait::Create(*this) : NULL;
318
319 if (PtrID && A1)
320 RegisterPtr(PtrID,p);
321
322 Ptrs[i] = p;
323 }
285 if (ID3 && A3) RegisterPtr(ID3,P3);
324286 }
325287
326288 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 EmitBool(false);
60 else {
61 assert (ptr_id > PrevID);
62 assert (PrevID == 0 || ptr_id - PrevID == 1);
63 EmitBool(true);
64 }
65
66 return ptr_id;
67 }
68
6947
7048 template
7149 void EmitRef(const T& ref) { EmitPtr(&ref); }
7856
7957 template
8058 void BatchEmitOwnedPtrs(T1* p1, T2* p2) {
81 // Optimization: Only emit the differences between the IDs. Most of
82 // the time this difference will be "1", thus resulting in fewer bits.
83 assert (!isRegistered(p1));
84 assert (!isRegistered(p2));
85
86 EmitDiffPtrID(p2,EmitPtr(p1,true));
87
59 EmitPtr(p1);
60 EmitPtr(p2);
8861 if (p1) SerializeTrait::Emit(*this,*p1);
8962 if (p2) SerializeTrait::Emit(*this,*p2);
9063 }
9164
9265 template
9366 void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3) {
94 EmitDiffPtrID(p3,EmitDiffPtrID(p2,EmitPtr(p1)));
95
67 EmitPtr(p1);
68 EmitPtr(p2);
69 EmitPtr(p3);
9670 if (p1) SerializeTrait::Emit(*this,*p1);
9771 if (p2) SerializeTrait::Emit(*this,*p2);
9872 if (p3) SerializeTrait::Emit(*this,*p3);
10074
10175 template
10276 void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3, T4& p4) {
103 EmitDiffPtrID(p4,EmitDiffPtrID(p3,EmitDiffPtrID(p2,EmitPtr(p1))));
104
77 EmitPtr(p1);
78 EmitPtr(p2);
79 EmitPtr(p3);
80 EmitPtr(p4);
10581 if (p1) SerializeTrait::Emit(*this,*p1);
10682 if (p2) SerializeTrait::Emit(*this,*p2);
10783 if (p3) SerializeTrait::Emit(*this,*p3);
11086
11187 template
11288 void BatchEmitOwnedPtrs(unsigned NumPtrs, T* const * Ptrs) {
113 SerializedPtrID ID;
114
115 for (unsigned i = 0; i < NumPtrs; ++i) {
116 if (i == 0) ID = EmitPtr(Ptrs[i],true);
117 else ID = EmitDiffPtrID(Ptrs[i],ID);
118 }
89 for (unsigned i = 0; i < NumPtrs; ++i)
90 EmitPtr(Ptrs[i]);
11991
12092 for (unsigned i = 0; i < NumPtrs; ++i)
12193 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
12496 template
12597 void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, T2* p2) {
12698
127 SerializedPtrID ID = EmitPtr(p2,true);
128
12999 for (unsigned i = 0; i < NumT1Ptrs; ++i)
130 ID = EmitDiffPtrID(Ptrs[i],ID);
100 EmitPtr(Ptrs[i]);
101
102 EmitPtr(p2);
103
104 for (unsigned i = 0; i < NumT1Ptrs; ++i)
105 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
131106
132107 if (p2) SerializeTrait::Emit(*this,*p2);
133
134 for (unsigned i = 0; i < NumT1Ptrs; ++i)
135 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
136108 }
137109
138110 template
139111 void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs,
140112 T2* p2, T3* p3) {
141113
142 SerializedPtrID TempID = EmitDiffPtrID(p3,EmitPtr(p2,true));
114 for (unsigned i = 0; i < NumT1Ptrs; ++i)
115 EmitPtr(Ptrs[i]);
143116
144 for (unsigned i = 0; i < NumT1Ptrs; ++i)
145 TempID = EmitDiffPtrID(Ptrs[i],TempID);
146
147 if (p2) SerializeTrait::Emit(*this,*p2);
148 if (p3) SerializeTrait::Emit(*this,*p3);
117 EmitPtr(p2);
118 EmitPtr(p3);
149119
150120 for (unsigned i = 0; i < NumT1Ptrs; ++i)
151121 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
152122
123 if (p2) SerializeTrait::Emit(*this,*p2);
124 if (p3) SerializeTrait::Emit(*this,*p3);
153125 }
154126
155127 bool isRegistered(const void* p) const;