[Mlir-commits] [mlir] [mlir] Apply the default --split-input-file marker after parsing (PR #226361)
Fangrui Song
llvmlistbot at llvm.org
Thu Sep 24 22:33:33 PDT 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/226361
A bare --split-input-file selects the default marker. Apply it after
cl::ParseCommandLineOptions instead of using cl::callback, which will be
removed to enable migration to TableGen
https://discourse.llvm.org/t/rfc-declare-library-command-line-options-in-tablegen-one-struct-per-library/91877/3
LLM-aided
>From 93999a3c325108321a132d64c013d77866f3d6b3 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 24 Sep 2026 22:08:39 -0700
Subject: [PATCH] [mlir] Apply the default --split-input-file marker after
parsing
A bare --split-input-file selects the default marker. Apply it after
cl::ParseCommandLineOptions instead of using cl::callback, which will be
removed to enable migration to TableGen
https://discourse.llvm.org/t/rfc-declare-library-command-line-options-in-tablegen-one-struct-per-library/91877/3
LLM-aided
---
mlir/lib/Tools/mlir-opt/MlirOptMain.cpp | 15 ++++++++++-----
mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp | 9 +++------
.../Tools/mlir-translate/MlirTranslateMain.cpp | 8 +++-----
mlir/tools/mlir-irdl-to-cpp/mlir-irdl-to-cpp.cpp | 9 +++------
mlir/tools/mlir-pdll/mlir-pdll.cpp | 8 +++-----
5 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 8b49258e135d28..0c1edc818bd3a6 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -150,15 +150,11 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
static cl::opt<std::string, /*ExternalStorage=*/true> splitInputFile{
"split-input-file",
llvm::cl::ValueOptional,
- cl::callback([&](const std::string &str) {
- // Implicit value: use default marker if flag was used without value.
- if (str.empty())
- splitInputFile.setValue(kDefaultSplitMarker);
- }),
cl::desc("Split the input file into chunks using the given or "
"default marker and process each chunk independently"),
cl::location(splitInputFileFlag),
cl::init("")};
+ splitInputFileOption = &splitInputFile;
static cl::opt<std::string, /*ExternalStorage=*/true> outputSplitMarker(
"output-split-marker",
@@ -303,6 +299,11 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
/// Pointer to static dialectPlugins variable in constructor, needed by
/// setDialectPluginsCallback(DialectRegistry&).
cl::list<std::string> *dialectPlugins = nullptr;
+
+ /// Pointer to static splitInputFile variable in constructor, needed by
+ /// createFromCLOptions().
+ cl::opt<std::string, /*ExternalStorage=*/true> *splitInputFileOption =
+ nullptr;
};
/// A scoped diagnostic handler that suppresses certain diagnostics based on
@@ -352,6 +353,10 @@ void MlirOptMainConfig::registerCLOptions(DialectRegistry ®istry) {
MlirOptMainConfig MlirOptMainConfig::createFromCLOptions() {
clOptionsConfig->setDebugConfig(tracing::DebugConfig::createFromCLOptions());
+ // Without a value, --split-input-file selects the default marker.
+ if (clOptionsConfig->splitInputFileOption->getNumOccurrences() &&
+ clOptionsConfig->inputSplitMarker().empty())
+ clOptionsConfig->splitInputFile(kDefaultSplitMarker);
return *clOptionsConfig;
}
diff --git a/mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp b/mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp
index 73591e129b4793..72e4d3b0dec728 100644
--- a/mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp
+++ b/mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp
@@ -51,12 +51,6 @@ LogicalResult mlir::mlirReduceMain(int argc, char **argv,
static llvm::cl::opt<std::string> splitInputFile(
"split-input-file", llvm::cl::ValueOptional,
- llvm::cl::callback([&](const std::string &str) {
- // Implicit value: use default marker if flag was used without
- // value.
- if (str.empty())
- splitInputFile.setValue(kDefaultSplitMarker);
- }),
llvm::cl::desc("Split the input file into chunks using the given or "
"default marker and process each chunk independently"),
llvm::cl::init(""));
@@ -70,6 +64,9 @@ LogicalResult mlir::mlirReduceMain(int argc, char **argv,
PassPipelineCLParser parser("", "Reduction Passes to Run");
llvm::cl::ParseCommandLineOptions(argc, argv,
"MLIR test case reduction tool.\n");
+ // Without a value, --split-input-file selects the default marker.
+ if (splitInputFile.getNumOccurrences() && splitInputFile.empty())
+ splitInputFile.setValue(kDefaultSplitMarker);
if (allowUnregisteredDialects)
context.allowUnregisteredDialects();
diff --git a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
index d9db80afbf3fd8..bbec5429e388c6 100644
--- a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
+++ b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
@@ -155,11 +155,6 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
static llvm::cl::opt<std::string> inputSplitMarker{
"split-input-file", llvm::cl::ValueOptional,
- llvm::cl::callback([&](const std::string &str) {
- // Implicit value: use default marker if flag was used without value.
- if (str.empty())
- inputSplitMarker.setValue(kDefaultSplitMarker);
- }),
llvm::cl::desc("Split the input file into chunks using the given or "
"default marker and process each chunk independently"),
llvm::cl::init("")};
@@ -202,6 +197,9 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
registerTranslationCLOptions();
registerDefaultTimingManagerCLOptions();
llvm::cl::ParseCommandLineOptions(argc, argv, toolName);
+ // Without a value, --split-input-file selects the default marker.
+ if (inputSplitMarker.getNumOccurrences() && inputSplitMarker.empty())
+ inputSplitMarker.setValue(kDefaultSplitMarker);
// Initialize the timing manager.
DefaultTimingManager tm;
diff --git a/mlir/tools/mlir-irdl-to-cpp/mlir-irdl-to-cpp.cpp b/mlir/tools/mlir-irdl-to-cpp/mlir-irdl-to-cpp.cpp
index 4a512bd90874b1..834df9d9afe8db 100644
--- a/mlir/tools/mlir-irdl-to-cpp/mlir-irdl-to-cpp.cpp
+++ b/mlir/tools/mlir-irdl-to-cpp/mlir-irdl-to-cpp.cpp
@@ -87,12 +87,6 @@ static LogicalResult translateIRDLToCpp(int argc, char **argv) {
static llvm::cl::opt<std::string> splitInputFile(
"split-input-file", llvm::cl::ValueOptional,
- llvm::cl::callback([&](const std::string &str) {
- // Implicit value: use default marker if flag was used without
- // value.
- if (str.empty())
- splitInputFile.setValue(kDefaultSplitMarker);
- }),
llvm::cl::desc("Split the input file into chunks using the given or "
"default marker and process each chunk independently"),
llvm::cl::init(""));
@@ -100,6 +94,9 @@ static LogicalResult translateIRDLToCpp(int argc, char **argv) {
llvm::InitLLVM y(argc, argv);
llvm::cl::ParseCommandLineOptions(argc, argv, "mlir-irdl-to-cpp");
+ // Without a value, --split-input-file selects the default marker.
+ if (splitInputFile.getNumOccurrences() && splitInputFile.empty())
+ splitInputFile.setValue(kDefaultSplitMarker);
std::string errorMessage;
std::unique_ptr<llvm::MemoryBuffer> input =
diff --git a/mlir/tools/mlir-pdll/mlir-pdll.cpp b/mlir/tools/mlir-pdll/mlir-pdll.cpp
index 76122a04115139..30b5cb3f90c914 100644
--- a/mlir/tools/mlir-pdll/mlir-pdll.cpp
+++ b/mlir/tools/mlir-pdll/mlir-pdll.cpp
@@ -140,11 +140,6 @@ int main(int argc, char **argv) {
llvm::cl::init(false));
llvm::cl::opt<std::string> inputSplitMarker{
"split-input-file", llvm::cl::ValueOptional,
- llvm::cl::callback([&](const std::string &str) {
- // Implicit value: use default marker if flag was used without value.
- if (str.empty())
- inputSplitMarker.setValue(kDefaultSplitMarker);
- }),
llvm::cl::desc("Split the input file into chunks using the given or "
"default marker and process each chunk independently"),
llvm::cl::init("")};
@@ -180,6 +175,9 @@ int main(int argc, char **argv) {
llvm::InitLLVM y(argc, argv);
llvm::cl::ParseCommandLineOptions(argc, argv, "PDLL Frontend");
+ // Without a value, --split-input-file selects the default marker.
+ if (inputSplitMarker.getNumOccurrences() && inputSplitMarker.empty())
+ inputSplitMarker.setValue(kDefaultSplitMarker);
// Set up the input file.
std::string errorMessage;
More information about the Mlir-commits
mailing list