1 //===- ConvertFuncToLLVM.h - Convert Func to LLVM ---------------*- 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 // Provides a set of conversion patterns from the Func dialect to the LLVM IR 10 // dialect. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MLIR_CONVERSION_FUNCTOLLVM_CONVERTFUNCTOLLVM_H 15 #define MLIR_CONVERSION_FUNCTOLLVM_CONVERTFUNCTOLLVM_H 16 17 #include "mlir/Interfaces/FunctionInterfaces.h" 18 19 namespace mlir { 20 21 namespace LLVM { 22 class LLVMFuncOp; 23 } // namespace LLVM 24 25 class ConversionPatternRewriter; 26 class DialectRegistry; 27 class LLVMTypeConverter; 28 class RewritePatternSet; 29 class SymbolTable; 30 31 /// Convert input FunctionOpInterface operation to LLVMFuncOp by using the 32 /// provided LLVMTypeConverter. Return failure if failed to so. 33 FailureOr<LLVM::LLVMFuncOp> 34 convertFuncOpToLLVMFuncOp(FunctionOpInterface funcOp, 35 ConversionPatternRewriter &rewriter, 36 const LLVMTypeConverter &converter); 37 38 /// Collect the default pattern to convert a FuncOp to the LLVM dialect. If 39 /// `emitCWrappers` is set, the pattern will also produce functions 40 /// that pass memref descriptors by pointer-to-structure in addition to the 41 /// default unpacked form. 42 void populateFuncToLLVMFuncOpConversionPattern( 43 const LLVMTypeConverter &converter, RewritePatternSet &patterns); 44 45 /// Collect the patterns to convert from the Func dialect to LLVM. The 46 /// conversion patterns capture the LLVMTypeConverter and the LowerToLLVMOptions 47 /// by reference meaning the references have to remain alive during the entire 48 /// pattern lifetime. 49 /// 50 /// The `symbolTable` parameter can be used to speed up function lookups in the 51 /// module. It's good to provide it, but only if we know that the patterns will 52 /// be applied to a single module and the symbols referenced by the symbol table 53 /// will not be removed and new symbols will not be added during the usage of 54 /// the patterns. If provided, the lookups will have O(calls) cumulative 55 /// runtime, otherwise O(calls * functions). The symbol table is currently not 56 /// needed if `converter.getOptions().useBarePtrCallConv` is `true`, but it's 57 /// not an error to provide it anyway. 58 void populateFuncToLLVMConversionPatterns( 59 const LLVMTypeConverter &converter, RewritePatternSet &patterns, 60 const SymbolTable *symbolTable = nullptr); 61 62 void registerConvertFuncToLLVMInterface(DialectRegistry ®istry); 63 64 } // namespace mlir 65 66 #endif // MLIR_CONVERSION_FUNCTOLLVM_CONVERTFUNCTOLLVM_H 67