|
8 | 8 |
|
9 | 9 | #ifndef GC_TRANSFORMS_UTILS_VECTORUTILS_H |
10 | 10 | #define GC_TRANSFORMS_UTILS_VECTORUTILS_H |
| 11 | +#include "mlir/Dialect/Affine/IR/AffineOps.h" |
| 12 | +#include "mlir/Dialect/Func/IR/FuncOps.h" |
| 13 | +#include "mlir/Dialect/Tensor/IR/Tensor.h" |
11 | 14 | #include "mlir/Dialect/Vector/IR/VectorOps.h" |
12 | 15 | #include "mlir/IR/BuiltinTypes.h" |
13 | 16 | #include "mlir/IR/TypeUtilities.h" |
| 17 | +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" |
14 | 18 | #include "llvm/ADT/TypeSwitch.h" |
| 19 | +#include "llvm/Support/Debug.h" |
15 | 20 | #include <limits> |
16 | 21 | #include <stdint.h> |
17 | 22 | #include <variant> |
18 | 23 |
|
19 | 24 | namespace mlir { |
20 | 25 | namespace gc { |
| 26 | +/// Need to move some operations like extract_slice or insert_slice. |
| 27 | +/// Because those operation may interpret our analysis result. e.g.: |
| 28 | +/// ``` |
| 29 | +/// clang-format off |
| 30 | +/// %21 = vector.transfer_read %18[%c0, %c0], %cst {in_bounds = [true, true]} : |
| 31 | +/// tensor<16x16xf32>, vector<16x16xf32> %22 = arith.addf %21, %20 : |
| 32 | +/// vector<16x16xf32> %23 = vector.transfer_write %22, %extracted_slice_12[%c0, |
| 33 | +/// %c0] {in_bounds = [true, true]} : vector<16x16xf32>, tensor<16x16xf32> |
| 34 | +/// %inserted_slice_13 = tensor.insert_slice %18 into %arg14[%arg13, 0] [16, 16] |
| 35 | +/// [1, 1] : tensor<16x16xf32> into tensor<32x16xf32> %extracted_slice_14 = |
| 36 | +/// tensor.extract_slice %arg16[%arg13, 0] [16, 16] [1, 1] : tensor<32x16xf32> |
| 37 | +/// to tensor<16x16xf32> %24 = vector.transfer_read %cst_0[%c0, %c0], %cst |
| 38 | +/// {in_bounds = [true, true]} : tensor<16x16xf32>, vector<16x16xf32> %25 = |
| 39 | +/// arith.maximumf %22, %24 : vector<16x16xf32> %26 = vector.transfer_write %25, |
| 40 | +/// %extracted_slice_14[%c0, %c0] {in_bounds = [true, true]} : |
| 41 | +/// vector<16x16xf32>, tensor<16x16xf32> %inserted_slice_15 = |
| 42 | +/// tensor.insert_slice %23 into %arg15[%arg13, 0] [16, 16] [1, 1] : |
| 43 | +/// tensor<16x16xf32> into tensor<32x16xf32> %inserted_slice_16 = |
| 44 | +/// tensor.insert_slice %26 into %arg16[%arg13, 0] [16, 16] [1, 1] : |
| 45 | +/// tensor<16x16xf32> into tensor<32x16xf32> clang-format on |
| 46 | +/// ``` |
| 47 | +/// The maximumf and addf operation can be a same group, but the extract_slice |
| 48 | +/// operation interpret us. |
| 49 | +/// The move operation(extra_slice) will check its parameters. In order to |
| 50 | +/// ensure that it does not affect the correctness of the result, we will only |
| 51 | +/// move the moved op after the op to which the parameters belong to. If it's |
| 52 | +/// operand is all the block argument, we will move it to the begining of the |
| 53 | +/// block. |
| 54 | +/// insert_slice just move them to the privious of the first operation which |
| 55 | +/// use it. |
| 56 | +void moveSomeInterferenceOperation( |
| 57 | + func::FuncOp *func, MLIRContext *ctx, |
| 58 | + std::function<bool(Operation *)> &conditionalFunc); |
| 59 | + |
21 | 60 | /// build a constant operation of index type |
22 | 61 | Value makeIndexArithConstantOp(OpBuilder &opBuilder, const Location &loc, |
23 | 62 | int64_t x); |
|
0 commit comments