clang 23.0.0git
CIRGenVTables.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code dealing with C++ code generation of virtual tables.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CLANG_LIB_CIR_CODEGEN_CIRGENVTABLES_H
14#define CLANG_LIB_CIR_CODEGEN_CIRGENVTABLES_H
15
16#include "mlir/IR/Types.h"
20
21namespace clang {
22class CXXRecordDecl;
23}
24
25namespace clang::CIRGen {
26class CIRGenModule;
27
29 CIRGenModule &cgm;
30
31 clang::VTableContextBase *vtContext;
32
33 /// Address points for a single vtable.
34 using VTableAddressPointsMapTy = clang::VTableLayout::AddressPointsMapTy;
35 using BaseSubobjectPairTy =
36 std::pair<const clang::CXXRecordDecl *, clang::BaseSubobject>;
37 using SubVTTIndiciesMapTy = llvm::DenseMap<BaseSubobjectPairTy, uint64_t>;
38
39 /// Contains indices into the various sub-VTTs.
40 SubVTTIndiciesMapTy subVTTIndicies;
41
42 using SecondaryVirtualPointerIndicesMapTy =
43 llvm::DenseMap<BaseSubobjectPairTy, uint64_t>;
44
45 /// Contains the secondary virtual pointer
46 /// indices.
47 SecondaryVirtualPointerIndicesMapTy secondaryVirtualPointerIndices;
48
49 /// Cache for the pure virtual member call function.
50 cir::FuncOp pureVirtualFn = nullptr;
51 /// Cache for the deleted virtual member call function.
52 cir::FuncOp deletedVirtualFn = nullptr;
53
54 mlir::Attribute
55 getVTableComponent(const VTableLayout &layout, unsigned componentIndex,
56 mlir::Attribute rtti, unsigned &nextVTableThunkIndex,
57 unsigned vtableAddressPoint, bool vtableHasLocalLinkage);
58
59 mlir::Type getVTableComponentType();
60
61public:
63
64 /// Add vtable components for the given vtable layout to the given
65 /// global initializer.
66 void createVTableInitializer(cir::GlobalOp &vtable,
67 const clang::VTableLayout &layout,
68 mlir::Attribute rtti,
69 bool vtableHasLocalLinkage);
70
72 return *llvm::cast<clang::ItaniumVTableContext>(vtContext);
73 }
74
76 return *llvm::cast<clang::ItaniumVTableContext>(vtContext);
77 }
78
79 /// Generate a construction vtable for the given base subobject.
80 cir::GlobalOp
82 bool baseIsVirtual, cir::GlobalLinkageKind linkage,
83 VTableAddressPointsMapTy &addressPoints);
84
85 /// Get the address of the VTT for the given record decl.
86 cir::GlobalOp getAddrOfVTT(const CXXRecordDecl *rd);
87
88 /// Emit the definition of the given vtable.
89 void emitVTTDefinition(cir::GlobalOp vttOp, cir::GlobalLinkageKind linkage,
90 const CXXRecordDecl *rd);
91 /// Return the index of the sub-VTT for the base class of the given record
92 /// decl.
93 uint64_t getSubVTTIndex(const CXXRecordDecl *rd, BaseSubobject base);
94
95 /// Return the index in the VTT where the virtual pointer for the given
96 /// subobject is located.
98 BaseSubobject base);
99
100 /// Emit the associated thunks for the given global decl.
101 void emitThunks(GlobalDecl gd);
102
103 /// Emit a thunk for the given global decl if needed, or return an existing
104 /// thunk.
105 cir::FuncOp maybeEmitThunk(GlobalDecl gd, const ThunkInfo &thunkAdjustments,
106 bool forVTable);
107
108 /// Generate all the class data required to be generated upon definition of a
109 /// KeyFunction. This includes the vtable, the RTTI data structure (if RTTI
110 /// is enabled) and the VTT (if the class has virtual bases).
111 void generateClassData(const CXXRecordDecl *rd);
112
114
115 /// Returns the type of a vtable with the given layout. Normally a struct of
116 /// arrays of pointers, with one struct element for each vtable in the vtable
117 /// group.
118 cir::RecordType getVTableType(const clang::VTableLayout &layout);
119};
120
121} // namespace clang::CIRGen
122
123#endif // CLANG_LIB_CIR_CODEGEN_CIRGENVTABLES_H
This class organizes the cross-function state that is used while generating CIR code.
cir::RecordType getVTableType(const clang::VTableLayout &layout)
Returns the type of a vtable with the given layout.
void createVTableInitializer(cir::GlobalOp &vtable, const clang::VTableLayout &layout, mlir::Attribute rtti, bool vtableHasLocalLinkage)
Add vtable components for the given vtable layout to the given global initializer.
cir::GlobalOp generateConstructionVTable(const CXXRecordDecl *rd, const BaseSubobject &base, bool baseIsVirtual, cir::GlobalLinkageKind linkage, VTableAddressPointsMapTy &addressPoints)
Generate a construction vtable for the given base subobject.
uint64_t getSubVTTIndex(const CXXRecordDecl *rd, BaseSubobject base)
Return the index of the sub-VTT for the base class of the given record decl.
void emitThunks(GlobalDecl gd)
Emit the associated thunks for the given global decl.
void emitVTTDefinition(cir::GlobalOp vttOp, cir::GlobalLinkageKind linkage, const CXXRecordDecl *rd)
Emit the definition of the given vtable.
CIRGenVTables(CIRGenModule &cgm)
cir::FuncOp maybeEmitThunk(GlobalDecl gd, const ThunkInfo &thunkAdjustments, bool forVTable)
Emit a thunk for the given global decl if needed, or return an existing thunk.
const clang::ItaniumVTableContext & getItaniumVTableContext() const
void generateClassData(const CXXRecordDecl *rd)
Generate all the class data required to be generated upon definition of a KeyFunction.
cir::GlobalOp getAddrOfVTT(const CXXRecordDecl *rd)
Get the address of the VTT for the given record decl.
clang::ItaniumVTableContext & getItaniumVTableContext()
bool isVTableExternal(const clang::CXXRecordDecl *rd)
At this point in the translation unit, does it appear that can we rely on the vtable being defined el...
uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *rd, BaseSubobject base)
Return the index in the VTT where the virtual pointer for the given subobject is located.
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
llvm::DenseMap< BaseSubobject, AddressPointLocation > AddressPointsMapTy
The JSON file list parser is used to communicate input to InstallAPI.
The this pointer adjustment as well as an optional return adjustment for a thunk.
Definition Thunk.h:157