[Mlir-commits] [mlir] 07aa9ae - Ensure that multi-threading is disabled when enabling IRPrinting with module scope

Mehdi Amini llvmlistbot at llvm.org
Sat Feb 29 10:29:52 PST 2020


Author: Mehdi Amini
Date: 2020-02-29T18:28:54Z
New Revision: 07aa9ae23b8e19c185ec67d56a5157e6d34adb8e

URL: https://github.com/llvm/llvm-project/commit/07aa9ae23b8e19c185ec67d56a5157e6d34adb8e
DIFF: https://github.com/llvm/llvm-project/commit/07aa9ae23b8e19c185ec67d56a5157e6d34adb8e.diff

LOG: Ensure that multi-threading is disabled when enabling IRPrinting with module scope

This is avoid the user to shoot themselves in the foot and encounter
strange crashes that are confusing until one run with TSAN.

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

Added: 
    

Modified: 
    mlir/include/mlir/Pass/PassManager.h
    mlir/lib/Pass/IRPrinting.cpp
    mlir/lib/Pass/Pass.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h
index c770177c517b..3117d0f33dc6 100644
--- a/mlir/include/mlir/Pass/PassManager.h
+++ b/mlir/include/mlir/Pass/PassManager.h
@@ -139,6 +139,10 @@ class PassManager : public OpPassManager {
   /// Disable support for multi-threading within the pass manager.
   void disableMultithreading(bool disable = true);
 
+  /// Return true if the pass manager is configured with multi-threading
+  /// enabled.
+  bool isMultithreadingEnabled();
+
   /// Enable support for the pass manager to generate a reproducer on the event
   /// of a crash or a pass failure. `outputFile` is a .mlir filename used to
   /// write the generated reproducer.

diff  --git a/mlir/lib/Pass/IRPrinting.cpp b/mlir/lib/Pass/IRPrinting.cpp
index 0374b00cbe4d..b1792c497620 100644
--- a/mlir/lib/Pass/IRPrinting.cpp
+++ b/mlir/lib/Pass/IRPrinting.cpp
@@ -256,6 +256,9 @@ struct BasicIRPrinterConfig : public PassManager::IRPrinterConfig {
 /// Add an instrumentation to print the IR before and after pass execution,
 /// using the provided configuration.
 void PassManager::enableIRPrinting(std::unique_ptr<IRPrinterConfig> config) {
+  if (config->shouldPrintAtModuleScope() && isMultithreadingEnabled())
+    llvm::report_fatal_error("IR printing can't be setup on a pass-manager "
+                             "without disabling multi-threading first.");
   addInstrumentation(
       std::make_unique<IRPrinterInstrumentation>(std::move(config)));
 }

diff  --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index 41adb623e74d..68be02e7eb1c 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -598,6 +598,10 @@ void PassManager::disableMultithreading(bool disable) {
   getImpl().disableThreads = disable;
 }
 
+bool PassManager::isMultithreadingEnabled() {
+  return !getImpl().disableThreads;
+}
+
 /// Enable support for the pass manager to generate a reproducer on the event
 /// of a crash or a pass failure. `outputFile` is a .mlir filename used to write
 /// the generated reproducer.


        


More information about the Mlir-commits mailing list