]> granicus.if.org Git - clang/commitdiff
IRgen: Factor out ComputeBitFieldInfo.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 12 Apr 2010 21:01:28 +0000 (21:01 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 12 Apr 2010 21:01:28 +0000 (21:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101066 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGRecordLayoutBuilder.cpp

index 57438e6b06d926147372e6fe3404ed9887f6b075..ac6aae8bdca1788e55e0eea12ae05e667548de5d 100644 (file)
@@ -104,7 +104,6 @@ private:
   void AppendTailPadding(uint64_t RecordSize);
 
   unsigned getTypeAlignment(const llvm::Type *Ty) const;
-  uint64_t getTypeSizeInBytes(const llvm::Type *Ty) const;
 
   /// CheckForPointerToDataMember - Check if the given type contains a pointer
   /// to data member.
@@ -146,6 +145,20 @@ void CGRecordLayoutBuilder::Layout(const RecordDecl *D) {
   LayoutFields(D);
 }
 
+static CGBitFieldInfo ComputeBitFieldInfo(CodeGenTypes &Types,
+                                          const FieldDecl *FD,
+                                          uint64_t FieldOffset,
+                                          uint64_t FieldSize) {
+  const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(FD->getType());
+  uint64_t TypeSizeInBits = Types.getTargetData().getTypeAllocSize(Ty) * 8;
+
+  bool IsSigned = FD->getType()->isSignedIntegerType();
+  CGBitFieldInfo BFI(Ty, FieldOffset / TypeSizeInBits,
+                     FieldOffset % TypeSizeInBits, FieldSize, IsSigned);
+
+  return BFI;
+}
+
 void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D,
                                            uint64_t FieldOffset) {
   uint64_t FieldSize =
@@ -176,14 +189,9 @@ void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D,
     assert(NumBytesToAppend && "No bytes to append!");
   }
 
-  const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType());
-  uint64_t TypeSizeInBits = getTypeSizeInBytes(Ty) * 8;
-
-  bool IsSigned = D->getType()->isSignedIntegerType();
-  LLVMBitFields.push_back(LLVMBitFieldInfo(
-                            D, CGBitFieldInfo(Ty, FieldOffset / TypeSizeInBits,
-                                              FieldOffset % TypeSizeInBits,
-                                              FieldSize, IsSigned)));
+  // Add the bit field info.
+  LLVMBitFields.push_back(
+    LLVMBitFieldInfo(D, ComputeBitFieldInfo(Types, D, FieldOffset, FieldSize)));
 
   AppendBytes(NumBytesToAppend);
 
@@ -283,10 +291,9 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
         continue;
 
       // Add the bit field info.
-      bool IsSigned = Field->getType()->isSignedIntegerType();
-      LLVMBitFields.push_back(LLVMBitFieldInfo(
-                                *Field, CGBitFieldInfo(FieldTy, 0, 0, FieldSize,
-                                                       IsSigned)));
+      LLVMBitFields.push_back(
+        LLVMBitFieldInfo(*Field, ComputeBitFieldInfo(Types, *Field,
+                                                     0, FieldSize)));
     } else {
       LLVMFields.push_back(LLVMFieldInfo(*Field, 0));
     }
@@ -389,7 +396,7 @@ void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes,
   AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct,
                                    getTypeAlignment(FieldTy));
 
-  uint64_t FieldSizeInBytes = getTypeSizeInBytes(FieldTy);
+  uint64_t FieldSizeInBytes = Types.getTargetData().getTypeAllocSize(FieldTy);
 
   FieldTypes.push_back(FieldTy);
 
@@ -440,10 +447,6 @@ unsigned CGRecordLayoutBuilder::getTypeAlignment(const llvm::Type *Ty) const {
   return Types.getTargetData().getABITypeAlignment(Ty);
 }
 
-uint64_t CGRecordLayoutBuilder::getTypeSizeInBytes(const llvm::Type *Ty) const {
-  return Types.getTargetData().getTypeAllocSize(Ty);
-}
-
 void CGRecordLayoutBuilder::CheckForPointerToDataMember(QualType T) {
   // This record already contains a member pointer.
   if (ContainsPointerToDataMember)