[Mlir-commits] [mlir] a9d003e - [mlir][bytecodegen] Add ReservedOrDead marker.

Jacques Pienaar llvmlistbot at llvm.org
Sun Jun 4 14:59:57 PDT 2023


Author: Jacques Pienaar
Date: 2023-06-04T14:59:50-07:00
New Revision: a9d003ef855ff7ed1bf4f8229ee9944b55936e6f

URL: https://github.com/llvm/llvm-project/commit/a9d003ef855ff7ed1bf4f8229ee9944b55936e6f
DIFF: https://github.com/llvm/llvm-project/commit/a9d003ef855ff7ed1bf4f8229ee9944b55936e6f.diff

LOG: [mlir][bytecodegen] Add ReservedOrDead marker.

Enables reserving or marking dead in enum list, resulting in skipping in dispatches.

Added: 
    mlir/test/mlir-tblgen/bytecode-reserved.td

Modified: 
    mlir/include/mlir/IR/BytecodeBase.td
    mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/BytecodeBase.td b/mlir/include/mlir/IR/BytecodeBase.td
index 8cadf978b347a..3164bcad2d6c7 100644
--- a/mlir/include/mlir/IR/BytecodeBase.td
+++ b/mlir/include/mlir/IR/BytecodeBase.td
@@ -155,5 +155,10 @@ class DialectTypes<string d> {
 def attr;
 def type;
 
+// Marker to indicate a skipped attribute or type in the enum. Could either be
+// reserved for a future value or for marking a previously used value as dead.
+def none;
+def ReservedOrDead : DialectAttrOrType<(none)>;
+
 #endif // BYTECODE_BASE
 

diff  --git a/mlir/test/mlir-tblgen/bytecode-reserved.td b/mlir/test/mlir-tblgen/bytecode-reserved.td
new file mode 100644
index 0000000000000..028c529278673
--- /dev/null
+++ b/mlir/test/mlir-tblgen/bytecode-reserved.td
@@ -0,0 +1,26 @@
+// RUN: mlir-tblgen -gen-bytecode -bytecode-dialect=Test -I %S/../../include %s 2>&1 | FileCheck %s
+
+include "mlir/IR/BuiltinDialectBytecode.td"
+
+def TestDialectTypes : DialectTypes<"Test"> {
+// CHECK: static Type readType
+  let elems = [
+// CHECK:      case 0:
+// CHECK-NEXT:   return readIntegerType(context, reader);
+      IntegerType,
+// No case 1 generated as only reserved.
+      ReservedOrDead,
+// CHECK-NEXT: case 2:
+// CHECK-NEXT:   return readIndexType(context, reader);
+      IndexType,
+// CHECK-NEXT: case 3:
+// CHECK-NEXT:   return readBFloat16Type(context, reader);
+      BFloat16Type,
+// No case 4 generated as only reserved.
+      ReservedOrDead,
+// CHECK-NEXT: case 5:
+// CHECK-NEXT:   return readFloat16Type(context, reader);
+      Float16Type
+  ];
+}
+

diff  --git a/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp b/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
index f13bdd49413b0..f4e3e4f1c1605 100644
--- a/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
@@ -106,6 +106,9 @@ void Generator::emitParseDispatch(StringRef kind, ArrayRef<Record *> vec) {
   {
     auto switchScope = os.scope("{\n", "}\n");
     for (const auto &it : llvm::enumerate(vec)) {
+      if (it.value()->getName() == "ReservedOrDead")
+        continue;
+
       os << formatv("case {1}:\n  return read{0}(context, reader);\n",
                     it.value()->getName(), it.index());
     }
@@ -118,6 +121,9 @@ void Generator::emitParseDispatch(StringRef kind, ArrayRef<Record *> vec) {
 }
 
 void Generator::emitParse(StringRef kind, Record &x) {
+  if (x.getNameInitAsString() == "ReservedOrDead")
+    return;
+
   char const *head =
       R"(static {0} read{1}(MLIRContext* context, DialectBytecodeReader &reader) )";
   mlir::raw_indented_ostream os(output);
@@ -282,6 +288,9 @@ void Generator::emitParseHelper(StringRef kind, StringRef returnType,
 
 void Generator::emitPrint(StringRef kind, StringRef type,
                           ArrayRef<std::pair<int64_t, Record *>> vec) {
+  if (type == "ReservedOrDead")
+    return;
+
   char const *head =
       R"(static void write({0} {1}, DialectBytecodeWriter &writer) )";
   mlir::raw_indented_ostream os(output);
@@ -394,6 +403,9 @@ void Generator::emitPrintDispatch(StringRef kind, ArrayRef<std::string> vec) {
      << ")";
   auto switchScope = os.scope("", "");
   for (StringRef type : vec) {
+    if (type == "ReservedOrDead")
+      continue;
+
     os << "\n.Case([&](" << type << " t)";
     auto caseScope = os.scope(" {\n", "})");
     os << "return write(t, writer), success();\n";


        


More information about the Mlir-commits mailing list