[mlirbc] Switch generator to enable write's with failures. (#182464)
Previously one had to have a matching case per entry (e.g., one could use a printer predicate, but the assumption was one woujld never fallback) and just always return success.
This commit is contained in:
parent
ed8f080737
commit
32134a64b1
3 changed files with 36 additions and 12 deletions
|
|
@ -22,13 +22,6 @@ using namespace mlir::LLVM;
|
|||
|
||||
namespace {
|
||||
|
||||
// Provide some forward declarations of the functions that will be generated by
|
||||
// the include below.
|
||||
static void write(DIExpressionElemAttr attribute,
|
||||
DialectBytecodeWriter &writer);
|
||||
static LogicalResult writeAttribute(Attribute attribute,
|
||||
DialectBytecodeWriter &writer);
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Optional ArrayRefs
|
||||
//
|
||||
|
|
|
|||
28
mlir/test/mlir-tblgen/bytecode-write.td
Normal file
28
mlir/test/mlir-tblgen/bytecode-write.td
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// RUN: mlir-tblgen -gen-bytecode -bytecode-dialect=Test -I %S/../../include %s 2>&1 | FileCheck %s
|
||||
|
||||
// Test to show fall through behavior.
|
||||
|
||||
include "mlir/IR/BytecodeBase.td"
|
||||
|
||||
def Float64Type : DialectType<(type)> {
|
||||
let printerPredicate = "false";
|
||||
}
|
||||
|
||||
def TestDialectTypes : DialectTypes<"Test"> {
|
||||
let elems = [
|
||||
ReservedOrDead,
|
||||
Float64Type
|
||||
];
|
||||
}
|
||||
|
||||
// CHECK-LABEL: static LogicalResult write(Float64Type type, DialectBytecodeWriter &writer) {
|
||||
// CHECK: if (false) {
|
||||
// CHECK: writer.writeVarInt(/* Float64Type */ 1);
|
||||
// CHECK: return success();
|
||||
// CHECK: }
|
||||
// CHECK: return failure();
|
||||
// CHECK-LABEL: static LogicalResult writeType(Type type,
|
||||
// CHECK: return TypeSwitch<Type, LogicalResult>(type)
|
||||
// CHECK-NEXT: .Case([&](Float64Type t) {
|
||||
// CHECK-NEXT: return write(t, writer);
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ void Generator::emitPrint(StringRef kind, StringRef type,
|
|||
return;
|
||||
|
||||
char const *head =
|
||||
R"(static void write({0} {1}, DialectBytecodeWriter &writer) )";
|
||||
R"(static LogicalResult write({0} {1}, DialectBytecodeWriter &writer) )";
|
||||
mlir::raw_indented_ostream os(output);
|
||||
os << formatv(head, type, kind);
|
||||
auto funScope = os.scope("{\n", "}\n\n");
|
||||
|
|
@ -315,7 +315,7 @@ void Generator::emitPrint(StringRef kind, StringRef type,
|
|||
StringRef pred = rec->getValueAsString("printerPredicate");
|
||||
if (vec.size() > 1 && pred.empty())
|
||||
PrintError(rec->getLoc(),
|
||||
"Requires parsing predicate given common cType");
|
||||
"Requires printing predicate given common cType");
|
||||
}
|
||||
PrintFatalError("Unspecified for shared cType " + type);
|
||||
}
|
||||
|
|
@ -341,10 +341,14 @@ void Generator::emitPrint(StringRef kind, StringRef type,
|
|||
}
|
||||
|
||||
if (!pred.empty()) {
|
||||
os << "return success();\n";
|
||||
os.unindent();
|
||||
os << "}\n";
|
||||
} else {
|
||||
os << "return success();\n";
|
||||
}
|
||||
}
|
||||
os << "return failure();\n";
|
||||
}
|
||||
|
||||
void Generator::emitPrintHelper(const Record *memberRec, StringRef kind,
|
||||
|
|
@ -418,7 +422,7 @@ void Generator::emitPrintDispatch(StringRef kind, ArrayRef<std::string> vec) {
|
|||
|
||||
os << "\n.Case([&](" << type << " t)";
|
||||
auto caseScope = os.scope(" {\n", "})");
|
||||
os << "return write(t, writer), success();\n";
|
||||
os << "return write(t, writer);\n";
|
||||
}
|
||||
os << "\n.Default([&](" << capitalize(kind) << ") { return failure(); });\n";
|
||||
}
|
||||
|
|
@ -475,9 +479,8 @@ static bool emitBCRW(const RecordKeeper &records, raw_ostream &os) {
|
|||
gen.emitParseDispatch(kind, *vec);
|
||||
|
||||
SmallVector<std::string> types;
|
||||
for (const auto &it : perType) {
|
||||
for (const auto &it : perType)
|
||||
types.push_back(it.first);
|
||||
}
|
||||
gen.emitPrintDispatch(kind, types);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue