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
This commit is contained in:
Mehdi Amini 2020-02-29 06:04:38 +00:00
parent 692e0c9648
commit 07aa9ae23b
3 changed files with 11 additions and 0 deletions

View File

@ -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.

View File

@ -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)));
}

View File

@ -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.