[mlir] Enable specifying bytecode producer in mlir-opt. (#182846)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
5
mlir/test/Bytecode/bytecode_producer.mlir
Normal file
5
mlir/test/Bytecode/bytecode_producer.mlir
Normal file
@@ -0,0 +1,5 @@
|
||||
// RUN: mlir-opt %s -emit-bytecode -emit-bytecode-producer="MyCustomProducer" | llvm-strings | FileCheck %s
|
||||
|
||||
// CHECK: MyCustomProducer
|
||||
|
||||
module {}
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user