aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Peters <thomas.d.peters@gmail.com>2024-11-14 18:23:45 -0500
committerGitHub <noreply@github.com>2024-11-15 00:23:45 +0100
commitaa81c28cd54ec6be370a3a04c8546e9b65a1e6a0 (patch)
tree23f70a003993d446be780b4317eea13005aeb2f4
parentabff8fe2a940212b1c43af2d86a68fc92849f019 (diff)
downloadllvm-aa81c28cd54ec6be370a3a04c8546e9b65a1e6a0.zip
llvm-aa81c28cd54ec6be370a3a04c8546e9b65a1e6a0.tar.gz
llvm-aa81c28cd54ec6be370a3a04c8546e9b65a1e6a0.tar.bz2
[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
-rw-r--r--mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h10
-rw-r--r--mlir/lib/Tools/mlir-opt/MlirOptMain.cpp9
2 files changed, 17 insertions, 2 deletions
diff --git a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
index ef976c1..0e7ee9c 100644
--- a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
+++ b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
@@ -183,6 +183,13 @@ public:
}
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 @@ protected:
/// 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 5a7b176..d6a3669 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);