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

This commit is contained in:
Jacques Pienaar
2026-02-27 18:44:38 +02:00
committed by GitHub
parent 2265d3240f
commit 4b10a4c177
5 changed files with 30 additions and 1 deletions

View File

@@ -128,6 +128,17 @@ public:
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 @@ protected:
/// 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;

View File

@@ -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,10 @@ 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 =
producer ? BytecodeWriterConfig(fallbackResourceMap, producer.value())
: BytecodeWriterConfig(fallbackResourceMap);
if (auto v = config.bytecodeVersionToEmit())
writerConfig.setDesiredBytecodeVersion(*v);
if (config.shouldElideResourceDataFromBytecode())

View File

@@ -0,0 +1,5 @@
// RUN: mlir-opt %s -emit-bytecode -emit-bytecode-producer="MyCustomProducer" | llvm-strings | FileCheck %s
// CHECK: MyCustomProducer
module {}

View File

@@ -101,6 +101,7 @@ configure_lit_site_cfg(
)
set(MLIR_TEST_DEPENDS
llvm-strings
mlir-capi-ir-test
mlir-capi-irdl-test
mlir-capi-llvm-test

View File

@@ -187,6 +187,7 @@ for dirs in tool_dirs:
llvm_config.with_environment("PATH", dirs, append_path=True)
tools = [
"llvm-strings",
"mlir-tblgen",
"mlir-translate",
"mlir-lsp-server",