MLIR  16.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 // Standalone transformations and helpers.
29 //===----------------------------------------------------------------------===//
30 /// Split a vector.transfer operation into an in-bounds (i.e., no out-of-bounds
31 /// masking) fastpath and a slowpath.
32 /// If `ifOp` is not null and the result is `success, the `ifOp` points to the
33 /// newly created conditional upon function return.
34 /// To accomodate for the fact that the original vector.transfer indexing may be
35 /// arbitrary and the slow path indexes @[0...0] in the temporary buffer, the
36 /// scf.if op returns a view and values of type index.
37 /// At this time, only vector.transfer_read case is implemented.
38 ///
39 /// Example (a 2-D vector.transfer_read):
40 /// ```
41 /// %1 = vector.transfer_read %0[...], %pad : memref<A...>, vector<...>
42 /// ```
43 /// is transformed into:
44 /// ```
45 /// %1:3 = scf.if (%inBounds) {
46 /// // fastpath, direct cast
47 /// memref.cast %A: memref<A...> to compatibleMemRefType
48 /// scf.yield %view : compatibleMemRefType, index, index
49 /// } else {
50 /// // slowpath, not in-bounds vector.transfer or linalg.copy.
51 /// memref.cast %alloc: memref<B...> to compatibleMemRefType
52 /// scf.yield %4 : compatibleMemRefType, index, index
53 // }
54 /// %0 = vector.transfer_read %1#0[%1#1, %1#2] {in_bounds = [true ... true]}
55 /// ```
56 /// where `alloc` is a top of the function alloca'ed buffer of one vector.
57 ///
58 /// Preconditions:
59 /// 1. `xferOp.permutation_map()` must be a minor identity map
60 /// 2. the rank of the `xferOp.memref()` and the rank of the `xferOp.vector()`
61 /// must be equal. This will be relaxed in the future but requires
62 /// rank-reducing subviews.
63 LogicalResult splitFullAndPartialTransfer(
64  RewriterBase &b, VectorTransferOpInterface xferOp,
65  VectorTransformsOptions options = VectorTransformsOptions(),
66  scf::IfOp *ifOp = nullptr);
67 
68 /// Implements transfer op write to read forwarding and dead transfer write
69 /// optimizations.
70 void transferOpflowOpt(Operation *rootOp);
71 
72 } // namespace vector
73 } // namespace mlir
74 
75 #endif // MLIR_DIALECT_VECTOR_TRANSFORMS_VECTORTRANSFORMS_H
static llvm::ManagedStatic< PassManagerOptions > options
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(Operation *rootOp)
Implements transfer op write to read forwarding and dead transfer write optimizations.
Include the generated interface declarations.