2011-03-27 09:00:25 +00:00
|
|
|
//===--- CGVTables.h - Emit LLVM Code for C++ vtables -----------*- C++ -*-===//
|
2009-10-11 22:13:54 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This contains code dealing with C++ code generation of virtual tables.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_CGVTABLE_H
|
|
|
|
#define CLANG_CODEGEN_CGVTABLE_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2009-12-06 00:23:49 +00:00
|
|
|
#include "llvm/GlobalVariable.h"
|
2011-01-13 18:57:25 +00:00
|
|
|
#include "clang/Basic/ABI.h"
|
2011-09-26 01:56:16 +00:00
|
|
|
#include "clang/AST/BaseSubobject.h"
|
2011-03-24 01:21:01 +00:00
|
|
|
#include "clang/AST/CharUnits.h"
|
2011-06-14 04:02:39 +00:00
|
|
|
#include "clang/AST/GlobalDecl.h"
|
2009-10-11 22:13:54 +00:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class CXXRecordDecl;
|
2009-11-26 13:09:03 +00:00
|
|
|
|
2009-10-11 22:13:54 +00:00
|
|
|
namespace CodeGen {
|
|
|
|
class CodeGenModule;
|
2009-11-26 02:32:05 +00:00
|
|
|
|
2011-09-26 01:56:45 +00:00
|
|
|
/// VTableComponent - Represents a single component in a vtable.
|
|
|
|
class VTableComponent {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
|
|
|
CK_VCallOffset,
|
|
|
|
CK_VBaseOffset,
|
|
|
|
CK_OffsetToTop,
|
|
|
|
CK_RTTI,
|
|
|
|
CK_FunctionPointer,
|
|
|
|
|
|
|
|
/// CK_CompleteDtorPointer - A pointer to the complete destructor.
|
|
|
|
CK_CompleteDtorPointer,
|
|
|
|
|
|
|
|
/// CK_DeletingDtorPointer - A pointer to the deleting destructor.
|
|
|
|
CK_DeletingDtorPointer,
|
|
|
|
|
|
|
|
/// CK_UnusedFunctionPointer - In some cases, a vtable function pointer
|
|
|
|
/// will end up never being called. Such vtable function pointers are
|
|
|
|
/// represented as a CK_UnusedFunctionPointer.
|
|
|
|
CK_UnusedFunctionPointer
|
|
|
|
};
|
|
|
|
|
2011-09-26 01:56:50 +00:00
|
|
|
VTableComponent() { }
|
|
|
|
|
2011-09-26 01:56:45 +00:00
|
|
|
static VTableComponent MakeVCallOffset(CharUnits Offset) {
|
|
|
|
return VTableComponent(CK_VCallOffset, Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTableComponent MakeVBaseOffset(CharUnits Offset) {
|
|
|
|
return VTableComponent(CK_VBaseOffset, Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTableComponent MakeOffsetToTop(CharUnits Offset) {
|
|
|
|
return VTableComponent(CK_OffsetToTop, Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTableComponent MakeRTTI(const CXXRecordDecl *RD) {
|
|
|
|
return VTableComponent(CK_RTTI, reinterpret_cast<uintptr_t>(RD));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTableComponent MakeFunction(const CXXMethodDecl *MD) {
|
|
|
|
assert(!isa<CXXDestructorDecl>(MD) &&
|
|
|
|
"Don't use MakeFunction with destructors!");
|
|
|
|
|
|
|
|
return VTableComponent(CK_FunctionPointer,
|
|
|
|
reinterpret_cast<uintptr_t>(MD));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTableComponent MakeCompleteDtor(const CXXDestructorDecl *DD) {
|
|
|
|
return VTableComponent(CK_CompleteDtorPointer,
|
|
|
|
reinterpret_cast<uintptr_t>(DD));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTableComponent MakeDeletingDtor(const CXXDestructorDecl *DD) {
|
|
|
|
return VTableComponent(CK_DeletingDtorPointer,
|
|
|
|
reinterpret_cast<uintptr_t>(DD));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTableComponent MakeUnusedFunction(const CXXMethodDecl *MD) {
|
|
|
|
assert(!isa<CXXDestructorDecl>(MD) &&
|
|
|
|
"Don't use MakeUnusedFunction with destructors!");
|
|
|
|
return VTableComponent(CK_UnusedFunctionPointer,
|
|
|
|
reinterpret_cast<uintptr_t>(MD));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VTableComponent getFromOpaqueInteger(uint64_t I) {
|
|
|
|
return VTableComponent(I);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getKind - Get the kind of this vtable component.
|
|
|
|
Kind getKind() const {
|
|
|
|
return (Kind)(Value & 0x7);
|
|
|
|
}
|
|
|
|
|
|
|
|
CharUnits getVCallOffset() const {
|
|
|
|
assert(getKind() == CK_VCallOffset && "Invalid component kind!");
|
|
|
|
|
|
|
|
return getOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
CharUnits getVBaseOffset() const {
|
|
|
|
assert(getKind() == CK_VBaseOffset && "Invalid component kind!");
|
|
|
|
|
|
|
|
return getOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
CharUnits getOffsetToTop() const {
|
|
|
|
assert(getKind() == CK_OffsetToTop && "Invalid component kind!");
|
|
|
|
|
|
|
|
return getOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
const CXXRecordDecl *getRTTIDecl() const {
|
|
|
|
assert(getKind() == CK_RTTI && "Invalid component kind!");
|
|
|
|
|
|
|
|
return reinterpret_cast<CXXRecordDecl *>(getPointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
const CXXMethodDecl *getFunctionDecl() const {
|
|
|
|
assert(getKind() == CK_FunctionPointer);
|
|
|
|
|
|
|
|
return reinterpret_cast<CXXMethodDecl *>(getPointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
const CXXDestructorDecl *getDestructorDecl() const {
|
|
|
|
assert((getKind() == CK_CompleteDtorPointer ||
|
|
|
|
getKind() == CK_DeletingDtorPointer) && "Invalid component kind!");
|
|
|
|
|
|
|
|
return reinterpret_cast<CXXDestructorDecl *>(getPointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
const CXXMethodDecl *getUnusedFunctionDecl() const {
|
|
|
|
assert(getKind() == CK_UnusedFunctionPointer);
|
|
|
|
|
|
|
|
return reinterpret_cast<CXXMethodDecl *>(getPointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
VTableComponent(Kind ComponentKind, CharUnits Offset) {
|
|
|
|
assert((ComponentKind == CK_VCallOffset ||
|
|
|
|
ComponentKind == CK_VBaseOffset ||
|
|
|
|
ComponentKind == CK_OffsetToTop) && "Invalid component kind!");
|
|
|
|
assert(Offset.getQuantity() <= ((1LL << 56) - 1) && "Offset is too big!");
|
|
|
|
|
|
|
|
Value = ((Offset.getQuantity() << 3) | ComponentKind);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTableComponent(Kind ComponentKind, uintptr_t Ptr) {
|
|
|
|
assert((ComponentKind == CK_RTTI ||
|
|
|
|
ComponentKind == CK_FunctionPointer ||
|
|
|
|
ComponentKind == CK_CompleteDtorPointer ||
|
|
|
|
ComponentKind == CK_DeletingDtorPointer ||
|
|
|
|
ComponentKind == CK_UnusedFunctionPointer) &&
|
|
|
|
"Invalid component kind!");
|
|
|
|
|
|
|
|
assert((Ptr & 7) == 0 && "Pointer not sufficiently aligned!");
|
|
|
|
|
|
|
|
Value = Ptr | ComponentKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
CharUnits getOffset() const {
|
|
|
|
assert((getKind() == CK_VCallOffset || getKind() == CK_VBaseOffset ||
|
|
|
|
getKind() == CK_OffsetToTop) && "Invalid component kind!");
|
|
|
|
|
|
|
|
return CharUnits::fromQuantity(Value >> 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t getPointer() const {
|
|
|
|
assert((getKind() == CK_RTTI ||
|
|
|
|
getKind() == CK_FunctionPointer ||
|
|
|
|
getKind() == CK_CompleteDtorPointer ||
|
|
|
|
getKind() == CK_DeletingDtorPointer ||
|
|
|
|
getKind() == CK_UnusedFunctionPointer) &&
|
|
|
|
"Invalid component kind!");
|
|
|
|
|
|
|
|
return static_cast<uintptr_t>(Value & ~7ULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit VTableComponent(uint64_t Value)
|
|
|
|
: Value(Value) { }
|
|
|
|
|
|
|
|
/// The kind is stored in the lower 3 bits of the value. For offsets, we
|
|
|
|
/// make use of the facts that classes can't be larger than 2^55 bytes,
|
|
|
|
/// so we store the offset in the lower part of the 61 bytes that remain.
|
|
|
|
/// (The reason that we're not simply using a PointerIntPair here is that we
|
|
|
|
/// need the offsets to be 64-bit, even when on a 32-bit machine).
|
|
|
|
int64_t Value;
|
|
|
|
};
|
|
|
|
|
2011-09-26 01:56:50 +00:00
|
|
|
class VTableLayout {
|
|
|
|
public:
|
|
|
|
typedef std::pair<uint64_t, ThunkInfo> VTableThunkTy;
|
|
|
|
typedef llvm::SmallVector<ThunkInfo, 1> ThunkInfoVectorTy;
|
|
|
|
|
|
|
|
typedef const VTableComponent *vtable_component_iterator;
|
|
|
|
typedef const VTableThunkTy *vtable_thunk_iterator;
|
|
|
|
|
|
|
|
typedef llvm::DenseMap<BaseSubobject, uint64_t> AddressPointsMapTy;
|
|
|
|
private:
|
|
|
|
uint64_t NumVTableComponents;
|
|
|
|
VTableComponent *VTableComponents;
|
|
|
|
|
|
|
|
/// VTableThunks - Contains thunks needed by vtables.
|
|
|
|
uint64_t NumVTableThunks;
|
|
|
|
VTableThunkTy *VTableThunks;
|
|
|
|
|
|
|
|
/// Address points - Address points for all vtables.
|
|
|
|
AddressPointsMapTy AddressPoints;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VTableLayout(uint64_t NumVTableComponents,
|
|
|
|
const VTableComponent *VTableComponents,
|
|
|
|
uint64_t NumVTableThunks,
|
|
|
|
const VTableThunkTy *VTableThunks,
|
|
|
|
const AddressPointsMapTy &AddressPoints);
|
|
|
|
~VTableLayout();
|
|
|
|
|
|
|
|
uint64_t getNumVTableComponents() const {
|
|
|
|
return NumVTableComponents;
|
|
|
|
}
|
|
|
|
|
|
|
|
vtable_component_iterator vtable_component_begin() const {
|
|
|
|
return VTableComponents;
|
|
|
|
}
|
|
|
|
|
|
|
|
vtable_component_iterator vtable_component_end() const {
|
|
|
|
return VTableComponents+NumVTableComponents;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getNumVTableThunks() const {
|
|
|
|
return NumVTableThunks;
|
|
|
|
}
|
|
|
|
|
|
|
|
vtable_thunk_iterator vtable_thunk_begin() const {
|
|
|
|
return VTableThunks;
|
|
|
|
}
|
|
|
|
|
|
|
|
vtable_thunk_iterator vtable_thunk_end() const {
|
|
|
|
return VTableThunks+NumVTableThunks;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getAddressPoint(BaseSubobject Base) const {
|
|
|
|
assert(AddressPoints.count(Base) &&
|
|
|
|
"Did not find address point!");
|
|
|
|
|
|
|
|
uint64_t AddressPoint = AddressPoints.lookup(Base);
|
|
|
|
assert(AddressPoint && "Address point must not be zero!");
|
|
|
|
|
|
|
|
return AddressPoint;
|
|
|
|
}
|
2011-09-26 01:57:04 +00:00
|
|
|
|
|
|
|
const AddressPointsMapTy &getAddressPoints() const {
|
|
|
|
return AddressPoints;
|
|
|
|
}
|
2011-09-26 01:56:50 +00:00
|
|
|
};
|
|
|
|
|
2011-09-26 01:56:30 +00:00
|
|
|
class VTableContext {
|
|
|
|
ASTContext &Context;
|
2009-11-26 13:09:03 +00:00
|
|
|
|
2011-09-26 01:56:41 +00:00
|
|
|
public:
|
|
|
|
typedef SmallVector<std::pair<uint64_t, ThunkInfo>, 1>
|
|
|
|
VTableThunksTy;
|
|
|
|
typedef SmallVector<ThunkInfo, 1> ThunkInfoVectorTy;
|
|
|
|
|
|
|
|
private:
|
2010-04-17 20:15:18 +00:00
|
|
|
/// MethodVTableIndices - Contains the index (relative to the vtable address
|
2009-10-11 22:13:54 +00:00
|
|
|
/// point) where the function pointer for a virtual function is stored.
|
2010-04-17 20:15:18 +00:00
|
|
|
typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
|
|
|
|
MethodVTableIndicesTy MethodVTableIndices;
|
2009-11-26 13:09:03 +00:00
|
|
|
|
2011-09-26 01:56:50 +00:00
|
|
|
typedef llvm::DenseMap<const CXXRecordDecl *, const VTableLayout *>
|
|
|
|
VTableLayoutMapTy;
|
|
|
|
VTableLayoutMapTy VTableLayouts;
|
|
|
|
|
2011-09-26 01:56:30 +00:00
|
|
|
/// NumVirtualFunctionPointers - Contains the number of virtual function
|
|
|
|
/// pointers in the vtable for a given record decl.
|
|
|
|
llvm::DenseMap<const CXXRecordDecl *, uint64_t> NumVirtualFunctionPointers;
|
|
|
|
|
2009-10-11 22:13:54 +00:00
|
|
|
typedef std::pair<const CXXRecordDecl *,
|
|
|
|
const CXXRecordDecl *> ClassPairTy;
|
2009-11-26 13:09:03 +00:00
|
|
|
|
2010-03-11 07:15:17 +00:00
|
|
|
/// VirtualBaseClassOffsetOffsets - Contains the vtable offset (relative to
|
2011-04-07 01:22:42 +00:00
|
|
|
/// the address point) in chars where the offsets for virtual bases of a class
|
2010-03-11 07:15:17 +00:00
|
|
|
/// are stored.
|
2011-04-07 01:22:42 +00:00
|
|
|
typedef llvm::DenseMap<ClassPairTy, CharUnits>
|
2010-03-11 07:15:17 +00:00
|
|
|
VirtualBaseClassOffsetOffsetsMapTy;
|
|
|
|
VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
|
2009-11-10 07:44:33 +00:00
|
|
|
|
2011-09-26 01:56:41 +00:00
|
|
|
typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy> ThunksMapTy;
|
|
|
|
|
|
|
|
/// Thunks - Contains all thunks that a given method decl will need.
|
|
|
|
ThunksMapTy Thunks;
|
|
|
|
|
2011-09-26 01:56:30 +00:00
|
|
|
void ComputeMethodVTableIndices(const CXXRecordDecl *RD);
|
|
|
|
|
2011-09-26 01:56:41 +00:00
|
|
|
/// ComputeVTableRelatedInformation - Compute and store all vtable related
|
|
|
|
/// information (vtable layout, vbase offset offsets, thunks etc) for the
|
|
|
|
/// given record decl.
|
|
|
|
void ComputeVTableRelatedInformation(const CXXRecordDecl *RD);
|
|
|
|
|
2011-09-26 01:56:30 +00:00
|
|
|
public:
|
|
|
|
VTableContext(ASTContext &Context) : Context(Context) {}
|
2011-09-26 01:56:50 +00:00
|
|
|
~VTableContext();
|
2011-09-26 01:56:30 +00:00
|
|
|
|
2011-09-26 01:56:50 +00:00
|
|
|
const VTableLayout &getVTableLayout(const CXXRecordDecl *RD) {
|
2011-09-26 01:56:41 +00:00
|
|
|
ComputeVTableRelatedInformation(RD);
|
2011-09-26 01:56:50 +00:00
|
|
|
assert(VTableLayouts.count(RD) && "No layout for this record decl!");
|
2011-09-26 01:56:41 +00:00
|
|
|
|
2011-09-26 01:56:50 +00:00
|
|
|
return *VTableLayouts[RD];
|
2011-09-26 01:56:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 01:56:55 +00:00
|
|
|
VTableLayout *
|
|
|
|
createConstructionVTableLayout(const CXXRecordDecl *MostDerivedClass,
|
|
|
|
CharUnits MostDerivedClassOffset,
|
|
|
|
bool MostDerivedClassIsVirtual,
|
|
|
|
const CXXRecordDecl *LayoutClass);
|
|
|
|
|
2011-09-26 01:56:41 +00:00
|
|
|
const ThunkInfoVectorTy *getThunkInfo(const CXXMethodDecl *MD) {
|
|
|
|
ComputeVTableRelatedInformation(MD->getParent());
|
|
|
|
|
|
|
|
ThunksMapTy::const_iterator I = Thunks.find(MD);
|
|
|
|
if (I == Thunks.end()) {
|
|
|
|
// We did not find a thunk for this method.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &I->second;
|
|
|
|
}
|
|
|
|
|
2011-09-26 01:56:30 +00:00
|
|
|
/// getNumVirtualFunctionPointers - Return the number of virtual function
|
|
|
|
/// pointers in the vtable for a given record decl.
|
|
|
|
uint64_t getNumVirtualFunctionPointers(const CXXRecordDecl *RD);
|
|
|
|
|
|
|
|
/// getMethodVTableIndex - Return the index (relative to the vtable address
|
|
|
|
/// point) where the function pointer for the given virtual function is
|
|
|
|
/// stored.
|
|
|
|
uint64_t getMethodVTableIndex(GlobalDecl GD);
|
|
|
|
|
|
|
|
/// getVirtualBaseOffsetOffset - Return the offset in chars (relative to the
|
|
|
|
/// vtable address point) where the offset of the virtual base that contains
|
|
|
|
/// the given base is stored, otherwise, if no virtual base contains the given
|
|
|
|
/// class, return 0. Base must be a virtual base class or an unambigious
|
|
|
|
/// base.
|
|
|
|
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD,
|
|
|
|
const CXXRecordDecl *VBase);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CodeGenVTables {
|
|
|
|
CodeGenModule &CGM;
|
|
|
|
|
|
|
|
VTableContext VTContext;
|
|
|
|
|
2010-04-17 20:15:18 +00:00
|
|
|
/// VTables - All the vtables which have been defined.
|
|
|
|
llvm::DenseMap<const CXXRecordDecl *, llvm::GlobalVariable *> VTables;
|
2009-11-27 20:47:55 +00:00
|
|
|
|
2010-03-26 03:56:54 +00:00
|
|
|
/// VTableAddressPointsMapTy - Address points for a single vtable.
|
|
|
|
typedef llvm::DenseMap<BaseSubobject, uint64_t> VTableAddressPointsMapTy;
|
|
|
|
|
2011-09-26 01:56:41 +00:00
|
|
|
typedef std::pair<const CXXRecordDecl *, BaseSubobject> BaseSubobjectPairTy;
|
2010-05-03 00:55:11 +00:00
|
|
|
typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> SubVTTIndiciesMapTy;
|
2010-03-26 04:23:58 +00:00
|
|
|
|
|
|
|
/// SubVTTIndicies - Contains indices into the various sub-VTTs.
|
|
|
|
SubVTTIndiciesMapTy SubVTTIndicies;
|
|
|
|
|
2010-05-03 00:55:11 +00:00
|
|
|
typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t>
|
2010-03-26 04:23:58 +00:00
|
|
|
SecondaryVirtualPointerIndicesMapTy;
|
|
|
|
|
|
|
|
/// SecondaryVirtualPointerIndices - Contains the secondary virtual pointer
|
|
|
|
/// indices.
|
|
|
|
SecondaryVirtualPointerIndicesMapTy SecondaryVirtualPointerIndices;
|
2010-01-02 01:01:18 +00:00
|
|
|
|
2010-03-23 16:36:50 +00:00
|
|
|
/// EmitThunk - Emit a single thunk.
|
2011-02-06 18:31:40 +00:00
|
|
|
void EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
|
|
|
|
bool UseAvailableExternallyLinkage);
|
|
|
|
|
|
|
|
/// 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);
|
|
|
|
|
2010-03-25 15:26:28 +00:00
|
|
|
/// CreateVTableInitializer - Create a vtable initializer for the given record
|
|
|
|
/// decl.
|
|
|
|
/// \param Components - The vtable components; this is really an array of
|
|
|
|
/// VTableComponents.
|
|
|
|
llvm::Constant *CreateVTableInitializer(const CXXRecordDecl *RD,
|
2011-09-26 01:56:50 +00:00
|
|
|
const VTableComponent *Components,
|
2010-03-25 15:26:28 +00:00
|
|
|
unsigned NumComponents,
|
2011-09-26 01:56:50 +00:00
|
|
|
const VTableLayout::VTableThunkTy *VTableThunks,
|
|
|
|
unsigned NumVTableThunks);
|
2010-03-26 03:56:54 +00:00
|
|
|
|
2009-10-11 22:13:54 +00:00
|
|
|
public:
|
2011-09-26 01:56:30 +00:00
|
|
|
CodeGenVTables(CodeGenModule &CGM);
|
|
|
|
|
|
|
|
VTableContext &getVTableContext() { return VTContext; }
|
2009-10-11 22:13:54 +00:00
|
|
|
|
2010-10-11 03:25:57 +00:00
|
|
|
/// \brief True if the VTable of this record must be emitted in the
|
|
|
|
/// translation unit.
|
|
|
|
bool ShouldEmitVTableInThisTU(const CXXRecordDecl *RD);
|
2010-04-19 00:44:22 +00:00
|
|
|
|
2010-01-02 01:01:18 +00:00
|
|
|
/// needsVTTParameter - Return whether the given global decl needs a VTT
|
|
|
|
/// parameter, which it does if it's a base constructor or destructor with
|
|
|
|
/// virtual bases.
|
|
|
|
static bool needsVTTParameter(GlobalDecl GD);
|
|
|
|
|
|
|
|
/// getSubVTTIndex - Return the index of the sub-VTT for the base class of the
|
|
|
|
/// given record decl.
|
2010-05-02 23:53:25 +00:00
|
|
|
uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base);
|
2010-01-02 01:01:18 +00:00
|
|
|
|
2010-03-26 04:23:58 +00:00
|
|
|
/// getSecondaryVirtualPointerIndex - Return the index in the VTT where the
|
|
|
|
/// virtual pointer for the given subobject is located.
|
|
|
|
uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD,
|
|
|
|
BaseSubobject Base);
|
|
|
|
|
2010-03-29 02:08:26 +00:00
|
|
|
/// getAddressPoint - Get the address point of the given subobject in the
|
|
|
|
/// class decl.
|
|
|
|
uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD);
|
|
|
|
|
2010-03-24 05:32:05 +00:00
|
|
|
/// GetAddrOfVTable - Get the address of the vtable for the given record decl.
|
2010-03-30 03:35:35 +00:00
|
|
|
llvm::GlobalVariable *GetAddrOfVTable(const CXXRecordDecl *RD);
|
2010-03-24 03:57:14 +00:00
|
|
|
|
2010-03-29 03:38:52 +00:00
|
|
|
/// EmitVTableDefinition - Emit the definition of the given vtable.
|
|
|
|
void EmitVTableDefinition(llvm::GlobalVariable *VTable,
|
|
|
|
llvm::GlobalVariable::LinkageTypes Linkage,
|
|
|
|
const CXXRecordDecl *RD);
|
|
|
|
|
2010-03-25 00:35:49 +00:00
|
|
|
/// GenerateConstructionVTable - Generate a construction vtable for the given
|
|
|
|
/// base subobject.
|
|
|
|
llvm::GlobalVariable *
|
|
|
|
GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base,
|
|
|
|
bool BaseIsVirtual,
|
2011-03-27 09:00:25 +00:00
|
|
|
llvm::GlobalVariable::LinkageTypes Linkage,
|
2010-03-26 03:56:54 +00:00
|
|
|
VTableAddressPointsMapTy& AddressPoints);
|
2011-01-29 19:16:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// GetAddrOfVTable - Get the address of the VTT for the given record decl.
|
|
|
|
llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD);
|
|
|
|
|
|
|
|
/// EmitVTTDefinition - Emit the definition of the given vtable.
|
|
|
|
void EmitVTTDefinition(llvm::GlobalVariable *VTT,
|
|
|
|
llvm::GlobalVariable::LinkageTypes Linkage,
|
|
|
|
const CXXRecordDecl *RD);
|
2010-03-10 02:19:29 +00:00
|
|
|
|
Rework when and how vtables are emitted, by tracking where vtables are
"used" (e.g., we will refer to the vtable in the generated code) and
when they are defined (i.e., because we've seen the key function
definition). Previously, we were effectively tracking "potential
definitions" rather than uses, so we were a bit too eager about emitting
vtables for classes without key functions.
The new scheme:
- For every use of a vtable, Sema calls MarkVTableUsed() to indicate
the use. For example, this occurs when calling a virtual member
function of the class, defining a constructor of that class type,
dynamic_cast'ing from that type to a derived class, casting
to/through a virtual base class, etc.
- For every definition of a vtable, Sema calls MarkVTableUsed() to
indicate the definition. This happens at the end of the translation
unit for classes whose key function has been defined (so we can
delay computation of the key function; see PR6564), and will also
occur with explicit template instantiation definitions.
- For every vtable defined/used, we mark all of the virtual member
functions of that vtable as defined/used, unless we know that the key
function is in another translation unit. This instantiates virtual
member functions when needed.
- At the end of the translation unit, Sema tells CodeGen (via the
ASTConsumer) which vtables must be defined (CodeGen will define
them) and which may be used (for which CodeGen will define the
vtables lazily).
From a language perspective, both the old and the new schemes are
permissible: we're allowed to instantiate virtual member functions
whenever we want per the standard. However, all other C++ compilers
were more lazy than we were, and our eagerness was both a performance
issue (we instantiated too much) and a portability problem (we broke
Boost test cases, which now pass).
Notes:
(1) There's a ton of churn in the tests, because the order in which
vtables get emitted to IR has changed. I've tried to isolate some of
the larger tests from these issues.
(2) Some diagnostics related to
implicitly-instantiated/implicitly-defined virtual member functions
have moved to the point of first use/definition. It's better this
way.
(3) I could use a review of the places where we MarkVTableUsed, to
see if I missed any place where the language effectively requires a
vtable.
Fixes PR7114 and PR6564.
llvm-svn: 103718
2010-05-13 16:44:06 +00:00
|
|
|
/// EmitThunks - Emit the associated thunks for the given global decl.
|
|
|
|
void EmitThunks(GlobalDecl GD);
|
|
|
|
|
2010-03-23 18:18:41 +00:00
|
|
|
/// GenerateClassData - Generate all the class data required to be generated
|
2010-03-10 02:19:29 +00:00
|
|
|
/// upon definition of a KeyFunction. This includes the vtable, the
|
|
|
|
/// rtti data structure and the VTT.
|
|
|
|
///
|
|
|
|
/// \param Linkage - The desired linkage of the vtable, the RTTI and the VTT.
|
|
|
|
void GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage,
|
|
|
|
const CXXRecordDecl *RD);
|
2009-10-11 22:13:54 +00:00
|
|
|
};
|
2009-11-26 13:09:03 +00:00
|
|
|
|
2010-01-14 02:29:07 +00:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
2009-10-11 22:13:54 +00:00
|
|
|
#endif
|