• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ViewLikeInterface.h - View-like operations interface ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the operation interface for view-like operations.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_INTERFACES_VIEWLIKEINTERFACE_H_
14 #define MLIR_INTERFACES_VIEWLIKEINTERFACE_H_
15 
16 #include "mlir/IR/Builders.h"
17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/OpImplementation.h"
19 
20 namespace mlir {
21 /// Auxiliary range data structure to unpack the offset, size and stride
22 /// operands into a list of triples. Such a list can be more convenient to
23 /// manipulate.
24 struct Range {
25   Value offset;
26   Value size;
27   Value stride;
28 };
29 
30 class OffsetSizeAndStrideOpInterface;
31 LogicalResult verify(OffsetSizeAndStrideOpInterface op);
32 } // namespace mlir
33 
34 /// Include the generated interface declarations.
35 #include "mlir/Interfaces/ViewLikeInterface.h.inc"
36 
37 namespace mlir {
38 /// Print part of an op of the form:
39 /// ```
40 ///   <optional-offset-prefix>`[` offset-list `]`
41 ///   <optional-size-prefix>`[` size-list `]`
42 ///   <optional-stride-prefix>[` stride-list `]`
43 /// ```
44 void printOffsetsSizesAndStrides(
45     OpAsmPrinter &p, OffsetSizeAndStrideOpInterface op,
46     StringRef offsetPrefix = "", StringRef sizePrefix = " ",
47     StringRef stridePrefix = " ",
48     ArrayRef<StringRef> elidedAttrs =
49         OffsetSizeAndStrideOpInterface::getSpecialAttrNames());
50 
51 /// Parse trailing part of an op of the form:
52 /// ```
53 ///   <optional-offset-prefix>`[` offset-list `]`
54 ///   <optional-size-prefix>`[` size-list `]`
55 ///   <optional-stride-prefix>[` stride-list `]`
56 /// ```
57 /// Each entry in the offset, size and stride list either resolves to an integer
58 /// constant or an operand of index type.
59 /// Constants are added to the `result` as named integer array attributes with
60 /// name `OffsetSizeAndStrideOpInterface::getStaticOffsetsAttrName()` (resp.
61 /// `getStaticSizesAttrName()`, `getStaticStridesAttrName()`).
62 ///
63 /// Append the number of offset, size and stride operands to `segmentSizes`
64 /// before adding it to `result` as the named attribute:
65 /// `OpTrait::AttrSizedOperandSegments<void>::getOperandSegmentSizeAttr()`.
66 ///
67 /// Offset, size and stride operands resolution occurs after `preResolutionFn`
68 /// to give a chance to leading operands to resolve first, after parsing the
69 /// types.
70 ParseResult parseOffsetsSizesAndStrides(
71     OpAsmParser &parser, OperationState &result, ArrayRef<int> segmentSizes,
72     llvm::function_ref<ParseResult(OpAsmParser &, OperationState &)>
73         preResolutionFn = nullptr,
74     llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalOffsetPrefix =
75         nullptr,
76     llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalSizePrefix =
77         nullptr,
78     llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalStridePrefix =
79         nullptr);
80 /// `preResolutionFn`-less version of `parseOffsetsSizesAndStrides`.
81 ParseResult parseOffsetsSizesAndStrides(
82     OpAsmParser &parser, OperationState &result, ArrayRef<int> segmentSizes,
83     llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalOffsetPrefix =
84         nullptr,
85     llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalSizePrefix =
86         nullptr,
87     llvm::function_ref<ParseResult(OpAsmParser &)> parseOptionalStridePrefix =
88         nullptr);
89 
90 } // namespace mlir
91 
92 #endif // MLIR_INTERFACES_VIEWLIKEINTERFACE_H_
93