[clang] [CIR] Add support for emitting vtables (PR #154808)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 22 10:12:13 PDT 2025
================
@@ -33,13 +35,215 @@ mlir::Type CIRGenVTables::getVTableComponentType() {
return cgm.getVTableComponentType();
}
-mlir::Type CIRGenVTables::getVTableType(const VTableLayout &layout) {
+cir::RecordType CIRGenVTables::getVTableType(const VTableLayout &layout) {
SmallVector<mlir::Type, 4> tys;
- auto componentType = getVTableComponentType();
+ mlir::Type componentType = getVTableComponentType();
for (unsigned i = 0, e = layout.getNumVTables(); i != e; ++i)
tys.push_back(cir::ArrayType::get(componentType, layout.getVTableSize(i)));
// FIXME(cir): should VTableLayout be encoded like we do for some
// AST nodes?
return cgm.getBuilder().getAnonRecordTy(tys, /*incomplete=*/false);
}
+
+/// This is a callback from Sema to tell us that a particular vtable is
+/// required to be emitted in this translation unit.
+///
+/// This is only called for vtables that _must_ be emitted (mainly due to key
+/// functions). For weak vtables, CodeGen tracks when they are needed and
+/// emits them as-needed.
+void CIRGenModule::emitVTable(const CXXRecordDecl *rd) {
+ vtables.generateClassData(rd);
+}
+
+void CIRGenVTables::generateClassData(const CXXRecordDecl *rd) {
+ assert(!cir::MissingFeatures::generateDebugInfo());
+
+ if (rd->getNumVBases())
+ cgm.errorNYI(rd->getSourceRange(), "emitVirtualInheritanceTables");
+
+ cgm.getCXXABI().emitVTableDefinitions(*this, rd);
+}
+
+mlir::Attribute CIRGenVTables::getVTableComponent(
+ const VTableLayout &layout, unsigned componentIndex, mlir::Attribute rtti,
+ unsigned &nextVTableThunkIndex, unsigned vtableAddressPoint,
+ bool vtableHasLocalLinkage) {
+ auto &component = layout.vtable_components()[componentIndex];
----------------
Andres-Salamanca wrote:
```suggestion
VTableComponent &component = layout.vtable_components()[componentIndex];
```
I didn’t know what `VTableComponent` was, so the explicit type makes it clearer.
https://github.com/llvm/llvm-project/pull/154808
More information about the cfe-commits
mailing list