Revert 192220 as it fails on an assertion
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192225 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCXXABI.h b/lib/CodeGen/CGCXXABI.h
index eaeb971..3a1c8d1 100644
--- a/lib/CodeGen/CGCXXABI.h
+++ b/lib/CodeGen/CGCXXABI.h
@@ -339,17 +339,11 @@
SourceLocation CallLoc,
llvm::Value *This) = 0;
- virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF,
- GlobalDecl GD,
- CallArgList &CallArgs) {}
-
/// Emit any tables needed to implement virtual inheritance. For Itanium,
/// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
/// base tables.
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
- virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable) = 0;
-
virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
RValue RV, QualType ResultType);
diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp
index 5ede565..b987eb4 100644
--- a/lib/CodeGen/CGVTables.cpp
+++ b/lib/CodeGen/CGVTables.cpp
@@ -333,9 +333,6 @@
// Add our adjusted 'this' pointer.
CallArgs.add(RValue::get(AdjustedThisPtr), ThisType);
- if (isa<CXXDestructorDecl>(MD))
- CGM.getCXXABI().adjustCallArgsForDestructorThunk(*this, GD, CallArgs);
-
// Add the rest of the parameters.
for (FunctionDecl::param_const_iterator I = MD->param_begin(),
E = MD->param_end(); I != E; ++I) {
@@ -393,8 +390,14 @@
setThunkVisibility(CGM, MD, Thunk, Fn);
}
-void CodeGenVTables::emitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
- bool ForVTable) {
+void CodeGenVTables::EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
+ bool UseAvailableExternallyLinkage)
+{
+ if (CGM.getTarget().getCXXABI().isMicrosoft()) {
+ // Emission of thunks is not supported yet in Microsoft ABI.
+ return;
+ }
+
const CGFunctionInfo &FnInfo = CGM.getTypes().arrangeGlobalDeclaration(GD);
// FIXME: re-use FnInfo in this computation.
@@ -432,11 +435,9 @@
}
llvm::Function *ThunkFn = cast<llvm::Function>(Entry);
- bool ABIHasKeyFunctions = CGM.getTarget().getCXXABI().hasKeyFunctions();
- bool UseAvailableExternallyLinkage = ForVTable && ABIHasKeyFunctions;
if (!ThunkFn->isDeclaration()) {
- if (!ABIHasKeyFunctions || UseAvailableExternallyLinkage) {
+ if (UseAvailableExternallyLinkage) {
// There is already a thunk emitted for this function, do nothing.
return;
}
@@ -465,17 +466,14 @@
CodeGenFunction(CGM).GenerateThunk(ThunkFn, FnInfo, GD, Thunk);
}
- CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable);
+ if (UseAvailableExternallyLinkage)
+ ThunkFn->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
}
-void CodeGenVTables::maybeEmitThunkForVTable(GlobalDecl GD,
- const ThunkInfo &Thunk) {
- // If the ABI has key functions, only the TU with the key function should emit
- // the thunk. However, we can allow inlining of thunks if we emit them with
- // available_externally linkage together with vtables when optimizations are
- // enabled.
- if (CGM.getTarget().getCXXABI().hasKeyFunctions() &&
- !CGM.getCodeGenOpts().OptimizationLevel)
+void CodeGenVTables::MaybeEmitThunkAvailableExternally(GlobalDecl GD,
+ const ThunkInfo &Thunk) {
+ // We only want to do this when building with optimizations.
+ if (!CGM.getCodeGenOpts().OptimizationLevel)
return;
// We can't emit thunks for member functions with incomplete types.
@@ -484,7 +482,7 @@
cast<FunctionType>(MD->getType().getTypePtr())))
return;
- emitThunk(GD, Thunk, /*ForVTable=*/true);
+ EmitThunk(GD, Thunk, /*UseAvailableExternallyLinkage=*/true);
}
void CodeGenVTables::EmitThunks(GlobalDecl GD)
@@ -496,18 +494,21 @@
if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() == Dtor_Base)
return;
- const VTableContext::ThunkInfoVectorTy *ThunkInfoVector;
if (VFTContext.isValid()) {
- ThunkInfoVector = VFTContext->getThunkInfo(GD);
- } else {
- ThunkInfoVector = VTContext.getThunkInfo(GD);
+ // FIXME: This is a temporary solution to force generation of vftables in
+ // Microsoft ABI. Remove when we thread VFTableContext through CodeGen.
+ VFTContext->getVFPtrOffsets(MD->getParent());
+ return;
}
+ const VTableContext::ThunkInfoVectorTy *ThunkInfoVector =
+ VTContext.getThunkInfo(MD);
if (!ThunkInfoVector)
return;
for (unsigned I = 0, E = ThunkInfoVector->size(); I != E; ++I)
- emitThunk(GD, (*ThunkInfoVector)[I], /*ForVTable=*/false);
+ EmitThunk(GD, (*ThunkInfoVector)[I],
+ /*UseAvailableExternallyLinkage=*/false);
}
llvm::Constant *
@@ -602,7 +603,7 @@
VTableThunks[NextVTableThunkIndex].first == I) {
const ThunkInfo &Thunk = VTableThunks[NextVTableThunkIndex].second;
- maybeEmitThunkForVTable(GD, Thunk);
+ MaybeEmitThunkAvailableExternally(GD, Thunk);
Init = CGM.GetAddrOfThunk(GD, Thunk);
NextVTableThunkIndex++;
diff --git a/lib/CodeGen/CGVTables.h b/lib/CodeGen/CGVTables.h
index e17ad89..9b95952 100644
--- a/lib/CodeGen/CGVTables.h
+++ b/lib/CodeGen/CGVTables.h
@@ -52,12 +52,15 @@
/// indices.
SecondaryVirtualPointerIndicesMapTy SecondaryVirtualPointerIndices;
- /// emitThunk - Emit a single thunk.
- void emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, bool ForVTable);
+ /// EmitThunk - Emit a single thunk.
+ void EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
+ bool UseAvailableExternallyLinkage);
- /// maybeEmitThunkForVTable - Emit the given thunk for the vtable if needed by
- /// the ABI.
- void maybeEmitThunkForVTable(GlobalDecl GD, const ThunkInfo &Thunk);
+ /// MaybeEmitThunkAvailableExternally - Try to emit the given thunk with
+ /// available_externally linkage to allow for inlining of thunks.
+ /// This will be done iff optimizations are enabled and the member function
+ /// doesn't contain any incomplete types.
+ void MaybeEmitThunkAvailableExternally(GlobalDecl GD, const ThunkInfo &Thunk);
public:
/// CreateVTableInitializer - Create a vtable initializer for the given record
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp
index 1e34a16..ecf5d57 100644
--- a/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/lib/CodeGen/ItaniumCXXABI.cpp
@@ -173,13 +173,6 @@
void emitVirtualInheritanceTables(const CXXRecordDecl *RD);
- void setThunkLinkage(llvm::Function *Thunk, bool ForVTable) {
- // Allow inlining of thunks by emitting them with available_externally
- // linkage together with vtables when needed.
- if (ForVTable)
- Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
- }
-
StringRef GetPureVirtualCallName() { return "__cxa_pure_virtual"; }
StringRef GetDeletedVirtualCallName() { return "__cxa_deleted_virtual"; }
diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp
index 7452c86..1d73b21 100644
--- a/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -173,20 +173,8 @@
CXXDtorType DtorType, SourceLocation CallLoc,
llvm::Value *This);
- void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, GlobalDecl GD,
- CallArgList &CallArgs) {
- assert(GD.getDtorType() == Dtor_Deleting &&
- "Only deleting destructor thunks are available in this ABI");
- CallArgs.add(RValue::get(getStructorImplicitParamValue(CGF)),
- CGM.getContext().IntTy);
- }
-
void emitVirtualInheritanceTables(const CXXRecordDecl *RD);
- void setThunkLinkage(llvm::Function *Thunk, bool ForVTable) {
- Thunk->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
- }
-
void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
llvm::GlobalVariable *DeclPtr,
bool PerformInit);