This is an archive of the discontinued LLVM Phabricator instance.

[mlir] NFC - Refactor and expose a parsing helper for OffsetSizeAndStrideInterface
ClosedPublic

Authored by nicolasvasilache on Nov 24 2020, 6:53 AM.

Details

Summary

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);

Diff Detail

Event Timeline

nicolasvasilache requested review of this revision.Nov 24 2020, 6:53 AM
pifon2a accepted this revision.Nov 24 2020, 7:09 AM
pifon2a added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
3176

here as well

3775

nit: inline in parseOffsetsSizesAndStrides call?

3883

and here

mlir/lib/Interfaces/ViewLikeInterface.cpp
138

nit: move auto b = ... above
auto indexType = b.getIndexType().

This revision is now accepted and ready to land.Nov 24 2020, 7:09 AM
nicolasvasilache marked 4 inline comments as done.Nov 24 2020, 11:28 AM

Thanks pifon@, made your suggestions and squashed in the followup commit.

mlir/lib/Interfaces/ViewLikeInterface.cpp
138

Actually, just inlined it.

nicolasvasilache marked an inline comment as done.Nov 24 2020, 11:31 AM