Skip to content

Commit 07aa9ae

Browse files
author
Mehdi Amini
committed
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
1 parent 692e0c9 commit 07aa9ae

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

mlir/include/mlir/Pass/PassManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ class PassManager : public OpPassManager {
139139
/// Disable support for multi-threading within the pass manager.
140140
void disableMultithreading(bool disable = true);
141141

142+
/// Return true if the pass manager is configured with multi-threading
143+
/// enabled.
144+
bool isMultithreadingEnabled();
145+
142146
/// Enable support for the pass manager to generate a reproducer on the event
143147
/// of a crash or a pass failure. `outputFile` is a .mlir filename used to
144148
/// write the generated reproducer.

mlir/lib/Pass/IRPrinting.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ struct BasicIRPrinterConfig : public PassManager::IRPrinterConfig {
256256
/// Add an instrumentation to print the IR before and after pass execution,
257257
/// using the provided configuration.
258258
void PassManager::enableIRPrinting(std::unique_ptr<IRPrinterConfig> config) {
259+
if (config->shouldPrintAtModuleScope() && isMultithreadingEnabled())
260+
llvm::report_fatal_error("IR printing can't be setup on a pass-manager "
261+
"without disabling multi-threading first.");
259262
addInstrumentation(
260263
std::make_unique<IRPrinterInstrumentation>(std::move(config)));
261264
}

mlir/lib/Pass/Pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ void PassManager::disableMultithreading(bool disable) {
598598
getImpl().disableThreads = disable;
599599
}
600600

601+
bool PassManager::isMultithreadingEnabled() {
602+
return !getImpl().disableThreads;
603+
}
604+
601605
/// Enable support for the pass manager to generate a reproducer on the event
602606
/// of a crash or a pass failure. `outputFile` is a .mlir filename used to write
603607
/// the generated reproducer.

0 commit comments

Comments
 (0)