[cfe-commits] r98197 - in /cfe/trunk/lib/AST: RecordLayoutBuilder.cpp RecordLayoutBuilder.h
Anders Carlsson
andersca at mac.com
Wed Mar 10 14:21:28 PST 2010
Author: andersca
Date: Wed Mar 10 16:21:28 2010
New Revision: 98197
URL: http://llvm.org/viewvc/llvm-project?rev=98197&view=rev
Log:
More shuffling.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/lib/AST/RecordLayoutBuilder.h
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=98197&r1=98196&r2=98197&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Mar 10 16:21:28 2010
@@ -41,22 +41,6 @@
}
}
-void
-ASTRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD) {
- for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
- e = RD->bases_end(); i != e; ++i) {
- if (!i->isVirtual()) {
- assert(!i->getType()->isDependentType() &&
- "Cannot layout class with dependent bases.");
- const CXXRecordDecl *Base =
- cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
- // Skip the PrimaryBase here, as it is laid down first.
- if (Base != PrimaryBase.getBase() || PrimaryBase.isVirtual())
- LayoutBaseNonVirtually(Base, false);
- }
- }
-}
-
/// IsNearlyEmpty - Indicates when a class has a vtable pointer, but
/// no other data.
bool ASTRecordLayoutBuilder::IsNearlyEmpty(const CXXRecordDecl *RD) const {
@@ -174,10 +158,6 @@
setPrimaryBase(FirstPrimary, /*IsVirtual=*/true);
}
-void ASTRecordLayoutBuilder::LayoutVirtualBase(const CXXRecordDecl *RD) {
- LayoutBaseNonVirtually(RD, true);
-}
-
uint64_t ASTRecordLayoutBuilder::getBaseOffset(const CXXRecordDecl *Base) {
for (size_t i = 0; i < Bases.size(); ++i) {
if (Bases[i].first == Base)
@@ -191,6 +171,25 @@
return 0;
}
+void
+ASTRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD) {
+ for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
+ e = RD->bases_end(); i != e; ++i) {
+ if (!i->isVirtual()) {
+ assert(!i->getType()->isDependentType() &&
+ "Cannot layout class with dependent bases.");
+ const CXXRecordDecl *Base =
+ cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+ // Skip the PrimaryBase here, as it is laid down first.
+ if (Base != PrimaryBase.getBase() || PrimaryBase.isVirtual())
+ LayoutBaseNonVirtually(Base, false);
+ }
+ }
+}
+
+void ASTRecordLayoutBuilder::LayoutNonVirtualBase(const CXXRecordDecl *RD) {
+ LayoutBaseNonVirtually(RD, false);
+}
void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *Class,
const CXXRecordDecl *RD,
@@ -244,6 +243,51 @@
}
}
+void ASTRecordLayoutBuilder::LayoutVirtualBase(const CXXRecordDecl *RD) {
+ LayoutBaseNonVirtually(RD, true);
+}
+
+uint64_t ASTRecordLayoutBuilder::LayoutBase(const CXXRecordDecl *RD) {
+ const ASTRecordLayout &BaseInfo = Ctx.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());
+
+ return 0;
+ }
+
+ unsigned BaseAlign = BaseInfo.getNonVirtualAlign();
+
+ // Round up the current record size to the base's alignment boundary.
+ uint64_t Offset = llvm::RoundUpToAlignment(DataSize, BaseAlign);
+
+ // Try to place the base.
+ while (true) {
+ if (canPlaceRecordAtOffset(RD, Offset))
+ break;
+
+ Offset += BaseAlign;
+ }
+
+ if (!RD->isEmpty()) {
+ // Update the data size.
+ DataSize = Offset + BaseInfo.getNonVirtualSize();
+
+ Size = std::max(Size, DataSize);
+ } else
+ Size = std::max(Size, Offset + BaseInfo.getSize());
+
+ // Remember max struct/class alignment.
+ UpdateAlignment(BaseAlign);
+
+ UpdateEmptyClassOffsets(RD, Offset);
+ return Offset;
+}
+
bool ASTRecordLayoutBuilder::canPlaceRecordAtOffset(const CXXRecordDecl *RD,
uint64_t Offset) const {
// Look for an empty class with the same type at the same offset.
@@ -390,47 +434,6 @@
}
}
-uint64_t ASTRecordLayoutBuilder::LayoutBase(const CXXRecordDecl *RD) {
- const ASTRecordLayout &BaseInfo = Ctx.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());
-
- return 0;
- }
-
- unsigned BaseAlign = BaseInfo.getNonVirtualAlign();
-
- // Round up the current record size to the base's alignment boundary.
- uint64_t Offset = llvm::RoundUpToAlignment(DataSize, BaseAlign);
-
- // Try to place the base.
- while (true) {
- if (canPlaceRecordAtOffset(RD, Offset))
- break;
-
- Offset += BaseAlign;
- }
-
- if (!RD->isEmpty()) {
- // Update the data size.
- DataSize = Offset + BaseInfo.getNonVirtualSize();
-
- Size = std::max(Size, DataSize);
- } else
- Size = std::max(Size, Offset + BaseInfo.getSize());
-
- // Remember max struct/class alignment.
- UpdateAlignment(BaseAlign);
-
- UpdateEmptyClassOffsets(RD, Offset);
- return Offset;
-}
-
void ASTRecordLayoutBuilder::LayoutBaseNonVirtually(const CXXRecordDecl *RD,
bool IsVirtualBase) {
// Layout the base.
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.h?rev=98197&r1=98196&r2=98197&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Wed Mar 10 16:21:28 2010
@@ -101,10 +101,6 @@
bool IsNearlyEmpty(const CXXRecordDecl *RD) const;
- /// LayoutBase - Will lay out a base and return the offset where it was
- /// placed, in bits.
- uint64_t LayoutBase(const CXXRecordDecl *RD);
-
/// LayoutNonVirtualBases - Determines the primary base class (if any) and
/// lays it out. Will then proceed to lay out all non-virtual base clasess.
void LayoutNonVirtualBases(const CXXRecordDecl *RD);
@@ -121,6 +117,10 @@
/// LayoutVirtualBase - Lays out a single virtual base.
void LayoutVirtualBase(const CXXRecordDecl *RD);
+ /// LayoutBase - Will lay out a base and return the offset where it was
+ /// placed, in bits.
+ uint64_t LayoutBase(const CXXRecordDecl *RD);
+
void LayoutVtable(const CXXRecordDecl *RD);
void LayoutBaseNonVirtually(const CXXRecordDecl *RD, bool IsVBase);
More information about the cfe-commits
mailing list