Skip to content

Commit aa81c28

Browse files
authored
[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
1 parent abff8fe commit aa81c28

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ class MlirOptMainConfig {
183183
}
184184
bool shouldVerifyPasses() const { return verifyPassesFlag; }
185185

186+
/// Set whether to run the verifier on parsing.
187+
MlirOptMainConfig &verifyOnParsing(bool verify) {
188+
disableVerifierOnParsingFlag = !verify;
189+
return *this;
190+
}
191+
bool shouldVerifyOnParsing() const { return !disableVerifierOnParsingFlag; }
192+
186193
/// Set whether to run the verifier after each transformation pass.
187194
MlirOptMainConfig &verifyRoundtrip(bool verify) {
188195
verifyRoundtripFlag = verify;
@@ -252,6 +259,9 @@ class MlirOptMainConfig {
252259
/// Run the verifier after each transformation pass.
253260
bool verifyPassesFlag = true;
254261

262+
/// Disable the verifier on parsing.
263+
bool disableVerifierOnParsingFlag = false;
264+
255265
/// Verify that the input IR round-trips perfectly.
256266
bool verifyRoundtripFlag = false;
257267

mlir/lib/Tools/mlir-opt/MlirOptMain.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
159159
cl::desc("Run the verifier after each transformation pass"),
160160
cl::location(verifyPassesFlag), cl::init(true));
161161

162+
static cl::opt<bool, /*ExternalStorage=*/true> disableVerifyOnParsing(
163+
"mlir-very-unsafe-disable-verifier-on-parsing",
164+
cl::desc("Disable the verifier on parsing (very unsafe)"),
165+
cl::location(disableVerifierOnParsingFlag), cl::init(false));
166+
162167
static cl::opt<bool, /*ExternalStorage=*/true> verifyRoundtrip(
163168
"verify-roundtrip",
164169
cl::desc("Round-trip the IR after parsing and ensure it succeeds"),
@@ -310,7 +315,7 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
310315
OpPrintingFlags().printGenericOpForm().enableDebugInfo());
311316
}
312317
FallbackAsmResourceMap fallbackResourceMap;
313-
ParserConfig parseConfig(&roundtripContext, /*verifyAfterParse=*/true,
318+
ParserConfig parseConfig(&roundtripContext, config.shouldVerifyOnParsing(),
314319
&fallbackResourceMap);
315320
roundtripModule = parseSourceString<Operation *>(buffer, parseConfig);
316321
if (!roundtripModule) {
@@ -377,7 +382,7 @@ performActions(raw_ostream &os,
377382
// untouched.
378383
PassReproducerOptions reproOptions;
379384
FallbackAsmResourceMap fallbackResourceMap;
380-
ParserConfig parseConfig(context, /*verifyAfterParse=*/true,
385+
ParserConfig parseConfig(context, config.shouldVerifyOnParsing(),
381386
&fallbackResourceMap);
382387
if (config.shouldRunReproducer())
383388
reproOptions.attachResourceParser(parseConfig);

0 commit comments

Comments
 (0)