[Mlir-commits] [mlir] [mlirbc] Switch generator to enable write's with failures. (PR #182464)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Feb 20 01:49:46 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-llvm

Author: Jacques Pienaar (jpienaar)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/182464.diff


2 Files Affected:

- (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp (+1-1) 
- (modified) mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp (+7-4) 


``````````diff
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp
index 41d1f80580cf7..493078cb883e8 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp
@@ -24,7 +24,7 @@ namespace {
 
 // Provide some forward declarations of the functions that will be generated by
 // the include below.
-static void write(DIExpressionElemAttr attribute,
+static LogicalResult write(DIExpressionElemAttr attribute,
                   DialectBytecodeWriter &writer);
 static LogicalResult writeAttribute(Attribute attribute,
                                     DialectBytecodeWriter &writer);
diff --git a/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp b/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
index a759ad4d68197..7a4b9bd8929d9 100644
--- a/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
@@ -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");
@@ -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);
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/182464


More information about the Mlir-commits mailing list