14 #ifndef LLVM_CLANG_AST_VTABLEBUILDER_H
15 #define LLVM_CLANG_AST_VTABLEBUILDER_H
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/SetVector.h"
73 assert(!isa<CXXDestructorDecl>(MD) &&
74 "Don't use MakeFunction with destructors!");
77 reinterpret_cast<uintptr_t>(MD));
82 reinterpret_cast<uintptr_t>(DD));
87 reinterpret_cast<uintptr_t>(DD));
91 assert(!isa<CXXDestructorDecl>(MD) &&
92 "Don't use MakeUnusedFunction with destructors!");
94 reinterpret_cast<uintptr_t>(MD));
154 assert(Offset.
getQuantity() < (1LL << 56) &&
"Offset is too big!");
155 assert(Offset.
getQuantity() >= -(1LL << 56) &&
"Offset is too small!");
161 assert((ComponentKind ==
CK_RTTI ||
166 "Invalid component kind!");
168 assert((Ptr & 7) == 0 &&
"Pointer not sufficiently aligned!");
170 Value = Ptr | ComponentKind;
173 CharUnits getOffset()
const {
180 uintptr_t getPointer()
const {
186 "Invalid component kind!");
188 return static_cast<uintptr_t
>(
Value & ~7ULL);
211 uint64_t NumVTableComponents;
212 std::unique_ptr<VTableComponent[]> VTableComponents;
215 uint64_t NumVTableThunks;
216 std::unique_ptr<VTableThunkTy[]> VTableThunks;
226 uint64_t NumVTableThunks,
229 bool IsMicrosoftABI);
233 return NumVTableComponents;
237 return VTableComponents.get();
241 return VTableComponents.get() + NumVTableComponents;
247 return VTableThunks.get();
251 return VTableThunks.get() + NumVTableThunks;
255 assert(AddressPoints.count(Base) &&
256 "Did not find address point!");
258 uint64_t AddressPoint = AddressPoints.lookup(Base);
259 assert(AddressPoint != 0 || IsMicrosoftABI);
260 (void)IsMicrosoftABI;
266 return AddressPoints;
279 typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy>
ThunksMapTy;
297 ThunksMapTy::const_iterator I =
Thunks.find(MD);
314 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
315 MethodVTableIndicesTy MethodVTableIndices;
317 typedef llvm::DenseMap<const CXXRecordDecl *, const VTableLayout *>
319 VTableLayoutMapTy VTableLayouts;
328 typedef llvm::DenseMap<ClassPairTy, CharUnits>
329 VirtualBaseClassOffsetOffsetsMapTy;
330 VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
332 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
339 computeVTableRelatedInformation(RD);
340 assert(VTableLayouts.count(RD) &&
"No layout for this record decl!");
342 return *VTableLayouts[RD];
348 bool MostDerivedClassIsVirtual,
466 : VBTableIndex(VBTableIndex), VBase(VBase),
467 VFPtrOffset(VFPtrOffset), Index(Index) {}
482 typedef llvm::DenseMap<GlobalDecl, MethodVFTableLocation>
483 MethodVFTableLocationsTy;
484 MethodVFTableLocationsTy MethodVFTableLocations;
486 typedef llvm::DenseMap<const CXXRecordDecl *, VPtrInfoVector *>
488 VFPtrLocationsMapTy VFPtrLocations;
490 typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
491 typedef llvm::DenseMap<VFTableIdTy, const VTableLayout *> VFTableLayoutMapTy;
492 VFTableLayoutMapTy VFTableLayouts;
494 llvm::DenseMap<const CXXRecordDecl *, VirtualBaseInfo *> VBaseInfo;
498 void computeVTableRelatedInformation(
const CXXRecordDecl *RD)
override;
501 const MethodVFTableLocationsTy &NewMethods,
507 void computeVTablePaths(
bool ForVBTables,
const CXXRecordDecl *RD,
525 if (isa<CXXDestructorDecl>(GD.
getDecl()) &&
CharUnits getOffsetToTop() const
VTableLayout * createConstructionVTableLayout(const CXXRecordDecl *MostDerivedClass, CharUnits MostDerivedClassOffset, bool MostDerivedClassIsVirtual, const CXXRecordDecl *LayoutClass)
ItaniumVTableContext(ASTContext &Context)
static VTableComponent MakeRTTI(const CXXRecordDecl *RD)
VPtrInfoVector VBPtrPaths
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
vtable_component_iterator vtable_component_begin() const
const VTableThunkTy * vtable_thunk_iterator
vtable_component_iterator vtable_component_end() const
static VTableComponent MakeUnusedFunction(const CXXMethodDecl *MD)
static VTableComponent getFromOpaqueInteger(uint64_t I)
static VTableComponent MakeVCallOffset(CharUnits Offset)
const CXXRecordDecl * getVBaseWithVPtr() const
The vptr is stored inside the non-virtual component of this virtual base.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
BasePath PathToBaseWithVPtr
uint64_t getNumVTableComponents() const
VTableLayout(uint64_t NumVTableComponents, const VTableComponent *VTableComponents, uint64_t NumVTableThunks, const VTableThunkTy *VTableThunks, const AddressPointsMapTy &AddressPoints, bool IsMicrosoftABI)
static VTableComponent MakeCompleteDtor(const CXXDestructorDecl *DD)
llvm::DenseMap< const CXXRecordDecl *, unsigned > VBTableIndices
const VTableComponent * vtable_component_iterator
const Decl * getDecl() const
const CXXRecordDecl * NextBaseToMangle
uint64_t getAddressPoint(BaseSubobject Base) const
const CXXMethodDecl * getFunctionDecl() const
~ItaniumVTableContext() override
llvm::DenseMap< const CXXMethodDecl *, ThunkInfoVectorTy > ThunksMapTy
~MicrosoftVTableContext() override
CharUnits getVCallOffset() const
const CXXRecordDecl * getParent() const
const VPtrInfoVector & getVFPtrOffsets(const CXXRecordDecl *RD)
Enums/classes describing ABI related information about constructors, destructors and thunks...
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase)
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
static VTableComponent MakeDeletingDtor(const CXXDestructorDecl *DD)
uint64_t VBTableIndex
If nonzero, holds the vbtable index of the virtual base with the vfptr.
BasePath ContainingVBases
const CXXRecordDecl * VBase
CXXDtorType getDtorType() const
SmallVector< ThunkInfo, 1 > ThunkInfoVectorTy
static bool classof(const VTableContextBase *VT)
bool operator<(const MethodVFTableLocation &other) const
Represents a C++ destructor within a class.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
vtable_thunk_iterator vtable_thunk_end() const
llvm::DenseMap< BaseSubobject, uint64_t > AddressPointsMapTy
MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase, CharUnits VFPtrOffset, uint64_t Index)
SmallVector< VPtrInfo *, 2 > VPtrInfoVector
The result type of a method or function.
SmallVector< const CXXRecordDecl *, 1 > BasePath
const CXXRecordDecl * ReusingBase
const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD) override
unsigned getVBTableIndex(const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the index of VBase in the vbtable of Derived. VBase must be a morally virtual base of Derived...
const CXXRecordDecl * getRTTIDecl() const
uint64_t getNumVTableThunks() const
virtual ~VTableContextBase()
Represents a single component in a vtable.
Represents a static or instance method of a struct/union/class.
const VTableLayout & getVFTableLayout(const CXXRecordDecl *RD, CharUnits VFPtrOffset)
const CXXDestructorDecl * getDestructorDecl() const
const CXXRecordDecl * BaseWithVPtr
The vptr is stored inside this subobject.
VTableContextBase(bool MS)
MicrosoftVTableContext(ASTContext &Context)
static VTableComponent MakeVBaseOffset(CharUnits Offset)
const VPtrInfoVector & enumerateVBTables(const CXXRecordDecl *RD)
ThunksMapTy Thunks
Contains all thunks that a given method decl will need.
CharUnits getVBaseOffset() const
VPtrInfo(const CXXRecordDecl *RD)
CharUnits NonVirtualOffset
vtable_thunk_iterator vtable_thunk_begin() const
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
Represents a C++ struct/union/class.
std::pair< uint64_t, ThunkInfo > VTableThunkTy
CharUnits FullOffsetInMDC
uint64_t Index
Method's index in the vftable.
A pointer to the deleting destructor.
static VTableComponent MakeFunction(const CXXMethodDecl *MD)
Kind getKind() const
Get the kind of this vtable component.
const AddressPointsMapTy & getAddressPoints() const
const CXXMethodDecl * getUnusedFunctionDecl() const
A pointer to the complete destructor.
An entry that is never used.
const MethodVFTableLocation & getMethodVFTableLocation(GlobalDecl GD)
virtual void computeVTableRelatedInformation(const CXXRecordDecl *RD)=0
static bool classof(const VTableContextBase *VT)
static VTableComponent MakeOffsetToTop(CharUnits Offset)