clang 22.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 mlir::Attribute
50 getVTableComponent(const VTableLayout &layout, unsigned componentIndex,
51 mlir::Attribute rtti, unsigned &nextVTableThunkIndex,
52 unsigned vtableAddressPoint, bool vtableHasLocalLinkage);
53
54 mlir::Type getVTableComponentType();
55
56public:
58
59 /// Add vtable components for the given vtable layout to the given
60 /// global initializer.
61 void createVTableInitializer(cir::GlobalOp &vtable,
62 const clang::VTableLayout &layout,
63 mlir::Attribute rtti,
64 bool vtableHasLocalLinkage);
65
67 return *llvm::cast<clang::ItaniumVTableContext>(vtContext);
68 }
69
71 return *llvm::cast<clang::ItaniumVTableContext>(vtContext);
72 }
73
74 /// Generate a construction vtable for the given base subobject.
75 cir::GlobalOp
77 bool baseIsVirtual, cir::GlobalLinkageKind linkage,
78 VTableAddressPointsMapTy &addressPoints);
79
80 /// Get the address of the VTT for the given record decl.
81 cir::GlobalOp getAddrOfVTT(const CXXRecordDecl *rd);
82
83 /// Emit the definition of the given vtable.
84 void emitVTTDefinition(cir::GlobalOp vttOp, cir::GlobalLinkageKind linkage,
85 const CXXRecordDecl *rd);
86 /// Return the index of the sub-VTT for the base class of the given record
87 /// decl.
88 uint64_t getSubVTTIndex(const CXXRecordDecl *rd, BaseSubobject base);
89
90 /// Return the index in the VTT where the virtual pointer for the given
91 /// subobject is located.
93 BaseSubobject base);
94
95 /// Emit the associated thunks for the given global decl.
96 void emitThunks(GlobalDecl gd);
97
98 /// Generate all the class data required to be generated upon definition of a
99 /// KeyFunction. This includes the vtable, the RTTI data structure (if RTTI
100 /// is enabled) and the VTT (if the class has virtual bases).
101 void generateClassData(const CXXRecordDecl *rd);
102
103 /// Returns the type of a vtable with the given layout. Normally a struct of
104 /// arrays of pointers, with one struct element for each vtable in the vtable
105 /// group.
106 cir::RecordType getVTableType(const clang::VTableLayout &layout);
107};
108
109} // namespace clang::CIRGen
110
111#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)
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()
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.