MLIR  16.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 
24 /// Return a vector of OpFoldResults given the special value
25 /// that indicates whether of the value is dynamic or not.
26 SmallVector<OpFoldResult, 4> getMixedValues(ArrayAttr staticValues,
27  ValueRange dynamicValues,
28  int64_t dynamicValueIndicator);
29 
30 /// Return a vector of all the static and dynamic offsets/strides.
31 SmallVector<OpFoldResult, 4> getMixedStridesOrOffsets(ArrayAttr staticValues,
32  ValueRange dynamicValues);
33 
34 /// Return a vector of all the static and dynamic sizes.
35 SmallVector<OpFoldResult, 4> getMixedSizes(ArrayAttr staticValues,
36  ValueRange dynamicValues);
37 
38 /// Decompose a vector of mixed static or dynamic values into the corresponding
39 /// pair of arrays. This is the inverse function of `getMixedValues`.
40 std::pair<ArrayAttr, SmallVector<Value>>
41 decomposeMixedValues(Builder &b,
42  const SmallVectorImpl<OpFoldResult> &mixedValues,
43  const int64_t dynamicValueIndicator);
44 
45 /// Decompose a vector of mixed static and dynamic strides/offsets into the
46 /// corresponding pair of arrays. This is the inverse function of
47 /// `getMixedStridesOrOffsets`.
48 std::pair<ArrayAttr, SmallVector<Value>> decomposeMixedStridesOrOffsets(
49  OpBuilder &b, const SmallVectorImpl<OpFoldResult> &mixedValues);
50 
51 /// Decompose a vector of mixed static or dynamic strides/offsets into the
52 /// corresponding pair of arrays. This is the inverse function of
53 /// `getMixedSizes`.
54 std::pair<ArrayAttr, SmallVector<Value>>
55 decomposeMixedSizes(OpBuilder &b,
56  const SmallVectorImpl<OpFoldResult> &mixedValues);
57 
58 class OffsetSizeAndStrideOpInterface;
59 
60 namespace detail {
61 
62 LogicalResult verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op);
63 
65  OffsetSizeAndStrideOpInterface a, OffsetSizeAndStrideOpInterface b,
66  llvm::function_ref<bool(OpFoldResult, OpFoldResult)> cmp);
67 
68 } // namespace detail
69 } // namespace mlir
70 
71 /// Include the generated interface declarations.
72 #include "mlir/Interfaces/ViewLikeInterface.h.inc"
73 
74 namespace mlir {
75 
76 /// Printer hook for custom directive in assemblyFormat.
77 ///
78 /// custom<DynamicIndexList>($values, $integers)
79 ///
80 /// where `values` is of ODS type `Variadic<Index>` and `integers` is of ODS
81 /// type `I64ArrayAttr`. Prints a list with either (1) the static integer value
82 /// in `integers` is `dynVal` or (2) the next value otherwise. This allows
83 /// idiomatic printing of mixed value and integer attributes in a list. E.g.
84 /// `[%arg0, 7, 42, %arg42]`.
85 void printDynamicIndexList(OpAsmPrinter &printer, Operation *op,
86  OperandRange values, ArrayAttr integers,
87  int64_t dynVal);
88 
89 /// Pasrer hook for custom directive in assemblyFormat.
90 ///
91 /// custom<DynamicIndexList>($values, $integers)
92 ///
93 /// where `values` is of ODS type `Variadic<Index>` and `integers` is of ODS
94 /// type `I64ArrayAttr`. Parse a mixed list with either (1) static integer
95 /// values or (2) SSA values. Fill `integers` with the integer ArrayAttr, where
96 /// `dynVal` encodes the position of SSA values. Add the parsed SSA values
97 /// to `values` in-order.
98 //
99 /// E.g. after parsing "[%arg0, 7, 42, %arg42]":
100 /// 1. `result` is filled with the i64 ArrayAttr "[`dynVal`, 7, 42, `dynVal`]"
101 /// 2. `ssa` is filled with "[%arg0, %arg1]".
102 ParseResult
103 parseDynamicIndexList(OpAsmParser &parser,
104  SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
105  ArrayAttr &integers, int64_t dynVal);
106 
107 /// Verify that a the `values` has as many elements as the number of entries in
108 /// `attr` for which `isDynamic` evaluates to true.
109 LogicalResult verifyListOfOperandsOrIntegers(
110  Operation *op, StringRef name, unsigned expectedNumElements, ArrayAttr attr,
111  ValueRange values, function_ref<bool(int64_t)> isDynamic);
112 
113 } // namespace mlir
114 
115 #endif // MLIR_INTERFACES_VIEWLIKEINTERFACE_H_
Include the generated interface declarations.
SmallVector< OpFoldResult, 4 > getMixedSizes(ArrayAttr staticValues, ValueRange dynamicValues)
Return a vector of all the static and dynamic sizes.
llvm::function_ref< Fn > function_ref
Definition: LLVM.h:149
void printDynamicIndexList(OpAsmPrinter &printer, Operation *op, OperandRange values, ArrayAttr integers, int64_t dynVal)
Printer hook for custom directive in assemblyFormat.
std::pair< ArrayAttr, SmallVector< Value > > decomposeMixedStridesOrOffsets(OpBuilder &b, const SmallVectorImpl< OpFoldResult > &mixedValues)
Decompose a vector of mixed static and dynamic strides/offsets into the corresponding pair of arrays...
ParseResult parseDynamicIndexList(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, ArrayAttr &integers, int64_t dynVal)
Pasrer hook for custom directive in assemblyFormat.
std::pair< ArrayAttr, SmallVector< Value > > decomposeMixedSizes(OpBuilder &b, const SmallVectorImpl< OpFoldResult > &mixedValues)
Decompose a vector of mixed static or dynamic strides/offsets into the corresponding pair of arrays...
SmallVector< OpFoldResult, 4 > getMixedValues(ArrayAttr staticValues, ValueRange dynamicValues, int64_t dynamicValueIndicator)
Return a vector of OpFoldResults given the special value that indicates whether of the value is dynam...
LogicalResult verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op)
LogicalResult verifyListOfOperandsOrIntegers(Operation *op, StringRef name, unsigned expectedNumElements, ArrayAttr attr, ValueRange values, 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...
std::pair< ArrayAttr, SmallVector< Value > > decomposeMixedValues(Builder &b, const SmallVectorImpl< OpFoldResult > &mixedValues, const int64_t dynamicValueIndicator)
Decompose a vector of mixed static or dynamic values into the corresponding pair of arrays...
bool sameOffsetsSizesAndStrides(OffsetSizeAndStrideOpInterface a, OffsetSizeAndStrideOpInterface b, llvm::function_ref< bool(OpFoldResult, OpFoldResult)> cmp)
SmallVector< OpFoldResult, 4 > getMixedStridesOrOffsets(ArrayAttr staticValues, ValueRange dynamicValues)
Return a vector of all the static and dynamic offsets/strides.