[Mlir-commits] [mlir] 470f3ce - [mlir] Catch the case using ir print without disabling multithread

Kai Sasaki llvmlistbot at llvm.org
Sat Apr 1 23:51:50 PDT 2023


Author: Kai Sasaki
Date: 2023-04-02T15:47:11+09:00
New Revision: 470f3cee3557974bb1820722bf82d86b8909199b

URL: https://github.com/llvm/llvm-project/commit/470f3cee3557974bb1820722bf82d86b8909199b
DIFF: https://github.com/llvm/llvm-project/commit/470f3cee3557974bb1820722bf82d86b8909199b.diff

LOG: [mlir] Catch the case using ir print without disabling multithread

-mlir-print-ir-module-scope option cannot be used without disabling multithread for pass manager. For the usability, we can throw a validation error in mlir-opt instead of assertion failure.

Issue: https://github.com/llvm/llvm-project/issues/61578

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D146785

Added: 
    

Modified: 
    mlir/include/mlir/Pass/PassManager.h
    mlir/lib/Pass/PassManagerOptions.cpp
    mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
    mlir/test/Pass/invalid-pass.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h
index 71982c3f61688..c7cf37af0dc03 100644
--- a/mlir/include/mlir/Pass/PassManager.h
+++ b/mlir/include/mlir/Pass/PassManager.h
@@ -461,7 +461,7 @@ void registerPassManagerCLOptions();
 
 /// Apply any values provided to the pass manager options that were registered
 /// with 'registerPassManagerOptions'.
-void applyPassManagerCLOptions(PassManager &pm);
+LogicalResult applyPassManagerCLOptions(PassManager &pm);
 
 /// Apply any values provided to the timing manager options that were registered
 /// with `registerDefaultTimingManagerOptions`. This is a handy helper function

diff  --git a/mlir/lib/Pass/PassManagerOptions.cpp b/mlir/lib/Pass/PassManagerOptions.cpp
index 7b725b2904b10..ffc53b7e3ed02 100644
--- a/mlir/lib/Pass/PassManagerOptions.cpp
+++ b/mlir/lib/Pass/PassManagerOptions.cpp
@@ -130,9 +130,9 @@ void mlir::registerPassManagerCLOptions() {
   *options;
 }
 
-void mlir::applyPassManagerCLOptions(PassManager &pm) {
+LogicalResult mlir::applyPassManagerCLOptions(PassManager &pm) {
   if (!options.isConstructed())
-    return;
+    return failure();
 
   // Generate a reproducer on crash/failure.
   if (options->reproducerFile.getNumOccurrences())
@@ -143,8 +143,16 @@ void mlir::applyPassManagerCLOptions(PassManager &pm) {
   if (options->passStatistics)
     pm.enableStatistics(options->passStatisticsDisplayMode);
 
+  if (options->printModuleScope && pm.getContext()->isMultithreadingEnabled()) {
+    emitError(UnknownLoc::get(pm.getContext()))
+        << "IR print for module scope can't be setup on a pass-manager "
+           "without disabling multi-threading first.\n";
+    return failure();
+  }
+
   // Add the IR printing instrumentation.
   options->addPrinterInstrumentation(pm);
+  return success();
 }
 
 void mlir::applyDefaultTimingPassManagerCLOptions(PassManager &pm) {

diff  --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 14f702fc999cc..dfc51171b5e4d 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -210,7 +210,8 @@ performActions(raw_ostream &os,
   // Prepare the pass manager, applying command-line and reproducer options.
   PassManager pm(op.get()->getName(), PassManager::Nesting::Implicit);
   pm.enableVerifier(config.shouldVerifyPasses());
-  applyPassManagerCLOptions(pm);
+  if (failed(applyPassManagerCLOptions(pm)))
+    return failure();
   pm.enableTiming(timing);
   if (failed(reproOptions.apply(pm)) || failed(config.setupPassPipeline(pm)))
     return failure();

diff  --git a/mlir/test/Pass/invalid-pass.mlir b/mlir/test/Pass/invalid-pass.mlir
index c9e37cc4984af..649f723aa8f72 100644
--- a/mlir/test/Pass/invalid-pass.mlir
+++ b/mlir/test/Pass/invalid-pass.mlir
@@ -1,6 +1,9 @@
 // RUN: not mlir-opt %s -pass-pipeline='builtin.module(builtin.module(test-module-pass{test-option=a}))' 2>&1 | FileCheck %s
+// RUN: not mlir-opt %s -mlir-print-ir-module-scope -mlir-print-ir-before=cse 2>&1 | FileCheck -check-prefix=PRINT_MODULE_IR_WITH_MULTITHREAD %s
 
 // CHECK: <Pass-Options-Parser>: no such option test-option
 // CHECK: failed to add `test-module-pass` with options `test-option=a`
 // CHECK: failed to add `builtin.module` with options `` to inner pipeline
 module {}
+
+// PRINT_MODULE_IR_WITH_MULTITHREAD: IR print for module scope can't be setup on a pass-manager without disabling multi-threading first.


        


More information about the Mlir-commits mailing list