More vtable work; preparations for moving over to the new vtable layout code (finally).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99381 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index f492169..c9b099b 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -3551,6 +3551,19 @@
return I->second;
}
+const CodeGenVTables::AddrSubMap_t &
+CodeGenVTables::getAddressPoints(const CXXRecordDecl *RD) {
+ if (!AddressPoints[RD]) {
+ AddressPointsMapTy AddressPoints;
+ OldVtableBuilder b(RD, RD, 0, CGM, false, AddressPoints);
+
+ b.GenerateVtableForBase(RD, 0);
+ b.GenerateVtableForVBases(RD, 0);
+ }
+
+ return *(*AddressPoints[RD])[RD];
+}
+
llvm::GlobalVariable *
CodeGenVTables::GenerateVtable(llvm::GlobalVariable::LinkageTypes Linkage,
bool GenerateDefinition,
@@ -3583,8 +3596,7 @@
llvm::StringRef Name = OutName.str();
llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name);
- if (GV == 0 || CGM.getVTables().AddressPoints[LayoutClass] == 0 ||
- GV->isDeclaration()) {
+ if (GV == 0 || GV->isDeclaration()) {
OldVtableBuilder b(RD, LayoutClass, Offset, CGM, GenerateDefinition,
AddressPoints);
@@ -3906,17 +3918,26 @@
GenerateVTT(Linkage, /*GenerateDefinition=*/true, RD);
}
-llvm::GlobalVariable *CodeGenVTables::getVtable(const CXXRecordDecl *RD) {
- llvm::GlobalVariable *Vtable = Vtables.lookup(RD);
-
- if (!Vtable) {
- AddressPointsMapTy AddressPoints;
- Vtable = GenerateVtable(llvm::GlobalValue::ExternalLinkage,
- /*GenerateDefinition=*/false, RD, RD, 0,
- /*IsVirtual=*/false, AddressPoints);
- }
+llvm::Constant *CodeGenVTables::getAddrOfVTable(const CXXRecordDecl *RD) {
+ llvm::SmallString<256> OutName;
+ CGM.getMangleContext().mangleCXXVtable(RD, OutName);
+ llvm::StringRef Name = OutName.str();
- return Vtable;
+ const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
+ llvm::ArrayType *ArrayType = llvm::ArrayType::get(Int8PtrTy, 0);
+
+ llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name);
+ if (GV) {
+ if (!GV->isDeclaration() || GV->getType()->getElementType() == ArrayType)
+ return GV;
+
+ return llvm::ConstantExpr::getBitCast(GV, ArrayType->getPointerTo());
+ }
+
+ GV = new llvm::GlobalVariable(CGM.getModule(), ArrayType, /*isConstant=*/true,
+ llvm::GlobalValue::ExternalLinkage, 0, Name);
+
+ return GV;
}
void CodeGenVTables::EmitVTableRelatedData(GlobalDecl GD) {