MLIR  17.0.0git
VectorTransforms.h
Go to the documentation of this file.
1 //===- VectorTransforms.h - Vector transformations as patterns --*- 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_VECTOR_TRANSFORMS_VECTORTRANSFORMS_H
10 #define MLIR_DIALECT_VECTOR_TRANSFORMS_VECTORTRANSFORMS_H
11 
14 
15 namespace mlir {
16 class MLIRContext;
17 class VectorTransferOpInterface;
18 class RewritePatternSet;
19 class RewriterBase;
20 
21 namespace scf {
22 class IfOp;
23 } // namespace scf
24 
25 namespace vector {
26 
27 //===----------------------------------------------------------------------===//
28 // Vector transformation options exposed as auxiliary structs.
29 //===----------------------------------------------------------------------===//
30 /// Structure to control the behavior of vector transform patterns.
32  /// Option to control the lowering of vector.contract.
33  VectorContractLowering vectorContractLowering = VectorContractLowering::Dot;
35  setVectorTransformsOptions(VectorContractLowering opt) {
37  return *this;
38  }
39  /// Option to control the lowering of vector.multi_reduction.
40  VectorMultiReductionLowering vectorMultiReductionLowering =
41  VectorMultiReductionLowering::InnerParallel;
43  setVectorMultiReductionLowering(VectorMultiReductionLowering opt) {
45  return *this;
46  }
47  /// Option to control the lowering of vector.transpose.
48  VectorTransposeLowering vectorTransposeLowering =
49  VectorTransposeLowering::EltWise;
51  setVectorTransposeLowering(VectorTransposeLowering opt) {
53  return *this;
54  }
55  /// Option to control the splitting of vector transfers.
57  VectorTransformsOptions &setVectorTransferSplit(VectorTransferSplit opt) {
58  vectorTransferSplit = opt;
59  return *this;
60  }
61 };
62 
63 //===----------------------------------------------------------------------===//
64 // Standalone transformations and helpers.
65 //===----------------------------------------------------------------------===//
66 /// Split a vector.transfer operation into an in-bounds (i.e., no
67 /// out-of-bounds masking) fastpath and a slowpath. If `ifOp` is not null and
68 /// the result is `success, the `ifOp` points to the newly created conditional
69 /// upon function return. To accomodate for the fact that the original
70 /// vector.transfer indexing may be arbitrary and the slow path indexes
71 /// @[0...0] in the temporary buffer, the scf.if op returns a view and values
72 /// of type index. At this time, only vector.transfer_read case is
73 /// implemented.
74 ///
75 /// Example (a 2-D vector.transfer_read):
76 /// ```
77 /// %1 = vector.transfer_read %0[...], %pad : memref<A...>, vector<...>
78 /// ```
79 /// is transformed into:
80 /// ```
81 /// %1:3 = scf.if (%inBounds) {
82 /// // fastpath, direct cast
83 /// memref.cast %A: memref<A...> to compatibleMemRefType
84 /// scf.yield %view : compatibleMemRefType, index, index
85 /// } else {
86 /// // slowpath, not in-bounds vector.transfer or linalg.copy.
87 /// memref.cast %alloc: memref<B...> to compatibleMemRefType
88 /// scf.yield %4 : compatibleMemRefType, index, index
89 // }
90 /// %0 = vector.transfer_read %1#0[%1#1, %1#2] {in_bounds = [true ...
91 /// true]}
92 /// ```
93 /// where `alloc` is a top of the function alloca'ed buffer of one vector.
94 ///
95 /// Preconditions:
96 /// 1. `xferOp.permutation_map()` must be a minor identity map
97 /// 2. the rank of the `xferOp.memref()` and the rank of the
98 /// `xferOp.vector()` must be equal. This will be relaxed in the future but
99 /// requires rank-reducing subviews.
101  RewriterBase &b, VectorTransferOpInterface xferOp,
102  VectorTransformsOptions options = VectorTransformsOptions(),
103  scf::IfOp *ifOp = nullptr);
104 
105 /// Implements transfer op write to read forwarding and dead transfer write
106 /// optimizations.
107 void transferOpflowOpt(RewriterBase &rewriter, Operation *rootOp);
108 
109 } // namespace vector
110 } // namespace mlir
111 
112 #endif // MLIR_DIALECT_VECTOR_TRANSFORMS_VECTORTRANSFORMS_H
@ None
static llvm::ManagedStatic< PassManagerOptions > options
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Definition: PatternMatch.h:399
LogicalResult splitFullAndPartialTransfer(RewriterBase &b, VectorTransferOpInterface xferOp, VectorTransformsOptions options=VectorTransformsOptions(), scf::IfOp *ifOp=nullptr)
Split a vector.transfer operation into an in-bounds (i.e., no out-of-bounds masking) fastpath and a s...
void transferOpflowOpt(RewriterBase &rewriter, Operation *rootOp)
Implements transfer op write to read forwarding and dead transfer write optimizations.
This header declares functions that assit transformations in the MemRef dialect.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
Structure to control the behavior of vector transform patterns.
VectorTransferSplit vectorTransferSplit
Option to control the splitting of vector transfers.
VectorTransformsOptions & setVectorMultiReductionLowering(VectorMultiReductionLowering opt)
VectorMultiReductionLowering vectorMultiReductionLowering
Option to control the lowering of vector.multi_reduction.
VectorTransformsOptions & setVectorTransposeLowering(VectorTransposeLowering opt)
VectorTransformsOptions & setVectorTransferSplit(VectorTransferSplit opt)
VectorTransformsOptions & setVectorTransformsOptions(VectorContractLowering opt)
VectorContractLowering vectorContractLowering
Option to control the lowering of vector.contract.
VectorTransposeLowering vectorTransposeLowering
Option to control the lowering of vector.transpose.