Skip to content

Commit 9f4b97e

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

File tree

1 file changed

+58
-40
lines changed

1 file changed

+58
-40
lines changed

mlir/include/mlir/Interfaces/ViewLikeInterface.h

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,35 @@ 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]`.
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` with its corresponding type, otherwise.
98+
///
99+
/// The type for integer elements is `i64` by default and not printed.
100+
///
101+
/// If `valueTypes` is provided, verify that each type matches the type of the
102+
/// corresponding `values`. Providing `valueTypes` is redundant for printing so
103+
/// we don't use `valueTypes` after the verification.
104+
///
105+
/// Integer indices can also be scalable, denoted with square brackets (e.g.,
106+
/// "[2, [4], 8]"). For each value in `integers`, the corresponding `bool` in
107+
/// `scalables` encodes whether it's a scalable index. If `scalables` is empty
108+
/// then assume that all indices are non-scalable.
109+
///
110+
/// Examples:
111+
/// * For `integers = [kDynamic, 7, 42, kDynamic]`,
112+
/// `values = [%arg0, %arg42]`,Using the default type for integers and
113+
/// `valueTypes` for `values`:
114+
/// `[%arg0 : index, 7, 42, %arg42 : i32]`
115+
/// * Using `scalables`:
116+
/// `[2, [4], 8]`
101117
///
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.
107118
void printDynamicIndexList(
108119
OpAsmPrinter &printer, Operation *op, OperandRange values,
109120
ArrayRef<int64_t> integers, ArrayRef<bool> scalables,
@@ -113,64 +124,71 @@ inline void printDynamicIndexList(
113124
OpAsmPrinter &printer, Operation *op, OperandRange values,
114125
ArrayRef<int64_t> integers, TypeRange valueTypes = TypeRange(),
115126
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
116-
return printDynamicIndexList(printer, op, values, integers, {}, valueTypes,
117-
delimiter);
127+
return printDynamicIndexList(printer, op, values, integers, /*scalables=*/{},
128+
valueTypes, delimiter);
118129
}
119130

120-
/// Parser hook for custom directive in assemblyFormat.
131+
/// Parser hooks for custom directive in assemblyFormat.
121132
///
122133
/// custom<DynamicIndexList>($values, $integers)
123134
/// custom<DynamicIndexList>($values, $integers, type($values))
124135
///
125136
/// 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.
137+
/// type `I64ArrayAttr`. Parse a mixed list where each element is either a
138+
/// static integer or an SSA value. Fill `integers` with the integer ArrayAttr,
139+
/// where `kDynamic` encodes the position of SSA values. Add the parsed SSA
140+
/// values to `values` in-order.
131141
///
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]".
142+
/// If `valueTypes` is provided, fill it with the types corresponding to each
143+
/// value in `values`. Otherwise, the caller must handle the types.
136144
///
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.
145+
/// Integer indices can also be scalable, denoted by the square bracket (e.g.,
146+
/// "[2, [4], 8]"). For each value in `integers`, the corresponding `bool` in
147+
/// `scalables` encodes whether it's a scalable index.
148+
///
149+
/// Examples:
150+
/// * After parsing "[%arg0 : index, 7, 42, %arg42 : i32]":
151+
/// 1. `result` is filled with the i64 ArrayAttr `[kDynamic, 7, 42,
152+
/// kDynamic]`
153+
/// 2. `values` is filled with "[%arg0, %arg1]".
154+
/// 3. `scalables` is filled with `[false, true, false]`.
155+
///
156+
/// * After parsing `[2, [4], 8]`:
157+
/// 1. `result` is filled with the i64 ArrayAttr `[2, 4, 8]`
158+
/// 2. `values` is empty.
159+
/// 3. `scalables` is filled with `[false, true, false]`.
141160
ParseResult parseDynamicIndexList(
142161
OpAsmParser &parser,
143162
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
144-
DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableVals,
163+
DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalables,
145164
SmallVectorImpl<Type> *valueTypes = nullptr,
146165
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square);
147166
inline ParseResult parseDynamicIndexList(
148167
OpAsmParser &parser,
149168
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
150169
DenseI64ArrayAttr &integers, SmallVectorImpl<Type> *valueTypes = nullptr,
151170
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
152-
DenseBoolArrayAttr scalableVals = {};
153-
return parseDynamicIndexList(parser, values, integers, scalableVals,
154-
valueTypes, delimiter);
171+
DenseBoolArrayAttr scalables;
172+
return parseDynamicIndexList(parser, values, integers, scalables, valueTypes,
173+
delimiter);
155174
}
156175
inline ParseResult parseDynamicIndexList(
157176
OpAsmParser &parser,
158177
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
159178
DenseI64ArrayAttr &integers, SmallVectorImpl<Type> &valueTypes,
160179
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
161-
DenseBoolArrayAttr scalableVals = {};
162-
return parseDynamicIndexList(parser, values, integers, scalableVals,
163-
&valueTypes, delimiter);
180+
DenseBoolArrayAttr scalables;
181+
return parseDynamicIndexList(parser, values, integers, scalables, &valueTypes,
182+
delimiter);
164183
}
165184
inline ParseResult parseDynamicIndexList(
166185
OpAsmParser &parser,
167186
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
168187
DenseI64ArrayAttr &integers, SmallVectorImpl<Type> &valueTypes,
169-
DenseBoolArrayAttr &scalableVals,
188+
DenseBoolArrayAttr &scalables,
170189
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) {
171-
172-
return parseDynamicIndexList(parser, values, integers, scalableVals,
173-
&valueTypes, delimiter);
190+
return parseDynamicIndexList(parser, values, integers, scalables, &valueTypes,
191+
delimiter);
174192
}
175193

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

0 commit comments

Comments
 (0)