llvm.org GIT mirror llvm / ff155f0
Move the operator new and operator delete out of line. This fixes an issue with operator new() referring to the static initTags function, which has to be in the same linkage unit as any file including User.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51136 91177308-0d34-0410-b5e6-96231b3b80d8 Nate Begeman 12 years ago
2 changed file(s) with 21 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
226226 ///
227227 unsigned NumOperands;
228228
229 void *operator new(size_t s, unsigned Us) {
230 void *Storage = ::operator new(s + sizeof(Use) * Us);
231 Use *Start = static_cast(Storage);
232 Use *End = Start + Us;
233 User *Obj = reinterpret_cast(End);
234 Obj->OperandList = Start;
235 Obj->NumOperands = Us;
236 Use::initTags(Start, End);
237 return Obj;
238 }
229 void *operator new(size_t s, unsigned Us);
239230 User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps)
240231 : Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {}
241232 Use *allocHungoffUses(unsigned) const;
250241 ~User() {
251242 Use::zap(OperandList, OperandList + NumOperands);
252243 }
253 void operator delete(void *Usr) {
254 User *Start = static_cast(Usr);
255 Use *Storage = static_cast(Usr) - Start->NumOperands;
256 ::operator delete(Storage == Start->OperandList
257 ? Storage
258 : Usr);
259 }
244 void operator delete(void *Usr);
260245 template Use &Op() {
261246 return OperandTraits::op_begin(this)[Idx];
262247 }
354354 setOperand(i, To); // Fix it now...
355355 }
356356 }
357
358 void *User::operator new(size_t s, unsigned Us) {
359 void *Storage = ::operator new(s + sizeof(Use) * Us);
360 Use *Start = static_cast(Storage);
361 Use *End = Start + Us;
362 User *Obj = reinterpret_cast(End);
363 Obj->OperandList = Start;
364 Obj->NumOperands = Us;
365 Use::initTags(Start, End);
366 return Obj;
367 }
368
369 void User::operator delete(void *Usr) {
370 User *Start = static_cast(Usr);
371 Use *Storage = static_cast(Usr) - Start->NumOperands;
372 ::operator delete(Storage == Start->OperandList
373 ? Storage
374 : Usr);
375 }