2020-04-22 23:16:34 +08:00
|
|
|
//===- ViewLikeInterface.cpp - View-like operations in MLIR ---------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "mlir/Interfaces/ViewLikeInterface.h"
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ViewLike Interfaces
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Include the definitions of the loop-like interfaces.
|
|
|
|
#include "mlir/Interfaces/ViewLikeInterface.cpp.inc"
|
[mlir] NFC - Expose an OffsetSizeAndStrideOpInterface
This revision will make it easier to create new ops base on the strided memref abstraction outside of the std dialect.
OffsetSizeAndStrideOpInterface is an interface for ops that allow specifying mixed dynamic and static offsets, sizes and strides variadic operands.
Ops that implement this interface need to expose the following methods:
1. `getArrayAttrRanks` to specify the length of static integer
attributes.
2. `offsets`, `sizes` and `strides` variadic operands.
3. `static_offsets`, resp. `static_sizes` and `static_strides` integer
array attributes.
The invariants of this interface are:
1. `static_offsets`, `static_sizes` and `static_strides` have length
exactly `getArrayAttrRanks()`[0] (resp. [1], [2]).
2. `offsets`, `sizes` and `strides` have each length at most
`getArrayAttrRanks()`[0] (resp. [1], [2]).
3. if an entry of `static_offsets` (resp. `static_sizes`,
`static_strides`) is equal to a special sentinel value, namely
`ShapedType::kDynamicStrideOrOffset` (resp. `ShapedType::kDynamicSize`,
`ShapedType::kDynamicStrideOrOffset`), then the corresponding entry is
a dynamic offset (resp. size, stride).
4. a variadic `offset` (resp. `sizes`, `strides`) operand must be present
for each dynamic offset (resp. size, stride).
This interface is useful to factor out common behavior and provide support
for carrying or injecting static behavior through the use of the static
attributes.
Differential Revision: https://reviews.llvm.org/D92011
2020-11-24 22:23:57 +08:00
|
|
|
|
2020-12-18 06:42:40 +08:00
|
|
|
LogicalResult mlir::verifyListOfOperandsOrIntegers(
|
|
|
|
Operation *op, StringRef name, unsigned expectedNumElements, ArrayAttr attr,
|
|
|
|
ValueRange values, llvm::function_ref<bool(int64_t)> isDynamic) {
|
[mlir] NFC - Expose an OffsetSizeAndStrideOpInterface
This revision will make it easier to create new ops base on the strided memref abstraction outside of the std dialect.
OffsetSizeAndStrideOpInterface is an interface for ops that allow specifying mixed dynamic and static offsets, sizes and strides variadic operands.
Ops that implement this interface need to expose the following methods:
1. `getArrayAttrRanks` to specify the length of static integer
attributes.
2. `offsets`, `sizes` and `strides` variadic operands.
3. `static_offsets`, resp. `static_sizes` and `static_strides` integer
array attributes.
The invariants of this interface are:
1. `static_offsets`, `static_sizes` and `static_strides` have length
exactly `getArrayAttrRanks()`[0] (resp. [1], [2]).
2. `offsets`, `sizes` and `strides` have each length at most
`getArrayAttrRanks()`[0] (resp. [1], [2]).
3. if an entry of `static_offsets` (resp. `static_sizes`,
`static_strides`) is equal to a special sentinel value, namely
`ShapedType::kDynamicStrideOrOffset` (resp. `ShapedType::kDynamicSize`,
`ShapedType::kDynamicStrideOrOffset`), then the corresponding entry is
a dynamic offset (resp. size, stride).
4. a variadic `offset` (resp. `sizes`, `strides`) operand must be present
for each dynamic offset (resp. size, stride).
This interface is useful to factor out common behavior and provide support
for carrying or injecting static behavior through the use of the static
attributes.
Differential Revision: https://reviews.llvm.org/D92011
2020-11-24 22:23:57 +08:00
|
|
|
/// Check static and dynamic offsets/sizes/strides breakdown.
|
|
|
|
if (attr.size() != expectedNumElements)
|
2020-12-18 06:42:40 +08:00
|
|
|
return op->emitError("expected ")
|
[mlir] NFC - Expose an OffsetSizeAndStrideOpInterface
This revision will make it easier to create new ops base on the strided memref abstraction outside of the std dialect.
OffsetSizeAndStrideOpInterface is an interface for ops that allow specifying mixed dynamic and static offsets, sizes and strides variadic operands.
Ops that implement this interface need to expose the following methods:
1. `getArrayAttrRanks` to specify the length of static integer
attributes.
2. `offsets`, `sizes` and `strides` variadic operands.
3. `static_offsets`, resp. `static_sizes` and `static_strides` integer
array attributes.
The invariants of this interface are:
1. `static_offsets`, `static_sizes` and `static_strides` have length
exactly `getArrayAttrRanks()`[0] (resp. [1], [2]).
2. `offsets`, `sizes` and `strides` have each length at most
`getArrayAttrRanks()`[0] (resp. [1], [2]).
3. if an entry of `static_offsets` (resp. `static_sizes`,
`static_strides`) is equal to a special sentinel value, namely
`ShapedType::kDynamicStrideOrOffset` (resp. `ShapedType::kDynamicSize`,
`ShapedType::kDynamicStrideOrOffset`), then the corresponding entry is
a dynamic offset (resp. size, stride).
4. a variadic `offset` (resp. `sizes`, `strides`) operand must be present
for each dynamic offset (resp. size, stride).
This interface is useful to factor out common behavior and provide support
for carrying or injecting static behavior through the use of the static
attributes.
Differential Revision: https://reviews.llvm.org/D92011
2020-11-24 22:23:57 +08:00
|
|
|
<< expectedNumElements << " " << name << " values";
|
|
|
|
unsigned expectedNumDynamicEntries =
|
|
|
|
llvm::count_if(attr.getValue(), [&](Attribute attr) {
|
|
|
|
return isDynamic(attr.cast<IntegerAttr>().getInt());
|
|
|
|
});
|
|
|
|
if (values.size() != expectedNumDynamicEntries)
|
2020-12-18 06:42:40 +08:00
|
|
|
return op->emitError("expected ")
|
[mlir] NFC - Expose an OffsetSizeAndStrideOpInterface
This revision will make it easier to create new ops base on the strided memref abstraction outside of the std dialect.
OffsetSizeAndStrideOpInterface is an interface for ops that allow specifying mixed dynamic and static offsets, sizes and strides variadic operands.
Ops that implement this interface need to expose the following methods:
1. `getArrayAttrRanks` to specify the length of static integer
attributes.
2. `offsets`, `sizes` and `strides` variadic operands.
3. `static_offsets`, resp. `static_sizes` and `static_strides` integer
array attributes.
The invariants of this interface are:
1. `static_offsets`, `static_sizes` and `static_strides` have length
exactly `getArrayAttrRanks()`[0] (resp. [1], [2]).
2. `offsets`, `sizes` and `strides` have each length at most
`getArrayAttrRanks()`[0] (resp. [1], [2]).
3. if an entry of `static_offsets` (resp. `static_sizes`,
`static_strides`) is equal to a special sentinel value, namely
`ShapedType::kDynamicStrideOrOffset` (resp. `ShapedType::kDynamicSize`,
`ShapedType::kDynamicStrideOrOffset`), then the corresponding entry is
a dynamic offset (resp. size, stride).
4. a variadic `offset` (resp. `sizes`, `strides`) operand must be present
for each dynamic offset (resp. size, stride).
This interface is useful to factor out common behavior and provide support
for carrying or injecting static behavior through the use of the static
attributes.
Differential Revision: https://reviews.llvm.org/D92011
2020-11-24 22:23:57 +08:00
|
|
|
<< expectedNumDynamicEntries << " dynamic " << name << " values";
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
LogicalResult mlir::verify(OffsetSizeAndStrideOpInterface op) {
|
|
|
|
std::array<unsigned, 3> ranks = op.getArrayAttrRanks();
|
2020-12-18 06:42:40 +08:00
|
|
|
if (failed(verifyListOfOperandsOrIntegers(
|
|
|
|
op, "offset", ranks[0], op.static_offsets(), op.offsets(),
|
|
|
|
ShapedType::isDynamicStrideOrOffset)))
|
[mlir] NFC - Expose an OffsetSizeAndStrideOpInterface
This revision will make it easier to create new ops base on the strided memref abstraction outside of the std dialect.
OffsetSizeAndStrideOpInterface is an interface for ops that allow specifying mixed dynamic and static offsets, sizes and strides variadic operands.
Ops that implement this interface need to expose the following methods:
1. `getArrayAttrRanks` to specify the length of static integer
attributes.
2. `offsets`, `sizes` and `strides` variadic operands.
3. `static_offsets`, resp. `static_sizes` and `static_strides` integer
array attributes.
The invariants of this interface are:
1. `static_offsets`, `static_sizes` and `static_strides` have length
exactly `getArrayAttrRanks()`[0] (resp. [1], [2]).
2. `offsets`, `sizes` and `strides` have each length at most
`getArrayAttrRanks()`[0] (resp. [1], [2]).
3. if an entry of `static_offsets` (resp. `static_sizes`,
`static_strides`) is equal to a special sentinel value, namely
`ShapedType::kDynamicStrideOrOffset` (resp. `ShapedType::kDynamicSize`,
`ShapedType::kDynamicStrideOrOffset`), then the corresponding entry is
a dynamic offset (resp. size, stride).
4. a variadic `offset` (resp. `sizes`, `strides`) operand must be present
for each dynamic offset (resp. size, stride).
This interface is useful to factor out common behavior and provide support
for carrying or injecting static behavior through the use of the static
attributes.
Differential Revision: https://reviews.llvm.org/D92011
2020-11-24 22:23:57 +08:00
|
|
|
return failure();
|
2020-12-18 06:42:40 +08:00
|
|
|
if (failed(verifyListOfOperandsOrIntegers(op, "size", ranks[1],
|
|
|
|
op.static_sizes(), op.sizes(),
|
|
|
|
ShapedType::isDynamic)))
|
[mlir] NFC - Expose an OffsetSizeAndStrideOpInterface
This revision will make it easier to create new ops base on the strided memref abstraction outside of the std dialect.
OffsetSizeAndStrideOpInterface is an interface for ops that allow specifying mixed dynamic and static offsets, sizes and strides variadic operands.
Ops that implement this interface need to expose the following methods:
1. `getArrayAttrRanks` to specify the length of static integer
attributes.
2. `offsets`, `sizes` and `strides` variadic operands.
3. `static_offsets`, resp. `static_sizes` and `static_strides` integer
array attributes.
The invariants of this interface are:
1. `static_offsets`, `static_sizes` and `static_strides` have length
exactly `getArrayAttrRanks()`[0] (resp. [1], [2]).
2. `offsets`, `sizes` and `strides` have each length at most
`getArrayAttrRanks()`[0] (resp. [1], [2]).
3. if an entry of `static_offsets` (resp. `static_sizes`,
`static_strides`) is equal to a special sentinel value, namely
`ShapedType::kDynamicStrideOrOffset` (resp. `ShapedType::kDynamicSize`,
`ShapedType::kDynamicStrideOrOffset`), then the corresponding entry is
a dynamic offset (resp. size, stride).
4. a variadic `offset` (resp. `sizes`, `strides`) operand must be present
for each dynamic offset (resp. size, stride).
This interface is useful to factor out common behavior and provide support
for carrying or injecting static behavior through the use of the static
attributes.
Differential Revision: https://reviews.llvm.org/D92011
2020-11-24 22:23:57 +08:00
|
|
|
return failure();
|
2020-12-18 06:42:40 +08:00
|
|
|
if (failed(verifyListOfOperandsOrIntegers(
|
|
|
|
op, "stride", ranks[2], op.static_strides(), op.strides(),
|
|
|
|
ShapedType::isDynamicStrideOrOffset)))
|
[mlir] NFC - Expose an OffsetSizeAndStrideOpInterface
This revision will make it easier to create new ops base on the strided memref abstraction outside of the std dialect.
OffsetSizeAndStrideOpInterface is an interface for ops that allow specifying mixed dynamic and static offsets, sizes and strides variadic operands.
Ops that implement this interface need to expose the following methods:
1. `getArrayAttrRanks` to specify the length of static integer
attributes.
2. `offsets`, `sizes` and `strides` variadic operands.
3. `static_offsets`, resp. `static_sizes` and `static_strides` integer
array attributes.
The invariants of this interface are:
1. `static_offsets`, `static_sizes` and `static_strides` have length
exactly `getArrayAttrRanks()`[0] (resp. [1], [2]).
2. `offsets`, `sizes` and `strides` have each length at most
`getArrayAttrRanks()`[0] (resp. [1], [2]).
3. if an entry of `static_offsets` (resp. `static_sizes`,
`static_strides`) is equal to a special sentinel value, namely
`ShapedType::kDynamicStrideOrOffset` (resp. `ShapedType::kDynamicSize`,
`ShapedType::kDynamicStrideOrOffset`), then the corresponding entry is
a dynamic offset (resp. size, stride).
4. a variadic `offset` (resp. `sizes`, `strides`) operand must be present
for each dynamic offset (resp. size, stride).
This interface is useful to factor out common behavior and provide support
for carrying or injecting static behavior through the use of the static
attributes.
Differential Revision: https://reviews.llvm.org/D92011
2020-11-24 22:23:57 +08:00
|
|
|
return failure();
|
|
|
|
return success();
|
|
|
|
}
|
[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
2020-11-24 22:54:06 +08:00
|
|
|
|
2020-12-18 06:42:40 +08:00
|
|
|
void mlir::printListOfOperandsOrIntegers(
|
|
|
|
OpAsmPrinter &p, ValueRange values, ArrayAttr arrayAttr,
|
|
|
|
llvm::function_ref<bool(int64_t)> isDynamic) {
|
2020-11-25 03:52:24 +08:00
|
|
|
p << '[';
|
|
|
|
unsigned idx = 0;
|
|
|
|
llvm::interleaveComma(arrayAttr, p, [&](Attribute a) {
|
|
|
|
int64_t val = a.cast<IntegerAttr>().getInt();
|
|
|
|
if (isDynamic(val))
|
|
|
|
p << values[idx++];
|
|
|
|
else
|
|
|
|
p << val;
|
|
|
|
});
|
|
|
|
p << ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
void mlir::printOffsetsSizesAndStrides(OpAsmPrinter &p,
|
|
|
|
OffsetSizeAndStrideOpInterface op,
|
|
|
|
StringRef offsetPrefix,
|
|
|
|
StringRef sizePrefix,
|
|
|
|
StringRef stridePrefix,
|
|
|
|
ArrayRef<StringRef> elidedAttrs) {
|
|
|
|
p << offsetPrefix;
|
|
|
|
printListOfOperandsOrIntegers(p, op.offsets(), op.static_offsets(),
|
|
|
|
ShapedType::isDynamicStrideOrOffset);
|
|
|
|
p << sizePrefix;
|
|
|
|
printListOfOperandsOrIntegers(p, op.sizes(), op.static_sizes(),
|
|
|
|
ShapedType::isDynamic);
|
|
|
|
p << stridePrefix;
|
|
|
|
printListOfOperandsOrIntegers(p, op.strides(), op.static_strides(),
|
|
|
|
ShapedType::isDynamicStrideOrOffset);
|
|
|
|
p.printOptionalAttrDict(op.getAttrs(), elidedAttrs);
|
|
|
|
}
|
|
|
|
|
2020-12-18 06:42:40 +08:00
|
|
|
ParseResult mlir::parseListOfOperandsOrIntegers(
|
|
|
|
OpAsmParser &parser, OperationState &result, StringRef attrName,
|
|
|
|
int64_t dynVal, SmallVectorImpl<OpAsmParser::OperandType> &ssa) {
|
[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
2020-11-24 22:54:06 +08:00
|
|
|
if (failed(parser.parseLSquare()))
|
|
|
|
return failure();
|
|
|
|
// 0-D.
|
|
|
|
if (succeeded(parser.parseOptionalRSquare())) {
|
|
|
|
result.addAttribute(attrName, parser.getBuilder().getArrayAttr({}));
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<int64_t, 4> attrVals;
|
|
|
|
while (true) {
|
|
|
|
OpAsmParser::OperandType operand;
|
|
|
|
auto res = parser.parseOptionalOperand(operand);
|
|
|
|
if (res.hasValue() && succeeded(res.getValue())) {
|
|
|
|
ssa.push_back(operand);
|
|
|
|
attrVals.push_back(dynVal);
|
|
|
|
} else {
|
|
|
|
IntegerAttr attr;
|
|
|
|
if (failed(parser.parseAttribute<IntegerAttr>(attr)))
|
|
|
|
return parser.emitError(parser.getNameLoc())
|
|
|
|
<< "expected SSA value or integer";
|
|
|
|
attrVals.push_back(attr.getInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (succeeded(parser.parseOptionalComma()))
|
|
|
|
continue;
|
|
|
|
if (failed(parser.parseRSquare()))
|
|
|
|
return failure();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto arrayAttr = parser.getBuilder().getI64ArrayAttr(attrVals);
|
|
|
|
result.addAttribute(attrName, arrayAttr);
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseResult mlir::parseOffsetsSizesAndStrides(
|
2020-11-25 03:52:24 +08:00
|
|
|
OpAsmParser &parser, OperationState &result, ArrayRef<int> segmentSizes,
|
|
|
|
llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalOffsetPrefix,
|
|
|
|
llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalSizePrefix,
|
|
|
|
llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalStridePrefix) {
|
|
|
|
return parseOffsetsSizesAndStrides(
|
|
|
|
parser, result, segmentSizes, nullptr, parseOptionalOffsetPrefix,
|
|
|
|
parseOptionalSizePrefix, parseOptionalStridePrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseResult mlir::parseOffsetsSizesAndStrides(
|
|
|
|
OpAsmParser &parser, OperationState &result, ArrayRef<int> segmentSizes,
|
[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
2020-11-24 22:54:06 +08:00
|
|
|
llvm::function_ref<ParseResult(OpAsmParser &, OperationState &)>
|
|
|
|
preResolutionFn,
|
|
|
|
llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalOffsetPrefix,
|
|
|
|
llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalSizePrefix,
|
|
|
|
llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalStridePrefix) {
|
|
|
|
SmallVector<OpAsmParser::OperandType, 4> offsetsInfo, sizesInfo, stridesInfo;
|
|
|
|
auto indexType = parser.getBuilder().getIndexType();
|
|
|
|
if ((parseOptionalOffsetPrefix && parseOptionalOffsetPrefix(parser)) ||
|
|
|
|
parseListOfOperandsOrIntegers(
|
|
|
|
parser, result,
|
|
|
|
OffsetSizeAndStrideOpInterface::getStaticOffsetsAttrName(),
|
|
|
|
ShapedType::kDynamicStrideOrOffset, offsetsInfo) ||
|
|
|
|
(parseOptionalSizePrefix && parseOptionalSizePrefix(parser)) ||
|
|
|
|
parseListOfOperandsOrIntegers(
|
|
|
|
parser, result,
|
|
|
|
OffsetSizeAndStrideOpInterface::getStaticSizesAttrName(),
|
|
|
|
ShapedType::kDynamicSize, sizesInfo) ||
|
|
|
|
(parseOptionalStridePrefix && parseOptionalStridePrefix(parser)) ||
|
|
|
|
parseListOfOperandsOrIntegers(
|
|
|
|
parser, result,
|
|
|
|
OffsetSizeAndStrideOpInterface::getStaticStridesAttrName(),
|
|
|
|
ShapedType::kDynamicStrideOrOffset, stridesInfo))
|
|
|
|
return failure();
|
|
|
|
// Add segment sizes to result
|
2020-11-25 03:52:24 +08:00
|
|
|
SmallVector<int, 4> segmentSizesFinal(segmentSizes.begin(),
|
|
|
|
segmentSizes.end());
|
[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
2020-11-24 22:54:06 +08:00
|
|
|
segmentSizesFinal.append({static_cast<int>(offsetsInfo.size()),
|
2020-11-25 03:52:24 +08:00
|
|
|
static_cast<int>(sizesInfo.size()),
|
|
|
|
static_cast<int>(stridesInfo.size())});
|
[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
2020-11-24 22:54:06 +08:00
|
|
|
result.addAttribute(
|
|
|
|
OpTrait::AttrSizedOperandSegments<void>::getOperandSegmentSizeAttr(),
|
2020-11-25 03:52:24 +08:00
|
|
|
parser.getBuilder().getI32VectorAttr(segmentSizesFinal));
|
[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
2020-11-24 22:54:06 +08:00
|
|
|
return failure(
|
|
|
|
(preResolutionFn && preResolutionFn(parser, result)) ||
|
|
|
|
parser.resolveOperands(offsetsInfo, indexType, result.operands) ||
|
|
|
|
parser.resolveOperands(sizesInfo, indexType, result.operands) ||
|
|
|
|
parser.resolveOperands(stridesInfo, indexType, result.operands));
|
|
|
|
}
|