aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGClass.cpp
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
commitd103f9f9b401b419e756f8c1849683cd77586067 (patch)
treef885c96942b39735d31aca8e5357363adf5efff0 /lib/CodeGen/CGClass.cpp
parent02024a9f0d8e6c898de276193af604c42ee41269 (diff)
Factor vtable pointer setting code out into a separate function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99773 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGClass.cpp')
-rw-r--r--lib/CodeGen/CGClass.cpp53
1 files changed, 32 insertions, 21 deletions
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp
index 8a084926e7..2fa5837289 100644
--- a/lib/CodeGen/CGClass.cpp
+++ b/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);
}