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

Jacques Pienaar llvmlistbot at llvm.org
Fri Feb 20 01:57:10 PST 2026


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

>From 67e8d9e679a6d4fac446b4623cb78ddeb2748d0a Mon Sep 17 00:00:00 2001
From: Jacques Pienaar <jpienaar at google.com>
Date: Fri, 20 Feb 2026 11:05:54 +0200
Subject: [PATCH 1/2] [mlirbc] Switch generator to enable write's with
 failures.

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).
---
 mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp |  2 +-
 mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp      | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

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);
   }
 

>From 7da32b0d228754bbebff58263721c7066243b1cc Mon Sep 17 00:00:00 2001
From: Jacques Pienaar <jpienaar at google.com>
Date: Fri, 20 Feb 2026 11:53:53 +0200
Subject: [PATCH 2/2] Fixup format

---
 mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp
index 493078cb883e8..d737a5648313c 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialectBytecode.cpp
@@ -25,7 +25,7 @@ namespace {
 // Provide some forward declarations of the functions that will be generated by
 // the include below.
 static LogicalResult write(DIExpressionElemAttr attribute,
-                  DialectBytecodeWriter &writer);
+                           DialectBytecodeWriter &writer);
 static LogicalResult writeAttribute(Attribute attribute,
                                     DialectBytecodeWriter &writer);
 



More information about the Mlir-commits mailing list