MLIR  20.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 
31 /// Structure to control the behavior of vector transform patterns.
33  /// Option to control the lowering of vector.contract.
34  VectorContractLowering vectorContractLowering = VectorContractLowering::Dot;
36  setVectorTransformsOptions(VectorContractLowering opt) {
38  return *this;
39  }
40  /// Option to control the lowering of vector.multi_reduction.
41  VectorMultiReductionLowering vectorMultiReductionLowering =
42  VectorMultiReductionLowering::InnerParallel;
44  setVectorMultiReductionLowering(VectorMultiReductionLowering opt) {
46  return *this;
47  }
48  /// Option to control the lowering of vector.transpose.
49  VectorTransposeLowering vectorTransposeLowering =
50  VectorTransposeLowering::EltWise;
52  setVectorTransposeLowering(VectorTransposeLowering opt) {
54  return *this;
55  }
56  /// Option to control the splitting of vector transfers.
58  VectorTransformsOptions &setVectorTransferSplit(VectorTransferSplit opt) {
59  vectorTransferSplit = opt;
60  return *this;
61  }
62 };
63 
64 //===----------------------------------------------------------------------===//
65 // Standalone transformations and helpers.
66 //===----------------------------------------------------------------------===//
67 
68 /// Split a vector.transfer operation into an in-bounds (i.e., no
69 /// out-of-bounds masking) fastpath and a slowpath. If `ifOp` is not null and
70 /// the result is `success, the `ifOp` points to the newly created conditional
71 /// upon function return. To accomodate for the fact that the original
72 /// vector.transfer indexing may be arbitrary and the slow path indexes
73 /// @[0...0] in the temporary buffer, the scf.if op returns a view and values
74 /// of type index. At this time, only vector.transfer_read case is
75 /// implemented.
76 ///
77 /// Example (a 2-D vector.transfer_read):
78 /// ```
79 /// %1 = vector.transfer_read %0[...], %pad : memref<A...>, vector<...>
80 /// ```
81 /// is transformed into:
82 /// ```
83 /// %1:3 = scf.if (%inBounds) {
84 /// // fastpath, direct cast
85 /// memref.cast %A: memref<A...> to compatibleMemRefType
86 /// scf.yield %view : compatibleMemRefType, index, index
87 /// } else {
88 /// // slowpath, not in-bounds vector.transfer or linalg.copy.
89 /// memref.cast %alloc: memref<B...> to compatibleMemRefType
90 /// scf.yield %4 : compatibleMemRefType, index, index
91 // }
92 /// %0 = vector.transfer_read %1#0[%1#1, %1#2] {in_bounds = [true ...
93 /// true]}
94 /// ```
95 /// where `alloc` is a top of the function alloca'ed buffer of one vector.
96 ///
97 /// Preconditions:
98 /// 1. `xferOp.permutation_map()` must be a minor identity map
99 /// 2. the rank of the `xferOp.memref()` and the rank of the
100 /// `xferOp.vector()` must be equal. This will be relaxed in the future but
101 /// requires rank-reducing subviews.
102 LogicalResult splitFullAndPartialTransfer(
103  RewriterBase &b, VectorTransferOpInterface xferOp,
104  VectorTransformsOptions options = VectorTransformsOptions(),
105  scf::IfOp *ifOp = nullptr);
106 
107 /// Implements transfer op write to read forwarding and dead transfer write
108 /// optimizations.
109 void transferOpflowOpt(RewriterBase &rewriter, Operation *rootOp);
110 
111 /// Cast away the leading unit dim, if exists, for the given contract op.
112 /// Return success if the transformation applies; return failure otherwise.
113 FailureOr<Value>
114 castAwayContractionLeadingOneDim(vector::ContractionOp contractOp,
115  MaskingOpInterface maskingOp,
116  RewriterBase &rewriter);
117 
118 } // namespace vector
119 } // namespace mlir
120 
121 #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:400
FailureOr< Value > castAwayContractionLeadingOneDim(vector::ContractionOp contractOp, MaskingOpInterface maskingOp, RewriterBase &rewriter)
Cast away the leading unit dim, if exists, for the given contract op.
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.
Include the generated interface declarations.
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.