From 07aa9ae23b8e19c185ec67d56a5157e6d34adb8e Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sat, 29 Feb 2020 06:04:38 +0000 Subject: [PATCH] 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 --- mlir/include/mlir/Pass/PassManager.h | 4 ++++ mlir/lib/Pass/IRPrinting.cpp | 3 +++ mlir/lib/Pass/Pass.cpp | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h index c770177..3117d0f 100644 --- a/mlir/include/mlir/Pass/PassManager.h +++ b/mlir/include/mlir/Pass/PassManager.h @@ -139,6 +139,10 @@ public: /// 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 0374b00..b1792c4 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 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(std::move(config))); } diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp index 41adb62..68be02e 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. -- 2.7.4