summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-03-28 19:40:00 +0000
committerAnders Carlsson <andersca@mac.com>2010-03-28 19:40:00 +0000
commite87fae9afa223534d48da8ea3f9462ef297aff42 (patch)
treece5329c684554d9b75d861b24d0e81a5c66b96f6 /clang/lib/CodeGen
parent32bdaef3fec910e7c5d29248cdb25ab57c2115bf (diff)
downloadbcm5719-llvm-e87fae9afa223534d48da8ea3f9462ef297aff42.tar.gz
bcm5719-llvm-e87fae9afa223534d48da8ea3f9462ef297aff42.zip
Factor vtable pointer setting code out into a separate function.
llvm-svn: 99773
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGClass.cpp53
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h14
2 files changed, 45 insertions, 22 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 8a084926e76..2fa58372895 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -139,7 +139,7 @@ CodeGenFunction::GetAddressOfBaseOfCompleteClass(llvm::Value *This,
V = Builder.CreateBitCast(V, ConvertType(Base)->getPointerTo());
return V;
-}
+}
llvm::Value *
CodeGenFunction::GetAddressOfBaseClass(llvm::Value *Value,
@@ -1556,6 +1556,34 @@ CodeGenFunction::GetVirtualBaseClassOffset(llvm::Value *This,
return VBaseOffset;
}
+void
+CodeGenFunction::InitializeVTablePointer(BaseSubobject Base,
+ bool BaseIsMorallyVirtual,
+ llvm::Constant *VTable,
+ const CXXRecordDecl *VTableClass) {
+
+ // Compute the address point.
+ const CodeGenVTables::AddrSubMap_t& AddressPoints =
+ CGM.getVTables().getAddressPoints(VTableClass);
+
+ uint64_t AddressPoint =
+ AddressPoints.lookup(std::make_pair(Base.getBase(), Base.getBaseOffset()));
+ llvm::Value *VTableAddressPoint =
+ Builder.CreateConstInBoundsGEP2_64(VTable, 0, AddressPoint);
+
+ // Compute where to store the address point.
+ const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
+ llvm::Value *VTableField = Builder.CreateBitCast(LoadCXXThis(), Int8PtrTy);
+ VTableField =
+ Builder.CreateConstInBoundsGEP1_64(VTableField, Base.getBaseOffset() / 8);
+
+ // Finally, store the address point.
+ const llvm::Type *AddressPointPtrTy =
+ VTableAddressPoint->getType()->getPointerTo();
+ VTableField = Builder.CreateBitCast(VTableField, AddressPointPtrTy);
+ Builder.CreateStore(VTableAddressPoint, VTableField);
+}
+
void CodeGenFunction::InitializeVtablePtrs(const CXXRecordDecl *RD) {
if (!RD->isDynamicClass())
return;
@@ -1607,25 +1635,8 @@ void CodeGenFunction::InitializeVtablePtrs(BaseSubobject Base,
InitializeVtablePtrs(BaseSubobject(BaseDecl, BaseOffset),
VTable, VTableClass);
}
-
- // Compute the address point.
- const CodeGenVTables::AddrSubMap_t& AddressPoints =
- CGM.getVTables().getAddressPoints(VTableClass);
-
- uint64_t AddressPoint =
- AddressPoints.lookup(std::make_pair(Base.getBase(), Base.getBaseOffset()));
- llvm::Value *VTableAddressPoint =
- Builder.CreateConstInBoundsGEP2_64(VTable, 0, AddressPoint);
- // Compute where to store the address point.
- const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
- llvm::Value *VTableField = Builder.CreateBitCast(LoadCXXThis(), Int8PtrTy);
- VTableField =
- Builder.CreateConstInBoundsGEP1_64(VTableField, Base.getBaseOffset() / 8);
-
- // Finally, store the address point.
- const llvm::Type *AddressPointPtrTy =
- VTableAddressPoint->getType()->getPointerTo();
- VTableField = Builder.CreateBitCast(VTableField, AddressPointPtrTy);
- Builder.CreateStore(VTableAddressPoint, VTableField);
+ // FIXME: BaseIsMorallyVirtual is not correct here.
+ InitializeVTablePointer(Base, /*BaseIsMorallyVirtual=*/false, VTable,
+ VTableClass);
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 4ecb03dca05..3d7165b0a97 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -509,11 +509,23 @@ public:
void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type);
- void InitializeVtablePtrs(const CXXRecordDecl *ClassDecl);
+ /// InitializeVTablePointer - Initialize the vtable pointer of the given
+ /// subobject.
+ ///
+ /// \param BaseIsMorallyVirtual - Whether the base subobject is a virtual base
+ /// or a direct or indirect base of a virtual base.
+ void InitializeVTablePointer(BaseSubobject Base, bool BaseIsMorallyVirtual,
+ llvm::Constant *VTable,
+ const CXXRecordDecl *VTableClass);
+
+ typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy;
void InitializeVtablePtrs(BaseSubobject Base, llvm::Constant *VTable,
const CXXRecordDecl *VTableClass);
+ void InitializeVtablePtrs(const CXXRecordDecl *ClassDecl);
+
+
void SynthesizeCXXCopyConstructor(const FunctionArgList &Args);
void SynthesizeCXXCopyAssignment(const FunctionArgList &Args);
OpenPOWER on IntegriCloud