[cfe-commits] r120268 - /cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Anders Carlsson
andersca at mac.com
Sun Nov 28 15:06:23 PST 2010
Author: andersca
Date: Sun Nov 28 17:06:23 2010
New Revision: 120268
URL: http://llvm.org/viewvc/llvm-project?rev=120268&view=rev
Log:
Don't store the maximum alignment, we can trivially compute it.
Modified:
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=120268&r1=120267&r2=120268&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Sun Nov 28 17:06:23 2010
@@ -88,10 +88,6 @@
// 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 @@
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 @@
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 @@
// 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 @@
// 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 @@
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::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 @@
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)
More information about the cfe-commits
mailing list