Debian Codegraph @

clang/lib/CIR/CodeGen/CIRGenVTables.h

raw
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"
17 #include "clang/AST/GlobalDecl.h"
18 #include "clang/AST/VTableBuilder.h"
19 #include "clang/CIR/Dialect/IR/CIRDialect.h"
20
21 namespace clang {
22 class CXXRecordDecl;
23 }
24
25 namespace clang::CIRGen {
26 class CIRGenModule;
27
28 class CIRGenVTables {
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
56 public:
57 CIRGenVTables(CIRGenModule &cgm);
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
66 clang::ItaniumVTableContext &getItaniumVTableContext() {
67 return *llvm::cast<clang::ItaniumVTableContext>(vtContext);
68 }
69
70 const clang::ItaniumVTableContext &getItaniumVTableContext() const {
71 return *llvm::cast<clang::ItaniumVTableContext>(vtContext);
72 }
73
74 /// Generate a construction vtable for the given base subobject.
75 cir::GlobalOp
76 generateConstructionVTable(const CXXRecordDecl *rd, const BaseSubobject &base,
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.
92 uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *rd,
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 bool isVTableExternal(const clang::CXXRecordDecl *rd);
104
105 /// Returns the type of a vtable with the given layout. Normally a struct of
106 /// arrays of pointers, with one struct element for each vtable in the vtable
107 /// group.
108 cir::RecordType getVTableType(const clang::VTableLayout &layout);
109 };
110
111 } // namespace clang::CIRGen
112
113 #endif // CLANG_LIB_CIR_CODEGEN_CIRGENVTABLES_H