[Mlir-commits] [mlir] [MLIR][mlir-opt] Add option to turn off verifier on parsing (PR #116287)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Nov 14 14:03:28 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-core

Author: Thomas Peters (tdp2110)

<details>
<summary>Changes</summary>

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)

---
Full diff: https://github.com/llvm/llvm-project/pull/116287.diff


2 Files Affected:

- (modified) mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h (+10) 
- (modified) mlir/lib/Tools/mlir-opt/MlirOptMain.cpp (+7-2) 


``````````diff
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);

``````````

</details>


https://github.com/llvm/llvm-project/pull/116287


More information about the Mlir-commits mailing list