[Mlir-commits] [mlir] aa81c28 - [MLIR][mlir-opt] Add option to turn off verifier on parsing (#116287)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Nov 14 15:23:49 PST 2024
Author: Thomas Peters
Date: 2024-11-15T00:23:45+01:00
New Revision: aa81c28cd54ec6be370a3a04c8546e9b65a1e6a0
URL: https://github.com/llvm/llvm-project/commit/aa81c28cd54ec6be370a3a04c8546e9b65a1e6a0
DIFF: https://github.com/llvm/llvm-project/commit/aa81c28cd54ec6be370a3a04c8546e9b65a1e6a0.diff
LOG: [MLIR][mlir-opt] Add option to turn off verifier on parsing (#116287)
Sometimes, a developer may not wish to wait for the verifier
(imagine they did not follow the verifier guidelines and chased use-def
chains), or may wish to disable it.
Add a command-line option,
`--mlir-very-unsafe-disable-verifier-on-parsing`, which turns off the
verifier on parsing.
------
This implements the discussion from
https://discourse.llvm.org/t/optionally-turn-off-verifier-during-parsing/82805
Added:
Modified:
mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
index ef976c1155795b..0e7ee9c89cb475 100644
--- a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
+++ b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
@@ -183,6 +183,13 @@ class MlirOptMainConfig {
}
bool shouldVerifyPasses() const { return verifyPassesFlag; }
+ /// Set whether to run the verifier on parsing.
+ MlirOptMainConfig &verifyOnParsing(bool verify) {
+ disableVerifierOnParsingFlag = !verify;
+ return *this;
+ }
+ bool shouldVerifyOnParsing() const { return !disableVerifierOnParsingFlag; }
+
/// Set whether to run the verifier after each transformation pass.
MlirOptMainConfig &verifyRoundtrip(bool verify) {
verifyRoundtripFlag = verify;
@@ -252,6 +259,9 @@ class MlirOptMainConfig {
/// Run the verifier after each transformation pass.
bool verifyPassesFlag = true;
+ /// Disable the verifier on parsing.
+ bool disableVerifierOnParsingFlag = false;
+
/// Verify that the input IR round-trips perfectly.
bool verifyRoundtripFlag = false;
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 5a7b17672c518b..d6a366940bc385 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -159,6 +159,11 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
cl::desc("Run the verifier after each transformation pass"),
cl::location(verifyPassesFlag), cl::init(true));
+ static cl::opt<bool, /*ExternalStorage=*/true> disableVerifyOnParsing(
+ "mlir-very-unsafe-disable-verifier-on-parsing",
+ cl::desc("Disable the verifier on parsing (very unsafe)"),
+ cl::location(disableVerifierOnParsingFlag), cl::init(false));
+
static cl::opt<bool, /*ExternalStorage=*/true> verifyRoundtrip(
"verify-roundtrip",
cl::desc("Round-trip the IR after parsing and ensure it succeeds"),
@@ -310,7 +315,7 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
OpPrintingFlags().printGenericOpForm().enableDebugInfo());
}
FallbackAsmResourceMap fallbackResourceMap;
- ParserConfig parseConfig(&roundtripContext, /*verifyAfterParse=*/true,
+ ParserConfig parseConfig(&roundtripContext, config.shouldVerifyOnParsing(),
&fallbackResourceMap);
roundtripModule = parseSourceString<Operation *>(buffer, parseConfig);
if (!roundtripModule) {
@@ -377,7 +382,7 @@ performActions(raw_ostream &os,
// untouched.
PassReproducerOptions reproOptions;
FallbackAsmResourceMap fallbackResourceMap;
- ParserConfig parseConfig(context, /*verifyAfterParse=*/true,
+ ParserConfig parseConfig(context, config.shouldVerifyOnParsing(),
&fallbackResourceMap);
if (config.shouldRunReproducer())
reproOptions.attachResourceParser(parseConfig);
More information about the Mlir-commits
mailing list