[mlir] NFC - Refactor and expose a parsing helper for OffsetSizeAndStrideInterface
authorNicolas Vasilache <nicolas.vasilache@gmail.com>
Tue, 24 Nov 2020 14:54:06 +0000 (14:54 +0000)
committerNicolas Vasilache <nicolas.vasilache@gmail.com>
Tue, 24 Nov 2020 19:45:16 +0000 (19:45 +0000)
commitb6c71c13a38b76942c9561575837c94215f23c9e
tree958284c4ea35031b9f3659cafd6e333b78bd971a
parent5f0c1e380661f5a28fb8e87d70a68fa31e923436
[mlir] NFC - Refactor and expose a parsing helper for OffsetSizeAndStrideInterface

Parse trailing part of an op of the form:
```
  <optional-offset-prefix>`[` offset-list `]`
  <optional-size-prefix>`[` size-list `]`
  <optional-stride-prefix>[` stride-list `]`
```
Each entry in the offset, size and stride list either resolves to an integer
constant or an operand of index type.
Constants are added to the `result` as named integer array attributes with
name `OffsetSizeAndStrideOpInterface::getStaticOffsetsAttrName()` (resp.
`getStaticSizesAttrName()`, `getStaticStridesAttrName()`).

Append the number of offset, size and stride operands to `segmentSizes`
before adding it to `result` as the named attribute:
`OpTrait::AttrSizedOperandSegments<void>::getOperandSegmentSizeAttr()`.
Offset, size and stride operands resolution occurs after `preResolutionFn`
to give a chance to leading operands to resolve first, after parsing the
types.
```
ParseResult parseOffsetsSizesAndStrides(
    OpAsmParser &parser, OperationState &result, ArrayRef<int> segmentSizes,
    llvm::function_ref<ParseResult(OpAsmParser &, OperationState &)>
        preResolutionFn = nullptr,
    llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalOffsetPrefix =
        nullptr,
    llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalSizePrefix =
        nullptr,
    llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalStridePrefix =
        nullptr);
```

Differential revision: https://reviews.llvm.org/D92030
mlir/include/mlir/Interfaces/ViewLikeInterface.h
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/lib/Interfaces/ViewLikeInterface.cpp