diff options
author | Anders Carlsson <andersca@mac.com> | 2009-09-12 03:29:09 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-09-12 03:29:09 +0000 |
commit | 29f898a36b1d2023ba0fd6cdaf2d955332f3b137 (patch) | |
tree | 57b9819e5e79b75e05695d08f10675c6e7db3c0a /lib/CodeGen/CGCXX.cpp | |
parent | 18be84c37b2b796fddfb36447c2b29141d7fdd18 (diff) |
Add CGCXXClass.cpp. and move CodeGenFunction::AddressCXXOfBaseClass there.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81604 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 7def3c7834..c3c40443b8 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -276,73 +276,6 @@ llvm::Value *CodeGenFunction::LoadCXXThis() { return Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this"); } -static bool -GetNestedPaths(llvm::SmallVectorImpl<const CXXRecordDecl *> &NestedBasePaths, - const CXXRecordDecl *ClassDecl, - const CXXRecordDecl *BaseClassDecl) { - for (CXXRecordDecl::base_class_const_iterator i = ClassDecl->bases_begin(), - e = ClassDecl->bases_end(); i != e; ++i) { - if (i->isVirtual()) - continue; - const CXXRecordDecl *Base = - cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); - if (Base == BaseClassDecl) { - NestedBasePaths.push_back(BaseClassDecl); - return true; - } - } - // BaseClassDecl not an immediate base of ClassDecl. - for (CXXRecordDecl::base_class_const_iterator i = ClassDecl->bases_begin(), - e = ClassDecl->bases_end(); i != e; ++i) { - if (i->isVirtual()) - continue; - const CXXRecordDecl *Base = - cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); - if (GetNestedPaths(NestedBasePaths, Base, BaseClassDecl)) { - NestedBasePaths.push_back(Base); - return true; - } - } - return false; -} - -llvm::Value *CodeGenFunction::AddressCXXOfBaseClass(llvm::Value *BaseValue, - const CXXRecordDecl *ClassDecl, - const CXXRecordDecl *BaseClassDecl) { - if (ClassDecl == BaseClassDecl) - return BaseValue; - - llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext)); - llvm::SmallVector<const CXXRecordDecl *, 16> NestedBasePaths; - GetNestedPaths(NestedBasePaths, ClassDecl, BaseClassDecl); - assert(NestedBasePaths.size() > 0 && - "AddressCXXOfBaseClass - inheritence path failed"); - NestedBasePaths.push_back(ClassDecl); - uint64_t Offset = 0; - - // Accessing a member of the base class. Must add delata to - // the load of 'this'. - for (unsigned i = NestedBasePaths.size()-1; i > 0; i--) { - const CXXRecordDecl *DerivedClass = NestedBasePaths[i]; - const CXXRecordDecl *BaseClass = NestedBasePaths[i-1]; - const ASTRecordLayout &Layout = - getContext().getASTRecordLayout(DerivedClass); - Offset += Layout.getBaseClassOffset(BaseClass) / 8; - } - llvm::Value *OffsetVal = - llvm::ConstantInt::get( - CGM.getTypes().ConvertType(CGM.getContext().LongTy), Offset); - BaseValue = Builder.CreateBitCast(BaseValue, I8Ptr); - BaseValue = Builder.CreateGEP(BaseValue, OffsetVal, "add.ptr"); - QualType BTy = - getContext().getCanonicalType( - getContext().getTypeDeclType(const_cast<CXXRecordDecl*>(BaseClassDecl))); - const llvm::Type *BasePtr = ConvertType(BTy); - BasePtr = llvm::PointerType::getUnqual(BasePtr); - BaseValue = Builder.CreateBitCast(BaseValue, BasePtr); - return BaseValue; -} - /// EmitCXXAggrConstructorCall - This routine essentially creates a (nested) /// for-loop to call the default constructor on individual members of the /// array. 'Array' is the array type, 'This' is llvm pointer of the start |