MLIR
18.0.0git
|
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
#include "mlir/Analysis/DataLayoutAnalysis.h"
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Conversion/LLVMCommon/VectorPattern.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/FunctionCallUtils.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributeInterfaces.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Transforms/Passes.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormatVariadic.h"
#include <algorithm>
#include <functional>
#include <optional>
#include "mlir/Conversion/Passes.h.inc"
Go to the source code of this file.
Namespaces | |
mlir | |
Include the generated interface declarations. | |
Macros | |
#define | GEN_PASS_DEF_CONVERTFUNCTOLLVMPASS |
#define | GEN_PASS_DEF_SETLLVMMODULEDATALAYOUTPASS |
#define | PASS_NAME "convert-func-to-llvm" |
Functions | |
static bool | shouldUseBarePtrCallConv (Operation *op, const LLVMTypeConverter *typeConverter) |
Return true if the op should use bare pointer calling convention. More... | |
static void | filterFuncAttributes (FunctionOpInterface func, SmallVectorImpl< NamedAttribute > &result) |
Only retain those attributes that are not constructed by LLVMFuncOp::build . More... | |
static void | propagateArgResAttrs (OpBuilder &builder, bool resultStructType, FunctionOpInterface funcOp, LLVM::LLVMFuncOp wrapperFuncOp) |
Propagate argument/results attributes. More... | |
static void | wrapForExternalCallers (OpBuilder &rewriter, Location loc, const LLVMTypeConverter &typeConverter, FunctionOpInterface funcOp, LLVM::LLVMFuncOp newFuncOp) |
Creates an auxiliary function with pointer-to-memref-descriptor-struct arguments instead of unpacked arguments. More... | |
static void | wrapExternalFunction (OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, FunctionOpInterface funcOp, LLVM::LLVMFuncOp newFuncOp) |
Creates an auxiliary function with pointer-to-memref-descriptor-struct arguments instead of unpacked arguments. More... | |
static void | modifyFuncOpToUseBarePtrCallingConv (ConversionPatternRewriter &rewriter, Location loc, const LLVMTypeConverter &typeConverter, LLVM::LLVMFuncOp funcOp, TypeRange oldArgTypes) |
Modifies the body of the function to construct the MemRefDescriptor from the bare pointer calling convention lowering of memref types. More... | |
Variables | |
static constexpr StringRef | varargsAttrName = "func.varargs" |
static constexpr StringRef | linkageAttrName = "llvm.linkage" |
static constexpr StringRef | barePtrAttrName = "llvm.bareptr" |
#define GEN_PASS_DEF_CONVERTFUNCTOLLVMPASS |
Definition at line 55 of file FuncToLLVM.cpp.
#define GEN_PASS_DEF_SETLLVMMODULEDATALAYOUTPASS |
Definition at line 56 of file FuncToLLVM.cpp.
#define PASS_NAME "convert-func-to-llvm" |
Definition at line 62 of file FuncToLLVM.cpp.
|
static |
Only retain those attributes that are not constructed by LLVMFuncOp::build
.
Definition at line 77 of file FuncToLLVM.cpp.
References linkageAttrName, and varargsAttrName.
Referenced by mlir::convertFuncOpToLLVMFuncOp(), wrapExternalFunction(), and wrapForExternalCallers().
|
static |
Modifies the body of the function to construct the MemRefDescriptor
from the bare pointer calling convention lowering of memref
types.
Definition at line 274 of file FuncToLLVM.cpp.
References mlir::LLVMTypeConverter::convertType(), mlir::OpBuilder::create(), mlir::MemRefDescriptor::fromStaticShape(), mlir::Block::front(), mlir::Block::getArguments(), mlir::ConversionPatternRewriter::replaceOp(), mlir::ConversionPatternRewriter::replaceUsesOfBlockArgument(), and mlir::OpBuilder::setInsertionPointToStart().
|
static |
Propagate argument/results attributes.
Definition at line 89 of file FuncToLLVM.cpp.
References mlir::Builder::getDictionaryAttr().
Referenced by wrapExternalFunction(), and wrapForExternalCallers().
|
static |
Return true
if the op
should use bare pointer calling convention.
Definition at line 69 of file FuncToLLVM.cpp.
Referenced by mlir::convertFuncOpToLLVMFuncOp().
|
static |
Creates an auxiliary function with pointer-to-memref-descriptor-struct arguments instead of unpacked arguments.
Creates a body for the (external) newFuncOp
that allocates a memref descriptor on stack, packs the individual arguments into this descriptor and passes a pointer to it into the auxiliary function. If the result of the function cannot be directly returned, we write it to a special first argument that provides a pointer to a corresponding struct. This auxiliary external function is now compatible with functions defined in C using pointers to C structs corresponding to a memref descriptor.
Definition at line 180 of file FuncToLLVM.cpp.
References mlir::LLVMTypeConverter::convertFunctionTypeCWrapper(), mlir::LLVMTypeConverter::convertType(), mlir::OpBuilder::create(), filterFuncAttributes(), mlir::get(), mlir::Builder::getContext(), mlir::Builder::getIndexType(), mlir::Builder::getIntegerAttr(), mlir::UnrankedMemRefDescriptor::getNumUnpackedValues(), mlir::MemRefDescriptor::getNumUnpackedValues(), mlir::Value::getType(), mlir::MemRefDescriptor::pack(), mlir::UnrankedMemRefDescriptor::pack(), propagateArgResAttrs(), and mlir::OpBuilder::setInsertionPointToStart().
|
static |
Creates an auxiliary function with pointer-to-memref-descriptor-struct arguments instead of unpacked arguments.
This function can be called from C by passing a pointer to a C struct corresponding to a memref descriptor. Similarly, returned memrefs are passed via pointers to a C struct that is passed as additional argument. Internally, the auxiliary function unpacks the descriptor into individual components and forwards them to newFuncOp
and forwards the results to the extra arguments.
Definition at line 120 of file FuncToLLVM.cpp.
References mlir::LLVMTypeConverter::convertFunctionTypeCWrapper(), mlir::LLVMTypeConverter::convertType(), mlir::OpBuilder::create(), mlir::detail::enumerate(), filterFuncAttributes(), propagateArgResAttrs(), mlir::OpBuilder::setInsertionPointToStart(), mlir::MemRefDescriptor::unpack(), and mlir::UnrankedMemRefDescriptor::unpack().
|
staticconstexpr |
Definition at line 66 of file FuncToLLVM.cpp.
|
staticconstexpr |
Definition at line 65 of file FuncToLLVM.cpp.
Referenced by mlir::convertFuncOpToLLVMFuncOp(), and filterFuncAttributes().
|
staticconstexpr |
Definition at line 64 of file FuncToLLVM.cpp.
Referenced by mlir::convertFuncOpToLLVMFuncOp(), and filterFuncAttributes().