Skip to content

Commit 6b6045e

Browse files
committed
[mlir][Interfaces][NFC] Update doc of ViewLikeOpInterface parser/printer handlers.
This PR addresses part of the feedback provided in llvm#115808.
1 parent b6dbda6 commit 6b6045e

File tree

1 file changed

+73
-43
lines changed

1 file changed

+73
-43
lines changed

mlir/include/mlir/Interfaces/ViewLikeInterface.h

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,46 @@ class OpWithOffsetSizesAndStridesConstantArgumentFolder final
8686
}
8787
};
8888

89-
/// Printer hook for custom directive in assemblyFormat.
89+
/// Printer hooks for custom directive in assemblyFormat.
9090
///
9191
/// custom<DynamicIndexList>($values, $integers)
9292
/// custom<DynamicIndexList>($values, $integers, type($values))
9393
///
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`. The type for integer elements is
102+
/// `i64` by default and never printed.
103+
///
104+
/// Integer indices can also be scalable, denoted with square brackets (e.g.,
105+
/// "[2, [4], 8]"). For each value in `integers`, the corresponding `bool` in
106+
/// `scalables` encodes whether it's a scalable index. If `scalables` is empty
107+
/// then assume that all indices are non-scalable.
108+
///
109+
/// Examples:
110+
///
111+
/// * Input: `integers = [kDynamic, 7, 42, kDynamic]`,
112+
/// `values = [%arg0, %arg42]` and
113+
/// `valueTypes = [index, index]`
114+
/// prints:
115+
/// `[%arg0 : index, 7, 42, %arg42 : i32]`
116+
///
117+
/// * Input: `integers = [kDynamic, 7, 42, kDynamic]`,
118+
/// `values = [%arg0, %arg42]` and
119+
/// `valueTypes = []`
120+
/// prints:
121+
/// `[%arg0, 7, 42, %arg42]`
122+
///
123+
/// * Input: `integers = [2, 4, 8]`,
124+
/// `values = []` and
125+
/// `scalables = [false, true, false]`
126+
/// prints:
127+
/// `[2, [4], 8]`
128+
///
107129
void printDynamicIndexList(
108130
OpAsmPrinter &printer, Operation *op, OperandRange values,
109131
ArrayRef<int64_t> integers, ArrayRef<bool> scalables,
@@ -113,64 +135,72 @@ inline void printDynamicIndexList(
113135
OpAsmPrinter &printer, Operation *op, OperandRange values,
114136
ArrayRef<int64_t> integers, TypeRange valueTypes = TypeRange(),
115137
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
116-
return printDynamicIndexList(printer, op, values, integers, {}, valueTypes,
117-
delimiter);
138+
return printDynamicIndexList(printer, op, values, integers, /*scalables=*/{},
139+
valueTypes, delimiter);
118140
}
119141

120-
/// Parser hook for custom directive in assemblyFormat.
142+
/// Parser hooks for custom directive in assemblyFormat.
121143
///
122144
/// custom<DynamicIndexList>($values, $integers)
123145
/// custom<DynamicIndexList>($values, $integers, type($values))
124146
///
125147
/// 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.
148+
/// type `I64ArrayAttr`. Parse a mixed list where each element is either a
149+
/// static integer or an SSA value. Fill `integers` with the integer ArrayAttr,
150+
/// where `kDynamic` encodes the position of SSA values. Add the parsed SSA
151+
/// values to `values` in-order.
152+
///
153+
/// If `valueTypes` is provided, fill it with the types corresponding to each
154+
/// value in `values`. Otherwise, the caller must handle the types.
155+
///
156+
/// Integer indices can also be scalable, denoted by the square bracket (e.g.,
157+
/// "[2, [4], 8]"). For each value in `integers`, the corresponding `bool` in
158+
/// `scalables` encodes whether it's a scalable index.
159+
///
160+
/// Examples:
161+
///
162+
/// * After parsing "[%arg0 : index, 7, 42, %arg42 : i32]":
163+
/// 1. `result` is filled with `[kDynamic, 7, 42, kDynamic]`
164+
/// 2. `values` is filled with "[%arg0, %arg1]".
165+
/// 3. `scalables` is filled with `[false, true, false]`.
166+
///
167+
/// * After parsing `[2, [4], 8]`:
168+
/// 1. `result` is filled with `[2, 4, 8]`
169+
/// 2. `values` is empty.
170+
/// 3. `scalables` is filled with `[false, true, false]`.
171+
///
141172
ParseResult parseDynamicIndexList(
142173
OpAsmParser &parser,
143174
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
144-
DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableVals,
175+
DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalables,
145176
SmallVectorImpl<Type> *valueTypes = nullptr,
146177
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square);
147178
inline ParseResult parseDynamicIndexList(
148179
OpAsmParser &parser,
149180
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
150181
DenseI64ArrayAttr &integers, SmallVectorImpl<Type> *valueTypes = nullptr,
151182
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
152-
DenseBoolArrayAttr scalableVals = {};
153-
return parseDynamicIndexList(parser, values, integers, scalableVals,
154-
valueTypes, delimiter);
183+
DenseBoolArrayAttr scalables;
184+
return parseDynamicIndexList(parser, values, integers, scalables, valueTypes,
185+
delimiter);
155186
}
156187
inline ParseResult parseDynamicIndexList(
157188
OpAsmParser &parser,
158189
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
159190
DenseI64ArrayAttr &integers, SmallVectorImpl<Type> &valueTypes,
160191
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
161-
DenseBoolArrayAttr scalableVals = {};
162-
return parseDynamicIndexList(parser, values, integers, scalableVals,
163-
&valueTypes, delimiter);
192+
DenseBoolArrayAttr scalables;
193+
return parseDynamicIndexList(parser, values, integers, scalables, &valueTypes,
194+
delimiter);
164195
}
165196
inline ParseResult parseDynamicIndexList(
166197
OpAsmParser &parser,
167198
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
168199
DenseI64ArrayAttr &integers, SmallVectorImpl<Type> &valueTypes,
169-
DenseBoolArrayAttr &scalableVals,
200+
DenseBoolArrayAttr &scalables,
170201
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
171-
172-
return parseDynamicIndexList(parser, values, integers, scalableVals,
173-
&valueTypes, delimiter);
202+
return parseDynamicIndexList(parser, values, integers, scalables, &valueTypes,
203+
delimiter);
174204
}
175205

176206
/// Verify that a the `values` has as many elements as the number of entries in

0 commit comments

Comments
 (0)