Add lowering of vector dialect to LLVM dialect.
authorNicolas Vasilache <ntv@google.com>
Mon, 12 Aug 2019 11:08:26 +0000 (04:08 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Mon, 12 Aug 2019 11:08:57 +0000 (04:08 -0700)
commit252ada493276eace3e23802fb70ff3c7be53837d
tree3a40800f55e5486089cc8d6ae58dda343b88d474
parent5290e8c36d4e4aac4d8ce2726f6d373e87501945
Add lowering of vector dialect to LLVM dialect.

This CL is step 3/n towards building a simple, programmable and portable vector abstraction in MLIR that can go all the way down to generating assembly vector code via LLVM's opt and llc tools.

This CL adds support for converting MLIR n-D vector types to (n-1)-D arrays of 1-D LLVM vectors and a conversion VectorToLLVM that lowers the `vector.extractelement` and `vector.outerproduct` instructions to the proper mix of `llvm.vectorshuffle`, `llvm.extractelement` and `llvm.mulf`.

This has been independently verified to produce proper avx2 code.

Input:
```
func @vec_1d(%arg0: vector<4xf32>, %arg1: vector<8xf32>) -> vector<8xf32> {
  %2 = vector.outerproduct %arg0, %arg1 : vector<4xf32>, vector<8xf32>
  %3 = vector.extractelement %2[0 : i32]: vector<4x8xf32>
  return %3 : vector<8xf32>
}
```

Command:
```
mlir-opt vector-to-llvm.mlir -vector-lower-to-llvm-dialect --disable-pass-threading | mlir-opt -lower-to-cfg -lower-to-llvm | mlir-translate --mlir-to-llvmir | opt -O3 | llc -O3 -march=x86-64 -mcpu=haswell -mattr=fma,avx2
```

Output:
```
vec_1d:                                 # @vec_1d
# %bb.0:
        vbroadcastss    %xmm0, %ymm0
        vmulps  %ymm1, %ymm0, %ymm0
        retq
```
PiperOrigin-RevId: 262895929
mlir/g3doc/ConversionToLLVMDialect.md
mlir/include/mlir/Conversion/VectorToLLVM/VectorToLLVM.h [new file with mode: 0644]
mlir/lib/Conversion/CMakeLists.txt
mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Conversion/VectorToLLVM/VectorToLLVM.cpp [new file with mode: 0644]
mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir [new file with mode: 0644]
mlir/tools/mlir-opt/CMakeLists.txt