================
@@ -1193,6 +1216,45 @@ void
DefGenerator::emitParsePrintDispatch(ArrayRef<AttrOrTypeDef> defs) {
printer.writeDeclTo(indentedOs);
}
+bool DefGenerator::hasRegistrationHook(ArrayRef<AttrOrTypeDef> defs) const {
+ Dialect dialect = defs.front().getDialect();
+ return isAttrGenerator ? dialect.useDefaultAttributeRegistration()
+ : dialect.useDefaultTypeRegistration();
+}
+
+void DefGenerator::emitRegistrationHookDecl(raw_ostream &os,
+ ArrayRef<AttrOrTypeDef> defs,
+ StringRef registrationName) {
+ Dialect dialect = defs.front().getDialect();
+ std::string dialectClass = dialect.getCppClassName();
+ os << "class " << dialectClass << ";\n"
+ << llvm::formatv("/// Registers the {0}s defined in this file with "
+ "`dialect`.\n",
+ valueType.lower())
+ << llvm::formatv("void {0}({1} *dialect);\n",
+ getAttrOrTypeRegistrationHookName(dialect, valueType,
+ registrationName),
+ dialectClass);
+}
+
+/// Emit the hook that registers the defs with their dialect. Registering
+/// requires the definitions of the storage classes, so the hook is defined
+/// alongside the defs. Every set of defs of a dialect must hence use a
distinct
+/// `registrationName` (e.g. the defs of dialect extensions).
+void DefGenerator::emitRegistrationHookDef(ArrayRef<AttrOrTypeDef> defs,
+ StringRef registrationName) {
+ Dialect dialect = defs.front().getDialect();
+ DialectNamespaceEmitter ns(os, dialect);
+ os << llvm::formatv(
+ "void {0}({1} *dialect) {{\n",
+ getAttrOrTypeRegistrationHookName(dialect, valueType, registrationName),
+ dialect.getCppClassName());
+ for (const AttrOrTypeDef &def : defs)
+ os << llvm::formatv(" ::mlir::Abstract{0}::insert<{1}>(*dialect);\n",
----------------
zero9178 wrote:
They are not exactly cheap on a nominal scale but there isn't really a way to
avoid registering types and attributes here :sweat_smile:
We do save a decent bit of compile time here by not using the variadic
`addAttributes` and `addTypes` though!
https://github.com/llvm/llvm-project/pull/243481
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits