Skip to content

Commit e98838d

Browse files
committed
Get rid of "whole new type" by introducing "context dependent" default valued attr class
Should probably be moved to CommonAttrConstraints.td
1 parent 85426f6 commit e98838d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -557,17 +557,19 @@ def BroadcastOp : LinalgStructuredBase_Op<"broadcast", [
557557

558558

559559
// DONOTMERGE(rolfmorel): explain why the below is necessary
560-
def DefaultValuedMatmulIndexingMapsAttr :
561-
Attr<AffineMapArrayAttr.predicate, AffineMapArrayAttr.summary> {
562-
let storageType = AffineMapArrayAttr.storageType;
563-
let returnType = AffineMapArrayAttr.returnType;
564-
let convertFromStorage = AffineMapArrayAttr.convertFromStorage;
565-
let constBuilderCall = "$_builder.getAffineMapArrayAttr($0.empty() ? MatmulOp::getDefaultIndexingMaps($_builder.getContext()) : $0)";
566-
let defaultValue = "SmallVector<AffineMap>()";
567-
let valueType = AffineMapArrayAttr.valueType;
560+
class DefaultValuedContextDependentAttr<Attr attr,
561+
string builderCall,
562+
string default> :
563+
Attr<attr.predicate, attr.summary> {
564+
let storageType = attr.storageType;
565+
let returnType = attr.returnType;
566+
let convertFromStorage = attr.convertFromStorage;
567+
let constBuilderCall = builderCall; // DONOTMERGE(rolfmorel): explain why this needs to be a parameter
568+
let defaultValue = default;
569+
let valueType = attr.valueType;
568570
let isOptional = 1;
569571

570-
let baseAttr = AffineMapArrayAttr;
572+
let baseAttr = attr;
571573
}
572574

573575

@@ -622,7 +624,10 @@ def MatmulOp : LinalgStructuredBase_Op<"matmul", [
622624
let arguments = (ins
623625
Variadic<AnyType>:$inputs,
624626
Variadic<AnyShaped>:$outputs,
625-
DefaultValuedMatmulIndexingMapsAttr:$indexing_maps, // DONOTMERGE(rolfmorel): explain why this is necessary
627+
DefaultValuedContextDependentAttr<AffineMapArrayAttr,
628+
builderCall = [{ $_builder.getAffineMapArrayAttr(
629+
$0.empty() ? MatmulOp::getDefaultIndexingMaps($_builder.getContext()) : $0
630+
)}], default = "SmallVector<AffineMap>()">:$indexing_maps,
626631
DefaultValuedOptionalAttr<TypeFnAttr, "TypeFn::cast_signed">:$cast
627632
);
628633
let results = (outs Variadic<AnyRankedTensor>:$result_tensors);

mlir/python/mlir/dialects/linalg/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ def __init__(
149149
generic = region_op(GenericOp_, terminator=YieldOp)
150150

151151

152-
@register_attribute_builder("DefaultValuedMatmulIndexingMapsAttr")
153-
def _DefaultValuedMatmulIndexingMapsAttr(x, context):
154-
return ArrayAttr.get([AffineMapAttr.get(v) for v in x])
155-
156-
157152
def matmul(
158153
inputs: Sequence[Union[Operation, OpView, Value]],
159154
*,

0 commit comments

Comments
 (0)