llvm.org GIT mirror llvm / 8b351e4
Added a version of User::new for hung off uses. There are now 2 versions of User::new. The first takes a size_t and is the current implementation for subclasses which need 0 or more Use's allocated for their operands. The new version takes no extra arguments to say that this subclass needs 'hung off uses'. The HungOffUses bool is now set in this version of User::new and we can assert in allocHungOffUses that we are allowed to have hung off uses. This ensures we call the correct version of User::new for subclasses which need hung off uses. A future commit will then allocate space for a single Use* which will be used in place of User::OperandList once that field has been removed. Reviewed by Duncan Exon Smith. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239622 91177308-0d34-0410-b5e6-96231b3b80d8 Pete Cooper 4 years ago
3 changed file(s) with 26 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
22252225 PHINode(const PHINode &PN);
22262226 // allocate space for exactly zero operands
22272227 void *operator new(size_t s) {
2228 return User::operator new(s, 0);
2228 return User::operator new(s);
22292229 }
22302230 explicit PHINode(Type *Ty, unsigned NumReservedValues,
22312231 const Twine &NameStr = "",
24332433 void *operator new(size_t, unsigned) = delete;
24342434 // Allocate space for exactly zero operands.
24352435 void *operator new(size_t s) {
2436 return User::operator new(s, 0);
2436 return User::operator new(s);
24372437 }
24382438 void growOperands(unsigned Size);
24392439 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
27072707 void growOperands();
27082708 // allocate space for exactly zero operands
27092709 void *operator new(size_t s) {
2710 return User::operator new(s, 0);
2710 return User::operator new(s);
27112711 }
27122712 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
27132713 /// switch on and a default destination. The number of additional cases can
30143014 void growOperands();
30153015 // allocate space for exactly zero operands
30163016 void *operator new(size_t s) {
3017 return User::operator new(s, 0);
3017 return User::operator new(s);
30183018 }
30193019 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
30203020 /// Address to jump to. The number of expected destinations can be specified
3333
3434 class User : public Value {
3535 User(const User &) = delete;
36 void *operator new(size_t) = delete;
3736 template
3837 friend struct HungoffOperandTraits;
3938 virtual void anchor();
4746 Use *LegacyOperandList;
4847
4948 protected:
50 void *operator new(size_t s, unsigned Us);
49 /// Allocate a User with an operand pointer co-allocated.
50 ///
51 /// This is used for subclasses which need to allocate a variable number
52 /// of operands, ie, 'hung off uses'.
53 void *operator new(size_t Size);
54
55 /// Allocate a User with the operands co-allocated.
56 ///
57 /// This is used for subclasses which have a fixed number of operands.
58 void *operator new(size_t Size, unsigned Us);
5159
5260 User(Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
5361 : Value(ty, vty) {
4040 //===----------------------------------------------------------------------===//
4141
4242 void User::allocHungoffUses(unsigned N, bool IsPhi) {
43 assert(HasHungOffUses && "alloc must have hung off uses");
4344 // Allocate the array of Uses, followed by a pointer (with bottom bit set) to
4445 // the User.
4546 size_t size = N * sizeof(Use) + sizeof(Use::UserRef);
4950 Use *End = Begin + N;
5051 (void) new(End) Use::UserRef(const_cast(this), 1);
5152 setOperandList(Use::initTags(Begin, End));
52 // Tag this operand list as being a hung off.
53 HasHungOffUses = true;
5453 }
5554
5655 void User::growHungoffUses(unsigned NewNumUses, bool IsPhi) {
8483 // User operator new Implementations
8584 //===----------------------------------------------------------------------===//
8685
87 void *User::operator new(size_t s, unsigned Us) {
86 void *User::operator new(size_t Size, unsigned Us) {
8887 assert(Us < (1u << NumUserOperandsBits) && "Too many operands");
89 void *Storage = ::operator new(s + sizeof(Use) * Us);
88 void *Storage = ::operator new(Size + sizeof(Use) * Us);
9089 Use *Start = static_cast(Storage);
9190 Use *End = Start + Us;
9291 User *Obj = reinterpret_cast(End);
9493 Obj->HasHungOffUses = false;
9594 Obj->NumUserOperands = Us;
9695 Use::initTags(Start, End);
96 return Obj;
97 }
98
99 void *User::operator new(size_t Size) {
100 void *Storage = ::operator new(Size);
101 User *Obj = reinterpret_cast(Storage);
102 Obj->setOperandList(nullptr);
103 Obj->HasHungOffUses = true;
104 Obj->NumUserOperands = 0;
97105 return Obj;
98106 }
99107