[Mlir-commits] [mlir] [mlir] Enable specifying bytecode producer in mlir-opt. (PR #182846)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Feb 23 05:43:05 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Jacques Pienaar (jpienaar)

<details>
<summary>Changes</summary>



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


3 Files Affected:

- (modified) mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h (+14) 
- (modified) mlir/lib/Tools/mlir-opt/MlirOptMain.cpp (+8-1) 
- (added) mlir/test/Bytecode/bytecode_producer.mlir (+5) 


``````````diff
diff --git a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
index 79dfd7a2795f0..7e0b7024608c9 100644
--- a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
+++ b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
@@ -128,6 +128,17 @@ class MlirOptMainConfig {
     return emitBytecodeVersion;
   }
 
+  /// Set the bytecode producer to use.
+  MlirOptMainConfig &emitBytecodeProducer(StringRef producer) {
+    emitBytecodeProducerFlag = producer.str();
+    return *this;
+  }
+  std::optional<StringRef> bytecodeProducerToEmit() const {
+    if (emitBytecodeProducerFlag.empty())
+      return std::nullopt;
+    return emitBytecodeProducerFlag;
+  }
+
   /// Set the callback to populate the pass manager.
   MlirOptMainConfig &
   setPassPipelineSetupFn(std::function<LogicalResult(PassManager &)> callback) {
@@ -309,6 +320,9 @@ class MlirOptMainConfig {
   /// Emit bytecode at given version.
   std::optional<int64_t> emitBytecodeVersion = std::nullopt;
 
+  /// Emit bytecode with given producer.
+  std::string emitBytecodeProducerFlag = "";
+
   /// The callback to populate the pass manager.
   std::function<LogicalResult(PassManager &)> passPipelineCallback;
 
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 560ef6effd2fb..7973f6992621f 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -94,6 +94,11 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
         cl::desc("Elide resources when generating bytecode"),
         cl::location(elideResourceDataFromBytecodeFlag), cl::init(false));
 
+    static cl::opt<std::string, /*ExternalStorage=*/true> emitBytecodeProducer(
+        "emit-bytecode-producer",
+        cl::desc("Use specified producer when generating bytecode output"),
+        cl::location(emitBytecodeProducerFlag), cl::init(""));
+
     static cl::opt<std::optional<int64_t>, /*ExternalStorage=*/true,
                    BytecodeVersionParser>
         bytecodeVersion(
@@ -602,7 +607,9 @@ performActions(raw_ostream &os,
   // Print the output.
   TimingScope outputTiming = timing.nest("Output");
   if (config.shouldEmitBytecode()) {
-    BytecodeWriterConfig writerConfig(fallbackResourceMap);
+    std::optional<StringRef> producer = config.bytecodeProducerToEmit();
+    BytecodeWriterConfig writerConfig(
+        fallbackResourceMap, producer.value_or("MLIR" LLVM_VERSION_STRING));
     if (auto v = config.bytecodeVersionToEmit())
       writerConfig.setDesiredBytecodeVersion(*v);
     if (config.shouldElideResourceDataFromBytecode())
diff --git a/mlir/test/Bytecode/bytecode_producer.mlir b/mlir/test/Bytecode/bytecode_producer.mlir
new file mode 100644
index 0000000000000..5b47e7d210a91
--- /dev/null
+++ b/mlir/test/Bytecode/bytecode_producer.mlir
@@ -0,0 +1,5 @@
+// RUN: mlir-opt %s -emit-bytecode -emit-bytecode-producer="MyCustomProducer" | strings | FileCheck %s
+
+// CHECK: MyCustomProducer
+
+module {}

``````````

</details>


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


More information about the Mlir-commits mailing list