[Mlir-commits] [mlir] bb542f2 - [mlir] StandardToLLVM: option to disable AllocOp lowering
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun May 30 07:58:10 PDT 2021
Author: Butygin
Date: 2021-05-30T17:50:25+03:00
New Revision: bb542f2a76d4256e98e4bf249b77f5b18163fc24
URL: https://github.com/llvm/llvm-project/commit/bb542f2a76d4256e98e4bf249b77f5b18163fc24
DIFF: https://github.com/llvm/llvm-project/commit/bb542f2a76d4256e98e4bf249b77f5b18163fc24.diff
LOG: [mlir] StandardToLLVM: option to disable AllocOp lowering
Differential Revision: https://reviews.llvm.org/D103237
Added:
Modified:
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h
index a7a68ef0a9c62..25be9f9d7c93c 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h
@@ -37,8 +37,19 @@ class LowerToLLVMOptions {
bool useBarePtrCallConv = false;
bool emitCWrappers = false;
- /// Use aligned_alloc for heap allocations.
- bool useAlignedAlloc = false;
+ enum class AllocLowering {
+ /// Use malloc for for heap allocations.
+ Malloc,
+
+ /// Use aligned_alloc for heap allocations.
+ AlignedAlloc,
+
+ /// Do not lower heap allocations. Users must provide their own patterns for
+ /// AllocOp and DeallocOp lowering.
+ None
+ };
+
+ AllocLowering allocLowering = AllocLowering::Malloc;
/// The data layout of the module to produce. This must be consistent with the
/// data layout used in the upper levels of the lowering pipeline.
diff --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
index a9560cf5d5222..2fbfa1103aa39 100644
--- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
@@ -3922,7 +3922,6 @@ void mlir::populateStdToLLVMMemoryConversionPatterns(
// clang-format off
patterns.add<
AssumeAlignmentOpLowering,
- DeallocOpLowering,
DimOpLowering,
GlobalMemrefOpLowering,
GetGlobalMemrefOpLowering,
@@ -3936,10 +3935,11 @@ void mlir::populateStdToLLVMMemoryConversionPatterns(
TransposeOpLowering,
ViewOpLowering>(converter);
// clang-format on
- if (converter.getOptions().useAlignedAlloc)
- patterns.add<AlignedAllocOpLowering>(converter);
- else
- patterns.add<AllocOpLowering>(converter);
+ auto allocLowering = converter.getOptions().allocLowering;
+ if (allocLowering == LowerToLLVMOptions::AllocLowering::AlignedAlloc)
+ patterns.add<AlignedAllocOpLowering, DeallocOpLowering>(converter);
+ else if (allocLowering == LowerToLLVMOptions::AllocLowering::Malloc)
+ patterns.add<AllocOpLowering, DeallocOpLowering>(converter);
}
void mlir::populateStdToLLVMFuncOpConversionPattern(
@@ -4071,7 +4071,9 @@ struct LLVMLoweringPass : public ConvertStandardToLLVMBase<LLVMLoweringPass> {
options.emitCWrappers = emitCWrappers;
if (indexBitwidth != kDeriveIndexBitwidthFromDataLayout)
options.overrideIndexBitwidth(indexBitwidth);
- options.useAlignedAlloc = useAlignedAlloc;
+ options.allocLowering =
+ (useAlignedAlloc ? LowerToLLVMOptions::AllocLowering::AlignedAlloc
+ : LowerToLLVMOptions::AllocLowering::Malloc);
options.dataLayout = llvm::DataLayout(this->dataLayout);
LLVMTypeConverter typeConverter(&getContext(), options);
@@ -4139,9 +4141,16 @@ std::unique_ptr<OperationPass<ModuleOp>> mlir::createLowerToLLVMPass() {
std::unique_ptr<OperationPass<ModuleOp>>
mlir::createLowerToLLVMPass(const LowerToLLVMOptions &options) {
+ auto allocLowering = options.allocLowering;
+ // There is no way to provide additional patterns for pass, so
+ // AllocLowering::None will always fail.
+ assert(allocLowering != LowerToLLVMOptions::AllocLowering::None &&
+ "LLVMLoweringPass doesn't support AllocLowering::None");
+ bool useAlignedAlloc =
+ (allocLowering == LowerToLLVMOptions::AllocLowering::AlignedAlloc);
return std::make_unique<LLVMLoweringPass>(
options.useBarePtrCallConv, options.emitCWrappers,
- options.getIndexBitwidth(), options.useAlignedAlloc, options.dataLayout);
+ options.getIndexBitwidth(), useAlignedAlloc, options.dataLayout);
}
mlir::LowerToLLVMOptions::LowerToLLVMOptions(MLIRContext *ctx)
More information about the Mlir-commits
mailing list