Commit 07aa9ae2 authored by Mehdi Amini's avatar Mehdi Amini
Browse files

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
parent 692e0c96
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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.
+3 −0
Original line number Diff line number Diff line
@@ -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)));
}
+4 −0
Original line number Diff line number Diff line
@@ -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.