Skip to content

[mlir][linalg][gpu] Clean up printing. NFC. #136330

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 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,7 @@ static void printAsyncDependencies(OpAsmPrinter &printer, Operation *op,
return;
if (asyncTokenType)
printer << ' ';
printer << '[';
llvm::interleaveComma(asyncDependencies, printer);
printer << ']';
printer << llvm::interleaved_array(asyncDependencies);
}

// GPU Memory attributions functions shared by LaunchOp and GPUFuncOp.
Expand Down
40 changes: 13 additions & 27 deletions mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/InterleavedRange.h"
#include "llvm/Support/LogicalResult.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -3660,17 +3661,13 @@ ParseResult MatmulOp::parse(OpAsmParser &parser, OperationState &result) {
}

void MatmulOp::print(OpAsmPrinter &p) {
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector(
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector<3>(
MatmulOp::getDefaultIndexingMaps(getContext()),
[](AffineMap map) -> Attribute { return AffineMapAttr::get(map); });
if (!llvm::equal(getIndexingMaps(), indexingMaps)) {
p << " indexing_maps = [";
llvm::interleaveComma(getIndexingMaps(), p,
[&](Attribute attr) { p.printAttribute(attr); });
p << "]";
}
if (!llvm::equal(getIndexingMaps(), indexingMaps))
p << " indexing_maps = " << llvm::interleaved_array(getIndexingMaps());

SmallVector<StringRef, 3> elidedAttrs = {
std::array<StringRef, 3> elidedAttrs = {
"operandSegmentSizes", "linalg.memoized_indexing_maps", "indexing_maps"};
printNamedStructuredOp(p, getOperation(), getInputs(), getOutputs(),
elidedAttrs);
Expand Down Expand Up @@ -3777,10 +3774,7 @@ ParseResult ContractOp::parse(OpAsmParser &parser, OperationState &result) {
}

void ContractOp::print(OpAsmPrinter &p) {
p << " indexing_maps = [";
llvm::interleaveComma(getIndexingMaps(), p,
[&](Attribute attr) { p.printAttribute(attr); });
p << "]";
p << " indexing_maps = " << llvm::interleaved_array(getIndexingMaps());
printNamedStructuredOp(
p, getOperation(), getInputs(), getOutputs(),
/*elidedAttrs=*/{"indexing_maps", "operandSegmentSizes"});
Expand Down Expand Up @@ -4013,17 +4007,13 @@ ParseResult BatchMatmulOp::parse(OpAsmParser &parser, OperationState &result) {
}

void BatchMatmulOp::print(OpAsmPrinter &p) {
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector(
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector<3>(
BatchMatmulOp::getDefaultIndexingMaps(getContext()),
[](AffineMap map) -> Attribute { return AffineMapAttr::get(map); });
if (!llvm::equal(getIndexingMaps(), indexingMaps)) {
p << " indexing_maps = [";
llvm::interleaveComma(getIndexingMaps(), p,
[&](Attribute attr) { p.printAttribute(attr); });
p << "]";
}
if (!llvm::equal(getIndexingMaps(), indexingMaps))
p << " indexing_maps = " << llvm::interleaved_array(getIndexingMaps());

SmallVector<StringRef, 3> elidedAttrs = {
std::array<StringRef, 3> elidedAttrs = {
"operandSegmentSizes", "linalg.memoized_indexing_maps", "indexing_maps"};
::printNamedStructuredOp(p, getOperation(), getInputs(), getOutputs(),
elidedAttrs);
Expand Down Expand Up @@ -4204,17 +4194,13 @@ void ElementwiseOp::print(OpAsmPrinter &p) {
getArityGroupAsUInt(getArityGroupAndKind(getKind()).arityGroup);
unsigned numDims = getResultRank();

SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector(
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector<3>(
ElementwiseOp::getDefaultIndexingMaps(arity + 1 /*output*/, numDims,
getContext()),
[](AffineMap map) -> Attribute { return AffineMapAttr::get(map); });

if (!llvm::equal(getIndexingMaps(), indexingMaps)) {
p << " indexing_maps = [";
llvm::interleaveComma(getIndexingMaps(), p,
[&](Attribute attr) { p.printAttribute(attr); });
p << "]";
}
if (!llvm::equal(getIndexingMaps(), indexingMaps))
p << " indexing_maps = " << llvm::interleaved_array(getIndexingMaps());

printNamedStructuredOp(p, getOperation(), getInputs(), getOutputs(),
elidedAttrs);
Expand Down
Loading