clang side to match the LLVM IR type system rewrite patch.

llvm-svn: 134831
diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 6daf2ea..2b07baf 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -35,7 +35,7 @@
 public:
   /// FieldTypes - Holds the LLVM types that the struct is created from.
   /// 
-  llvm::SmallVector<const llvm::Type *, 16> FieldTypes;
+  llvm::SmallVector<llvm::Type *, 16> FieldTypes;
 
   /// BaseSubobjectType - Holds the LLVM type for the non-virtual part
   /// of the struct. For example, consider:
@@ -52,7 +52,7 @@
   ///
   /// This only gets initialized if the base subobject type is
   /// different from the complete-object type.
-  const llvm::StructType *BaseSubobjectType;
+  llvm::StructType *BaseSubobjectType;
 
   /// FieldInfo - Holds a field and its corresponding LLVM field number.
   llvm::DenseMap<const FieldDecl *, unsigned> Fields;
@@ -109,8 +109,8 @@
 
   /// LayoutUnionField - Will layout a field in an union and return the type
   /// that the field will have.
-  const llvm::Type *LayoutUnionField(const FieldDecl *Field,
-                                     const ASTRecordLayout &Layout);
+  llvm::Type *LayoutUnionField(const FieldDecl *Field,
+                               const ASTRecordLayout &Layout);
   
   /// LayoutUnion - Will layout a union RecordDecl.
   void LayoutUnion(const RecordDecl *D);
@@ -151,7 +151,7 @@
   void LayoutBitField(const FieldDecl *D, uint64_t FieldOffset);
 
   /// AppendField - Appends a field with the given offset and type.
-  void AppendField(CharUnits fieldOffset, const llvm::Type *FieldTy);
+  void AppendField(CharUnits fieldOffset, llvm::Type *FieldTy);
 
   /// AppendPadding - Appends enough padding bytes so that the total
   /// struct size is a multiple of the field alignment.
@@ -165,7 +165,7 @@
 
   /// getByteArrayType - Returns a byte array type with the given number of
   /// elements.
-  const llvm::Type *getByteArrayType(CharUnits NumBytes);
+  llvm::Type *getByteArrayType(CharUnits NumBytes);
   
   /// AppendBytes - Append a given number of bytes to the record.
   void AppendBytes(CharUnits numBytes);
@@ -230,7 +230,7 @@
                                uint64_t FieldSize,
                                uint64_t ContainingTypeSizeInBits,
                                unsigned ContainingTypeAlign) {
-  const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(FD->getType());
+  const llvm::Type *Ty = Types.ConvertTypeForMem(FD->getType());
   CharUnits TypeSizeInBytes =
     CharUnits::fromQuantity(Types.getTargetData().getTypeAllocSize(Ty));
   uint64_t TypeSizeInBits = Types.getContext().toBits(TypeSizeInBytes);
@@ -440,7 +440,7 @@
   CharUnits fieldOffsetInBytes
     = Types.getContext().toCharUnitsFromBits(fieldOffset);
 
-  const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType());
+  llvm::Type *Ty = Types.ConvertTypeForMem(D->getType());
   CharUnits typeAlignment = getTypeAlignment(Ty);
 
   // If the type alignment is larger then the struct alignment, we must use
@@ -488,7 +488,7 @@
   return true;
 }
 
-const llvm::Type *
+llvm::Type *
 CGRecordLayoutBuilder::LayoutUnionField(const FieldDecl *Field,
                                         const ASTRecordLayout &Layout) {
   if (Field->isBitField()) {
@@ -499,7 +499,7 @@
     if (FieldSize == 0)
       return 0;
 
-    const llvm::Type *FieldTy = llvm::Type::getInt8Ty(Types.getLLVMContext());
+    llvm::Type *FieldTy = llvm::Type::getInt8Ty(Types.getLLVMContext());
     CharUnits NumBytesToAppend = Types.getContext().toCharUnitsFromBits(
       llvm::RoundUpToAlignment(FieldSize, 
                                Types.getContext().Target.getCharAlign()));
@@ -515,7 +515,7 @@
 
   // This is a regular union field.
   Fields[Field] = 0;
-  return Types.ConvertTypeForMemRecursive(Field->getType());
+  return Types.ConvertTypeForMem(Field->getType());
 }
 
 void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
@@ -523,7 +523,7 @@
 
   const ASTRecordLayout &layout = Types.getContext().getASTRecordLayout(D);
 
-  const llvm::Type *unionType = 0;
+  llvm::Type *unionType = 0;
   CharUnits unionSize = CharUnits::Zero();
   CharUnits unionAlign = CharUnits::Zero();
 
@@ -534,7 +534,7 @@
        fieldEnd = D->field_end(); field != fieldEnd; ++field, ++fieldNo) {
     assert(layout.getFieldOffset(fieldNo) == 0 &&
           "Union field offset did not start at the beginning of record!");
-    const llvm::Type *fieldType = LayoutUnionField(*field, layout);
+    llvm::Type *fieldType = LayoutUnionField(*field, layout);
 
     if (!fieldType)
       continue;
@@ -599,10 +599,8 @@
   // approximation, which is to use the base subobject type if it
   // has the same LLVM storage size as the nvsize.
 
-  const llvm::StructType *subobjectType = baseLayout.getBaseSubobjectLLVMType();
+  llvm::StructType *subobjectType = baseLayout.getBaseSubobjectLLVMType();
   AppendField(baseOffset, subobjectType);
-
-  Types.addBaseSubobjectTypeName(base, baseLayout);
 }
 
 void CGRecordLayoutBuilder::LayoutNonVirtualBase(const CXXRecordDecl *base,
@@ -736,13 +734,14 @@
     FieldTypes.push_back(getByteArrayType(NumBytes));
   }
 
-  BaseSubobjectType = llvm::StructType::get(Types.getLLVMContext(),
-                                            FieldTypes, Packed);
+  
+  BaseSubobjectType = llvm::StructType::createNamed(Types.getLLVMContext(), "",
+                                                    FieldTypes, Packed);
+  Types.addRecordTypeName(RD, BaseSubobjectType, ".base");
 
-  if (needsPadding) {
-    // Pull the padding back off.
+  // Pull the padding back off.
+  if (needsPadding)
     FieldTypes.pop_back();
-  }
 
   return true;
 }
@@ -819,7 +818,7 @@
 }
 
 void CGRecordLayoutBuilder::AppendField(CharUnits fieldOffset,
-                                        const llvm::Type *fieldType) {
+                                        llvm::Type *fieldType) {
   CharUnits fieldSize =
     CharUnits::fromQuantity(Types.getTargetData().getTypeAllocSize(fieldType));
 
@@ -865,10 +864,10 @@
   return true;
 }
 
-const llvm::Type *CGRecordLayoutBuilder::getByteArrayType(CharUnits numBytes) {
+llvm::Type *CGRecordLayoutBuilder::getByteArrayType(CharUnits numBytes) {
   assert(!numBytes.isZero() && "Empty byte arrays aren't allowed.");
 
-  const llvm::Type *Ty = llvm::Type::getInt8Ty(Types.getLLVMContext());
+  llvm::Type *Ty = llvm::Type::getInt8Ty(Types.getLLVMContext());
   if (numBytes > CharUnits::One())
     Ty = llvm::ArrayType::get(Ty, numBytes.getQuantity());
 
@@ -924,17 +923,16 @@
   }
 }
 
-CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) {
+CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D,
+                                                  llvm::StructType *Ty) {
   CGRecordLayoutBuilder Builder(*this);
 
   Builder.Layout(D);
 
-  const llvm::StructType *Ty = llvm::StructType::get(getLLVMContext(),
-                                                     Builder.FieldTypes,
-                                                     Builder.Packed);
+  Ty->setBody(Builder.FieldTypes, Builder.Packed);
 
   // If we're in C++, compute the base subobject type.
-  const llvm::StructType *BaseTy = 0;
+  llvm::StructType *BaseTy = 0;
   if (isa<CXXRecordDecl>(D)) {
     BaseTy = Builder.BaseSubobjectType;
     if (!BaseTy) BaseTy = Ty;