diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h @@ -22,6 +22,7 @@ #include "mlir/Interfaces/DestinationStyleOpInterface.h" #include "mlir/Interfaces/InferTypeOpInterface.h" #include "mlir/Interfaces/ViewLikeInterface.h" +#include "mlir/Support/RawOstreamExtras.h" namespace mlir { namespace linalg { @@ -90,7 +91,7 @@ /// the failed precondition is send to the `errs` stream, if provided. bool isContractionBody(Block &block, function_ref isaPair, - llvm::raw_ostream &errs = llvm::nulls()); + llvm::raw_ostream &errs = mlir::thread_safe_nulls()); /// Result of matching a Linalg generic against the predicates of it being a /// contraction. diff --git a/mlir/include/mlir/Support/RawOstreamExtras.h b/mlir/include/mlir/Support/RawOstreamExtras.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Support/RawOstreamExtras.h @@ -0,0 +1,17 @@ +//===- RawOstreamExtras.h - Extensions to LLVM's raw_ostream.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +namespace llvm { +class raw_ostream; +} // namespace llvm + +namespace mlir { +/// Returns a raw output stream that simply discards the output, but in a +/// thread-safe manner. Similar to llvm::nulls. +llvm::raw_ostream &thread_safe_nulls(); +} // namespace mlir diff --git a/mlir/lib/Support/CMakeLists.txt b/mlir/lib/Support/CMakeLists.txt --- a/mlir/lib/Support/CMakeLists.txt +++ b/mlir/lib/Support/CMakeLists.txt @@ -10,6 +10,7 @@ add_mlir_library(MLIRSupport FileUtilities.cpp InterfaceSupport.cpp + RawOstreamExtras.cpp StorageUniquer.cpp Timing.cpp ToolUtilities.cpp diff --git a/mlir/lib/Support/RawOstreamExtras.cpp b/mlir/lib/Support/RawOstreamExtras.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Support/RawOstreamExtras.cpp @@ -0,0 +1,15 @@ +//===- RawOstreamExtras.cpp - Extensions to LLVM's raw_ostream ------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "mlir/Support/RawOstreamExtras.h" +#include "llvm/Support/raw_ostream.h" + +llvm::raw_ostream &mlir::thread_safe_nulls() { + static thread_local llvm::raw_null_ostream stream; + return stream; +}