diff options
author | Mike Stump <mrs@apple.com> | 2009-08-13 22:53:07 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-08-13 22:53:07 +0000 |
commit | 4ef980984fd0e131fca3f9e6ba15e8a79cabf88c (patch) | |
tree | 4c320b00a365c50011ae3e1ff1ddbc22ae178d6e /lib/CodeGen/CGCXX.cpp | |
parent | 0032b2781b4deb131f8c9b7968f2030bf2489cdd (diff) |
Refine vtable layout for virtual bases and keep better track of
primaries. WIP.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78950 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 2940f18b4d..24e87f521f 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -617,10 +617,10 @@ llvm::Constant *CodeGenFunction::GenerateRtti(const CXXRecordDecl *RD) { 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::GenerateMethods(std::vector<llvm::Constant *> &methods, } } +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 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { 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()); |