aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGCXX.cpp
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-08-05 22:37:18 +0000
committerMike Stump <mrs@apple.com>2009-08-05 22:37:18 +0000
commit6f376336138ea719e3c4757ae046a5768043b276 (patch)
tree4721570e1f90e01e46ddac8f5b7443914789c1f6 /lib/CodeGen/CGCXX.cpp
parentaed2b3e5f3a1f849ee864c2a12e8d6a1bf8150c5 (diff)
Calculate the primary base class better and use that when laying down
the vtable. Still a work in progress. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78252 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r--lib/CodeGen/CGCXX.cpp47
1 files changed, 36 insertions, 11 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 97937ea89a..375c9ac40e 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -540,9 +540,12 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
llvm::Type *Ptr8Ty;
Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0);
m = llvm::Constant::getNullValue(Ptr8Ty);
- int64_t offset = 0;
- methods.push_back(m); offset += LLVMPointerWidth;
- methods.push_back(GenerateRtti(RD)); offset += LLVMPointerWidth;
+ int64_t Offset = 0;
+ methods.push_back(m); Offset += LLVMPointerWidth;
+ methods.push_back(GenerateRtti(RD)); Offset += LLVMPointerWidth;
+
+ const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
+ const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
@@ -550,6 +553,16 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
continue;
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+ if (PrimaryBase != Base) {
+ const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
+ int64_t BaseOffset = -(Layout.getBaseClassOffset(Base) / 8);
+ m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset);
+ m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
+ methods.push_back(m);
+ // FIXME: GenerateRtti for Base in RD.
+ m = llvm::Constant::getNullValue(Ptr8Ty);
+ methods.push_back(m);
+ }
for (meth_iter mi = Base->method_begin(), me = Base->method_end(); mi != me;
++mi) {
if (mi->isVirtual()) {
@@ -558,16 +571,28 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
methods.push_back(m);
}
}
+ if (PrimaryBase == Base) {
+ for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
+ ++mi) {
+ if (mi->isVirtual()) {
+ m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
+ m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
+ methods.push_back(m);
+ }
+ }
+ }
}
-
- for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
- ++mi) {
- if (mi->isVirtual()) {
- m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
- m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
- methods.push_back(m);
+ if (PrimaryBase == 0) {
+ for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me;
+ ++mi) {
+ if (mi->isVirtual()) {
+ m = CGM.GetAddrOfFunction(GlobalDecl(*mi));
+ m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty);
+ methods.push_back(m);
+ }
}
}
+
llvm::Constant *C;
llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, methods.size());
C = llvm::ConstantArray::get(type, methods);
@@ -577,7 +602,7 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
// FIXME: finish layout for virtual bases
vtable = Builder.CreateGEP(vtable,
llvm::ConstantInt::get(llvm::Type::Int64Ty,
- offset/8));
+ Offset/8));
return vtable;
}