MLIR  22.0.0git
IRDLToCpp.cpp
Go to the documentation of this file.
1 //===- IRDLToCpp.cpp - Converts IRDL definitions to C++ -------------------===//
2 //
3 // Part of the LLVM Project, under the A0ache 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 
11 #include "mlir/Support/LLVM.h"
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/TypeSwitch.h"
17 #include "llvm/Support/FormatVariadic.h"
18 #include "llvm/Support/raw_ostream.h"
19 
20 #include "TemplatingUtils.h"
21 
22 using namespace mlir;
23 
24 constexpr char headerTemplateText[] =
25 #include "Templates/Header.txt"
26  ;
27 
28 constexpr char declarationMacroFlag[] = "GEN_DIALECT_DECL_HEADER";
29 constexpr char definitionMacroFlag[] = "GEN_DIALECT_DEF";
30 
31 namespace {
32 
33 /// The set of strings that can be generated from a Dialect declaraiton
34 struct DialectStrings {
35  std::string dialectName;
36  std::string dialectCppName;
37  std::string dialectCppShortName;
38  std::string dialectBaseTypeName;
39 
40  std::string namespaceOpen;
41  std::string namespaceClose;
42  std::string namespacePath;
43 };
44 
45 /// The set of strings that can be generated from a Type declaraiton
46 struct TypeStrings {
47  StringRef typeName;
48  std::string typeCppName;
49 };
50 
51 /// The set of strings that can be generated from an Operation declaraiton
52 struct OpStrings {
53  StringRef opName;
54  std::string opCppName;
55  SmallVector<std::string> opResultNames;
56  SmallVector<std::string> opOperandNames;
57 };
58 
59 static std::string joinNameList(llvm::ArrayRef<std::string> names) {
60  std::string nameArray;
61  llvm::raw_string_ostream nameArrayStream(nameArray);
62  nameArrayStream << "{\"" << llvm::join(names, "\", \"") << "\"}";
63 
64  return nameArray;
65 }
66 
67 /// Generates the C++ type name for a TypeOp
68 static std::string typeToCppName(irdl::TypeOp type) {
69  return llvm::formatv("{0}Type",
70  convertToCamelFromSnakeCase(type.getSymName(), true));
71 }
72 
73 /// Generates the C++ class name for an OperationOp
74 static std::string opToCppName(irdl::OperationOp op) {
75  return llvm::formatv("{0}Op",
76  convertToCamelFromSnakeCase(op.getSymName(), true));
77 }
78 
79 /// Generates TypeStrings from a TypeOp
80 static TypeStrings getStrings(irdl::TypeOp type) {
81  TypeStrings strings;
82  strings.typeName = type.getSymName();
83  strings.typeCppName = typeToCppName(type);
84  return strings;
85 }
86 
87 /// Generates OpStrings from an OperatioOp
88 static OpStrings getStrings(irdl::OperationOp op) {
89  auto operandOp = op.getOp<irdl::OperandsOp>();
90 
91  auto resultOp = op.getOp<irdl::ResultsOp>();
92 
93  OpStrings strings;
94  strings.opName = op.getSymName();
95  strings.opCppName = opToCppName(op);
96 
97  if (operandOp) {
98  strings.opOperandNames = SmallVector<std::string>(
99  llvm::map_range(operandOp->getNames(), [](Attribute attr) {
100  return llvm::formatv("{0}", cast<StringAttr>(attr));
101  }));
102  }
103 
104  if (resultOp) {
105  strings.opResultNames = SmallVector<std::string>(
106  llvm::map_range(resultOp->getNames(), [](Attribute attr) {
107  return llvm::formatv("{0}", cast<StringAttr>(attr));
108  }));
109  }
110 
111  return strings;
112 }
113 
114 /// Fills a dictionary with values from TypeStrings
115 static void fillDict(irdl::detail::dictionary &dict,
116  const TypeStrings &strings) {
117  dict["TYPE_NAME"] = strings.typeName;
118  dict["TYPE_CPP_NAME"] = strings.typeCppName;
119 }
120 
121 /// Fills a dictionary with values from OpStrings
122 static void fillDict(irdl::detail::dictionary &dict, const OpStrings &strings) {
123  const auto operandCount = strings.opOperandNames.size();
124  const auto resultCount = strings.opResultNames.size();
125 
126  dict["OP_NAME"] = strings.opName;
127  dict["OP_CPP_NAME"] = strings.opCppName;
128  dict["OP_OPERAND_COUNT"] = std::to_string(strings.opOperandNames.size());
129  dict["OP_RESULT_COUNT"] = std::to_string(strings.opResultNames.size());
130  dict["OP_OPERAND_INITIALIZER_LIST"] =
131  operandCount ? joinNameList(strings.opOperandNames) : "{\"\"}";
132  dict["OP_RESULT_INITIALIZER_LIST"] =
133  resultCount ? joinNameList(strings.opResultNames) : "{\"\"}";
134 }
135 
136 /// Fills a dictionary with values from DialectStrings
137 static void fillDict(irdl::detail::dictionary &dict,
138  const DialectStrings &strings) {
139  dict["DIALECT_NAME"] = strings.dialectName;
140  dict["DIALECT_BASE_TYPE_NAME"] = strings.dialectBaseTypeName;
141  dict["DIALECT_CPP_NAME"] = strings.dialectCppName;
142  dict["DIALECT_CPP_SHORT_NAME"] = strings.dialectCppShortName;
143  dict["NAMESPACE_OPEN"] = strings.namespaceOpen;
144  dict["NAMESPACE_CLOSE"] = strings.namespaceClose;
145  dict["NAMESPACE_PATH"] = strings.namespacePath;
146 }
147 
148 static LogicalResult generateTypedefList(irdl::DialectOp &dialect,
149  SmallVector<std::string> &typeNames) {
150  auto typeOps = dialect.getOps<irdl::TypeOp>();
151  auto range = llvm::map_range(typeOps, typeToCppName);
152  typeNames = SmallVector<std::string>(range);
153  return success();
154 }
155 
156 static LogicalResult generateOpList(irdl::DialectOp &dialect,
157  SmallVector<std::string> &opNames) {
158  auto operationOps = dialect.getOps<irdl::OperationOp>();
159  auto range = llvm::map_range(operationOps, opToCppName);
160  opNames = SmallVector<std::string>(range);
161  return success();
162 }
163 
164 } // namespace
165 
166 static LogicalResult generateTypeInclude(irdl::TypeOp type, raw_ostream &output,
167  irdl::detail::dictionary &dict) {
168  static const auto typeDeclTemplate = irdl::detail::Template(
169 #include "Templates/TypeDecl.txt"
170  );
171 
172  fillDict(dict, getStrings(type));
173  typeDeclTemplate.render(output, dict);
174 
175  return success();
176 }
177 
179  const OpStrings &opStrings) {
180  auto opGetters = std::string{};
181  auto resGetters = std::string{};
182 
183  for (size_t i = 0, end = opStrings.opOperandNames.size(); i < end; ++i) {
184  const auto op =
185  llvm::convertToCamelFromSnakeCase(opStrings.opOperandNames[i], true);
186  opGetters += llvm::formatv("::mlir::Value get{0}() { return "
187  "getStructuredOperands({1}).front(); }\n ",
188  op, i);
189  }
190  for (size_t i = 0, end = opStrings.opResultNames.size(); i < end; ++i) {
191  const auto op =
192  llvm::convertToCamelFromSnakeCase(opStrings.opResultNames[i], true);
193  resGetters += llvm::formatv(
194  R"(::mlir::Value get{0}() { return ::llvm::cast<::mlir::Value>(getStructuredResults({1}).front()); }
195  )",
196  op, i);
197  }
198 
199  dict["OP_OPERAND_GETTER_DECLS"] = opGetters;
200  dict["OP_RESULT_GETTER_DECLS"] = resGetters;
201 }
202 
204  const OpStrings &opStrings) {
205  std::string buildDecls;
206  llvm::raw_string_ostream stream{buildDecls};
207 
208  auto resultParams =
209  llvm::join(llvm::map_range(opStrings.opResultNames,
210  [](StringRef name) -> std::string {
211  return llvm::formatv(
212  "::mlir::Type {0}, ",
213  llvm::convertToCamelFromSnakeCase(name));
214  }),
215  "");
216 
217  auto operandParams =
218  llvm::join(llvm::map_range(opStrings.opOperandNames,
219  [](StringRef name) -> std::string {
220  return llvm::formatv(
221  "::mlir::Value {0}, ",
222  llvm::convertToCamelFromSnakeCase(name));
223  }),
224  "");
225 
226  stream << llvm::formatv(
227  R"(static void build(::mlir::OpBuilder &opBuilder, ::mlir::OperationState &opState, {0} {1} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
228  resultParams, operandParams);
229  stream << "\n";
230  stream << llvm::formatv(
231  R"(static {0} create(::mlir::OpBuilder &opBuilder, ::mlir::Location location, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
232  opStrings.opCppName, resultParams, operandParams);
233  stream << "\n";
234  stream << llvm::formatv(
235  R"(static {0} create(::mlir::ImplicitLocOpBuilder &opBuilder, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
236  opStrings.opCppName, resultParams, operandParams);
237  stream << "\n";
238  dict["OP_BUILD_DECLS"] = buildDecls;
239 }
240 
241 static LogicalResult generateOperationInclude(irdl::OperationOp op,
242  raw_ostream &output,
243  irdl::detail::dictionary &dict) {
244  static const auto perOpDeclTemplate = irdl::detail::Template(
245 #include "Templates/PerOperationDecl.txt"
246  );
247  const auto opStrings = getStrings(op);
248  fillDict(dict, opStrings);
249 
250  generateOpGetterDeclarations(dict, opStrings);
251  generateOpBuilderDeclarations(dict, opStrings);
252 
253  perOpDeclTemplate.render(output, dict);
254  return success();
255 }
256 
257 static LogicalResult generateInclude(irdl::DialectOp dialect,
258  raw_ostream &output,
259  DialectStrings &dialectStrings) {
260  static const auto dialectDeclTemplate = irdl::detail::Template(
261 #include "Templates/DialectDecl.txt"
262  );
263  static const auto typeHeaderDeclTemplate = irdl::detail::Template(
264 #include "Templates/TypeHeaderDecl.txt"
265  );
266 
268  fillDict(dict, dialectStrings);
269 
270  dialectDeclTemplate.render(output, dict);
271  typeHeaderDeclTemplate.render(output, dict);
272 
273  auto typeOps = dialect.getOps<irdl::TypeOp>();
274  auto operationOps = dialect.getOps<irdl::OperationOp>();
275 
276  for (auto &&typeOp : typeOps) {
277  if (failed(generateTypeInclude(typeOp, output, dict)))
278  return failure();
279  }
280 
281  SmallVector<std::string> opNames;
282  if (failed(generateOpList(dialect, opNames)))
283  return failure();
284 
285  auto classDeclarations =
286  llvm::join(llvm::map_range(opNames,
287  [](llvm::StringRef name) -> std::string {
288  return llvm::formatv("class {0};", name);
289  }),
290  "\n");
291  const auto forwardDeclarations = llvm::formatv(
292  "{1}\n{0}\n{2}", std::move(classDeclarations),
293  dialectStrings.namespaceOpen, dialectStrings.namespaceClose);
294 
295  output << forwardDeclarations;
296  for (auto &&operationOp : operationOps) {
297  if (failed(generateOperationInclude(operationOp, output, dict)))
298  return failure();
299  }
300 
301  return success();
302 }
303 
304 static std::string generateOpDefinition(irdl::detail::dictionary &dict,
305  irdl::OperationOp op) {
306  static const auto perOpDefTemplate = mlir::irdl::detail::Template{
307 #include "Templates/PerOperationDef.txt"
308  };
309 
310  auto opStrings = getStrings(op);
311  fillDict(dict, opStrings);
312 
313  const auto operandCount = opStrings.opOperandNames.size();
314  const auto operandNames =
315  operandCount ? joinNameList(opStrings.opOperandNames) : "{\"\"}";
316 
317  const auto resultNames = joinNameList(opStrings.opResultNames);
318 
319  auto resultTypes = llvm::join(
320  llvm::map_range(opStrings.opResultNames,
321  [](StringRef attr) -> std::string {
322  return llvm::formatv("::mlir::Type {0}, ", attr);
323  }),
324  "");
325  auto operandTypes = llvm::join(
326  llvm::map_range(opStrings.opOperandNames,
327  [](StringRef attr) -> std::string {
328  return llvm::formatv("::mlir::Value {0}, ", attr);
329  }),
330  "");
331  auto operandAdder =
332  llvm::join(llvm::map_range(opStrings.opOperandNames,
333  [](StringRef attr) -> std::string {
334  return llvm::formatv(
335  " opState.addOperands({0});", attr);
336  }),
337  "\n");
338  auto resultAdder = llvm::join(
339  llvm::map_range(opStrings.opResultNames,
340  [](StringRef attr) -> std::string {
341  return llvm::formatv(" opState.addTypes({0});", attr);
342  }),
343  "\n");
344 
345  const auto buildDefinition = llvm::formatv(
346  R"(
347 void {0}::build(::mlir::OpBuilder &opBuilder, ::mlir::OperationState &opState, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {{
348 {3}
349 {4}
350 }
351 
352 {0} {0}::create(::mlir::OpBuilder &opBuilder, ::mlir::Location location, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {{
353  ::mlir::OperationState __state__(location, getOperationName());
354  build(opBuilder, __state__, {5} {6} attributes);
355  auto __res__ = ::llvm::dyn_cast<{0}>(opBuilder.create(__state__));
356  assert(__res__ && "builder didn't return the right type");
357  return __res__;
358 }
359 
360 {0} {0}::create(::mlir::ImplicitLocOpBuilder &opBuilder, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {{
361  return create(opBuilder, opBuilder.getLoc(), {5} {6} attributes);
362 }
363 )",
364  opStrings.opCppName, std::move(resultTypes), std::move(operandTypes),
365  std::move(operandAdder), std::move(resultAdder),
366  llvm::join(opStrings.opResultNames, ",") +
367  (!opStrings.opResultNames.empty() ? "," : ""),
368  llvm::join(opStrings.opOperandNames, ",") +
369  (!opStrings.opOperandNames.empty() ? "," : ""));
370 
371  dict["OP_BUILD_DEFS"] = buildDefinition;
372 
373  std::string str;
374  llvm::raw_string_ostream stream{str};
375  perOpDefTemplate.render(stream, dict);
376  return str;
377 }
378 
379 static std::string
380 generateTypeVerifierCase(StringRef name, const DialectStrings &dialectStrings) {
381  return llvm::formatv(
382  R"(.Case({1}::{0}::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
383 value = {1}::{0}::get(parser.getContext());
384 return ::mlir::success(!!value);
385 }))",
386  name, dialectStrings.namespacePath);
387 }
388 
389 static LogicalResult generateLib(irdl::DialectOp dialect, raw_ostream &output,
390  DialectStrings &dialectStrings) {
391 
392  static const auto typeHeaderDefTemplate = mlir::irdl::detail::Template{
393 #include "Templates/TypeHeaderDef.txt"
394  };
395  static const auto typeDefTemplate = mlir::irdl::detail::Template{
396 #include "Templates/TypeDef.txt"
397  };
398  static const auto dialectDefTemplate = mlir::irdl::detail::Template{
399 #include "Templates/DialectDef.txt"
400  };
401 
403  fillDict(dict, dialectStrings);
404 
405  typeHeaderDefTemplate.render(output, dict);
406 
407  SmallVector<std::string> typeNames;
408  if (failed(generateTypedefList(dialect, typeNames)))
409  return failure();
410 
411  dict["TYPE_LIST"] = llvm::join(
412  llvm::map_range(typeNames,
413  [&dialectStrings](llvm::StringRef name) -> std::string {
414  return llvm::formatv(
415  "{0}::{1}", dialectStrings.namespacePath, name);
416  }),
417  ",\n");
418 
419  auto typeVerifierGenerator =
420  [&dialectStrings](llvm::StringRef name) -> std::string {
421  return generateTypeVerifierCase(name, dialectStrings);
422  };
423 
424  auto typeCase =
425  llvm::join(llvm::map_range(typeNames, typeVerifierGenerator), "\n");
426 
427  dict["TYPE_PARSER"] = llvm::formatv(
428  R"(static ::mlir::OptionalParseResult generatedTypeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type &value) {
429  return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
430  {0}
431  .Default([&](llvm::StringRef keyword, llvm::SMLoc) {{
432  *mnemonic = keyword;
433  return std::nullopt;
434  });
435 })",
436  std::move(typeCase));
437 
438  auto typePrintCase =
439  llvm::join(llvm::map_range(typeNames,
440  [&](llvm::StringRef name) -> std::string {
441  return llvm::formatv(
442  R"(.Case<{1}::{0}>([&](auto t) {
443  printer << {1}::{0}::getMnemonic();
444  return ::mlir::success();
445  }))",
446  name, dialectStrings.namespacePath);
447  }),
448  "\n");
449  dict["TYPE_PRINTER"] = llvm::formatv(
450  R"(static ::llvm::LogicalResult generatedTypePrinter(::mlir::Type def, ::mlir::AsmPrinter &printer) {
451  return ::llvm::TypeSwitch<::mlir::Type, ::llvm::LogicalResult>(def)
452  {0}
453  .Default([](auto) {{ return ::mlir::failure(); });
454 })",
455  std::move(typePrintCase));
456 
457  dict["TYPE_DEFINES"] =
458  join(map_range(typeNames,
459  [&](StringRef name) -> std::string {
460  return formatv("MLIR_DEFINE_EXPLICIT_TYPE_ID({1}::{0})",
461  name, dialectStrings.namespacePath);
462  }),
463  "\n");
464 
465  typeDefTemplate.render(output, dict);
466 
467  auto operations = dialect.getOps<irdl::OperationOp>();
468  SmallVector<std::string> opNames;
469  if (failed(generateOpList(dialect, opNames)))
470  return failure();
471 
472  const auto commaSeparatedOpList = llvm::join(
473  map_range(opNames,
474  [&dialectStrings](llvm::StringRef name) -> std::string {
475  return llvm::formatv("{0}::{1}", dialectStrings.namespacePath,
476  name);
477  }),
478  ",\n");
479 
480  const auto opDefinitionGenerator = [&dict](irdl::OperationOp op) {
481  return generateOpDefinition(dict, op);
482  };
483 
484  const auto perOpDefinitions =
485  llvm::join(llvm::map_range(operations, opDefinitionGenerator), "\n");
486 
487  dict["OP_LIST"] = commaSeparatedOpList;
488  dict["OP_CLASSES"] = perOpDefinitions;
489  output << perOpDefinitions;
490  dialectDefTemplate.render(output, dict);
491 
492  return success();
493 }
494 
495 static LogicalResult verifySupported(irdl::DialectOp dialect) {
496  LogicalResult res = success();
497  dialect.walk([&](mlir::Operation *op) {
498  res =
500  .Case<irdl::DialectOp>(([](irdl::DialectOp) { return success(); }))
501  .Case<irdl::OperationOp>(
502  ([](irdl::OperationOp) { return success(); }))
503  .Case<irdl::TypeOp>(([](irdl::TypeOp) { return success(); }))
504  .Case<irdl::OperandsOp>(([](irdl::OperandsOp op) -> LogicalResult {
505  if (llvm::all_of(
506  op.getVariadicity(), [](irdl::VariadicityAttr attr) {
507  return attr.getValue() == irdl::Variadicity::single;
508  }))
509  return success();
510  return op.emitError("IRDL C++ translation does not yet support "
511  "variadic operations");
512  }))
513  .Case<irdl::ResultsOp>(([](irdl::ResultsOp op) -> LogicalResult {
514  if (llvm::all_of(
515  op.getVariadicity(), [](irdl::VariadicityAttr attr) {
516  return attr.getValue() == irdl::Variadicity::single;
517  }))
518  return success();
519  return op.emitError(
520  "IRDL C++ translation does not yet support variadic results");
521  }))
522  .Case<irdl::AnyOp>(([](irdl::AnyOp) { return success(); }))
523  .Default([](mlir::Operation *op) -> LogicalResult {
524  return op->emitError("IRDL C++ translation does not yet support "
525  "translation of ")
526  << op->getName() << " operation";
527  });
528 
529  if (failed(res))
530  return WalkResult::interrupt();
531 
532  return WalkResult::advance();
533  });
534 
535  return res;
536 }
537 
538 LogicalResult
540  raw_ostream &output) {
541  static const auto typeDefTempl = detail::Template(
542 #include "Templates/TypeDef.txt"
543  );
544 
545  llvm::SmallMapVector<DialectOp, DialectStrings, 2> dialectStringTable;
546 
547  for (auto dialect : dialects) {
548  if (failed(verifySupported(dialect)))
549  return failure();
550 
551  StringRef dialectName = dialect.getSymName();
552 
553  SmallVector<SmallString<8>> namespaceAbsolutePath{{"mlir"}, dialectName};
554  std::string namespaceOpen;
555  std::string namespaceClose;
556  std::string namespacePath;
557  llvm::raw_string_ostream namespaceOpenStream(namespaceOpen);
558  llvm::raw_string_ostream namespaceCloseStream(namespaceClose);
559  llvm::raw_string_ostream namespacePathStream(namespacePath);
560  for (auto &pathElement : namespaceAbsolutePath) {
561  namespaceOpenStream << "namespace " << pathElement << " {\n";
562  namespaceCloseStream << "} // namespace " << pathElement << "\n";
563  namespacePathStream << "::" << pathElement;
564  }
565 
566  std::string cppShortName =
567  llvm::convertToCamelFromSnakeCase(dialectName, true);
568  std::string dialectBaseTypeName = llvm::formatv("{0}Type", cppShortName);
569  std::string cppName = llvm::formatv("{0}Dialect", cppShortName);
570 
571  DialectStrings dialectStrings;
572  dialectStrings.dialectName = dialectName;
573  dialectStrings.dialectBaseTypeName = dialectBaseTypeName;
574  dialectStrings.dialectCppName = cppName;
575  dialectStrings.dialectCppShortName = cppShortName;
576  dialectStrings.namespaceOpen = namespaceOpen;
577  dialectStrings.namespaceClose = namespaceClose;
578  dialectStrings.namespacePath = namespacePath;
579 
580  dialectStringTable[dialect] = std::move(dialectStrings);
581  }
582 
583  // generate the actual header
584  output << headerTemplateText;
585 
586  output << llvm::formatv("#ifdef {0}\n#undef {0}\n", declarationMacroFlag);
587  for (auto dialect : dialects) {
588 
589  auto &dialectStrings = dialectStringTable[dialect];
590  auto &dialectName = dialectStrings.dialectName;
591 
592  if (failed(generateInclude(dialect, output, dialectStrings)))
593  return dialect->emitError("Error in Dialect " + dialectName +
594  " while generating headers");
595  }
596  output << llvm::formatv("#endif // #ifdef {}\n", declarationMacroFlag);
597 
598  output << llvm::formatv("#ifdef {0}\n#undef {0}\n ", definitionMacroFlag);
599  for (auto &dialect : dialects) {
600  auto &dialectStrings = dialectStringTable[dialect];
601  auto &dialectName = dialectStrings.dialectName;
602 
603  if (failed(generateLib(dialect, output, dialectStrings)))
604  return dialect->emitError("Error in Dialect " + dialectName +
605  " while generating library");
606  }
607  output << llvm::formatv("#endif // #ifdef {}\n", definitionMacroFlag);
608 
609  return success();
610 }
static LogicalResult verifySupported(irdl::DialectOp dialect)
Definition: IRDLToCpp.cpp:460
static LogicalResult generateInclude(irdl::DialectOp dialect, raw_ostream &output, DialectStrings &dialectStrings)
Definition: IRDLToCpp.cpp:256
static LogicalResult generateOperationInclude(irdl::OperationOp op, raw_ostream &output, irdl::detail::dictionary &dict)
Definition: IRDLToCpp.cpp:240
static void generateOpGetterDeclarations(irdl::detail::dictionary &dict, const OpStrings &opStrings)
Definition: IRDLToCpp.cpp:178
static void generateOpBuilderDeclarations(irdl::detail::dictionary &dict, const OpStrings &opStrings)
Definition: IRDLToCpp.cpp:202
constexpr char declarationMacroFlag[]
Definition: IRDLToCpp.cpp:28
constexpr char headerTemplateText[]
Definition: IRDLToCpp.cpp:24
static std::string generateTypeVerifierCase(StringRef name, const DialectStrings &dialectStrings)
Definition: IRDLToCpp.cpp:362
static LogicalResult generateTypeInclude(irdl::TypeOp type, raw_ostream &output, irdl::detail::dictionary &dict)
Definition: IRDLToCpp.cpp:166
static LogicalResult generateLib(irdl::DialectOp dialect, raw_ostream &output, DialectStrings &dialectStrings)
Definition: IRDLToCpp.cpp:368
constexpr char definitionMacroFlag[]
Definition: IRDLToCpp.cpp:29
static std::string generateOpDefinition(irdl::detail::dictionary &dict, irdl::OperationOp op)
Definition: IRDLToCpp.cpp:303
Attributes are known-constant values of operations.
Definition: Attributes.h:25
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
Definition: Operation.cpp:267
OperationName getName()
The name of an operation is the key identifier for it.
Definition: Operation.h:119
static WalkResult advance()
Definition: WalkResult.h:47
static WalkResult interrupt()
Definition: WalkResult.h:46
Template Code as used by IRDL-to-Cpp.
llvm::StringMap< llvm::SmallString< 8 > > dictionary
A dictionary stores a mapping of template variable names to their assigned string values.
LogicalResult translateIRDLDialectToCpp(llvm::ArrayRef< irdl::DialectOp > dialects, raw_ostream &output)
Translates an IRDL dialect definition to a C++ definition that can be used with MLIR.
Definition: IRDLToCpp.cpp:504
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition: Remarks.h:491
Include the generated interface declarations.