-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[mlir][Interfaces][NFC] Update doc of ViewLikeOpInterface parser/printer handlers #122555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,71 +86,109 @@ class OpWithOffsetSizesAndStridesConstantArgumentFolder final | |
} | ||
}; | ||
|
||
/// Printer hook for custom directive in assemblyFormat. | ||
/// Printer hooks for custom directive in assemblyFormat. | ||
/// | ||
/// custom<DynamicIndexList>($values, $integers) | ||
/// custom<DynamicIndexList>($values, $integers, type($values)) | ||
/// | ||
/// where `values` is of ODS type `Variadic<*>` and `integers` is of ODS | ||
/// type `I64ArrayAttr`. Prints a list with either (1) the static integer value | ||
/// in `integers` is `kDynamic` or (2) the next value otherwise. If `valueTypes` | ||
/// is non-empty, it is expected to contain as many elements as `values` | ||
/// indicating their types. This allows idiomatic printing of mixed value and | ||
/// integer attributes in a list. E.g. | ||
/// `[%arg0 : index, 7, 42, %arg42 : i32]`. | ||
/// | ||
/// Indices can be scalable. For example, "4" in "[2, [4], 8]" is scalable. | ||
/// This notation is similar to how scalable dims are marked when defining | ||
/// Vectors. For each value in `integers`, the corresponding `bool` in | ||
/// `scalables` encodes whether it's a scalable index. If `scalableVals` is | ||
/// empty then assume that all indices are non-scalable. | ||
/// where `values` is of ODS type `Variadic<*>` and `integers` is of ODS type | ||
/// `I64ArrayAttr`. Print a list where each element is either: | ||
/// 1. the static integer value in `integers`, if it's not `kDynamic` or, | ||
/// 2. the next value in `values`, otherwise. | ||
/// | ||
/// If `valueTypes` is provided, the corresponding type of each dynamic value is | ||
/// printed. Otherwise, the type is not printed. Each type must match the type | ||
/// of the corresponding value in `values`. `valueTypes` is redundant for | ||
/// printing as we can retrieve the types from the actual `values`. However, | ||
/// `valueTypes` is needed for parsing and we must keep the API symmetric for | ||
/// parsing and printing. The type for integer elements is `i64` by default and | ||
/// never printed. | ||
/// | ||
/// Integer indices can also be scalable in the context of scalable vectors, | ||
/// denoted by square brackets (e.g., "[2, [4], 8]"). For each value in | ||
/// `integers`, the corresponding `bool` in `scalableFlags` encodes whether it's | ||
/// a scalable index. If `scalableFlags` is empty then assume that all indices | ||
/// are non-scalable. | ||
/// | ||
/// Examples: | ||
/// | ||
/// * Input: `integers = [kDynamic, 7, 42, kDynamic]`, | ||
/// `values = [%arg0, %arg42]` and | ||
/// `valueTypes = [index, index]` | ||
/// prints: | ||
/// `[%arg0 : index, 7, 42, %arg42 : i32]` | ||
/// | ||
/// * Input: `integers = [kDynamic, 7, 42, kDynamic]`, | ||
/// `values = [%arg0, %arg42]` and | ||
/// `valueTypes = []` | ||
/// prints: | ||
/// `[%arg0, 7, 42, %arg42]` | ||
/// | ||
/// * Input: `integers = [2, 4, 8]`, | ||
/// `values = []` and | ||
/// `scalableFlags = [false, true, false]` | ||
/// prints: | ||
/// `[2, [4], 8]` | ||
/// | ||
void printDynamicIndexList( | ||
OpAsmPrinter &printer, Operation *op, OperandRange values, | ||
ArrayRef<int64_t> integers, ArrayRef<bool> scalables, | ||
ArrayRef<int64_t> integers, ArrayRef<bool> scalableFlags, | ||
TypeRange valueTypes = TypeRange(), | ||
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square); | ||
inline void printDynamicIndexList( | ||
OpAsmPrinter &printer, Operation *op, OperandRange values, | ||
ArrayRef<int64_t> integers, TypeRange valueTypes = TypeRange(), | ||
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) { | ||
return printDynamicIndexList(printer, op, values, integers, {}, valueTypes, | ||
delimiter); | ||
return printDynamicIndexList(printer, op, values, integers, | ||
/*scalableFlags=*/{}, valueTypes, delimiter); | ||
} | ||
|
||
/// Parser hook for custom directive in assemblyFormat. | ||
/// Parser hooks for custom directive in assemblyFormat. | ||
/// | ||
/// custom<DynamicIndexList>($values, $integers) | ||
/// custom<DynamicIndexList>($values, $integers, type($values)) | ||
/// | ||
/// where `values` is of ODS type `Variadic<*>` and `integers` is of ODS | ||
/// type `I64ArrayAttr`. Parse a mixed list with either (1) static integer | ||
/// values or (2) SSA values. Fill `integers` with the integer ArrayAttr, where | ||
/// `kDynamic` encodes the position of SSA values. Add the parsed SSA values | ||
/// to `values` in-order. If `valueTypes` is non-null, fill it with types | ||
/// corresponding to values; otherwise the caller must handle the types. | ||
/// | ||
/// E.g. after parsing "[%arg0 : index, 7, 42, %arg42 : i32]": | ||
/// 1. `result` is filled with the i64 ArrayAttr "[`kDynamic`, 7, 42, | ||
/// `kDynamic`]" | ||
/// 2. `ssa` is filled with "[%arg0, %arg1]". | ||
/// | ||
/// Indices can be scalable. For example, "4" in "[2, [4], 8]" is scalable. | ||
/// This notation is similar to how scalable dims are marked when defining | ||
/// Vectors. For each value in `integers`, the corresponding `bool` in | ||
/// `scalableVals` encodes whether it's a scalable index. | ||
/// type `I64ArrayAttr`. Parse a mixed list where each element is either a | ||
/// static integer or an SSA value. Fill `integers` with the integer ArrayAttr, | ||
/// where `kDynamic` encodes the position of SSA values. Add the parsed SSA | ||
/// values to `values` in-order. | ||
/// | ||
/// If `valueTypes` is provided, fill it with the types corresponding to each | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe worth noting that if |
||
/// value in `values`. Otherwise, the caller must handle the types and parsing | ||
/// will fail if the type of the value is found (e.g., `[%arg0 : index, 3, %arg1 | ||
/// : index]`). | ||
/// | ||
/// Integer indices can also be scalable in the context of scalable vectors, | ||
/// denoted by square brackets (e.g., "[2, [4], 8]"). For each value in | ||
/// `integers`, the corresponding `bool` in `scalableFlags` encodes whether it's | ||
/// a scalable index. | ||
/// | ||
/// Examples: | ||
/// | ||
/// * After parsing "[%arg0 : index, 7, 42, %arg42 : i32]": | ||
/// 1. `result` is filled with `[kDynamic, 7, 42, kDynamic]` | ||
/// 2. `values` is filled with "[%arg0, %arg1]". | ||
/// 3. `scalableFlags` is filled with `[false, true, false]`. | ||
/// | ||
/// * After parsing `[2, [4], 8]`: | ||
/// 1. `result` is filled with `[2, 4, 8]` | ||
/// 2. `values` is empty. | ||
/// 3. `scalableFlags` is filled with `[false, true, false]`. | ||
/// | ||
ParseResult parseDynamicIndexList( | ||
OpAsmParser &parser, | ||
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values, | ||
DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableVals, | ||
DenseI64ArrayAttr &integers, DenseBoolArrayAttr &scalableFlags, | ||
SmallVectorImpl<Type> *valueTypes = nullptr, | ||
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square); | ||
inline ParseResult parseDynamicIndexList( | ||
OpAsmParser &parser, | ||
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values, | ||
DenseI64ArrayAttr &integers, SmallVectorImpl<Type> *valueTypes = nullptr, | ||
AsmParser::Delimiter delimiter = AsmParser::Delimiter::Square) { | ||
DenseBoolArrayAttr scalableVals = {}; | ||
return parseDynamicIndexList(parser, values, integers, scalableVals, | ||
DenseBoolArrayAttr scalableFlags; | ||
return parseDynamicIndexList(parser, values, integers, scalableFlags, | ||
valueTypes, delimiter); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a note here, that
valueTypes
could be deduced fromvalues
, but we have to make sure that the API for the parse/print functions is symmetric.