diff options
author | Anders Carlsson <andersca@mac.com> | 2010-11-28 23:06:23 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-11-28 23:06:23 +0000 |
commit | acf877be126d1c0d407a233957d79c8f4b32ea55 (patch) | |
tree | 159754bc34efa1506716255fe6291e57f36115ce /clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | |
parent | dcf6fc5dc4c582db7e2c9d5e2668b0e94cd679bc (diff) | |
download | bcm5719-llvm-acf877be126d1c0d407a233957d79c8f4b32ea55.tar.gz bcm5719-llvm-acf877be126d1c0d407a233957d79c8f4b32ea55.zip |
Don't store the maximum alignment, we can trivially compute it.
llvm-svn: 120268
Diffstat (limited to 'clang/lib/CodeGen/CGRecordLayoutBuilder.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 42b54160bf3..d5f50281ab9 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -88,10 +88,6 @@ private: // FIXME: This is not needed and should be removed. unsigned Alignment; - /// AlignmentAsLLVMStruct - Will contain the maximum alignment of all the - /// LLVM types. - unsigned AlignmentAsLLVMStruct; - /// BitsAvailableInLastField - If a bit field spans only part of a LLVM field, /// this will have the number of bits still available in the field. char BitsAvailableInLastField; @@ -156,6 +152,10 @@ private: unsigned getTypeAlignment(const llvm::Type *Ty) const; + /// getAlignmentAsLLVMStruct - Returns the maximum alignment of all the + /// LLVM element types. + unsigned getAlignmentAsLLVMStruct() const; + /// CheckZeroInitializable - Check if the given type contains a pointer /// to data member. void CheckZeroInitializable(QualType T); @@ -164,8 +164,8 @@ private: public: CGRecordLayoutBuilder(CodeGenTypes &Types) : NonVirtualBaseTypeIsSameAsCompleteType(false), IsZeroInitializable(true), - Packed(false), Types(Types), Alignment(0), AlignmentAsLLVMStruct(1), - BitsAvailableInLastField(0), NextFieldOffsetInBytes(0) { } + Packed(false), Types(Types), Alignment(0), BitsAvailableInLastField(0), + NextFieldOffsetInBytes(0) { } /// Layout - Will layout a RecordDecl. void Layout(const RecordDecl *D); @@ -188,7 +188,6 @@ void CGRecordLayoutBuilder::Layout(const RecordDecl *D) { // We weren't able to layout the struct. Try again with a packed struct Packed = true; - AlignmentAsLLVMStruct = 1; NextFieldOffsetInBytes = 0; FieldTypes.clear(); LLVMFields.clear(); @@ -632,7 +631,8 @@ CGRecordLayoutBuilder::ComputeNonVirtualBaseType(const CXXRecordDecl *RD) { // Check if we need padding. uint64_t AlignedNextFieldOffset = - llvm::RoundUpToAlignment(NextFieldOffsetInBytes, AlignmentAsLLVMStruct); + llvm::RoundUpToAlignment(NextFieldOffsetInBytes, + getAlignmentAsLLVMStruct()); assert(AlignedNextFieldOffset <= AlignedNonVirtualTypeSize && "Size mismatch!"); @@ -692,7 +692,8 @@ void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) { assert(NextFieldOffsetInBytes <= RecordSizeInBytes && "Size mismatch!"); uint64_t AlignedNextFieldOffset = - llvm::RoundUpToAlignment(NextFieldOffsetInBytes, AlignmentAsLLVMStruct); + llvm::RoundUpToAlignment(NextFieldOffsetInBytes, + getAlignmentAsLLVMStruct()); if (AlignedNextFieldOffset == RecordSizeInBytes) { // We don't need any padding. @@ -705,9 +706,6 @@ void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) { void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes, const llvm::Type *FieldTy) { - AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, - getTypeAlignment(FieldTy)); - uint64_t FieldSizeInBytes = Types.getTargetData().getTypeAllocSize(FieldTy); FieldTypes.push_back(FieldTy); @@ -759,6 +757,17 @@ unsigned CGRecordLayoutBuilder::getTypeAlignment(const llvm::Type *Ty) const { return Types.getTargetData().getABITypeAlignment(Ty); } +unsigned CGRecordLayoutBuilder::getAlignmentAsLLVMStruct() const { + if (Packed) + return 1; + + unsigned MaxAlignment = 1; + for (size_t i = 0; i != FieldTypes.size(); ++i) + MaxAlignment = std::max(MaxAlignment, getTypeAlignment(FieldTypes[i])); + + return MaxAlignment; +} + void CGRecordLayoutBuilder::CheckZeroInitializable(QualType T) { // This record already contains a member pointer. if (!IsZeroInitializable) |