forked from OSchip/llvm-project
CodeGenModule::GenerateVtable now returns a pointer directly to the vtable and not to the address point.
llvm-svn: 90676
This commit is contained in:
parent
a95d4c51dc
commit
b3f54b748d
|
@ -1682,8 +1682,7 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
|
||||||
const CXXRecordDecl *ClassDecl = CD->getParent();
|
const CXXRecordDecl *ClassDecl = CD->getParent();
|
||||||
|
|
||||||
// FIXME: Add vbase initialization
|
// FIXME: Add vbase initialization
|
||||||
llvm::Value *LoadOfThis = 0;
|
|
||||||
|
|
||||||
for (CXXConstructorDecl::init_const_iterator B = CD->init_begin(),
|
for (CXXConstructorDecl::init_const_iterator B = CD->init_begin(),
|
||||||
E = CD->init_end();
|
E = CD->init_end();
|
||||||
B != E; ++B) {
|
B != E; ++B) {
|
||||||
|
@ -1705,15 +1704,21 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
|
||||||
if (!ClassDecl->isDynamicClass())
|
if (!ClassDecl->isDynamicClass())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Initialize the vtable pointer
|
// Initialize the vtable pointer.
|
||||||
if (!LoadOfThis)
|
// FIXME: This needs to initialize secondary vtable pointers too.
|
||||||
LoadOfThis = LoadCXXThis();
|
llvm::Value *ThisPtr = LoadCXXThis();
|
||||||
|
|
||||||
const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext);
|
llvm::Constant *Vtable = CGM.getVtableInfo().getVtable(ClassDecl);
|
||||||
|
uint64_t AddressPoint = CGM.getVtableInfo().getVtableAddressPoint(ClassDecl);
|
||||||
|
|
||||||
|
llvm::Value *VtableAddressPoint =
|
||||||
|
Builder.CreateConstInBoundsGEP2_64(Vtable, 0, AddressPoint);
|
||||||
|
|
||||||
llvm::Value *VtableField =
|
llvm::Value *VtableField =
|
||||||
Builder.CreateBitCast(LoadOfThis, Int8PtrTy->getPointerTo());
|
Builder.CreateBitCast(ThisPtr,
|
||||||
llvm::Value *vtable = CGM.getVtableInfo().getVtable(ClassDecl);
|
VtableAddressPoint->getType()->getPointerTo());
|
||||||
Builder.CreateStore(vtable, VtableField);
|
|
||||||
|
Builder.CreateStore(VtableAddressPoint, VtableField);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitDtorEpilogue - Emit all code that comes at the end of class's
|
/// EmitDtorEpilogue - Emit all code that comes at the end of class's
|
||||||
|
|
|
@ -1155,16 +1155,8 @@ llvm::Constant *CodeGenModule::GenerateVtable(const CXXRecordDecl *LayoutClass,
|
||||||
if (Hidden)
|
if (Hidden)
|
||||||
GV->setVisibility(llvm::GlobalVariable::HiddenVisibility);
|
GV->setVisibility(llvm::GlobalVariable::HiddenVisibility);
|
||||||
}
|
}
|
||||||
llvm::Constant *vtable = llvm::ConstantExpr::getBitCast(GV, Ptr8Ty);
|
|
||||||
llvm::Constant *AddressPointC;
|
return GV;
|
||||||
uint32_t LLVMPointerWidth = getContext().Target.getPointerWidth(0);
|
|
||||||
AddressPointC = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
|
|
||||||
AddressPoint*LLVMPointerWidth/8);
|
|
||||||
vtable = llvm::ConstantExpr::getInBoundsGetElementPtr(vtable, &AddressPointC,
|
|
||||||
1);
|
|
||||||
|
|
||||||
assert(vtable->getType() == Ptr8Ty);
|
|
||||||
return vtable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -1184,12 +1176,13 @@ class VTTBuilder {
|
||||||
llvm::LLVMContext &VMContext;
|
llvm::LLVMContext &VMContext;
|
||||||
|
|
||||||
/// BuildVtablePtr - Build up a referene to the given secondary vtable
|
/// BuildVtablePtr - Build up a referene to the given secondary vtable
|
||||||
llvm::Constant *BuildVtablePtr(llvm::Constant *vtbl,
|
llvm::Constant *BuildVtablePtr(llvm::Constant *Vtable,
|
||||||
const CXXRecordDecl *VtblClass,
|
const CXXRecordDecl *VtableClass,
|
||||||
const CXXRecordDecl *RD,
|
const CXXRecordDecl *RD,
|
||||||
uint64_t Offset) {
|
uint64_t Offset) {
|
||||||
int64_t AddressPoint;
|
int64_t AddressPoint =
|
||||||
AddressPoint = (*AddressPoints[VtblClass])[std::make_pair(RD, Offset)];
|
(*AddressPoints[VtableClass])[std::make_pair(RD, Offset)];
|
||||||
|
|
||||||
// FIXME: We can never have 0 address point. Do this for now so gepping
|
// FIXME: We can never have 0 address point. Do this for now so gepping
|
||||||
// retains the same structure. Later we'll just assert.
|
// retains the same structure. Later we'll just assert.
|
||||||
if (AddressPoint == 0)
|
if (AddressPoint == 0)
|
||||||
|
@ -1197,12 +1190,17 @@ class VTTBuilder {
|
||||||
D1(printf("XXX address point for %s in %s layout %s at offset %d was %d\n",
|
D1(printf("XXX address point for %s in %s layout %s at offset %d was %d\n",
|
||||||
RD->getNameAsCString(), VtblClass->getNameAsCString(),
|
RD->getNameAsCString(), VtblClass->getNameAsCString(),
|
||||||
Class->getNameAsCString(), (int)Offset, (int)AddressPoint));
|
Class->getNameAsCString(), (int)Offset, (int)AddressPoint));
|
||||||
uint32_t LLVMPointerWidth = CGM.getContext().Target.getPointerWidth(0);
|
|
||||||
llvm::Constant *init;
|
llvm::Value *Idxs[] = {
|
||||||
init = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
|
llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), 0),
|
||||||
AddressPoint*LLVMPointerWidth/8);
|
llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), AddressPoint)
|
||||||
init = llvm::ConstantExpr::getInBoundsGetElementPtr(vtbl, &init, 1);
|
};
|
||||||
return init;
|
|
||||||
|
llvm::Constant *Init =
|
||||||
|
llvm::ConstantExpr::getInBoundsGetElementPtr(Vtable, Idxs, 2);
|
||||||
|
|
||||||
|
const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext);
|
||||||
|
return llvm::ConstantExpr::getBitCast(Init, Int8PtrTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Secondary - Add the secondary vtable pointers to Inits. Offset is the
|
/// Secondary - Add the secondary vtable pointers to Inits. Offset is the
|
||||||
|
@ -1321,8 +1319,7 @@ public:
|
||||||
VMContext(cgm.getModule().getContext()) {
|
VMContext(cgm.getModule().getContext()) {
|
||||||
|
|
||||||
// First comes the primary virtual table pointer for the complete class...
|
// First comes the primary virtual table pointer for the complete class...
|
||||||
ClassVtbl = cast<llvm::Constant>(CGM.getVtableInfo().getVtable(Class)
|
ClassVtbl = CGM.getVtableInfo().getVtable(Class);
|
||||||
->getOperand(0));
|
|
||||||
Inits.push_back(BuildVtablePtr(ClassVtbl, Class, Class, 0));
|
Inits.push_back(BuildVtablePtr(ClassVtbl, Class, Class, 0));
|
||||||
|
|
||||||
// then the secondary VTTs...
|
// then the secondary VTTs...
|
||||||
|
@ -1423,9 +1420,7 @@ llvm::Constant *CGVtableInfo::getVtable(const CXXRecordDecl *RD) {
|
||||||
llvm::Constant *CGVtableInfo::getCtorVtable(const CXXRecordDecl *LayoutClass,
|
llvm::Constant *CGVtableInfo::getCtorVtable(const CXXRecordDecl *LayoutClass,
|
||||||
const CXXRecordDecl *RD,
|
const CXXRecordDecl *RD,
|
||||||
uint64_t Offset) {
|
uint64_t Offset) {
|
||||||
llvm::Constant *Vtable = CGM.GenerateVtable(LayoutClass, RD, Offset);
|
return CGM.GenerateVtable(LayoutClass, RD, Offset);
|
||||||
|
|
||||||
return cast<llvm::Constant>(Vtable->getOperand(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGVtableInfo::MaybeEmitVtable(GlobalDecl GD) {
|
void CGVtableInfo::MaybeEmitVtable(GlobalDecl GD) {
|
||||||
|
|
Loading…
Reference in New Issue