[Mlir-commits] [mlir] Fix crash in --test-tosa-op-availability when running under the threaded pass manager (PR #183022)

Ayush Kumar Gaur llvmlistbot at llvm.org
Tue Feb 24 01:55:19 PST 2026


https://github.com/Ayush3941 created https://github.com/llvm/llvm-project/pull/183022

whats this Pr does :-
The PR adds a static lock (or lock + buffering) so only one thread prints at once, preventing raw_ostream assertions and garbled output.

>From 4d03f8d72269c00da7e95c5cabe23a9a0a3b6d99 Mon Sep 17 00:00:00 2001
From: Ayush3941 <ayushkgaur1 at gmail.com>
Date: Tue, 24 Feb 2026 04:21:47 -0500
Subject: [PATCH 1/3] [MLIR][TOSA] Serialize outs() in PrintOpAvailability

---
 mlir/test/Dialect/Tosa/op-availability-threading.mlir | 11 +++++++++++
 mlir/test/lib/Dialect/Tosa/TestAvailability.cpp       |  3 +++
 2 files changed, 14 insertions(+)
 create mode 100644 mlir/test/Dialect/Tosa/op-availability-threading.mlir

diff --git a/mlir/test/Dialect/Tosa/op-availability-threading.mlir b/mlir/test/Dialect/Tosa/op-availability-threading.mlir
new file mode 100644
index 0000000000000..edb12b80008d0
--- /dev/null
+++ b/mlir/test/Dialect/Tosa/op-availability-threading.mlir
@@ -0,0 +1,11 @@
+// RUN: env MLIR_NUM_THREADS=8 mlir-opt %s -test-tosa-op-availability > /dev/null
+
+func.func @f0(%arg0: tensor<4xf32>) -> tensor<4xf32> {
+  %0 = tosa.identity %arg0 : (tensor<4xf32>) -> tensor<4xf32>
+  return %0 : tensor<4xf32>
+}
+
+func.func @f1(%arg0: tensor<4xf32>) -> tensor<4xf32> {
+  %0 = tosa.identity %arg0 : (tensor<4xf32>) -> tensor<4xf32>
+  return %0 : tensor<4xf32>
+}
\ No newline at end of file
diff --git a/mlir/test/lib/Dialect/Tosa/TestAvailability.cpp b/mlir/test/lib/Dialect/Tosa/TestAvailability.cpp
index bec563d1ec747..8ddebad1240cb 100644
--- a/mlir/test/lib/Dialect/Tosa/TestAvailability.cpp
+++ b/mlir/test/lib/Dialect/Tosa/TestAvailability.cpp
@@ -26,9 +26,12 @@ struct PrintOpAvailability
   StringRef getArgument() const final { return "test-tosa-op-availability"; }
   StringRef getDescription() const final { return "Test Tosa op availability"; }
 };
+  static llvm::sys::SmartRWMutex<true> PrintMutex;
 } // namespace
 
 void PrintOpAvailability::runOnOperation() {
+  llvm::sys::SmartScopedWriter<true> lock(PrintMutex);
+
   auto f = getOperation();
   llvm::outs() << f.getName() << "\n";
 

>From 96157e0dc2c5c15e2077430d51f9a895782207ee Mon Sep 17 00:00:00 2001
From: Ayush3941 <ayushkgaur1 at gmail.com>
Date: Tue, 24 Feb 2026 04:40:58 -0500
Subject: [PATCH 2/3] removed useless test

---
 mlir/test/Dialect/Tosa/op-availability-threading.mlir | 11 -----------
 1 file changed, 11 deletions(-)
 delete mode 100644 mlir/test/Dialect/Tosa/op-availability-threading.mlir

diff --git a/mlir/test/Dialect/Tosa/op-availability-threading.mlir b/mlir/test/Dialect/Tosa/op-availability-threading.mlir
deleted file mode 100644
index edb12b80008d0..0000000000000
--- a/mlir/test/Dialect/Tosa/op-availability-threading.mlir
+++ /dev/null
@@ -1,11 +0,0 @@
-// RUN: env MLIR_NUM_THREADS=8 mlir-opt %s -test-tosa-op-availability > /dev/null
-
-func.func @f0(%arg0: tensor<4xf32>) -> tensor<4xf32> {
-  %0 = tosa.identity %arg0 : (tensor<4xf32>) -> tensor<4xf32>
-  return %0 : tensor<4xf32>
-}
-
-func.func @f1(%arg0: tensor<4xf32>) -> tensor<4xf32> {
-  %0 = tosa.identity %arg0 : (tensor<4xf32>) -> tensor<4xf32>
-  return %0 : tensor<4xf32>
-}
\ No newline at end of file

>From c183104fb1949d241c476bc24b21e254f134160c Mon Sep 17 00:00:00 2001
From: Ayush3941 <ayushkgaur1 at gmail.com>
Date: Tue, 24 Feb 2026 04:53:06 -0500
Subject: [PATCH 3/3] [MLIR][TOSA] Serialize outs() in PrintOpAvailability v2

---
 mlir/test/lib/Dialect/Tosa/TestAvailability.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/test/lib/Dialect/Tosa/TestAvailability.cpp b/mlir/test/lib/Dialect/Tosa/TestAvailability.cpp
index 8ddebad1240cb..9bd13a4518457 100644
--- a/mlir/test/lib/Dialect/Tosa/TestAvailability.cpp
+++ b/mlir/test/lib/Dialect/Tosa/TestAvailability.cpp
@@ -26,7 +26,7 @@ struct PrintOpAvailability
   StringRef getArgument() const final { return "test-tosa-op-availability"; }
   StringRef getDescription() const final { return "Test Tosa op availability"; }
 };
-  static llvm::sys::SmartRWMutex<true> PrintMutex;
+static llvm::sys::SmartRWMutex<true> PrintMutex;
 } // namespace
 
 void PrintOpAvailability::runOnOperation() {



More information about the Mlir-commits mailing list