@@ -86,71 +86,109 @@ class OpWithOffsetSizesAndStridesConstantArgumentFolder final
86
86
}
87
87
};
88
88
89
- // / Printer hook for custom directive in assemblyFormat.
89
+ // / Printer hooks for custom directive in assemblyFormat.
90
90
// /
91
91
// / custom<DynamicIndexList>($values, $integers)
92
92
// / custom<DynamicIndexList>($values, $integers, type($values))
93
93
// /
94
- // / where `values` is of ODS type `Variadic<*>` and `integers` is of ODS
95
- // / type `I64ArrayAttr`. Prints a list with either (1) the static integer value
96
- // / in `integers` is `kDynamic` or (2) the next value otherwise. If `valueTypes`
97
- // / is non-empty, it is expected to contain as many elements as `values`
98
- // / indicating their types. This allows idiomatic printing of mixed value and
99
- // / integer attributes in a list. E.g.
100
- // / `[%arg0 : index, 7, 42, %arg42 : i32]`.
101
- // /
102
- // / Indices can be scalable. For example, "4" in "[2, [4], 8]" is scalable.
103
- // / This notation is similar to how scalable dims are marked when defining
104
- // / Vectors. For each value in `integers`, the corresponding `bool` in
105
- // / `scalables` encodes whether it's a scalable index. If `scalableVals` is
106
- // / empty then assume that all indices are non-scalable.
94
+ // / where `values` is of ODS type `Variadic<*>` and `integers` is of ODS type
95
+ // / `I64ArrayAttr`. Print a list where each element is either:
96
+ // / 1. the static integer value in `integers`, if it's not `kDynamic` or,
97
+ // / 2. the next value in `values`, otherwise.
98
+ // /
99
+ // / If `valueTypes` is provided, the corresponding type of each dynamic value is
100
+ // / printed. Otherwise, the type is not printed. Each type must match the type
101
+ // / of the corresponding value in `values`. `valueTypes` is redundant for
102
+ // / printing as we can retrieve the types from the actual `values`. However,
103
+ // / `valueTypes` is needed for parsing and we must keep the API symmetric for
104
+ // / parsing and printing. The type for integer elements is `i64` by default and
105
+ // / never printed.
106
+ // /
107
+ // / Integer indices can also be scalable in the context of scalable vectors,
108
+ // / denoted by square brackets (e.g., "[2, [4], 8]"). For each value in
109
+ // / `integers`, the corresponding `bool` in `scalableFlags` encodes whether it's
110
+ // / a scalable index. If `scalableFlags` is empty then assume that all indices
111
+ // / are non-scalable.
112
+ // /
113
+ // / Examples:
114
+ // /
115
+ // / * Input: `integers = [kDynamic, 7, 42, kDynamic]`,
116
+ // / `values = [%arg0, %arg42]` and
117
+ // / `valueTypes = [index, index]`
118
+ // / prints:
119
+ // / `[%arg0 : index, 7, 42, %arg42 : i32]`
120
+ // /
121
+ // / * Input: `integers = [kDynamic, 7, 42, kDynamic]`,
122
+ // / `values = [%arg0, %arg42]` and
123
+ // / `valueTypes = []`
124
+ // / prints:
125
+ // / `[%arg0, 7, 42, %arg42]`
126
+ // /
127
+ // / * Input: `integers = [2, 4, 8]`,
128
+ // / `values = []` and
129
+ // / `scalableFlags = [false, true, false]`
130
+ // / prints:
131
+ // / `[2, [4], 8]`
132
+ // /
107
133
void printDynamicIndexList (
108
134
OpAsmPrinter &printer, Operation *op, OperandRange values,
109
- ArrayRef<int64_t > integers, ArrayRef<bool > scalables ,
135
+ ArrayRef<int64_t > integers, ArrayRef<bool > scalableFlags ,
110
136
TypeRange valueTypes = TypeRange(),
111
137
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square);
112
138
inline void printDynamicIndexList (
113
139
OpAsmPrinter &printer, Operation *op, OperandRange values,
114
140
ArrayRef<int64_t > integers, TypeRange valueTypes = TypeRange(),
115
141
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
116
- return printDynamicIndexList (printer, op, values, integers, {}, valueTypes,
117
- delimiter);
142
+ return printDynamicIndexList (printer, op, values, integers,
143
+ /* scalableFlags= */ {}, valueTypes, delimiter);
118
144
}
119
145
120
- // / Parser hook for custom directive in assemblyFormat.
146
+ // / Parser hooks for custom directive in assemblyFormat.
121
147
// /
122
148
// / custom<DynamicIndexList>($values, $integers)
123
149
// / custom<DynamicIndexList>($values, $integers, type($values))
124
150
// /
125
151
// / where `values` is of ODS type `Variadic<*>` and `integers` is of ODS
126
- // / type `I64ArrayAttr`. Parse a mixed list with either (1) static integer
127
- // / values or (2) SSA values. Fill `integers` with the integer ArrayAttr, where
128
- // / `kDynamic` encodes the position of SSA values. Add the parsed SSA values
129
- // / to `values` in-order. If `valueTypes` is non-null, fill it with types
130
- // / corresponding to values; otherwise the caller must handle the types.
131
- // /
132
- // / E.g. after parsing "[%arg0 : index, 7, 42, %arg42 : i32]":
133
- // / 1. `result` is filled with the i64 ArrayAttr "[`kDynamic`, 7, 42,
134
- // / `kDynamic`]"
135
- // / 2. `ssa` is filled with "[%arg0, %arg1]".
136
- // /
137
- // / Indices can be scalable. For example, "4" in "[2, [4], 8]" is scalable.
138
- // / This notation is similar to how scalable dims are marked when defining
139
- // / Vectors. For each value in `integers`, the corresponding `bool` in
140
- // / `scalableVals` encodes whether it's a scalable index.
152
+ // / type `I64ArrayAttr`. Parse a mixed list where each element is either a
153
+ // / static integer or an SSA value. Fill `integers` with the integer ArrayAttr,
154
+ // / where `kDynamic` encodes the position of SSA values. Add the parsed SSA
155
+ // / values to `values` in-order.
156
+ // /
157
+ // / If `valueTypes` is provided, fill it with the types corresponding to each
158
+ // / value in `values`. Otherwise, the caller must handle the types and parsing
159
+ // / will fail if the type of the value is found (e.g., `[%arg0 : index, 3, %arg1
160
+ // / : index]`).
161
+ // /
162
+ // / Integer indices can also be scalable in the context of scalable vectors,
163
+ // / denoted by square brackets (e.g., "[2, [4], 8]"). For each value in
164
+ // / `integers`, the corresponding `bool` in `scalableFlags` encodes whether it's
165
+ // / a scalable index.
166
+ // /
167
+ // / Examples:
168
+ // /
169
+ // / * After parsing "[%arg0 : index, 7, 42, %arg42 : i32]":
170
+ // / 1. `result` is filled with `[kDynamic, 7, 42, kDynamic]`
171
+ // / 2. `values` is filled with "[%arg0, %arg1]".
172
+ // / 3. `scalableFlags` is filled with `[false, true, false]`.
173
+ // /
174
+ // / * After parsing `[2, [4], 8]`:
175
+ // / 1. `result` is filled with `[2, 4, 8]`
176
+ // / 2. `values` is empty.
177
+ // / 3. `scalableFlags` is filled with `[false, true, false]`.
178
+ // /
141
179
ParseResult parseDynamicIndexList (
142
180
OpAsmParser &parser,
143
181
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
144
- DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableVals ,
182
+ DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableFlags ,
145
183
SmallVectorImpl<Type> *valueTypes = nullptr ,
146
184
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square);
147
185
inline ParseResult parseDynamicIndexList (
148
186
OpAsmParser &parser,
149
187
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
150
188
DenseI64ArrayAttr &integers, SmallVectorImpl<Type> *valueTypes = nullptr ,
151
189
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
152
- DenseBoolArrayAttr scalableVals = {} ;
153
- return parseDynamicIndexList (parser, values, integers, scalableVals ,
190
+ DenseBoolArrayAttr scalableFlags ;
191
+ return parseDynamicIndexList (parser, values, integers, scalableFlags ,
154
192
valueTypes, delimiter);
155
193
}
156
194
0 commit comments