[cfe-commits] r78950 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp lib/AST/RecordLayoutBuilder.h lib/CodeGen/CGCXX.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/virt.cpp
Mike Stump
mrs at apple.com
Thu Aug 13 15:53:07 PDT 2009
Author: mrs
Date: Thu Aug 13 17:53:07 2009
New Revision: 78950
URL: http://llvm.org/viewvc/llvm-project?rev=78950&view=rev
Log:
Refine vtable layout for virtual bases and keep better track of
primaries. WIP.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/lib/AST/RecordLayoutBuilder.h
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenCXX/virt.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=78950&r1=78949&r2=78950&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Thu Aug 13 17:53:07 2009
@@ -26,14 +26,15 @@
NextOffset(0), IsUnion(false), NonVirtualSize(0), NonVirtualAlignment(8) {}
/// LayoutVtable - Lay out the vtable and set PrimaryBase.
-void ASTRecordLayoutBuilder::LayoutVtable(const CXXRecordDecl *RD) {
+void ASTRecordLayoutBuilder::LayoutVtable(const CXXRecordDecl *RD,
+ llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
if (!RD->isDynamicClass()) {
// There is no primary base in this case.
setPrimaryBase(0, false);
return;
}
- SelectPrimaryBase(RD);
+ SelectPrimaryBase(RD, IndirectPrimary);
if (PrimaryBase == 0) {
int AS = 0;
UpdateAlignment(Ctx.Target.getPointerAlign(AS));
@@ -85,9 +86,8 @@
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
// Only bases with virtual bases participate in computing the
// indirect primary virtual base classes.
- if (Base->getNumVBases() == 0)
- continue;
- SelectPrimaryForBase(Base, IndirectPrimary);
+ if (Base->getNumVBases())
+ SelectPrimaryForBase(Base, IndirectPrimary);
}
}
@@ -117,7 +117,8 @@
/// SelectPrimaryBase - Selects the primary base for the given class and
/// record that with setPrimaryBase.
-void ASTRecordLayoutBuilder::SelectPrimaryBase(const CXXRecordDecl *RD) {
+void ASTRecordLayoutBuilder::SelectPrimaryBase(const CXXRecordDecl *RD,
+ llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
// The primary base is the first non-virtual indirect or direct base class,
// if one exists.
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
@@ -146,7 +147,6 @@
// First, we compute all the primary virtual bases for all of our direct and
// indirect bases, and record all their primary virtual base classes.
const CXXRecordDecl *FirstPrimary = 0;
- llvm::SmallSet<const CXXRecordDecl*, 32> IndirectPrimary;
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
const CXXRecordDecl *Base =
@@ -169,13 +169,19 @@
void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD,
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
- // FIXME: Though complete, this is the wrong order
- for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
- e = RD->vbases_end(); i != e; ++i) {
+ // FIXME: Calculate IndirectPrimary when !PrimaryBaseWasVirtual
+ // assert(PrimaryBaseWasVirtual && "FIXME: calculate IndirectPrimary");
+ for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
+ e = RD->bases_end(); i != e; ++i) {
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
- if (!IndirectPrimary.count(Base))
+ if (i->isVirtual() && !IndirectPrimary.count(Base)) {
+ // Mark it so we don't output it twice.
+ IndirectPrimary.insert(Base);
LayoutVirtualBase(Base);
+ }
+ if (Base->getNumVBases())
+ LayoutVirtualBases(Base, IndirectPrimary);
}
}
@@ -216,13 +222,12 @@
if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
UpdateAlignment(AA->getAlignment());
- // FIXME: Calculate this completely.
llvm::SmallSet<const CXXRecordDecl*, 32> IndirectPrimary;
// If this is a C++ class, lay out the nonvirtual bases.
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D);
if (RD) {
- LayoutVtable(RD);
+ LayoutVtable(RD, IndirectPrimary);
// PrimaryBase goes first.
if (PrimaryBase) {
// FIXME: We need all the primaries.
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.h?rev=78950&r1=78949&r2=78950&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Thu Aug 13 17:53:07 2009
@@ -53,7 +53,8 @@
void LayoutFields(const RecordDecl *D);
void LayoutField(const FieldDecl *D);
- void SelectPrimaryBase(const CXXRecordDecl *RD);
+ void SelectPrimaryBase(const CXXRecordDecl *RD,
+ llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
void SelectPrimaryVBase(const CXXRecordDecl *RD,
const CXXRecordDecl *&FirstPrimary,
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
@@ -64,7 +65,8 @@
PrimaryBaseWasVirtual = Virtual;
}
bool IsNearlyEmpty(const CXXRecordDecl *RD);
- void LayoutVtable(const CXXRecordDecl *RD);
+ void LayoutVtable(const CXXRecordDecl *RD,
+ llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
void LayoutNonVirtualBases(const CXXRecordDecl *RD);
void LayoutBaseNonVirtually(const CXXRecordDecl *RD);
void LayoutVirtualBase(const CXXRecordDecl *RD);
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=78950&r1=78949&r2=78950&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Aug 13 17:53:07 2009
@@ -617,10 +617,10 @@
llvm::GlobalVariable::LinkageTypes linktype;
linktype = llvm::GlobalValue::WeakAnyLinkage;
std::vector<llvm::Constant *> info;
- // assert (0 && "FIXME: implement rtti descriptor");
+ // assert(0 && "FIXME: implement rtti descriptor");
// FIXME: descriptor
info.push_back(llvm::Constant::getNullValue(Ptr8Ty));
- // assert (0 && "FIXME: implement rtti ts");
+ // assert(0 && "FIXME: implement rtti ts");
// FIXME: TS
info.push_back(llvm::Constant::getNullValue(Ptr8Ty));
@@ -666,6 +666,25 @@
}
}
+void CodeGenFunction::GenerateVtableForVBases(const CXXRecordDecl *RD,
+ llvm::Constant *rtti,
+ std::vector<llvm::Constant *> &methods,
+ llvm::SmallSet<const CXXRecordDecl *, 32> &IndirectPrimary) {
+ for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
+ e = RD->bases_end(); i != e; ++i) {
+ const CXXRecordDecl *Base =
+ cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+ if (i->isVirtual() && !IndirectPrimary.count(Base)) {
+ // Mark it so we don't output it twice.
+ IndirectPrimary.insert(Base);
+ GenerateVtableForBase(Base, RD, rtti, methods, false, true,
+ IndirectPrimary);
+ }
+ if (Base->getNumVBases())
+ GenerateVtableForVBases(Base, rtti, methods, IndirectPrimary);
+ }
+}
+
void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
const CXXRecordDecl *Class,
llvm::Constant *rtti,
@@ -776,15 +795,8 @@
IndirectPrimary);
}
- // FIXME: Though complete, this is the wrong order
- for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
- e = RD->vbases_end(); i != e; ++i) {
- const CXXRecordDecl *Base =
- cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
- if (!IndirectPrimary.count(Base))
- GenerateVtableForBase(Base, RD, rtti, methods, false, true,
- IndirectPrimary);
- }
+ // Then come the vtables for all the virtual bases.
+ GenerateVtableForVBases(RD, rtti, methods, IndirectPrimary);
llvm::Constant *C;
llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, methods.size());
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=78950&r1=78949&r2=78950&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Aug 13 17:53:07 2009
@@ -363,6 +363,10 @@
const CXXRecordDecl *RD, llvm::Type *Ptr8Ty);
void GenerateMethods(std::vector<llvm::Constant *> &methods,
const CXXRecordDecl *RD, llvm::Type *Ptr8Ty);
+void GenerateVtableForVBases(const CXXRecordDecl *RD,
+ llvm::Constant *rtti,
+ std::vector<llvm::Constant *> &methods,
+ llvm::SmallSet<const CXXRecordDecl *, 32> &IndirectPrimary);
void GenerateVtableForBase(const CXXRecordDecl *RD,
const CXXRecordDecl *Class,
llvm::Constant *rtti,
Modified: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=78950&r1=78949&r2=78950&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Thu Aug 13 17:53:07 2009
@@ -224,7 +224,7 @@
// CHECK-LP32 .long -4
// CHECK-LP32: .long __ZTI7test5_D
// CHECK-LP32: .long __ZN9test5_B237funcB23Ev
-// CHECK-LP32: .long __ZN9test5_B227funcB22Ev
+// CHECK-LP32 .long __ZN9test5_B227funcB22Ev
// CHECK-LP32 .long __ZN9test5_B217funcB21Ev
// CHECK-LP32 .space 4
// CHECK-LP32 .long 8
@@ -276,7 +276,7 @@
// CHECK-LP64 .quad 18446744073709551608
// CHECK-LP64: .quad __ZTI7test5_D
// CHECK-LP64: .quad __ZN9test5_B237funcB23Ev
-// CHECK-LP64: .quad __ZN9test5_B227funcB22Ev
+// CHECK-LP64 .quad __ZN9test5_B227funcB22Ev
// CHECK-LP64 .quad __ZN9test5_B217funcB21Ev
// CHECK-LP64 .space 8
// CHECK-LP64 .quad 16
More information about the cfe-commits
mailing list