mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-04 16:41:43 +00:00
[mlir][bytecodegen] Add ReservedOrDead marker.
Enables reserving or marking dead in enum list, resulting in skipping in dispatches.
This commit is contained in:
parent
ba0aa2ec1c
commit
a9d003ef85
@ -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
|
||||
|
||||
|
26
mlir/test/mlir-tblgen/bytecode-reserved.td
Normal file
26
mlir/test/mlir-tblgen/bytecode-reserved.td
Normal file
@ -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
|
||||
];
|
||||
}
|
||||
|
@ -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";
|
||||
|
Loading…
x
Reference in New Issue
Block a user