MLIR  19.0.0git
ViewLikeInterfaceUtils.h
Go to the documentation of this file.
1 //===- ViewLikeInterfaceUtils.h ---------------------------------*- C++ -*-===//
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 #ifndef MLIR_DIALECT_AFFINE_VIEWLIKEINTERFACEUTILS_H
10 #define MLIR_DIALECT_AFFINE_VIEWLIKEINTERFACEUTILS_H
11 
13 #include "mlir/IR/OpDefinition.h"
15 
16 namespace mlir {
17 class RewriterBase;
18 
19 namespace affine {
20 
21 /// Fills the `combinedOffsets`, `combinedSizes` and `combinedStrides` to use
22 /// when combining a producer slice **into** a consumer slice.
23 ///
24 /// This function performs the following computation:
25 /// - Combined offsets = producer_offsets * consumer_strides + consumer_offsets
26 /// - Combined sizes = consumer_sizes
27 /// - Combined strides = producer_strides * consumer_strides
28 // TODO: unify this API with resolveIndicesIntoOpWithOffsetsAndStrides or
29 // deprecate.
30 LogicalResult
31 mergeOffsetsSizesAndStrides(OpBuilder &builder, Location loc,
32  ArrayRef<OpFoldResult> producerOffsets,
33  ArrayRef<OpFoldResult> producerSizes,
34  ArrayRef<OpFoldResult> producerStrides,
35  const llvm::SmallBitVector &droppedProducerDims,
36  ArrayRef<OpFoldResult> consumerOffsets,
37  ArrayRef<OpFoldResult> consumerSizes,
38  ArrayRef<OpFoldResult> consumerStrides,
39  SmallVector<OpFoldResult> &combinedOffsets,
40  SmallVector<OpFoldResult> &combinedSizes,
41  SmallVector<OpFoldResult> &combinedStrides);
42 
43 /// Fills the `combinedOffsets`, `combinedSizes` and `combinedStrides` to use
44 /// when combining a `producer` slice op **into** a `consumer` slice op.
45 // TODO: unify this API with resolveIndicesIntoOpWithOffsetsAndStrides or
46 // deprecate.
47 LogicalResult
48 mergeOffsetsSizesAndStrides(OpBuilder &builder, Location loc,
49  OffsetSizeAndStrideOpInterface producer,
50  OffsetSizeAndStrideOpInterface consumer,
51  const llvm::SmallBitVector &droppedProducerDims,
52  SmallVector<OpFoldResult> &combinedOffsets,
53  SmallVector<OpFoldResult> &combinedSizes,
54  SmallVector<OpFoldResult> &combinedStrides);
55 
56 /// Given the 'consumerIndices' of a load/store operation operating on an op
57 /// with offsets and strides, return the combined indices.
58 ///
59 /// For example, using `memref.load` and `memref.subview` as an illustration:
60 ///
61 /// ```
62 /// %0 = ... : memref<12x42xf32>
63 /// %1 = memref.subview %0[%arg0, %arg1][...][%stride1, %stride2] :
64 /// memref<12x42xf32> to memref<4x4xf32, offset=?, strides=[?, ?]>
65 /// %2 = load %1[%i1, %i2] : memref<4x4xf32, offset=?, strides=[?, ?]>
66 /// ```
67 ///
68 /// could be folded into:
69 ///
70 /// ```
71 /// %2 = load %0[%arg0 + %i1 * %stride1][%arg1 + %i2 * %stride2] :
72 /// memref<12x42xf32>å
73 /// ```
75  RewriterBase &rewriter, Location loc,
76  ArrayRef<OpFoldResult> mixedSourceOffsets,
77  ArrayRef<OpFoldResult> mixedSourceStrides,
78  const llvm::SmallBitVector &rankReducedDims,
79  ArrayRef<OpFoldResult> consumerIndices,
80  SmallVectorImpl<Value> &resolvedIndices);
81 
83  RewriterBase &rewriter, Location loc,
84  ArrayRef<OpFoldResult> mixedSourceOffsets,
85  ArrayRef<OpFoldResult> mixedSourceStrides,
86  const llvm::SmallBitVector &rankReducedDims, ValueRange consumerIndices,
87  SmallVectorImpl<Value> &resolvedIndices) {
89  rewriter, loc, mixedSourceOffsets, mixedSourceStrides, rankReducedDims,
90  getAsOpFoldResult(consumerIndices), resolvedIndices);
91 }
92 
93 /// Given `sourceSizes`, `destSizes` and information about which dimensions are
94 /// dropped by the source: `rankReducedSourceDims`, compute the resolved sizes
95 /// that correspond to dest_op(source_op).
96 /// In practice, this amounts to filtering by `rankReducedSourceDims` and taking
97 /// from `sourceSizes` if a dimension is dropped, otherwise taking from
98 /// `destSizes`.
100  ArrayRef<OpFoldResult> sourceSizes, ArrayRef<OpFoldResult> destSizes,
101  const llvm::SmallBitVector &rankReducedSourceDims,
102  SmallVectorImpl<OpFoldResult> &resolvedSizes);
103 
104 } // namespace affine
105 } // namespace mlir
106 
107 #endif // MLIR_DIALECT_AFFINE_VIEWLIKEINTERFACEUTILS_H
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Definition: PatternMatch.h:400
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:381
void resolveSizesIntoOpWithSizes(ArrayRef< OpFoldResult > sourceSizes, ArrayRef< OpFoldResult > destSizes, const llvm::SmallBitVector &rankReducedSourceDims, SmallVectorImpl< OpFoldResult > &resolvedSizes)
Given sourceSizes, destSizes and information about which dimensions are dropped by the source: rankRe...
void resolveIndicesIntoOpWithOffsetsAndStrides(RewriterBase &rewriter, Location loc, ArrayRef< OpFoldResult > mixedSourceOffsets, ArrayRef< OpFoldResult > mixedSourceStrides, const llvm::SmallBitVector &rankReducedDims, ArrayRef< OpFoldResult > consumerIndices, SmallVectorImpl< Value > &resolvedIndices)
Given the 'consumerIndices' of a load/store operation operating on an op with offsets and strides,...
LogicalResult mergeOffsetsSizesAndStrides(OpBuilder &builder, Location loc, ArrayRef< OpFoldResult > producerOffsets, ArrayRef< OpFoldResult > producerSizes, ArrayRef< OpFoldResult > producerStrides, const llvm::SmallBitVector &droppedProducerDims, ArrayRef< OpFoldResult > consumerOffsets, ArrayRef< OpFoldResult > consumerSizes, ArrayRef< OpFoldResult > consumerStrides, SmallVector< OpFoldResult > &combinedOffsets, SmallVector< OpFoldResult > &combinedSizes, SmallVector< OpFoldResult > &combinedStrides)
Fills the combinedOffsets, combinedSizes and combinedStrides to use when combining a producer slice i...
Include the generated interface declarations.
OpFoldResult getAsOpFoldResult(Value val)
Given a value, try to extract a constant Attribute.