1 //===- ConvertVectorToLLVM.h - Utils to convert from the vector dialect ---===// 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 #ifndef MLIR_CONVERSION_VECTORTOLLVM_CONVERTVECTORTOLLVM_H_ 9 #define MLIR_CONVERSION_VECTORTOLLVM_CONVERTVECTORTOLLVM_H_ 10 11 #include "mlir/Transforms/DialectConversion.h" 12 13 namespace mlir { 14 class LLVMTypeConverter; 15 class ModuleOp; 16 template <typename T> 17 class OperationPass; 18 19 /// Options to control Vector to LLVM lowering. 20 /// 21 /// This should kept in sync with VectorToLLVM options defined for the 22 /// ConvertVectorToLLVM pass in include/mlir/Conversion/Passes.td 23 struct LowerVectorToLLVMOptions { LowerVectorToLLVMOptionsLowerVectorToLLVMOptions24 LowerVectorToLLVMOptions() 25 : reassociateFPReductions(false), enableIndexOptimizations(true), 26 enableAVX512(false) {} 27 setReassociateFPReductionsLowerVectorToLLVMOptions28 LowerVectorToLLVMOptions &setReassociateFPReductions(bool b) { 29 reassociateFPReductions = b; 30 return *this; 31 } setEnableIndexOptimizationsLowerVectorToLLVMOptions32 LowerVectorToLLVMOptions &setEnableIndexOptimizations(bool b) { 33 enableIndexOptimizations = b; 34 return *this; 35 } setEnableAVX512LowerVectorToLLVMOptions36 LowerVectorToLLVMOptions &setEnableAVX512(bool b) { 37 enableAVX512 = b; 38 return *this; 39 } 40 41 bool reassociateFPReductions; 42 bool enableIndexOptimizations; 43 bool enableAVX512; 44 }; 45 46 /// Collect a set of patterns to convert from Vector contractions to LLVM Matrix 47 /// Intrinsics. To lower to assembly, the LLVM flag -lower-matrix-intrinsics 48 /// will be needed when invoking LLVM. 49 void populateVectorToLLVMMatrixConversionPatterns( 50 LLVMTypeConverter &converter, OwningRewritePatternList &patterns); 51 52 /// Collect a set of patterns to convert from the Vector dialect to LLVM. 53 void populateVectorToLLVMConversionPatterns( 54 LLVMTypeConverter &converter, OwningRewritePatternList &patterns, 55 bool reassociateFPReductions = false, bool enableIndexOptimizations = true); 56 57 /// Create a pass to convert vector operations to the LLVMIR dialect. 58 std::unique_ptr<OperationPass<ModuleOp>> createConvertVectorToLLVMPass( 59 const LowerVectorToLLVMOptions &options = LowerVectorToLLVMOptions()); 60 61 } // namespace mlir 62 63 #endif // MLIR_CONVERSION_VECTORTOLLVM_CONVERTVECTORTOLLVM_H_ 64