Skip to content

Commit 881675e

Browse files
committed
Make the optional argument of buildMatmulOp() helper as non-optional.
1 parent 0b1cbee commit 881675e

File tree

2 files changed

+11
-36
lines changed

2 files changed

+11
-36
lines changed

mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,6 @@ def MatmulOp : LinalgStructuredBase_Op<"matmul", [
635635
MatmulOp::getDefaultIndexingMaps($_builder.getContext()));
636636
}]>,
637637
OpBuilder<
638-
(ins "TypeRange":$resultTensorTypes, "ValueRange":$operands,
639-
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes),
640-
[{
641-
$_state.addOperands(operands);
642-
$_state.addAttributes(attributes);
643-
$_state.addTypes(resultTensorTypes);
644-
(void)$_state.addRegion();
645-
}]>,
646-
OpBuilder<
647638
(ins "TypeRange":$resultTensorTypes, "ValueRange":$inputs,
648639
"ValueRange":$outputs,
649640
"Attribute":$cast, CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes),

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

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,6 @@ static void fillStructuredOpRegion(OpBuilder &opBuilder, Region &region,
155155
// iterator_types is an auto-generated method.
156156
}
157157

158-
/// Helper to create a typical indexing map for MatmulOp. Returns a list of
159-
/// AffineMap.
160-
static SmallVector<AffineMap, 3>
161-
getDefaultIndexingMapsForMatmul(MLIRContext *context) {
162-
AffineExpr d0, d1, d2;
163-
SmallVector<AffineMap, 3> indexingMaps;
164-
bindDims(context, d0, d1, d2);
165-
indexingMaps.push_back(AffineMap::get(3, 0, {d0, d2}, context));
166-
indexingMaps.push_back(AffineMap::get(3, 0, {d2, d1}, context));
167-
indexingMaps.push_back(AffineMap::get(3, 0, {d0, d1}, context));
168-
return indexingMaps;
169-
}
170-
171158
/// Creates a structured operation given `inputs`, `outputs`, and `attributes`.
172159
/// The result types are derived automatically if `resultTensorTypes` is none.
173160
/// The body of the operation is filled using `regionBuilder`. All ods-gen
@@ -200,21 +187,18 @@ static void buildStructuredOp(OpBuilder &b, OperationState &state,
200187
state.attributes.getAttrs(), regionBuilder);
201188
}
202189

203-
static void
204-
buildMatmulOp(OpBuilder &b, OperationState &state,
205-
std::optional<TypeRange> resultTensorTypes, ValueRange inputs,
206-
ValueRange outputs, ArrayRef<NamedAttribute> attributes,
207-
RegionBuilderFn regionBuilder,
208-
std::optional<ArrayRef<AffineMap>> indexingMaps = std::nullopt) {
209-
// Initialize indexingMaps, for MatmulOp.
190+
static void buildMatmulOp(OpBuilder &b, OperationState &state,
191+
std::optional<TypeRange> resultTensorTypes,
192+
ValueRange inputs, ValueRange outputs,
193+
ArrayRef<NamedAttribute> attributes,
194+
RegionBuilderFn regionBuilder,
195+
ArrayRef<AffineMap> indexingMaps) {
196+
// Initialize indexingMaps attribute, for MatmulOp.
210197
SmallVector<Attribute, 3> indexingMapsAttrVal;
211-
if (indexingMaps.has_value()) {
212-
for (mlir::AffineMap map : *indexingMaps) {
213-
// Convert each AffineMap to an AffineMapAttr
214-
indexingMapsAttrVal.push_back(AffineMapAttr::get(map));
215-
}
216-
state.addAttribute("indexing_maps", b.getArrayAttr(indexingMapsAttrVal));
217-
}
198+
indexingMapsAttrVal = llvm::map_to_vector(
199+
MatmulOp::getDefaultIndexingMaps(b.getContext()),
200+
[](AffineMap map) -> Attribute { return AffineMapAttr::get(map); });
201+
state.addAttribute("indexing_maps", b.getArrayAttr(indexingMapsAttrVal));
218202
return buildStructuredOp(b, state, resultTensorTypes, inputs, outputs,
219203
attributes, regionBuilder);
220204
}

0 commit comments

Comments
 (0)