Skip to content

[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

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 7 additions & 2 deletions mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Loading