-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MLIR][mlir-opt] Add option to turn off verifier on parsing #116287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MLIR][mlir-opt] Add option to turn off verifier on parsing #116287
Conversation
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.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Thomas Peters (tdp2110) ChangesThe MLIR developer guide advocates only verifying local aspects of an operation (see 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 Add a command-line option, This implements the discussion from https://discourse.llvm.org/t/optionally-turn-off-verifier-during-parsing/82805 Full diff: https://github.com/llvm/llvm-project/pull/116287.diff 2 Files Affected:
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);
|
@tdp2110 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
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)