Skip to content

Commit c62afbf

Browse files
authored
[mlir][linalg][gpu] Clean up printing. NFC. (#136330)
* Use `llvm::interleaved` from #135517 to simplify printing * Avoid needless vector allocations
1 parent 28c0d9d commit c62afbf

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,7 @@ static void printAsyncDependencies(OpAsmPrinter &printer, Operation *op,
451451
return;
452452
if (asyncTokenType)
453453
printer << ' ';
454-
printer << '[';
455-
llvm::interleaveComma(asyncDependencies, printer);
456-
printer << ']';
454+
printer << llvm::interleaved_array(asyncDependencies);
457455
}
458456

459457
// GPU Memory attributions functions shared by LaunchOp and GPUFuncOp.

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp

+13-27
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "llvm/ADT/StringSet.h"
4848
#include "llvm/ADT/TypeSwitch.h"
4949
#include "llvm/Support/FormatVariadic.h"
50+
#include "llvm/Support/InterleavedRange.h"
5051
#include "llvm/Support/LogicalResult.h"
5152
#include "llvm/Support/MathExtras.h"
5253
#include "llvm/Support/raw_ostream.h"
@@ -3660,17 +3661,13 @@ ParseResult MatmulOp::parse(OpAsmParser &parser, OperationState &result) {
36603661
}
36613662

36623663
void MatmulOp::print(OpAsmPrinter &p) {
3663-
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector(
3664+
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector<3>(
36643665
MatmulOp::getDefaultIndexingMaps(getContext()),
36653666
[](AffineMap map) -> Attribute { return AffineMapAttr::get(map); });
3666-
if (!llvm::equal(getIndexingMaps(), indexingMaps)) {
3667-
p << " indexing_maps = [";
3668-
llvm::interleaveComma(getIndexingMaps(), p,
3669-
[&](Attribute attr) { p.printAttribute(attr); });
3670-
p << "]";
3671-
}
3667+
if (!llvm::equal(getIndexingMaps(), indexingMaps))
3668+
p << " indexing_maps = " << llvm::interleaved_array(getIndexingMaps());
36723669

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

37793776
void ContractOp::print(OpAsmPrinter &p) {
3780-
p << " indexing_maps = [";
3781-
llvm::interleaveComma(getIndexingMaps(), p,
3782-
[&](Attribute attr) { p.printAttribute(attr); });
3783-
p << "]";
3777+
p << " indexing_maps = " << llvm::interleaved_array(getIndexingMaps());
37843778
printNamedStructuredOp(
37853779
p, getOperation(), getInputs(), getOutputs(),
37863780
/*elidedAttrs=*/{"indexing_maps", "operandSegmentSizes"});
@@ -4013,17 +4007,13 @@ ParseResult BatchMatmulOp::parse(OpAsmParser &parser, OperationState &result) {
40134007
}
40144008

40154009
void BatchMatmulOp::print(OpAsmPrinter &p) {
4016-
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector(
4010+
SmallVector<Attribute, 3> indexingMaps = llvm::map_to_vector<3>(
40174011
BatchMatmulOp::getDefaultIndexingMaps(getContext()),
40184012
[](AffineMap map) -> Attribute { return AffineMapAttr::get(map); });
4019-
if (!llvm::equal(getIndexingMaps(), indexingMaps)) {
4020-
p << " indexing_maps = [";
4021-
llvm::interleaveComma(getIndexingMaps(), p,
4022-
[&](Attribute attr) { p.printAttribute(attr); });
4023-
p << "]";
4024-
}
4013+
if (!llvm::equal(getIndexingMaps(), indexingMaps))
4014+
p << " indexing_maps = " << llvm::interleaved_array(getIndexingMaps());
40254015

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

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

4212-
if (!llvm::equal(getIndexingMaps(), indexingMaps)) {
4213-
p << " indexing_maps = [";
4214-
llvm::interleaveComma(getIndexingMaps(), p,
4215-
[&](Attribute attr) { p.printAttribute(attr); });
4216-
p << "]";
4217-
}
4202+
if (!llvm::equal(getIndexingMaps(), indexingMaps))
4203+
p << " indexing_maps = " << llvm::interleaved_array(getIndexingMaps());
42184204

42194205
printNamedStructuredOp(p, getOperation(), getInputs(), getOutputs(),
42204206
elidedAttrs);

0 commit comments

Comments
 (0)