1515#ifndef MLIR_CONVERSION_STANDARDTOLLVM_CONVERTSTANDARDTOLLVM_H
1616#define MLIR_CONVERSION_STANDARDTOLLVM_CONVERTSTANDARDTOLLVM_H
1717
18+ #include " mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h"
1819#include " mlir/Transforms/DialectConversion.h"
1920
2021namespace llvm {
@@ -35,22 +36,6 @@ class LLVMDialect;
3536class LLVMType ;
3637} // namespace LLVM
3738
38- // / Set of callbacks that allows the customization of LLVMTypeConverter.
39- struct LLVMTypeConverterCustomization {
40- using CustomCallback = std::function<LogicalResult(LLVMTypeConverter &, Type,
41- SmallVectorImpl<Type> &)>;
42-
43- // / Customize the type conversion of function arguments.
44- CustomCallback funcArgConverter;
45-
46- // / Used to determine the bitwidth of the LLVM integer type that the index
47- // / type gets lowered to. Defaults to deriving the size from the data layout.
48- unsigned indexBitwidth;
49-
50- // / Initialize customization to default callbacks.
51- LLVMTypeConverterCustomization ();
52- };
53-
5439// / Callback to convert function argument types. It converts a MemRef function
5540// / argument to a list of non-aggregate types containing descriptor
5641// / information, and an UnrankedmemRef function argument to a list containing
@@ -75,13 +60,11 @@ class LLVMTypeConverter : public TypeConverter {
7560public:
7661 using TypeConverter::convertType;
7762
78- // / Create an LLVMTypeConverter using the default
79- // / LLVMTypeConverterCustomization.
63+ // / Create an LLVMTypeConverter using the default LowerToLLVMOptions.
8064 LLVMTypeConverter (MLIRContext *ctx);
8165
82- // / Create an LLVMTypeConverter using 'custom' customizations.
83- LLVMTypeConverter (MLIRContext *ctx,
84- const LLVMTypeConverterCustomization &custom);
66+ // / Create an LLVMTypeConverter using custom LowerToLLVMOptions.
67+ LLVMTypeConverter (MLIRContext *ctx, const LowerToLLVMOptions &options);
8568
8669 // / Convert a function type. The arguments and results are converted one by
8770 // / one and results are packed into a wrapped LLVM IR structure type. `result`
@@ -127,7 +110,7 @@ class LLVMTypeConverter : public TypeConverter {
127110 LLVM::LLVMType getIndexType ();
128111
129112 // / Gets the bitwidth of the index type when converted to LLVM.
130- unsigned getIndexTypeBitwidth () { return customizations .indexBitwidth ; }
113+ unsigned getIndexTypeBitwidth () { return options .indexBitwidth ; }
131114
132115protected:
133116 // / LLVM IR module used to parse/create types.
@@ -193,8 +176,8 @@ class LLVMTypeConverter : public TypeConverter {
193176 // Convert a 1D vector type into an LLVM vector type.
194177 Type convertVectorType (VectorType type);
195178
196- // / Callbacks for customizing the type conversion .
197- LLVMTypeConverterCustomization customizations ;
179+ // / Options for customizing the llvm lowering .
180+ LowerToLLVMOptions options ;
198181};
199182
200183// / Helper class to produce LLVM dialect operations extracting or inserting
@@ -389,11 +372,17 @@ class UnrankedMemRefDescriptor : public StructBuilder {
389372};
390373
391374// / Base class for operation conversions targeting the LLVM IR dialect. Provides
392- // / conversion patterns with access to an LLVMTypeConverter.
375+ // / conversion patterns with access to an LLVMTypeConverter and the
376+ // / LowerToLLVMOptions.
393377class ConvertToLLVMPattern : public ConversionPattern {
394378public:
395379 ConvertToLLVMPattern (StringRef rootOpName, MLIRContext *context,
396380 LLVMTypeConverter &typeConverter,
381+ const LowerToLLVMOptions &options = {
382+ /* useBarePtrCallConv=*/ false ,
383+ /* emitCWrappers=*/ false ,
384+ /* indexBitwidth=*/ kDeriveIndexBitwidthFromDataLayout ,
385+ /* useAlignedAlloc=*/ false },
397386 PatternBenefit benefit = 1 );
398387
399388 // / Returns the LLVM dialect.
@@ -445,6 +434,9 @@ class ConvertToLLVMPattern : public ConversionPattern {
445434protected:
446435 // / Reference to the type converter, with potential extensions.
447436 LLVMTypeConverter &typeConverter;
437+
438+ // / Reference to the llvm lowering options.
439+ const LowerToLLVMOptions &options;
448440};
449441
450442// / Utility class for operation conversions targeting the LLVM dialect that
@@ -453,10 +445,11 @@ template <typename OpTy>
453445class ConvertOpToLLVMPattern : public ConvertToLLVMPattern {
454446public:
455447 ConvertOpToLLVMPattern (LLVMTypeConverter &typeConverter,
448+ const LowerToLLVMOptions &options,
456449 PatternBenefit benefit = 1 )
457450 : ConvertToLLVMPattern(OpTy::getOperationName(),
458451 &typeConverter.getContext(), typeConverter,
459- benefit) {}
452+ options, benefit) {}
460453};
461454
462455namespace LLVM {
0 commit comments