MLIR  17.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 class OffsetSizeAndStrideOpInterface;
25 
26 namespace detail {
27 
28 LogicalResult verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op);
29 
31  OffsetSizeAndStrideOpInterface a, OffsetSizeAndStrideOpInterface b,
32  llvm::function_ref<bool(OpFoldResult, OpFoldResult)> cmp);
33 
34 } // namespace detail
35 } // namespace mlir
36 
37 /// Include the generated interface declarations.
38 #include "mlir/Interfaces/ViewLikeInterface.h.inc"
39 
40 namespace mlir {
41 
42 /// Printer hook for custom directive in assemblyFormat.
43 ///
44 /// custom<DynamicIndexList>($values, $integers)
45 /// custom<DynamicIndexList>($values, $integers, type($values))
46 ///
47 /// where `values` is of ODS type `Variadic<*>` and `integers` is of ODS
48 /// type `I64ArrayAttr`. Prints a list with either (1) the static integer value
49 /// in `integers` is `kDynamic` or (2) the next value otherwise. If `valueTypes`
50 /// is non-empty, it is expected to contain as many elements as `values`
51 /// indicating their types. This allows idiomatic printing of mixed value and
52 /// integer attributes in a list. E.g.
53 /// `[%arg0 : index, 7, 42, %arg42 : i32]`.
54 ///
55 /// If `isTrailingIdxScalable` is true, then wrap the trailing index with
56 /// square brackets, e.g. `[42]`, to denote scalability. This would normally be
57 /// used for scalable tile or vector sizes.
59  OpAsmPrinter &printer, Operation *op, OperandRange values,
60  ArrayRef<int64_t> integers, TypeRange valueTypes = TypeRange(),
62  bool isTrailingIdxScalable = false);
63 
64 /// Parser hook for custom directive in assemblyFormat.
65 ///
66 /// custom<DynamicIndexList>($values, $integers)
67 /// custom<DynamicIndexList>($values, $integers, type($values))
68 ///
69 /// where `values` is of ODS type `Variadic<*>` and `integers` is of ODS
70 /// type `I64ArrayAttr`. Parse a mixed list with either (1) static integer
71 /// values or (2) SSA values. Fill `integers` with the integer ArrayAttr, where
72 /// `kDynamic` encodes the position of SSA values. Add the parsed SSA values
73 /// to `values` in-order. If `valueTypes` is non-null, fill it with types
74 /// corresponding to values; otherwise the caller must handle the types.
75 ///
76 /// E.g. after parsing "[%arg0 : index, 7, 42, %arg42 : i32]":
77 /// 1. `result` is filled with the i64 ArrayAttr "[`kDynamic`, 7, 42,
78 /// `kDynamic`]"
79 /// 2. `ssa` is filled with "[%arg0, %arg1]".
80 ///
81 /// Trailing indices can be scalable. For example, "42" in "[7, [42]]" is
82 /// scalable. This notation is similar to how scalable dims are marked when
83 /// defining Vectors. If /p isTrailingIdxScalable is null, scalable indices are
84 /// not allowed/expected. When it's not null, this hook will set the
85 /// corresponding value to:
86 /// * true if the trailing idx is scalable,
87 /// * false otherwise.
88 ParseResult parseDynamicIndexList(
89  OpAsmParser &parser,
90  SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values,
91  DenseI64ArrayAttr &integers, bool *isTrailingIdxScalable = nullptr,
92  SmallVectorImpl<Type> *valueTypes = nullptr,
95  OpAsmParser &parser,
97  DenseI64ArrayAttr &integers, SmallVectorImpl<Type> &valueTypes,
99  return parseDynamicIndexList(parser, values, integers,
100  /*isTrailingIdxScalable=*/nullptr, &valueTypes,
101  delimiter);
102 }
103 
104 /// Verify that a the `values` has as many elements as the number of entries in
105 /// `attr` for which `isDynamic` evaluates to true.
106 LogicalResult verifyListOfOperandsOrIntegers(Operation *op, StringRef name,
107  unsigned expectedNumElements,
108  ArrayRef<int64_t> attr,
109  ValueRange values);
110 
111 } // namespace mlir
112 
113 #endif // MLIR_INTERFACES_VIEWLIKEINTERFACE_H_
Delimiter
These are the supported delimiters around operand lists and region argument lists,...
@ Square
Square brackets surrounding zero or more operands.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This class represents success/failure for parsing-like operations that find it important to chain tog...
Base class for DenseArrayAttr that is instantiated and specialized for each supported element type be...
bool sameOffsetsSizesAndStrides(OffsetSizeAndStrideOpInterface a, OffsetSizeAndStrideOpInterface b, llvm::function_ref< bool(OpFoldResult, OpFoldResult)> cmp)
LogicalResult verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op)
This header declares functions that assit transformations in the MemRef dialect.
ParseResult parseDynamicIndexList(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, DenseI64ArrayAttr &integers, bool *isTrailingIdxScalable=nullptr, SmallVectorImpl< Type > *valueTypes=nullptr, AsmParser::Delimiter delimiter=AsmParser::Delimiter::Square)
Parser hook for custom directive in assemblyFormat.
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
void printDynamicIndexList(OpAsmPrinter &printer, Operation *op, OperandRange values, ArrayRef< int64_t > integers, TypeRange valueTypes=TypeRange(), AsmParser::Delimiter delimiter=AsmParser::Delimiter::Square, bool isTrailingIdxScalable=false)
Printer hook for custom directive in assemblyFormat.
LogicalResult verifyListOfOperandsOrIntegers(Operation *op, StringRef name, unsigned expectedNumElements, ArrayRef< int64_t > attr, ValueRange values)
Verify that a the values has as many elements as the number of entries in attr for which isDynamic ev...