@@ -45,7 +45,7 @@ def ApplyDecomposeTensorPackUnpackPatternsOp
4545 : Op<Transform_Dialect, "apply_patterns.linalg.decompose_pack_unpack",
4646 [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
4747 let description = [{
48- Collect patterns to decompose tensor .pack and tensor .unpack into e.g.
48+ Collect patterns to decompose linalg .pack and linalg .unpack into e.g.
4949 tensor::PadOp, linalg::transposeOp Ops. Requires all outer dims to be unit.
5050 }];
5151
@@ -126,6 +126,28 @@ def ApplyPadVectorizationPatternsOp : Op<Transform_Dialect,
126126 let assemblyFormat = "attr-dict";
127127}
128128
129+ def ApplyFoldIntoPackAndUnpackPatternsOp : Op<Transform_Dialect,
130+ "apply_patterns.tensor.fold_into_pack_and_unpack",
131+ [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
132+ let description = [{
133+ Indicates that operations like tensor.pad and tensor.extract_slice should
134+ be folded into tensor.pack and tensor.unpack operations, respectively.
135+ }];
136+
137+ let assemblyFormat = "attr-dict";
138+ }
139+
140+ def ApplyFoldPackUnpackIntoEmptyPatternsOp : Op<Transform_Dialect,
141+ "apply_patterns.linalg.fold_pack_unpack_into_empty",
142+ [DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
143+ let description = [{
144+ // TODO:
145+ }];
146+
147+ let arguments = (ins DefaultValuedAttr<BoolAttr, "false">:$fold_single_use_only);
148+ let assemblyFormat = "attr-dict";
149+ }
150+
129151//===----------------------------------------------------------------------===//
130152// BufferizeToAllocationOp
131153//===----------------------------------------------------------------------===//
@@ -547,19 +569,18 @@ def LowerPackOp : Op<Transform_Dialect, "structured.lower_pack", [
547569 TransformOpInterface,
548570 ReportTrackingListenerFailuresOpTrait]> {
549571 let description = [{
550- Rewrite a tensor .pack into tensor.pad + tensor.expand_shape + linalg.transpose.
572+ Rewrite a linalg .pack into tensor.pad + tensor.expand_shape + linalg.transpose.
551573
552574 #### Return modes
553575
554- This operation ignores non-pack ops and drops them in the return.
555- This operation produces a silenceable failure if the rewrite fails for any
556- reason.
557- If all the operations referred to by the `target` are rewritten, the
558- transform succeeds.
559- Return handles to the newly produced pad, expand_shape and transpose ops.
576+ This operation ignores non-pack ops and drops them in the return. This
577+ operation produces a silenceable failure if the rewrite fails for any
578+ reason. If all the operations referred to by the `target` are rewritten,
579+ the transform succeeds. Return handles to the newly produced pad,
580+ expand_shape and transpose ops.
560581 }];
561582
562- let arguments = (ins Transform_ConcreteOpType<"tensor .pack">:$target,
583+ let arguments = (ins Transform_ConcreteOpType<"linalg .pack">:$target,
563584 DefaultValuedAttr<BoolAttr, "true">:$lowerPadLikeWithInsertSlice);
564585 let results = (outs Transform_ConcreteOpType<"tensor.pad">:$pad_op,
565586 Transform_ConcreteOpType<"tensor.expand_shape">:$expand_shape_op,
@@ -571,7 +592,7 @@ def LowerPackOp : Op<Transform_Dialect, "structured.lower_pack", [
571592 let extraClassDeclaration = [{
572593 ::mlir::DiagnosedSilenceableFailure applyToOne(
573594 ::mlir::transform::TransformRewriter &rewriter,
574- ::mlir::tensor ::PackOp target,
595+ ::mlir::linalg ::PackOp target,
575596 ::mlir::transform::ApplyToEachResultList &transformResults,
576597 ::mlir::transform::TransformState &state);
577598 }];
@@ -587,20 +608,19 @@ def LowerUnPackOp : Op<Transform_Dialect, "structured.lower_unpack", [
587608 TransformOpInterface,
588609 ReportTrackingListenerFailuresOpTrait]> {
589610 let description = [{
590- Lower a tensor .unpack into empty + linalg.transpose + tensor.collapse_shape +
611+ Lower a linalg .unpack into empty + linalg.transpose + tensor.collapse_shape +
591612 tensor.extract_slice.
592613
593614 #### Return modes
594615
595- This operation ignores non-unpack ops and drops them in the return.
596- This operation produces a silenceable failure if the rewrite fails for any
597- reason.
598- If all the operations referred to by the `target` are rewritten, the
599- transform succeeds.
600- Return handles to the newly produced empty, transpose, collapse_shape and extract_slice ops.
616+ This operation ignores non-unpack ops and drops them in the return. This
617+ operation produces a silenceable failure if the rewrite fails for any
618+ reason. If all the operations referred to by the `target` are rewritten,
619+ the transform succeeds. Return handles to the newly produced empty,
620+ transpose, collapse_shape and extract_slice ops.
601621 }];
602622
603- let arguments = (ins Transform_ConcreteOpType<"tensor .unpack">:$target,
623+ let arguments = (ins Transform_ConcreteOpType<"linalg .unpack">:$target,
604624 DefaultValuedAttr<BoolAttr, "true">:$lowerUnpadLikeWithExtractSlice);
605625 let results = (outs Transform_ConcreteOpType<"tensor.empty">:$empty_op,
606626 Transform_ConcreteOpType<"linalg.transpose">:$transpose_op,
@@ -613,7 +633,7 @@ def LowerUnPackOp : Op<Transform_Dialect, "structured.lower_unpack", [
613633 let extraClassDeclaration = [{
614634 ::mlir::DiagnosedSilenceableFailure applyToOne(
615635 ::mlir::transform::TransformRewriter &rewriter,
616- ::mlir::tensor ::UnPackOp target,
636+ ::mlir::linalg ::UnPackOp target,
617637 ::mlir::transform::ApplyToEachResultList &transformResults,
618638 ::mlir::transform::TransformState &state);
619639 }];
@@ -791,7 +811,7 @@ def PackOp : Op<Transform_Dialect, "structured.pack", [
791811 Specifying a packed size of 0 for an iterator removes it from consideration
792812 for packing.
793813
794- `tensor .pack` (resp. `tensor .unpack`) operations are inserted for the operands
814+ `linalg .pack` (resp. `linalg .unpack`) operations are inserted for the operands
795815 (resp. results) that need to be packed (resp. unpacked) according to the
796816 `packed_sizes` specification.
797817
@@ -980,7 +1000,7 @@ def PackTransposeOp : Op<Transform_Dialect, "structured.pack_transpose", [
9801000 DeclareOpInterfaceMethods<TransformOpInterface>,
9811001 ReportTrackingListenerFailuresOpTrait]> {
9821002 let description = [{
983- Apply a transposition to a single `tensor .pack` (resp. `tensor .unpack`) and
1003+ Apply a transposition to a single `linalg .pack` (resp. `linalg .unpack`) and
9841004 update the `linalg.generic` op that consumes (resp. produces) the operation.
9851005
9861006 This transform allows composing a simple `structured.pack` with additional
@@ -989,19 +1009,19 @@ def PackTransposeOp : Op<Transform_Dialect, "structured.pack_transpose", [
9891009
9901010 The transpose spec must specify at least one of `outer_perm` or `inner_perm`
9911011 attributes, which will act upon the `outer_dims_perm` or `inner_dims_pos` of
992- the specified `tensor .pack` or `tensor .unpack` op.
1012+ the specified `linalg .pack` or `linalg .unpack` op.
9931013
994- If the `target` of this op is a `tensor .pack` then a new `tensor.empty` will
995- be created along with transposed versions of the `tensor .pack` and the
1014+ If the `target` of this op is a `linalg .pack` then a new `tensor.empty` will
1015+ be created along with transposed versions of the `linalg .pack` and the
9961016 consuming `linalg.generic`, which is expected to be the sole consumer.
9971017
998- If the `target` of this op is a `tensor .unpack` then the whole pack / compute
999- / unpack chain will be transposed and transposed clones of `tensor .pack`,
1000- the consuming `linalg.generic` and the tail `tensor .pack` will be created.
1018+ If the `target` of this op is a `linalg .unpack` then the whole pack / compute
1019+ / unpack chain will be transposed and transposed clones of `linalg .pack`,
1020+ the consuming `linalg.generic` and the tail `linalg .pack` will be created.
10011021
10021022 #### Return modes
10031023
1004- This operation targets a single `tensor .pack` / `tensor .unpack` op and a
1024+ This operation targets a single `linalg .pack` / `linalg .unpack` op and a
10051025 single matching `linalg.generic` that consumes / produces the op. Otherwise,
10061026 it produces a silenceableFailure.
10071027
@@ -1011,9 +1031,9 @@ def PackTransposeOp : Op<Transform_Dialect, "structured.pack_transpose", [
10111031 reason.
10121032
10131033 This operation returns 3 handles, one to the transformed LinalgOp, one to
1014- the transformed `tensor .pack` and one to the transformed `tensor .unpack`.
1015- The last handle for `tensor .unpack` is empty if `target_pack_or_unpack_op`
1016- was not itself a `tensor .unpack`.
1034+ the transformed `linalg .pack` and one to the transformed `linalg .unpack`.
1035+ The last handle for `linalg .unpack` is empty if `target_pack_or_unpack_op`
1036+ was not itself a `linalg .unpack`.
10171037 }];
10181038
10191039 let arguments = (ins TransformHandleTypeInterface:$target_pack_or_un_pack_op,
@@ -1143,7 +1163,7 @@ def HoistPadBuildPackingLoopNestOp :
11431163 creates the packing loop nest required by the hoist_pad operation and makes
11441164 that functionality available independently.
11451165
1146- TODO: In the future, we should consider rewriting as a tensor .pack after
1166+ TODO: In the future, we should consider rewriting as a linalg .pack after
11471167 hoisting since this abstraction is now available.
11481168
11491169 #### Return modes
@@ -1182,7 +1202,7 @@ def HoistPadOp : Op<Transform_Dialect, "structured.hoist_pad",
11821202 Hoist the tensor.pad target operation by at most the given number of loops.
11831203 Optionally apply the transpose attribute to the inner dimensions.
11841204
1185- TODO: In the future, we should consider rewriting as a tensor .pack after
1205+ TODO: In the future, we should consider rewriting as a linalg .pack after
11861206 hoisting since this abstraction is now available.
11871207 TODO: Maybe also return the linalg.generic transpose created at some point.
11881208
0 commit comments