MLIR  15.0.0git
ViewLikeInterface.h
Go to the documentation of this file.
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 
17 #include "mlir/IR/Builders.h"
19 #include "mlir/IR/BuiltinTypes.h"
21 
22 namespace mlir {
23 /// Auxiliary range data structure to unpack the offset, size and stride
24 /// operands into a list of triples. Such a list can be more convenient to
25 /// manipulate.
26 struct Range {
30 };
31 
32 class OffsetSizeAndStrideOpInterface;
33 
34 /// Return a vector of all the static or dynamic offsets of the op from provided
35 /// external static and dynamic offsets.
36 SmallVector<OpFoldResult, 4> getMixedOffsets(OffsetSizeAndStrideOpInterface op,
37  ArrayAttr staticOffsets,
38  ValueRange offsets);
39 
40 /// Return a vector of all the static or dynamic sizes of the op from provided
41 /// external static and dynamic sizes.
42 SmallVector<OpFoldResult, 4> getMixedSizes(OffsetSizeAndStrideOpInterface op,
43  ArrayAttr staticSizes,
44  ValueRange sizes);
45 
46 /// Return a vector of all the static or dynamic strides of the op from provided
47 /// external static and dynamic strides.
48 SmallVector<OpFoldResult, 4> getMixedStrides(OffsetSizeAndStrideOpInterface op,
49  ArrayAttr staticStrides,
50  ValueRange strides);
51 
52 namespace detail {
53 LogicalResult verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op);
54 
56  OffsetSizeAndStrideOpInterface a, OffsetSizeAndStrideOpInterface b,
58 } // namespace detail
59 } // namespace mlir
60 
61 /// Include the generated interface declarations.
62 #include "mlir/Interfaces/ViewLikeInterface.h.inc"
63 
64 namespace mlir {
65 
66 /// Printer hook for custom directive in assemblyFormat.
67 ///
68 /// custom<OperandsOrIntegersOffsetsOrStridesList>($values, $integers)
69 ///
70 /// where `values` is of ODS type `Variadic<Index>` and `integers` is of ODS
71 /// type `I64ArrayAttr`. for use in in assemblyFormat. Prints a list with
72 /// either (1) the static integer value in `integers` if the value is
73 /// ShapedType::kDynamicStrideOrOffset or (2) the next value otherwise. This
74 /// allows idiomatic printing of mixed value and integer attributes in a
75 /// list. E.g. `[%arg0, 7, 42, %arg42]`.
77  Operation *op,
78  OperandRange values,
79  ArrayAttr integers);
80 
81 /// Printer hook for custom directive in assemblyFormat.
82 ///
83 /// custom<OperandsOrIntegersSizesList>($values, $integers)
84 ///
85 /// where `values` is of ODS type `Variadic<Index>` and `integers` is of ODS
86 /// type `I64ArrayAttr`. for use in in assemblyFormat. Prints a list with
87 /// either (1) the static integer value in `integers` if the value is
88 /// ShapedType::kDynamicSize or (2) the next value otherwise. This
89 /// allows idiomatic printing of mixed value and integer attributes in a
90 /// list. E.g. `[%arg0, 7, 42, %arg42]`.
92  OperandRange values, ArrayAttr integers);
93 
94 /// Pasrer hook for custom directive in assemblyFormat.
95 ///
96 /// custom<OperandsOrIntegersOffsetsOrStridesList>($values, $integers)
97 ///
98 /// where `values` is of ODS type `Variadic<Index>` and `integers` is of ODS
99 /// type `I64ArrayAttr`. for use in in assemblyFormat. Parse a mixed list with
100 /// either (1) static integer values or (2) SSA values. Fill `integers` with
101 /// the integer ArrayAttr, where ShapedType::kDynamicStrideOrOffset encodes the
102 /// position of SSA values. Add the parsed SSA values to `values` in-order.
103 //
104 /// E.g. after parsing "[%arg0, 7, 42, %arg42]":
105 /// 1. `result` is filled with the i64 ArrayAttr "[`dynVal`, 7, 42, `dynVal`]"
106 /// 2. `ssa` is filled with "[%arg0, %arg1]".
110  ArrayAttr &integers);
111 
112 /// Pasrer hook for custom directive in assemblyFormat.
113 ///
114 /// custom<OperandsOrIntegersSizesList>($values, $integers)
115 ///
116 /// where `values` is of ODS type `Variadic<Index>` and `integers` is of ODS
117 /// type `I64ArrayAttr`. for use in in assemblyFormat. Parse a mixed list with
118 /// either (1) static integer values or (2) SSA values. Fill `integers` with
119 /// the integer ArrayAttr, where ShapedType::kDynamicSize encodes the
120 /// position of SSA values. Add the parsed SSA values to `values` in-order.
121 //
122 /// E.g. after parsing "[%arg0, 7, 42, %arg42]":
123 /// 1. `result` is filled with the i64 ArrayAttr "[`dynVal`, 7, 42, `dynVal`]"
124 /// 2. `ssa` is filled with "[%arg0, %arg1]".
128  ArrayAttr &integers);
129 
130 /// Verify that a the `values` has as many elements as the number of entries in
131 /// `attr` for which `isDynamic` evaluates to true.
133  Operation *op, StringRef name, unsigned expectedNumElements, ArrayAttr attr,
134  ValueRange values, llvm::function_ref<bool(int64_t)> isDynamic);
135 
136 } // namespace mlir
137 
138 #endif // MLIR_INTERFACES_VIEWLIKEINTERFACE_H_
Include the generated interface declarations.
SmallVector< OpFoldResult, 4 > getMixedOffsets(OffsetSizeAndStrideOpInterface op, ArrayAttr staticOffsets, ValueRange offsets)
Return a vector of all the static or dynamic offsets of the op from provided external static and dyna...
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
void printOperandsOrIntegersOffsetsOrStridesList(OpAsmPrinter &printer, Operation *op, OperandRange values, ArrayAttr integers)
Printer hook for custom directive in assemblyFormat.
ParseResult parseOperandsOrIntegersOffsetsOrStridesList(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, ArrayAttr &integers)
Pasrer hook for custom directive in assemblyFormat.
This class represents a single result from folding an operation.
Definition: OpDefinition.h:229
The OpAsmParser has methods for interacting with the asm parser: parsing things from it...
LogicalResult verifyListOfOperandsOrIntegers(Operation *op, StringRef name, unsigned expectedNumElements, ArrayAttr attr, ValueRange values, llvm::function_ref< bool(int64_t)> isDynamic)
Verify that a the values has as many elements as the number of entries in attr for which isDynamic ev...
Auxiliary range data structure to unpack the offset, size and stride operands into a list of triples...
void printOperandsOrIntegersSizesList(OpAsmPrinter &printer, Operation *op, OperandRange values, ArrayAttr integers)
Printer hook for custom directive in assemblyFormat.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
SmallVector< OpFoldResult, 4 > getMixedSizes(OffsetSizeAndStrideOpInterface op, ArrayAttr staticSizes, ValueRange sizes)
Return a vector of all the static or dynamic sizes of the op from provided external static and dynami...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:85
static bool sameOffsetsSizesAndStrides(tensor::ExtractSliceOp s, tensor::InsertSliceOp si)
Return true is all offsets, sizes and strides are equal.
Definition: Hoisting.cpp:77
This class implements the operand iterators for the Operation class.
LogicalResult verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op)
This class represents success/failure for parsing-like operations that find it important to chain tog...
This class provides an abstraction over the different types of ranges over Values.
SmallVector< OpFoldResult, 4 > getMixedStrides(OffsetSizeAndStrideOpInterface op, ArrayAttr staticStrides, ValueRange strides)
Return a vector of all the static or dynamic strides of the op from provided external static and dyna...
ParseResult parseOperandsOrIntegersSizesList(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, ArrayAttr &integers)
Pasrer hook for custom directive in assemblyFormat.