13#ifndef LLVM_CLANG_AST_VTABLEBUILDER_H
14#define LLVM_CLANG_AST_VTABLEBUILDER_H
22#include "llvm/ADT/DenseMap.h"
73 "Don't use MakeFunction with destructors!");
91 "Don't use MakeUnusedFunction with destructors!");
98 return (
Kind)(Value & 0x7);
120 assert(
isRTTIKind() &&
"Invalid component kind!");
155 "GlobalDecl can be created only from virtual function");
164 return GlobalDecl(DtorDecl, (HasVectorDeletingDtors)
172 llvm_unreachable(
"Only function pointers kinds");
174 llvm_unreachable(
"Should already return");
191 return ComponentKind ==
CK_RTTI;
198 assert(Offset.getQuantity() < (1LL << 56) &&
"Offset is too big!");
199 assert(Offset.getQuantity() >= -(1LL << 56) &&
"Offset is too small!");
201 Value = (
uint64_t(Offset.getQuantity()) << 3) | ComponentKind;
206 "Invalid component kind!");
208 assert((Ptr & 7) == 0 &&
"Pointer not sufficiently aligned!");
210 Value = Ptr | ComponentKind;
213 CharUnits getOffset()
const {
222 "Invalid component kind!");
224 return static_cast<uintptr_t>(Value & ~7ULL);
241 typedef llvm::DenseMap<BaseSubobject, AddressPointLocation>
275 return VTableComponents;
283 assert(AddressPoints.count(
Base) &&
"Did not find address point!");
284 return AddressPoints.lookup(
Base);
288 return AddressPoints;
292 return AddressPointIndices;
296 if (VTableIndices.empty())
298 return VTableIndices.size();
302 if (VTableIndices.empty()) {
306 return VTableIndices[i];
310 if (VTableIndices.empty()) {
315 size_t thisIndex = VTableIndices[i];
316 size_t nextIndex = (i + 1 == VTableIndices.size())
318 : VTableIndices[i + 1];
319 return nextIndex - thisIndex;
332 typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy>
ThunksMapTy;
350 ThunksMapTy::const_iterator I =
Thunks.find(MD);
367 typedef llvm::DenseMap<const CXXMethodDecl *, const CXXMethodDecl *>
374 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
375 MethodVTableIndicesTy MethodVTableIndices;
378 std::unique_ptr<const VTableLayout>>
380 VTableLayoutMapTy VTableLayouts;
389 typedef llvm::DenseMap<ClassPairTy, CharUnits>
390 VirtualBaseClassOffsetOffsetsMapTy;
391 VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
397 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
410 VTableComponentLayout ComponentLayout =
Pointer);
414 computeVTableRelatedInformation(RD);
415 assert(VTableLayouts.count(RD) &&
"No layout for this record decl!");
417 return *VTableLayouts[RD];
422 bool MostDerivedClassIsVirtual,
const CXXRecordDecl *LayoutClass);
450 OriginalMethodMap[Key] = Val;
456 return OriginalMethodMap;
464 return ComponentLayout;
471 VTableComponentLayout ComponentLayout;
581 typedef llvm::DenseMap<GlobalDecl, MethodVFTableLocation>
582 MethodVFTableLocationsTy;
583 MethodVFTableLocationsTy MethodVFTableLocations;
585 typedef llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VPtrInfoVector>>
587 VFPtrLocationsMapTy VFPtrLocations;
589 typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
590 typedef llvm::DenseMap<VFTableIdTy, std::unique_ptr<const VTableLayout>>
592 VFTableLayoutMapTy VFTableLayouts;
594 llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VirtualBaseInfo>>
597 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
600 const MethodVFTableLocationsTy &NewMethods,
606 void computeVTablePaths(
bool ForVBTables,
const CXXRecordDecl *RD,
Enums/classes describing ABI related information about constructors, destructors and thunks.
Enums/classes describing THUNK related information about constructors, destructors and thunks.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Represents a C++ struct/union/class.
CharUnits - This is an opaque type for sizes expressed in character units.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
GlobalDecl - represents a global declaration.
CXXDtorType getDtorType() const
const Decl * getDecl() const
@ Relative
Components in the vtable are relative offsets between the vtable and the other structs/functions.
@ Pointer
Components in the vtable are pointers to other structs/functions.
bool isPointerLayout() const
const CXXMethodDecl * findOriginalMethodInMap(const CXXMethodDecl *MD) const
const OriginalMethodMapTy & getOriginalMethodMap()
This method is reserved for the implementation and shouldn't be used directly.
VTableComponentLayout getVTableComponentLayout() const
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
llvm::DenseMap< const CXXMethodDecl *, const CXXMethodDecl * > OriginalMethodMapTy
bool isRelativeLayout() const
std::unique_ptr< VTableLayout > createConstructionVTableLayout(const CXXRecordDecl *MostDerivedClass, CharUnits MostDerivedClassOffset, bool MostDerivedClassIsVirtual, const CXXRecordDecl *LayoutClass)
~ItaniumVTableContext() override
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase)
Return the offset in chars (relative to the vtable address point) where the offset of the virtual bas...
ItaniumVTableContext(ASTContext &Context, VTableComponentLayout ComponentLayout=Pointer)
GlobalDecl findOriginalMethod(GlobalDecl GD)
Return the method that added the v-table slot that will be used to call the given method.
void setOriginalMethod(const CXXMethodDecl *Key, const CXXMethodDecl *Val)
static bool classof(const VTableContextBase *VT)
static bool classof(const VTableContextBase *VT)
const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD) override
MicrosoftVTableContext(ASTContext &Context)
unsigned getVBTableIndex(const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the index of VBase in the vbtable of Derived.
const VPtrInfoVector & enumerateVBTables(const CXXRecordDecl *RD)
MethodVFTableLocation getMethodVFTableLocation(GlobalDecl GD)
const VPtrInfoVector & getVFPtrOffsets(const CXXRecordDecl *RD)
const VTableLayout & getVFTableLayout(const CXXRecordDecl *RD, CharUnits VFPtrOffset)
~MicrosoftVTableContext() override
VTableComponent()=default
static VTableComponent MakeCompleteDtor(const CXXDestructorDecl *DD)
static VTableComponent MakeRTTI(const CXXRecordDecl *RD)
const CXXMethodDecl * getUnusedFunctionDecl() const
static VTableComponent MakeOffsetToTop(CharUnits Offset)
bool isUsedFunctionPointerKind() const
bool isDestructorKind() const
CharUnits getVBaseOffset() const
static VTableComponent MakeUnusedFunction(const CXXMethodDecl *MD)
Kind getKind() const
Get the kind of this vtable component.
static VTableComponent MakeFunction(const CXXMethodDecl *MD)
@ CK_DeletingDtorPointer
A pointer to the deleting destructor.
@ CK_UnusedFunctionPointer
An entry that is never used.
@ CK_CompleteDtorPointer
A pointer to the complete destructor.
static VTableComponent MakeVBaseOffset(CharUnits Offset)
const CXXRecordDecl * getRTTIDecl() const
static VTableComponent MakeDeletingDtor(const CXXDestructorDecl *DD)
bool isFunctionPointerKind() const
CharUnits getOffsetToTop() const
const CXXMethodDecl * getFunctionDecl() const
GlobalDecl getGlobalDecl(bool HasVectorDeletingDtors) const
static VTableComponent MakeVCallOffset(CharUnits Offset)
CharUnits getVCallOffset() const
const CXXDestructorDecl * getDestructorDecl() const
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
VTableContextBase(bool MS)
static bool hasVtableSlot(const CXXMethodDecl *MD)
Determine whether this function should be assigned a vtable slot.
virtual ~VTableContextBase()
virtual void computeVTableRelatedInformation(const CXXRecordDecl *RD)=0
Compute and store all vtable related information (vtable layout, vbase offset offsets,...
SmallVector< ThunkInfo, 1 > ThunkInfoVectorTy
llvm::DenseMap< const CXXMethodDecl *, ThunkInfoVectorTy > ThunksMapTy
ThunksMapTy Thunks
Contains all thunks that a given method decl will need.
const AddressPointsIndexMapTy & getAddressPointIndices() const
size_t getVTableOffset(size_t i) const
llvm::SmallVector< unsigned, 4 > AddressPointsIndexMapTy
VTableLayout(ArrayRef< size_t > VTableIndices, ArrayRef< VTableComponent > VTableComponents, ArrayRef< VTableThunkTy > VTableThunks, const AddressPointsMapTy &AddressPoints)
llvm::DenseMap< BaseSubobject, AddressPointLocation > AddressPointsMapTy
AddressPointLocation getAddressPoint(BaseSubobject Base) const
std::pair< uint64_t, ThunkInfo > VTableThunkTy
ArrayRef< VTableComponent > vtable_components() const
size_t getNumVTables() const
ArrayRef< VTableThunkTy > vtable_thunks() const
const AddressPointsMapTy & getAddressPoints() const
size_t getVTableSize(size_t i) const
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
SmallVector< std::unique_ptr< VPtrInfo >, 2 > VPtrInfoVector
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
U cast(CodeGen::Address addr)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
bool operator<(const MethodVFTableLocation &other) const
const CXXRecordDecl * VBase
If nonnull, holds the last vbase which contains the vfptr that the method definition is adjusted to.
MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase, CharUnits VFPtrOffset, uint64_t Index)
CharUnits VFPtrOffset
This is the offset of the vfptr from the start of the last vbase, or the complete type if there are n...
uint64_t VBTableIndex
If nonzero, holds the vbtable index of the virtual base with the vfptr.
uint64_t Index
Method's index in the vftable.
CharUnits NonVirtualOffset
IntroducingObject is at this offset from its containing complete object or virtual base.
CharUnits FullOffsetInMDC
Static offset from the top of the most derived class to this vfptr, including any virtual base offset...
const CXXRecordDecl * getVBaseWithVPtr() const
The vptr is stored inside the non-virtual component of this virtual base.
SmallVector< const CXXRecordDecl *, 1 > BasePath
VPtrInfo(const CXXRecordDecl *RD)
BasePath ContainingVBases
The set of possibly indirect vbases that contain this vbtable.
const CXXRecordDecl * IntroducingObject
This is the class that introduced the vptr by declaring new virtual methods or virtual bases.
BasePath MangledPath
The bases from the inheritance path that got used to mangle the vbtable name.
const CXXRecordDecl * NextBaseToMangle
The next base to push onto the mangled path if this path is ambiguous in a derived class.
BasePath PathToIntroducingObject
This holds the base classes path from the complete type to the first base with the given vfptr offset...
const CXXRecordDecl * ObjectWithVPtr
This is the most derived class that has this vptr at offset zero.
unsigned AddressPointIndex
All virtual base related information about a given record decl.
VPtrInfoVector VBPtrPaths
Information on all virtual base tables used when this record is the most derived class.
llvm::DenseMap< const CXXRecordDecl *, unsigned > VBTableIndices
A map from virtual base to vbtable index for doing a conversion from the the derived class to the a b...