Skip to content

[mlir][transform] Clean up prints. NFC. #136401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2025
Merged

Conversation

kuhar
Copy link
Member

@kuhar kuhar commented Apr 19, 2025

Use llvm::interleaved from #135517 to simplify printing.

Use `llvm::interleaved` from llvm#135517 to simplify printing.
@llvmbot
Copy link
Member

llvmbot commented Apr 19, 2025

@llvm/pr-subscribers-mlir-gpu

@llvm/pr-subscribers-mlir

Author: Jakub Kuderski (kuhar)

Changes

Use llvm::interleaved from #135517 to simplify printing.


Full diff: https://github.com/llvm/llvm-project/pull/136401.diff

6 Files Affected:

  • (modified) mlir/lib/Dialect/GPU/TransformOps/Utils.cpp (+20-28)
  • (modified) mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp (+2-1)
  • (modified) mlir/lib/Dialect/Transform/IR/TransformOps.cpp (+3-5)
  • (modified) mlir/lib/Dialect/Transform/Interfaces/MatchInterfaces.cpp (+3-2)
  • (modified) mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp (+7-5)
  • (modified) mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp (+2-3)
diff --git a/mlir/lib/Dialect/GPU/TransformOps/Utils.cpp b/mlir/lib/Dialect/GPU/TransformOps/Utils.cpp
index f5a6d0893d9a9..9853e80828390 100644
--- a/mlir/lib/Dialect/GPU/TransformOps/Utils.cpp
+++ b/mlir/lib/Dialect/GPU/TransformOps/Utils.cpp
@@ -34,6 +34,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/InterleavedRange.h"
 
 using namespace mlir;
 using namespace mlir::gpu;
@@ -50,10 +51,8 @@ using namespace mlir::transform::gpu;
 template <typename ThreadOrBlockIdOp>
 static Value buildLinearId(RewriterBase &rewriter, Location loc,
                            ArrayRef<OpFoldResult> originalBasisOfr) {
-  LLVM_DEBUG(llvm::interleaveComma(
-                 originalBasisOfr,
-                 DBGS() << "----buildLinearId with originalBasisOfr:  ");
-             llvm::dbgs() << "\n");
+  LLVM_DEBUG(DBGS() << "----buildLinearId with originalBasisOfr:  "
+                    << llvm::interleaved(originalBasisOfr) << "\n");
   assert(originalBasisOfr.size() == 3 && "expected 3 sizes");
   IndexType indexType = rewriter.getIndexType();
   AffineExpr tx, ty, tz, bdx, bdy;
@@ -99,32 +98,25 @@ static GpuIdBuilderFnType commonLinearIdBuilderFn(int64_t multiplicity = 1) {
           affine::makeComposedAffineApply(rewriter, loc, e, {scaledLinearId}));
     }
 
-    // clang-format off
-      LLVM_DEBUG(llvm::interleaveComma(reverseBasisSizes,
-                                       DBGS() << "--delinearization basis: ");
-                 llvm::dbgs() << "\n";
-                 llvm::interleaveComma(strides,
-                                       DBGS() << "--delinearization strides: ");
-                 llvm::dbgs() << "\n";
-                 llvm::interleaveComma(delinearizingExprs,
-                                       DBGS() << "--delinearization exprs: ");
-                 llvm::dbgs() << "\n";
-                 llvm::interleaveComma(ids, DBGS() << "--ids: ");
-                 llvm::dbgs() << "\n";);
-    // clang-format on
+    LLVM_DEBUG(DBGS() << "--delinearization basis: "
+                      << llvm::interleaved(reverseBasisSizes) << "\n";
+               DBGS() << "--delinearization strides: "
+                      << llvm::interleaved(strides) << "\n";
+               DBGS() << "--delinearization exprs: "
+                      << llvm::interleaved(delinearizingExprs) << "\n";
+               DBGS() << "--ids: " << llvm::interleaved(ids) << "\n");
 
     // Return n-D ids for indexing and 1-D size + id for predicate generation.
-      return IdBuilderResult{
-          /*mappingIdOps=*/ids,
-          /*availableMappingSizes=*/
-          SmallVector<int64_t>{computeProduct(originalBasis)},
-          // `forallMappingSizes` iterate in the scaled basis, they need to be
-          // scaled back into the original basis to provide tight
-          // activeMappingSizes quantities for predication.
-          /*activeMappingSizes=*/
-          SmallVector<int64_t>{computeProduct(forallMappingSizes) *
-                               multiplicity},
-          /*activeIdOps=*/SmallVector<Value>{cast<Value>(linearId)}};
+    return IdBuilderResult{
+        /*mappingIdOps=*/ids,
+        /*availableMappingSizes=*/
+        SmallVector<int64_t>{computeProduct(originalBasis)},
+        // `forallMappingSizes` iterate in the scaled basis, they need to be
+        // scaled back into the original basis to provide tight
+        // activeMappingSizes quantities for predication.
+        /*activeMappingSizes=*/
+        SmallVector<int64_t>{computeProduct(forallMappingSizes) * multiplicity},
+        /*activeIdOps=*/SmallVector<Value>{cast<Value>(linearId)}};
   };
 
   return res;
diff --git a/mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp b/mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp
index 7ad017af485f9..7a9f8f4b1b528 100644
--- a/mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp
+++ b/mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp
@@ -11,6 +11,7 @@
 #include "mlir/Dialect/Transform/IR/TransformDialect.h"
 #include "mlir/Dialect/Transform/IR/TransformTypes.h"
 #include "mlir/IR/OpImplementation.h"
+#include "llvm/Support/InterleavedRange.h"
 
 using namespace mlir;
 
@@ -58,7 +59,7 @@ DiagnosedSilenceableFailure transform::DebugEmitParamAsRemarkOp::apply(
   llvm::raw_string_ostream os(str);
   if (getMessage())
     os << *getMessage() << " ";
-  llvm::interleaveComma(state.getParams(getParam()), os);
+  os << llvm::interleaved(state.getParams(getParam()));
   if (!getAnchor()) {
     emitRemark() << str;
     return DiagnosedSilenceableFailure::success();
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index 798853a75441a..4fe89f3f7fb9e 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -41,6 +41,7 @@
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/InterleavedRange.h"
 #include <optional>
 
 #define DEBUG_TYPE "transform-dialect"
@@ -2630,11 +2631,8 @@ static void printSequenceOpOperands(OpAsmPrinter &printer, Operation *op,
     printer << "(";
 
   printer << rootType;
-  if (hasExtras) {
-    printer << ", ";
-    llvm::interleaveComma(extraBindingTypes, printer.getStream());
-    printer << ")";
-  }
+  if (hasExtras)
+    printer << ", " << llvm::interleaved(extraBindingTypes) << ')';
 }
 
 /// Returns `true` if the given op operand may be consuming the handle value in
diff --git a/mlir/lib/Dialect/Transform/Interfaces/MatchInterfaces.cpp b/mlir/lib/Dialect/Transform/Interfaces/MatchInterfaces.cpp
index 783eb137b9aff..38f0dcfa189ff 100644
--- a/mlir/lib/Dialect/Transform/Interfaces/MatchInterfaces.cpp
+++ b/mlir/lib/Dialect/Transform/Interfaces/MatchInterfaces.cpp
@@ -8,6 +8,8 @@
 
 #include "mlir/Dialect/Transform/Interfaces/MatchInterfaces.h"
 
+#include "llvm/Support/InterleavedRange.h"
+
 using namespace mlir;
 
 //===----------------------------------------------------------------------===//
@@ -68,8 +70,7 @@ void transform::printTransformMatchDims(OpAsmPrinter &printer, Operation *op,
   if (isInverted) {
     printer << kDimExceptKeyword << "(";
   }
-  llvm::interleaveComma(rawDimList.asArrayRef(), printer.getStream(),
-                        [&](int64_t value) { printer << value; });
+  printer << llvm::interleaved(rawDimList.asArrayRef());
   if (isInverted) {
     printer << ")";
   }
diff --git a/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp b/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp
index e0a5df0c758b3..c0230e0d11e64 100644
--- a/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp
+++ b/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp
@@ -15,8 +15,10 @@
 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/iterator.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/InterleavedRange.h"
 
 #define DEBUG_TYPE "transform-dialect"
 #define DEBUG_TYPE_FULL "transform-dialect-full"
@@ -486,11 +488,11 @@ void transform::TransformState::recordOpHandleInvalidationOne(
     return;
 
   FULL_LDBG("--recordOpHandleInvalidationOne\n");
-  DEBUG_WITH_TYPE(
-      DEBUG_TYPE_FULL,
-      llvm::interleaveComma(potentialAncestors, DBGS() << "--ancestors: ",
-                            [](Operation *op) { llvm::dbgs() << *op; });
-      llvm::dbgs() << "\n");
+  DEBUG_WITH_TYPE(DEBUG_TYPE_FULL, {
+    (DBGS() << "--ancestors: "
+            << llvm::interleaved(llvm::make_pointee_range(potentialAncestors))
+            << "\n");
+  });
 
   Operation *owner = consumingHandle.getOwner();
   unsigned operandNo = consumingHandle.getOperandNumber();
diff --git a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp
index 9531837625878..721a815cf76b9 100644
--- a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp
+++ b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp
@@ -18,6 +18,7 @@
 #include "mlir/IR/Builders.h"
 #include "mlir/Interfaces/FunctionInterfaces.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Support/InterleavedRange.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace mlir {
@@ -58,9 +59,7 @@ struct Layout {
 };
 
 void Layout::print(llvm::raw_ostream &os) const {
-  os << "[";
-  llvm::interleaveComma(layout, os);
-  os << "]";
+  os << llvm::interleaved_array(layout);
 }
 
 int64_t Layout::operator[](size_t idx) const {

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@kuhar kuhar merged commit 198c5da into llvm:main Apr 19, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants