Lines Matching defs:dialect

1 //===- DialectGen.cpp - MLIR dialect definitions generator ----------------===//
36 static llvm::cl::OptionCategory dialectGenCat("Options for -gen-dialect-*");
38 selectedDialect("dialect", llvm::cl::desc("The dialect to gen for"),
41 /// Utility iterator used for filtering records for a specific dialect.
49 Dialect &dialect, const llvm::DagInit *discardableAttrDag,
56 PrintFatalError(dialect.getDef()->getLoc(),
64 /// the given dialect.
67 filterForDialect(ArrayRef<Record *> records, Dialect &dialect) {
69 return T(record).getDialect() == dialect;
78 llvm::errs() << "no dialect was found\n";
82 // Select the dialect to gen for.
87 llvm::errs() << "when more than 1 dialect is present, one must be selected "
88 "via '-dialect'\n";
92 const auto *dialectIt = llvm::find_if(dialects, [](const Dialect &dialect) {
93 return dialect.getName() == selectedDialect;
96 llvm::errs() << "selected dialect with '-dialect' does not exist\n";
106 /// The code block for the start of a dialect class declaration.
108 /// {0}: The name of the dialect class.
109 /// {1}: The dialect namespace.
110 /// {2}: The dialect parent class.
124 /// Registration for a single dependent dialect: to be inserted in the ctor
125 /// above for each dependent dialect.
131 /// Parse an attribute registered to this dialect.
135 /// Print an attribute registered to this dialect.
142 /// Parse a type registered to this dialect.
145 /// Print a type registered to this dialect.
169 /// Provides a hook for verifying dialect attributes attached to the given
177 /// Provides a hook for verifying dialect attributes attached to the given
186 /// Provides a hook for verifying dialect attributes attached to the given
238 /// Generate the declaration for the given dialect class.
239 static void emitDialectDecl(Dialect &dialect, raw_ostream &os) {
242 NamespaceEmitter nsEmitter(os, dialect);
245 std::string cppName = dialect.getCppClassName();
247 dialect.isExtensible() ? "ExtensibleDialect" : "Dialect";
248 os << llvm::formatv(dialectDeclBeginStr, cppName, dialect.getName(),
251 // If the dialect requested the default attribute printer and parser, emit
253 if (dialect.useDefaultAttributePrinterParser())
255 // If the dialect requested the default type printer and parser, emit the
257 if (dialect.useDefaultTypePrinterParser())
260 // Add the decls for the various features of the dialect.
261 if (dialect.hasCanonicalizer())
263 if (dialect.hasConstantMaterializer())
265 if (dialect.hasOperationAttrVerify())
267 if (dialect.hasRegionArgAttrVerify())
269 if (dialect.hasRegionResultAttrVerify())
271 if (dialect.hasOperationInterfaceFallback())
275 dialect.getDiscardableAttributes();
277 populateDiscardableAttributes(dialect, discardableAttrDag,
287 dialect.getName());
290 if (std::optional<StringRef> extraDecl = dialect.getExtraClassDeclaration())
293 // End the dialect decl.
296 if (!dialect.getCppNamespace().empty())
297 os << "MLIR_DECLARE_EXPLICIT_TYPE_ID(" << dialect.getCppNamespace()
298 << "::" << dialect.getCppClassName() << ")\n";
309 std::optional<Dialect> dialect = findDialectToGenerate(dialects);
310 if (!dialect)
312 emitDialectDecl(*dialect, os);
320 /// The code block to generate a dialect constructor definition.
322 /// {0}: The name of the dialect class.
324 /// initialize(), such as dependent dialect registration.
325 /// {2}: The dialect parent class.
339 /// {0}: The name of the dialect class.
345 static void emitDialectDef(Dialect &dialect, const RecordKeeper &records,
347 std::string cppClassName = dialect.getCppClassName();
350 if (!dialect.getCppNamespace().empty())
351 os << "MLIR_DEFINE_EXPLICIT_TYPE_ID(" << dialect.getCppNamespace()
355 NamespaceEmitter nsEmitter(os, dialect);
362 dialect.getDependentDialects(), dialectsOs,
372 dialect.isExtensible() ? "ExtensibleDialect" : "Dialect";
374 const llvm::DagInit *discardableAttrDag = dialect.getDiscardableAttributes();
376 populateDiscardableAttributes(dialect, discardableAttrDag,
389 if (!dialect.hasNonDefaultDestructor())
401 std::optional<Dialect> dialect = findDialectToGenerate(dialects);
402 if (!dialect)
404 emitDialectDef(*dialect, records, os);
413 genDialectDecls("gen-dialect-decls", "Generate dialect declarations",
419 genDialectDefs("gen-dialect-defs", "Generate dialect definitions",