From: Jacques Pienaar Date: Sun, 4 Jun 2023 21:59:50 +0000 (-0700) Subject: [mlir][bytecodegen] Add ReservedOrDead marker. X-Git-Tag: upstream/17.0.6~6233 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a9d003ef855ff7ed1bf4f8229ee9944b55936e6f;p=platform%2Fupstream%2Fllvm.git [mlir][bytecodegen] Add ReservedOrDead marker. Enables reserving or marking dead in enum list, resulting in skipping in dispatches. --- diff --git a/mlir/include/mlir/IR/BytecodeBase.td b/mlir/include/mlir/IR/BytecodeBase.td index 8cadf97..3164bca 100644 --- a/mlir/include/mlir/IR/BytecodeBase.td +++ b/mlir/include/mlir/IR/BytecodeBase.td @@ -155,5 +155,10 @@ class DialectTypes { 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 0000000..028c529 --- /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 f13bdd4..f4e3e4f 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 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 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> 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 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";