[Mlir-commits] [mlir] eb78b9b - [mlir] Clean up prints with `llvm::interleaved`. NFC. (#136468)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Apr 19 20:00:00 PDT 2025


Author: Jakub Kuderski
Date: 2025-04-19T22:59:57-04:00
New Revision: eb78b9b42f56c59a7fec7fae8f14b570e0a94646

URL: https://github.com/llvm/llvm-project/commit/eb78b9b42f56c59a7fec7fae8f14b570e0a94646
DIFF: https://github.com/llvm/llvm-project/commit/eb78b9b42f56c59a7fec7fae8f14b570e0a94646.diff

LOG: [mlir] Clean up prints with `llvm::interleaved`. NFC. (#136468)

Added: 
    

Modified: 
    mlir/lib/Analysis/FlatLinearValueConstraints.cpp
    mlir/lib/Debug/Observers/ActionLogging.cpp
    mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp
    mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
    mlir/lib/Dialect/Linalg/TransformOps/Syntax.cpp
    mlir/lib/IR/ExtensibleDialect.cpp
    mlir/lib/IR/PDL/PDLPatternMatch.cpp
    mlir/lib/Interfaces/InferTypeOpInterface.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/FlatLinearValueConstraints.cpp b/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
index 6ad39a3a91293..6cc5ec639f448 100644
--- a/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
+++ b/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/InterleavedRange.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 
@@ -1106,9 +1107,9 @@ IntegerSet FlatLinearConstraints::getAsIntegerSet(MLIRContext *context) const {
     }
     if (!noLocalRepVars.empty()) {
       LLVM_DEBUG({
-        llvm::dbgs() << "local variables at position(s) ";
-        llvm::interleaveComma(noLocalRepVars, llvm::dbgs());
-        llvm::dbgs() << " do not have an explicit representation in:\n";
+        llvm::dbgs() << "local variables at position(s) "
+                     << llvm::interleaved(noLocalRepVars)
+                     << " do not have an explicit representation in:\n";
         this->dump();
       });
       return IntegerSet();

diff  --git a/mlir/lib/Debug/Observers/ActionLogging.cpp b/mlir/lib/Debug/Observers/ActionLogging.cpp
index add16e84653e5..9c0d041b0d36f 100644
--- a/mlir/lib/Debug/Observers/ActionLogging.cpp
+++ b/mlir/lib/Debug/Observers/ActionLogging.cpp
@@ -9,6 +9,7 @@
 #include "mlir/Debug/Observers/ActionLogging.h"
 #include "mlir/Debug/BreakpointManager.h"
 #include "mlir/IR/Action.h"
+#include "llvm/Support/InterleavedRange.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -55,11 +56,9 @@ void ActionLogger::beforeExecute(const ActionActiveStack *action,
     action->getAction().print(os);
   else
     os << action->getAction().getTag();
-  if (printIRUnits) {
-    os << " (";
-    interleaveComma(action->getAction().getContextIRUnits(), os);
-    os << ")";
-  }
+  if (printIRUnits)
+    os << " (" << llvm::interleaved(action->getAction().getContextIRUnits())
+       << ")";
   os << "`\n";
 }
 

diff  --git a/mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp b/mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp
index 0657a87d1d1ac..5b569e11388b0 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/InterleavedRange.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cmath>
@@ -44,8 +45,8 @@ transform::gpu::CopyMappingInfo::CopyMappingInfo(MLIRContext *ctx,
          "only 1,2,3-D copies are supported for now");
 
   LDBG("START CopyMappingInfo, favorPredication: " << favorPredication);
-  LLVM_DEBUG(llvm::interleaveComma(copySizes, DBGS() << "--copy shape: ");
-             llvm::dbgs() << "\n";);
+  LLVM_DEBUG(DBGS() << "--copy shape: " << llvm::interleaved(copySizes)
+                    << "\n");
 
   // Greedily find the largest vector size that can be used to copy the most
   // minor dimension: we are in the business of filling kMaxVectorLoadBitWidth
@@ -63,11 +64,10 @@ transform::gpu::CopyMappingInfo::CopyMappingInfo(MLIRContext *ctx,
   if (status == Status::Invalid)
     return;
 
-  LLVM_DEBUG(llvm::interleaveComma(copySizes, DBGS() << "--copy: ");
-             llvm::dbgs() << "\n"; llvm::interleaveComma(
-                 this->numThreads, DBGS() << "--numThreads: ");
-             llvm::dbgs() << "\n";);
-  LDBG("--vectorSize: " << this->vectorSize);
+  LLVM_DEBUG(DBGS() << "--copy: " << llvm::interleaved(copySizes) << "\n"
+                    << "--numThreads: " << llvm::interleaved(this->numThreads)
+                    << "\n"
+                    << "--vectorSize: " << this->vectorSize << "\n");
   assert(this->numThreads.size() == copySizes.size() &&
          "compute copy mapping expected same number of threads and copy sizes");
 
@@ -158,10 +158,8 @@ static SmallVector<int64_t> maximizeNumThreads(ArrayRef<int64_t> sizes,
     int64_t localBest = factor * product(nestedThreadsPerDim);
     if (localBest > best && localBest <= maxNumThreads) {
       LDBG(indent << "new localBest: " << localBest);
-      LLVM_DEBUG(
-          llvm::interleaveComma(nestedThreadsPerDim,
-                                DBGS() << indent << "nestedThreadsPerDim: ");
-          llvm::dbgs() << "\n";);
+      LDBG(indent << "nestedThreadsPerDim: "
+                  << llvm::interleaved(nestedThreadsPerDim));
       localThreadsPerDim.clear();
       localThreadsPerDim.push_back(factor);
       llvm::append_range(localThreadsPerDim, nestedThreadsPerDim);
@@ -170,10 +168,7 @@ static SmallVector<int64_t> maximizeNumThreads(ArrayRef<int64_t> sizes,
   }
 
   LDBG(indent << "found globalBest: " << best);
-  LLVM_DEBUG(llvm::interleaveComma(localThreadsPerDim,
-                                   DBGS() << indent << "numThreads: ");
-             llvm::dbgs() << "\n";);
-
+  LDBG(indent << "numThreads: " << llvm::interleaved(localThreadsPerDim));
   return localThreadsPerDim;
 }
 
@@ -231,10 +226,8 @@ transform::gpu::CopyMappingInfo::inferNumThreadsImpl(
   SmallVector<int64_t> inferredNumThreads =
       maximizeNumThreads(scaledSizes, 0, totalNumThreads);
 
-  LLVM_DEBUG(llvm::interleaveComma(inferredNumThreads,
-                                   DBGS() << "inferred numThreads: ");
-             llvm::dbgs() << "\n";
-             LDBG("computed actualVectorSize: " << desiredVectorSize););
+  LDBG("inferred numThreads: " << llvm::interleaved(inferredNumThreads));
+  LDBG("computed actualVectorSize: " << desiredVectorSize);
 
   // Corner case: we cannot use more threads than available. If the dimension of
   // the copy is so bad it is because higher-level tiling did not do its job, we
@@ -255,13 +248,10 @@ transform::gpu::CopyMappingInfo::inferNumThreadsImpl(
 }
 
 void transform::gpu::CopyMappingInfo::print(llvm::raw_ostream &os) const {
-  os << "MappingInfo{";
-  os << "CopyMappingInfo: ";
-  os << "valid: " << (status != Status::Invalid) << ", ";
-  os << "vectorSize: " << vectorSize << ", ";
-  llvm::interleaveComma(numThreads, os << ", numThreads: {");
-  llvm::interleaveComma(smallestBoundingTileSizes,
-                        os << "}, smallestBoundingTileSizes: {");
-  llvm::interleaveComma(threadMapping, os << "}, threadMapping: {");
-  os << "}}";
+  os << "MappingInfo{"
+     << "CopyMappingInfo: " << "valid: " << (status != Status::Invalid) << ", "
+     << "vectorSize: " << vectorSize << ", numThreads: {"
+     << llvm::interleaved(numThreads) << "}, smallestBoundingTileSizes: {"
+     << llvm::interleaved(smallestBoundingTileSizes) << "}, threadMapping: {"
+     << llvm::interleaved(threadMapping) << "}}";
 }

diff  --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
index 5460f50328a45..67bb1de59dd43 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
@@ -18,6 +18,7 @@
 #include "mlir/Interfaces/FunctionImplementation.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/InterleavedRange.h"
 
 using namespace mlir;
 
@@ -219,14 +220,11 @@ LogicalResult transform::MatchStructuredBodyOp::verify() {
                        getElementwise() + getContraction().has_value();
 
   if (numOptions > 1) {
-    std::string attributeNames;
-    llvm::raw_string_ostream os(attributeNames);
-    llvm::interleaveComma(ArrayRef<StringAttr>{getReductionPositionAttrName(),
-                                               getPassthroughAttrName(),
-                                               getElementwiseAttrName(),
-                                               getContractionAttrName()},
-                          os);
-    return emitOpError() << "only one of {" << attributeNames << "} is allowed";
+    StringAttr attributeNames[] = {
+        getReductionPositionAttrName(), getPassthroughAttrName(),
+        getElementwiseAttrName(), getContractionAttrName()};
+    return emitOpError() << "only one of {" << llvm::interleaved(attributeNames)
+                         << "} is allowed";
   }
 
   if (std::optional<ArrayAttr> contractionAttr = getContraction()) {

diff  --git a/mlir/lib/Dialect/Linalg/TransformOps/Syntax.cpp b/mlir/lib/Dialect/Linalg/TransformOps/Syntax.cpp
index 266c9ad3314a3..e968c73d8e075 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/Syntax.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/Syntax.cpp
@@ -8,6 +8,7 @@
 
 #include "mlir/Dialect/Linalg/TransformOps/Syntax.h"
 #include "mlir/IR/OpImplementation.h"
+#include "llvm/Support/InterleavedRange.h"
 
 using namespace mlir;
 
@@ -67,7 +68,7 @@ void mlir::printSemiFunctionType(OpAsmPrinter &printer, Operation *op,
 
   if (resultType.size() > 1)
     printer << "(";
-  llvm::interleaveComma(resultType, printer.getStream());
+  printer << llvm::interleaved(resultType);
   if (resultType.size() > 1)
     printer << ")";
 }

diff  --git a/mlir/lib/IR/ExtensibleDialect.cpp b/mlir/lib/IR/ExtensibleDialect.cpp
index 8a7d74700006c..3312549ddfcd4 100644
--- a/mlir/lib/IR/ExtensibleDialect.cpp
+++ b/mlir/lib/IR/ExtensibleDialect.cpp
@@ -11,6 +11,7 @@
 #include "mlir/IR/DialectImplementation.h"
 #include "mlir/IR/OperationSupport.h"
 #include "mlir/IR/StorageUniquerSupport.h"
+#include "llvm/Support/InterleavedRange.h"
 
 using namespace mlir;
 
@@ -47,9 +48,7 @@ static void typeOrAttrPrinter(AsmPrinter &printer, ArrayRef<Attribute> params) {
   if (params.empty())
     return;
 
-  printer << "<";
-  interleaveComma(params, printer.getStream());
-  printer << ">";
+  printer << "<" << llvm::interleaved(params) << ">";
 }
 
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/IR/PDL/PDLPatternMatch.cpp b/mlir/lib/IR/PDL/PDLPatternMatch.cpp
index 0d05153bf7dab..28b39dd75e26c 100644
--- a/mlir/lib/IR/PDL/PDLPatternMatch.cpp
+++ b/mlir/lib/IR/PDL/PDLPatternMatch.cpp
@@ -11,6 +11,7 @@
 #include "mlir/IR/Iterators.h"
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/IR/RegionKindInterface.h"
+#include "llvm/Support/InterleavedRange.h"
 
 using namespace mlir;
 
@@ -34,13 +35,13 @@ void PDLValue::print(raw_ostream &os) const {
     os << cast<Type>();
     break;
   case Kind::TypeRange:
-    llvm::interleaveComma(cast<TypeRange>(), os);
+    os << llvm::interleaved(cast<TypeRange>());
     break;
   case Kind::Value:
     os << cast<Value>();
     break;
   case Kind::ValueRange:
-    llvm::interleaveComma(cast<ValueRange>(), os);
+    os << llvm::interleaved(cast<ValueRange>());
     break;
   }
 }

diff  --git a/mlir/lib/Interfaces/InferTypeOpInterface.cpp b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
index 6b5e103cd36c2..9f4f672fb9f4d 100644
--- a/mlir/lib/Interfaces/InferTypeOpInterface.cpp
+++ b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
@@ -15,6 +15,7 @@
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/Matchers.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/InterleavedRange.h"
 
 using namespace mlir;
 
@@ -176,9 +177,8 @@ void ShapeAdaptor::dump() const {
       return "?";
     return llvm::formatv("{0}", dim).str();
   });
-  llvm::errs() << "rank = " << getRank() << " dims = [";
-  llvm::interleave(mapped, llvm::errs(), "x");
-  llvm::errs() << "]\n";
+  llvm::errs() << "rank = " << getRank()
+               << " dims = " << llvm::interleaved_array(mapped, "x") << "\n";
 }
 
 ShapeAdaptor ValueShapeRange::getValueAsShape(int index) {
@@ -243,13 +243,12 @@ LogicalResult mlir::detail::verifyInferredResultTypes(Operation *op) {
 void mlir::detail::reportFatalInferReturnTypesError(OperationState &state) {
   std::string buffer;
   llvm::raw_string_ostream os(buffer);
-  os << "Failed to infer result type(s):\n";
-  os << "\"" << state.name << "\"(...) ";
-  os << state.attributes.getDictionary(state.location.getContext());
-  os << " : (";
-  llvm::interleaveComma(state.operands, os,
-                        [&](Value val) { os << val.getType(); });
-  os << ") -> ( ??? )";
+  os << "Failed to infer result type(s):\n"
+     << "\"" << state.name << "\"(...) "
+     << state.attributes.getDictionary(state.location.getContext()) << " : ("
+     << llvm::interleaved(llvm::map_range(
+            state.operands, [](Value val) { return val.getType(); }))
+     << ") -> ( ??? )";
   emitRemark(state.location, "location of op");
   llvm::report_fatal_error(llvm::StringRef(buffer));
 }


        


More information about the Mlir-commits mailing list