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.

llvm-svn: 239622
diff --git a/llvm/lib/IR/User.cpp b/llvm/lib/IR/User.cpp
index 1084a50..5ccf00e 100644
--- a/llvm/lib/IR/User.cpp
+++ b/llvm/lib/IR/User.cpp
@@ -41,6 +41,7 @@
 //===----------------------------------------------------------------------===//
 
 void User::allocHungoffUses(unsigned N, bool IsPhi) {
+  assert(HasHungOffUses && "alloc must have hung off uses");
   // Allocate the array of Uses, followed by a pointer (with bottom bit set) to
   // the User.
   size_t size = N * sizeof(Use) + sizeof(Use::UserRef);
@@ -50,8 +51,6 @@
   Use *End = Begin + N;
   (void) new(End) Use::UserRef(const_cast<User*>(this), 1);
   setOperandList(Use::initTags(Begin, End));
-  // Tag this operand list as being a hung off.
-  HasHungOffUses = true;
 }
 
 void User::growHungoffUses(unsigned NewNumUses, bool IsPhi) {
@@ -85,9 +84,9 @@
 //                         User operator new Implementations
 //===----------------------------------------------------------------------===//
 
-void *User::operator new(size_t s, unsigned Us) {
+void *User::operator new(size_t Size, unsigned Us) {
   assert(Us < (1u << NumUserOperandsBits) && "Too many operands");
-  void *Storage = ::operator new(s + sizeof(Use) * Us);
+  void *Storage = ::operator new(Size + sizeof(Use) * Us);
   Use *Start = static_cast<Use*>(Storage);
   Use *End = Start + Us;
   User *Obj = reinterpret_cast<User*>(End);
@@ -98,6 +97,15 @@
   return Obj;
 }
 
+void *User::operator new(size_t Size) {
+  void *Storage = ::operator new(Size);
+  User *Obj = reinterpret_cast<User*>(Storage);
+  Obj->setOperandList(nullptr);
+  Obj->HasHungOffUses = true;
+  Obj->NumUserOperands = 0;
+  return Obj;
+}
+
 //===----------------------------------------------------------------------===//
 //                         User operator delete Implementation
 //===----------------------------------------------------------------------===//