[Mlir-commits] [mlir] [MLIR][mlir-opt] Add option to turn off verifier on parsing (PR #116287)
Thomas Peters
llvmlistbot at llvm.org
Thu Nov 14 14:02:35 PST 2024
https://github.com/tdp2110 created https://github.com/llvm/llvm-project/pull/116287
The MLIR developer guide advocates only verifying local aspects of an operation (see
https://mlir.llvm.org/getting_started/DeveloperGuide/#ir-verifier). This likely implies that verifiers should be fast.
Sometimes, however, 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. Indeed, mlir-opt already contains the `--verify-each` flag which turns off the verifier in passes, but not in parsing.
Add a command-line option,
`--mlir-very-unsafe-disable-verifier-on-parsing`, which similarly turns off the verifier on parsing.
------
This implements the discussion from https://discourse.llvm.org/t/optionally-turn-off-verifier-during-parsing/82805
CC @joker-eph (thank you)
>From 0d8cc61c531f1cc1bda5ade50f7cb1943b325670 Mon Sep 17 00:00:00 2001
From: Thomas Peters <thomas.d.peters at gmail.com>
Date: Thu, 14 Nov 2024 20:14:05 +0000
Subject: [PATCH] [MLIR][mlir-opt] Add option to turn off verifier on parsing
The MLIR developer guide advocates only verifying local aspects
of an operation (see
https://mlir.llvm.org/getting_started/DeveloperGuide/#ir-verifier).
This likely implies that verifiers should be fast.
Sometimes, however, 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.
Indeed, mlir-opt already contains the `--verify-each` flag which
turns off the verifier in passes, but not in parsing.
Add a command-line option,
`--mlir-very-unsafe-disable-verifier-on-parsing`, which
similarly turns off the verifier on parsing.
---
mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h | 10 ++++++++++
mlir/lib/Tools/mlir-opt/MlirOptMain.cpp | 9 +++++++--
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 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