Add MicrosoftVFTableContext to AST
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187409 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp
index 9c4a5e0..c7bb54e 100644
--- a/lib/CodeGen/CGVTables.cpp
+++ b/lib/CodeGen/CGVTables.cpp
@@ -29,7 +29,14 @@
using namespace CodeGen;
CodeGenVTables::CodeGenVTables(CodeGenModule &CGM)
- : CGM(CGM), VTContext(CGM.getContext()) { }
+ : CGM(CGM), VTContext(CGM.getContext()) {
+ if (CGM.getTarget().getCXXABI().isMicrosoft()) {
+ // FIXME: Eventually, we should only have one of V*TContexts available.
+ // Today we use both in the Microsoft ABI as MicrosoftVFTableContext
+ // is not completely supported in CodeGen yet.
+ VFTContext.reset(new MicrosoftVFTableContext(CGM.getContext()));
+ }
+}
llvm::Constant *CodeGenModule::GetAddrOfThunk(GlobalDecl GD,
const ThunkInfo &Thunk) {
@@ -389,6 +396,11 @@
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.
@@ -485,6 +497,12 @@
if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() == Dtor_Base)
return;
+ if (VFTContext.isValid()) {
+ // 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());
+ }
+
const VTableContext::ThunkInfoVectorTy *ThunkInfoVector =
VTContext.getThunkInfo(MD);
if (!ThunkInfoVector)
@@ -804,6 +822,12 @@
void
CodeGenVTables::GenerateClassData(const CXXRecordDecl *RD) {
+ if (VFTContext.isValid()) {
+ // FIXME: This is a temporary solution to force generation of vftables in
+ // Microsoft ABI. Remove when we thread VFTableContext through CodeGen.
+ VFTContext->getVFPtrOffsets(RD);
+ }
+
// First off, check whether we've already emitted the v-table and
// associated stuff.
llvm::GlobalVariable *VTable = GetAddrOfVTable(RD);
diff --git a/lib/CodeGen/CGVTables.h b/lib/CodeGen/CGVTables.h
index fe51d50..bd70b5c 100644
--- a/lib/CodeGen/CGVTables.h
+++ b/lib/CodeGen/CGVTables.h
@@ -32,6 +32,7 @@
CodeGenModule &CGM;
VTableContext VTContext;
+ OwningPtr<MicrosoftVFTableContext> VFTContext;
/// VTables - All the vtables which have been defined.
llvm::DenseMap<const CXXRecordDecl *, llvm::GlobalVariable *> VTables;
diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp
index 0e01d8b..74575c3 100644
--- a/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -20,6 +20,7 @@
#include "MicrosoftVBTables.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
+#include "clang/AST/VTableBuilder.h"
using namespace clang;
using namespace CodeGen;
@@ -315,24 +316,6 @@
return Total;
}
-/// \brief Computes the index of BaseClassDecl in the vbtable of ClassDecl.
-/// BaseClassDecl must be a morally virtual base of ClassDecl. The vbtable is
-/// an array of i32 offsets. The first entry is a self entry, and the rest are
-/// offsets from the vbptr to virtual bases. The bases are ordered the same way
-/// our vbases are ordered: as they appear in a left-to-right depth-first search
-/// of the hierarchy.
-static unsigned GetVBTableIndex(const CXXRecordDecl *ClassDecl,
- const CXXRecordDecl *BaseClassDecl) {
- unsigned VBTableIndex = 1; // Start with one to skip the self entry.
- for (CXXRecordDecl::base_class_const_iterator I = ClassDecl->vbases_begin(),
- E = ClassDecl->vbases_end(); I != E; ++I) {
- if (I->getType()->getAsCXXRecordDecl() == BaseClassDecl)
- return VBTableIndex;
- VBTableIndex++;
- }
- llvm_unreachable("BaseClassDecl must be a vbase of ClassDecl");
-}
-
llvm::Value *
MicrosoftCXXABI::GetVirtualBaseClassOffset(CodeGenFunction &CGF,
llvm::Value *This,