-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use `llvm::interleaved` from llvm#135517 to simplify printing.
@llvm/pr-subscribers-mlir-gpu @llvm/pr-subscribers-mlir Author: Jakub Kuderski (kuhar) ChangesUse Full diff: https://github.com/llvm/llvm-project/pull/136401.diff 6 Files Affected:
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 {
|
kazutakahirata
approved these changes
Apr 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use
llvm::interleaved
from #135517 to simplify printing.