Skip to content

Commit bada353

Browse files
committed
[mlir][NFC] Remove unnecessary attr name getters from StructuredOpsUtils.h.
Those methods were added long time ago. Now we get the same methods generated by tablegen, so there is no need for duplicates. Differential Revision: https://reviews.llvm.org/D137544
1 parent 39dbfa7 commit bada353

File tree

4 files changed

+19
-54
lines changed

4 files changed

+19
-54
lines changed

mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,6 @@ bool isColumnMajorMatmul(ArrayAttr indexingMaps);
4848
/// the reduction.
4949
bool isRowMajorBatchMatmul(ArrayAttr indexingMaps);
5050

51-
/// Attribute name for the AffineArrayAttr which encodes the relationship
52-
/// between a structured op iterators' and its operands.
53-
constexpr StringRef getIndexingMapsAttrName() { return "indexing_maps"; }
54-
55-
/// Attribute name for the StrArrayAttr which encodes the type of a structured
56-
/// op's iterators.
57-
constexpr StringRef getIteratorTypesAttrName() { return "iterator_types"; }
58-
59-
/// Attribute name for the StrArrayAttr which encodes the distribution type for
60-
/// `linalg.tiled_loop`.
61-
constexpr StringRef getDistributionTypesAttrName() {
62-
return "distribution_types";
63-
}
64-
65-
/// Attribute name for the StringAttr which encodes an optional documentation
66-
/// string of the structured op.
67-
constexpr StringRef getDocAttrName() { return "doc"; }
68-
69-
/// Attribute name for the StrArrayAttr which encodes the external library
70-
/// function that implements the structured op.
71-
constexpr StringRef getLibraryCallAttrName() { return "library_call"; }
72-
73-
/// Attribute name for the StrArrayAttr which encodes the value of strides.
74-
constexpr StringRef getStridesAttrName() { return "strides"; }
75-
76-
/// Attribute name for the StrArrayAttr which encodes the value of dilations.
77-
constexpr StringRef getDilationsAttrName() { return "dilations"; }
78-
79-
/// Attribute name for the StrArrayAttr which encodes the value of paddings.
80-
constexpr StringRef getPaddingAttrName() { return "padding"; }
81-
8251
/// Use to encode that a particular iterator type has parallel semantics.
8352
constexpr StringRef getParallelIteratorTypeName() { return "parallel"; }
8453

mlir/include/mlir/Dialect/Vector/IR/VectorOps.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def Vector_ContractionOp :
244244
return getOperand(4).getType().cast<VectorType>();
245245
}
246246
Type getResultType() { return getResult().getType(); }
247-
ArrayRef<StringRef> getTraitAttrNames();
247+
SmallVector<StringRef> getTraitAttrNames();
248248
static unsigned getAccOperandIndex() { return 2; }
249249

250250
llvm::SmallVector<::mlir::AffineMap, 4> getIndexingMapsArray() {
@@ -265,8 +265,6 @@ def Vector_ContractionOp :
265265
std::vector<std::pair<int64_t, int64_t>> getContractingDimMap();
266266
std::vector<std::pair<int64_t, int64_t>> getBatchDimMap();
267267

268-
static constexpr StringRef getKindAttrStrName() { return "kind"; }
269-
270268
static CombiningKind getDefaultKind() {
271269
return CombiningKind::ADD;
272270
}

mlir/lib/Dialect/Linalg/Transforms/Interchange.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ mlir::linalg::interchangeGenericOp(RewriterBase &rewriter, GenericOp genericOp,
7373
m = m.compose(permutationMap);
7474
newIndexingMaps.push_back(m);
7575
}
76-
genericOp->setAttr(getIndexingMapsAttrName(),
77-
rewriter.getAffineMapArrayAttr(newIndexingMaps));
76+
genericOp.setIndexingMapsAttr(
77+
rewriter.getAffineMapArrayAttr(newIndexingMaps));
7878

7979
// 3. Compute the interchanged iterator types.
8080
ArrayRef<Attribute> itTypes = genericOp.getIteratorTypes().getValue();
@@ -83,8 +83,7 @@ mlir::linalg::interchangeGenericOp(RewriterBase &rewriter, GenericOp genericOp,
8383
SmallVector<int64_t> permutation(interchangeVector.begin(),
8484
interchangeVector.end());
8585
applyPermutationToVector(itTypesVector, permutation);
86-
genericOp->setAttr(getIteratorTypesAttrName(),
87-
ArrayAttr::get(context, itTypesVector));
86+
genericOp.setIteratorTypesAttr(rewriter.getArrayAttr(itTypesVector));
8887

8988
// 4. Transform the index operations by applying the permutation map.
9089
if (genericOp.hasIndexSemantics()) {

mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,11 @@ void vector::ContractionOp::build(OpBuilder &builder, OperationState &result,
508508
ArrayRef<IteratorType> iteratorTypes) {
509509
result.addOperands({lhs, rhs, acc});
510510
result.addTypes(acc.getType());
511-
result.addAttribute(::mlir::getIndexingMapsAttrName(),
511+
result.addAttribute(getIndexingMapsAttrName(result.name),
512512
builder.getAffineMapArrayAttr(
513513
AffineMap::inferFromExprList(indexingExprs)));
514514
result.addAttribute(
515-
::mlir::getIteratorTypesAttrName(),
515+
getIteratorTypesAttrName(result.name),
516516
builder.getArrayAttr(llvm::to_vector(llvm::map_range(
517517
iteratorTypes, [&](IteratorType t) -> mlir::Attribute {
518518
return IteratorTypeAttr::get(builder.getContext(), t);
@@ -533,9 +533,9 @@ void vector::ContractionOp::build(OpBuilder &builder, OperationState &result,
533533
ArrayAttr iteratorTypes, CombiningKind kind) {
534534
result.addOperands({lhs, rhs, acc});
535535
result.addTypes(acc.getType());
536-
result.addAttribute(::mlir::getIndexingMapsAttrName(), indexingMaps);
537-
result.addAttribute(::mlir::getIteratorTypesAttrName(), iteratorTypes);
538-
result.addAttribute(ContractionOp::getKindAttrStrName(),
536+
result.addAttribute(getIndexingMapsAttrName(result.name), indexingMaps);
537+
result.addAttribute(getIteratorTypesAttrName(result.name), iteratorTypes);
538+
result.addAttribute(getKindAttrName(result.name),
539539
CombiningKindAttr::get(builder.getContext(), kind));
540540
}
541541

@@ -570,7 +570,8 @@ ParseResult ContractionOp::parse(OpAsmParser &parser, OperationState &result) {
570570
// represented as an array of strings.
571571
// TODO: Remove this conversion once tests are fixed.
572572
ArrayAttr iteratorTypes =
573-
result.attributes.get("iterator_types").cast<ArrayAttr>();
573+
result.attributes.get(getIteratorTypesAttrName(result.name))
574+
.cast<ArrayAttr>();
574575

575576
SmallVector<Attribute> iteratorTypeAttrs;
576577

@@ -579,15 +580,15 @@ ParseResult ContractionOp::parse(OpAsmParser &parser, OperationState &result) {
579580
if (!maybeIteratorType.has_value())
580581
return parser.emitError(loc) << "unexpected iterator_type (" << s << ")";
581582

582-
iteratorTypeAttrs.push_back(IteratorTypeAttr::get(
583-
parser.getContext(), maybeIteratorType.value()));
583+
iteratorTypeAttrs.push_back(
584+
IteratorTypeAttr::get(parser.getContext(), maybeIteratorType.value()));
584585
}
585-
result.attributes.set("iterator_types",
586+
result.attributes.set(getIteratorTypesAttrName(result.name),
586587
parser.getBuilder().getArrayAttr(iteratorTypeAttrs));
587588

588-
if (!result.attributes.get(ContractionOp::getKindAttrStrName())) {
589+
if (!result.attributes.get(getKindAttrName(result.name))) {
589590
result.addAttribute(
590-
ContractionOp::getKindAttrStrName(),
591+
getKindAttrName(result.name),
591592
CombiningKindAttr::get(result.getContext(),
592593
ContractionOp::getDefaultKind()));
593594
}
@@ -822,11 +823,9 @@ LogicalResult ContractionOp::verify() {
822823
return success();
823824
}
824825

825-
ArrayRef<StringRef> ContractionOp::getTraitAttrNames() {
826-
static constexpr StringRef names[3] = {::mlir::getIndexingMapsAttrName(),
827-
::mlir::getIteratorTypesAttrName(),
828-
ContractionOp::getKindAttrStrName()};
829-
return llvm::makeArrayRef(names);
826+
SmallVector<StringRef> ContractionOp::getTraitAttrNames() {
827+
return SmallVector<StringRef>{getIndexingMapsAttrName(),
828+
getIteratorTypesAttrName(), getKindAttrName()};
830829
}
831830

832831
static int64_t getResultIndex(AffineMap map, AffineExpr targetExpr) {

0 commit comments

Comments
 (0)