xref: /llvm-project/mlir/test/lib/Interfaces/TilingInterface/TestTilingInterfaceTransformOps.td (revision 9bc3102bea80f422f4f3b788186f6e1c636e0fba)
1//===- TestTilingInterfaceTransformOps.td -----------------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef TEST_TILINGINTERFACE_TRANSFORM_OPS
10#define TEST_TILINGINTERFACE_TRANSFORM_OPS
11
12include "mlir/Dialect/SCF/IR/DeviceMappingInterface.td"
13include "mlir/Dialect/Transform/IR/TransformDialect.td"
14include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td"
15include "mlir/Dialect/Transform/IR/TransformTypes.td"
16include "mlir/Interfaces/SideEffectInterfaces.td"
17include "mlir/IR/OpBase.td"
18
19// Those operations in this file are meant for testing the tiling interface
20// transformations using scf operations. Over time these testing options
21// might be useful transformations in their own right. Move these over
22// as transform ops in the main repo (also find a proper place for them)
23
24def TestFuseAndYieldOp : Op<Transform_Dialect, "test.fuse_and_yield",
25  [FunctionalStyleTransformOpTrait, MemoryEffectsOpInterface,
26   DeclareOpInterfaceMethods<TransformOpInterface>,
27   ReportTrackingListenerFailuresOpTrait]> {
28  let description = [{
29    Tiles the operations pointed to by the target handle, fuses their
30    producers greedily using the options provided as attributes.
31    It also yields some of the fused producers for testing.
32
33    On success returns the tiled operations as well as generated loops. Emits
34    a definite failure if tiling fails.
35  }];
36
37  let arguments =
38    (ins TransformHandleTypeInterface:$target,
39        DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_sizes,
40        DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_interchange,
41        DefaultValuedAttr<BoolAttr, "false">:$use_forall);
42  let results = (outs TransformHandleTypeInterface:$transfomed,
43      Variadic<TransformHandleTypeInterface>:$loops);
44
45  let assemblyFormat = [{
46    $target ($tile_sizes^)? (`interchange` $tile_interchange^)?
47    (`use_forall` $use_forall^)? attr-dict
48    `:` functional-type(operands, results)
49  }];
50}
51
52def TestFuseConsumerOp : Op<Transform_Dialect, "test.fuse_consumer",
53       [DeclareOpInterfaceMethods<TransformOpInterface>,
54        DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
55        ReportTrackingListenerFailuresOpTrait]> {
56  let description = [{
57    Fuses the consumer of the operation pointed to by the target handle
58    using the options provided as attributes.
59  }];
60
61  let arguments =
62    (ins TransformHandleTypeInterface:$target,
63        DefaultValuedAttr<I32Attr, "1">:$num_consumer_to_fuse);
64  let results = (outs TransformHandleTypeInterface:$consumer,
65                      TransformHandleTypeInterface:$fused_consumer);
66
67  let assemblyFormat = [{
68    $target (`num_consumer_to_fuse` `=` $num_consumer_to_fuse^)?
69    attr-dict `:` functional-type(operands, results)
70  }];
71}
72
73def TestTileUsingForallOp : Op<Transform_Dialect, "test.tile_using_forall",
74       [DeclareOpInterfaceMethods<TransformOpInterface>,
75        DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
76        ReportTrackingListenerFailuresOpTrait]> {
77  let description = [{
78    Test operation use to test tiling using TilingInterface and scf.forall for
79    the loop constructs. This is similar to
80    `transform.structured.tile_using_for`. Use of this operation is an
81    intermediate state and will be replaced in due course with either
82    `transform.structured.tile_using_for` or
83    `transform.structured.tile_using_forall`.
84
85    On success returns the tiled operations as well as generated loops. Emits
86    a definite failure if tiling fails.
87  }];
88
89  let arguments = (ins TransformHandleTypeInterface:$target,
90                   DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_sizes,
91                   DefaultValuedOptionalAttr<I64ArrayAttr, "{}">:$interchange,
92                   OptionalAttr<DeviceMappingArrayAttr>:$mapping);
93  let results = (outs TransformHandleTypeInterface:$tiled_op,
94                      Variadic<TransformHandleTypeInterface>:$loops);
95
96  let assemblyFormat = [{
97    $target ($tile_sizes^)? (`interchange` `=` $interchange^)?
98    (`mapping` `=` $mapping^)?
99    attr-dict `:` functional-type(operands, results)
100  }];
101}
102
103def TestFuseUsingForallOp : Op<Transform_Dialect, "test.fuse_using_forall",
104    [DeclareOpInterfaceMethods<TransformOpInterface>,
105     DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
106     ReportTrackingListenerFailuresOpTrait]> {
107  let description = [{
108    Test operation to tile the operation pointed to by the target handle and
109    fuses their producers greedily using the options provided as attributes.
110    This operation uses scf.forall for the loop construct.
111  }];
112  let arguments = (ins TransformHandleTypeInterface:$root_op,
113                   DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_sizes,
114                   DefaultValuedOptionalAttr<I64ArrayAttr, "{}">:$interchange,
115                   OptionalAttr<DeviceMappingArrayAttr>:$mapping);
116  let results = (outs TransformHandleTypeInterface:$tiled_ops,
117                      Variadic<TransformHandleTypeInterface>:$loops);
118
119  let assemblyFormat = [{
120    $root_op ($tile_sizes^)? (`interchange` $interchange^)?
121    (`mapping` `=` $mapping^)?
122    attr-dict `:` functional-type(operands, results)
123  }];
124}
125
126#endif // TEST_TILINGINTERFACE_TRANSFORM_OPS
127