[cfe-commits] r103359 - in /cfe/trunk: include/clang/AST/RecordLayout.h lib/AST/RecordLayout.cpp lib/AST/RecordLayoutBuilder.cpp lib/AST/RecordLayoutBuilder.h
Anders Carlsson
andersca at mac.com
Sat May 8 15:35:05 PDT 2010
Author: andersca
Date: Sat May 8 17:35:05 2010
New Revision: 103359
URL: http://llvm.org/viewvc/llvm-project?rev=103359&view=rev
Log:
Add a SizeOfLargestEmptySubobject member to ASTRecordLayout. For C++ classes this will hold the largest empty subobject or 0 if the class doesn't have any empty subobjects.
Modified:
cfe/trunk/include/clang/AST/RecordLayout.h
cfe/trunk/lib/AST/RecordLayout.cpp
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/lib/AST/RecordLayoutBuilder.h
Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=103359&r1=103358&r2=103359&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Sat May 8 17:35:05 2010
@@ -109,6 +109,11 @@
/// which is the alignment of the object without virtual bases.
uint64_t NonVirtualAlign;
+ /// SizeOfLargestEmptySubobject - The size of the largest empty subobject
+ /// (either a base or a member). Will be zero if the class doesn't contain
+ /// any empty subobjects.
+ uint64_t SizeOfLargestEmptySubobject;
+
/// PrimaryBase - The primary base info for this record.
PrimaryBaseInfo PrimaryBase;
@@ -139,6 +144,7 @@
uint64_t size, unsigned alignment, uint64_t datasize,
const uint64_t *fieldoffsets, unsigned fieldcount,
uint64_t nonvirtualsize, unsigned nonvirtualalign,
+ uint64_t SizeOfLargestEmptySubobject,
const PrimaryBaseInfo &PrimaryBase,
const BaseOffsetsMapTy& BaseOffsets,
const BaseOffsetsMapTy& VBaseOffsets);
Modified: cfe/trunk/lib/AST/RecordLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayout.cpp?rev=103359&r1=103358&r2=103359&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayout.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayout.cpp Sat May 8 17:35:05 2010
@@ -44,6 +44,7 @@
unsigned fieldcount,
uint64_t nonvirtualsize,
unsigned nonvirtualalign,
+ uint64_t SizeOfLargestEmptySubobject,
const PrimaryBaseInfo &PrimaryBase,
const BaseOffsetsMapTy& BaseOffsets,
const BaseOffsetsMapTy& VBaseOffsets)
@@ -58,6 +59,7 @@
CXXInfo->PrimaryBase = PrimaryBase;
CXXInfo->NonVirtualSize = nonvirtualsize;
CXXInfo->NonVirtualAlign = nonvirtualalign;
+ CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
CXXInfo->BaseOffsets = BaseOffsets;
CXXInfo->VBaseOffsets = VBaseOffsets;
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=103359&r1=103358&r2=103359&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sat May 8 17:35:05 2010
@@ -24,7 +24,8 @@
ASTRecordLayoutBuilder::ASTRecordLayoutBuilder(ASTContext &Context)
: Context(Context), Size(0), Alignment(8), Packed(false),
UnfilledBitsInLastByte(0), MaxFieldAlignment(0), DataSize(0), IsUnion(false),
- NonVirtualSize(0), NonVirtualAlignment(8), FirstNearlyEmptyVBase(0) { }
+ SizeOfLargestEmptySubobject(0), NonVirtualSize(0), NonVirtualAlignment(8),
+ FirstNearlyEmptyVBase(0) { }
/// IsNearlyEmpty - Indicates when a class has a vtable pointer, but
/// no other data.
@@ -321,19 +322,19 @@
}
uint64_t ASTRecordLayoutBuilder::LayoutBase(const CXXRecordDecl *RD) {
- const ASTRecordLayout &BaseInfo = Context.getASTRecordLayout(RD);
+ const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
// If we have an empty base class, try to place it at offset 0.
if (RD->isEmpty() && canPlaceRecordAtOffset(RD, 0)) {
// We were able to place the class at offset 0.
UpdateEmptyClassOffsets(RD, 0);
- Size = std::max(Size, BaseInfo.getSize());
+ Size = std::max(Size, Layout.getSize());
return 0;
}
- unsigned BaseAlign = BaseInfo.getNonVirtualAlign();
+ unsigned BaseAlign = Layout.getNonVirtualAlign();
// Round up the current record size to the base's alignment boundary.
uint64_t Offset = llvm::RoundUpToAlignment(DataSize, BaseAlign);
@@ -348,11 +349,11 @@
if (!RD->isEmpty()) {
// Update the data size.
- DataSize = Offset + BaseInfo.getNonVirtualSize();
+ DataSize = Offset + Layout.getNonVirtualSize();
Size = std::max(Size, DataSize);
} else
- Size = std::max(Size, Offset + BaseInfo.getSize());
+ Size = std::max(Size, Offset + Layout.getSize());
// Remember max struct/class alignment.
UpdateAlignment(BaseAlign);
@@ -424,7 +425,7 @@
if (!RD)
return true;
- const ASTRecordLayout &Info = Context.getASTRecordLayout(RD);
+ const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
uint64_t NumElements = Context.getConstantArrayElementCount(AT);
uint64_t ElementOffset = Offset;
@@ -432,7 +433,7 @@
if (!canPlaceRecordAtOffset(RD, ElementOffset))
return false;
- ElementOffset += Info.getSize();
+ ElementOffset += Layout.getSize();
}
}
@@ -444,7 +445,7 @@
if (RD->isEmpty())
EmptyClassOffsets.insert(std::make_pair(Offset, RD));
- const ASTRecordLayout &Info = Context.getASTRecordLayout(RD);
+ const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
// Update bases.
for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
@@ -457,7 +458,7 @@
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
- uint64_t BaseClassOffset = Info.getBaseClassOffset(Base);
+ uint64_t BaseClassOffset = Layout.getBaseClassOffset(Base);
UpdateEmptyClassOffsets(Base, Offset + BaseClassOffset);
}
@@ -467,7 +468,7 @@
I != E; ++I, ++FieldNo) {
const FieldDecl *FD = *I;
- uint64_t FieldOffset = Info.getFieldOffset(FieldNo);
+ uint64_t FieldOffset = Layout.getFieldOffset(FieldNo);
UpdateEmptyClassOffsets(FD, Offset + FieldOffset);
}
@@ -838,6 +839,7 @@
Builder.FieldOffsets.size(),
NonVirtualSize,
Builder.NonVirtualAlignment,
+ Builder.SizeOfLargestEmptySubobject,
Builder.PrimaryBase,
Builder.Bases, Builder.VBases);
}
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.h?rev=103359&r1=103358&r2=103359&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Sat May 8 17:35:05 2010
@@ -78,6 +78,11 @@
/// avoid visiting virtual bases more than once.
llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBases;
+ /// SizeOfLargestEmptySubobject - When laying out C++ classes, this holds the
+ /// size of the largest empty subobject (either a base or a member).
+ /// Will be zero if the record being built doesn't contain any empty classes.
+ uint64_t SizeOfLargestEmptySubobject;
+
/// EmptyClassOffsets - A map from offsets to empty record decls.
typedef std::multimap<uint64_t, const CXXRecordDecl *> EmptyClassOffsetsTy;
EmptyClassOffsetsTy EmptyClassOffsets;
More information about the cfe-commits
mailing list