Skip to content

[MLIR][MemRefToLLVM] Remove last typed pointer remnants #71113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions mlir/include/mlir/Dialect/LLVMIR/FunctionCallUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ LLVM::LLVMFuncOp lookupOrCreatePrintCloseFn(ModuleOp moduleOp);
LLVM::LLVMFuncOp lookupOrCreatePrintCommaFn(ModuleOp moduleOp);
LLVM::LLVMFuncOp lookupOrCreatePrintNewlineFn(ModuleOp moduleOp);
LLVM::LLVMFuncOp lookupOrCreateMallocFn(ModuleOp moduleOp, Type indexType,
bool opaquePointers);
bool opaquePointers = true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not drop this argument entirely?

Copy link
Contributor Author

@Dinistro Dinistro Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a followup that removes all of these in one go, but I cannot stack PRs that use branches of my fork. The functions in FunctionCallUtils.h are also used in the LLVM utils helpers from LLVMCommon.

Once this and #71075 have been landed, I'll open the other PR that removes all of this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just hoped these were truly the last remnants :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are only the last remnants in the MemRefToLLVM lowering :)

LLVM::LLVMFuncOp lookupOrCreateAlignedAllocFn(ModuleOp moduleOp, Type indexType,
bool opaquePointers = true);
LLVM::LLVMFuncOp lookupOrCreateFreeFn(ModuleOp moduleOp,
bool opaquePointers = true);
LLVM::LLVMFuncOp lookupOrCreateGenericAllocFn(ModuleOp moduleOp, Type indexType,
bool opaquePointers);
LLVM::LLVMFuncOp lookupOrCreateGenericAlignedAllocFn(ModuleOp moduleOp,
Type indexType,
bool opaquePointers);
bool opaquePointers = true);
LLVM::LLVMFuncOp
lookupOrCreateGenericAlignedAllocFn(ModuleOp moduleOp, Type indexType,
bool opaquePointers = true);
LLVM::LLVMFuncOp lookupOrCreateGenericFreeFn(ModuleOp moduleOp,
bool opaquePointers = true);
LLVM::LLVMFuncOp lookupOrCreateMemRefCopyFn(ModuleOp moduleOp, Type indexType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def MemrefToLLVMTypeConverterOp : Op<Transform_Dialect,
machine word.
- `use_generic_functions`: Use generic allocation and deallocation functions
instead of the classic "malloc", "aligned_alloc" and "free" functions.
- `use_opaque_pointers`: Generate LLVM IR using opaque pointers instead of
typed pointers.
// TODO: the following two options don't really make sense for
// memref_to_llvm_type_converter specifically.
// We should have a single to_llvm_type_converter.
Expand All @@ -45,7 +43,6 @@ def MemrefToLLVMTypeConverterOp : Op<Transform_Dialect,
DefaultValuedOptionalAttr<BoolAttr, "false">:$use_aligned_alloc,
DefaultValuedOptionalAttr<I64Attr, "64">:$index_bitwidth,
DefaultValuedOptionalAttr<BoolAttr, "false">:$use_generic_functions,
DefaultValuedOptionalAttr<BoolAttr, "false">:$use_opaque_pointers,
DefaultValuedOptionalAttr<BoolAttr, "false">:$use_bare_ptr_call_conv,
OptionalAttr<StrAttr>:$data_layout);
let assemblyFormat = "attr-dict";
Expand Down
16 changes: 4 additions & 12 deletions mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ LLVM::LLVMFuncOp getNotalignedAllocFn(const LLVMTypeConverter *typeConverter,
bool useGenericFn = typeConverter->getOptions().useGenericFunctions;

if (useGenericFn)
return LLVM::lookupOrCreateGenericAllocFn(
module, indexType, typeConverter->useOpaquePointers());
return LLVM::lookupOrCreateGenericAllocFn(module, indexType);

return LLVM::lookupOrCreateMallocFn(module, indexType,
typeConverter->useOpaquePointers());
return LLVM::lookupOrCreateMallocFn(module, indexType);
}

LLVM::LLVMFuncOp getAlignedAllocFn(const LLVMTypeConverter *typeConverter,
ModuleOp module, Type indexType) {
bool useGenericFn = typeConverter->getOptions().useGenericFunctions;

if (useGenericFn)
return LLVM::lookupOrCreateGenericAlignedAllocFn(
module, indexType, typeConverter->useOpaquePointers());
return LLVM::lookupOrCreateGenericAlignedAllocFn(module, indexType);

return LLVM::lookupOrCreateAlignedAllocFn(module, indexType,
typeConverter->useOpaquePointers());
return LLVM::lookupOrCreateAlignedAllocFn(module, indexType);
}

} // end namespace
Expand Down Expand Up @@ -70,10 +66,6 @@ static Value castAllocFuncResult(ConversionPatternRewriter &rewriter,
typeConverter.getPointerType(allocatedPtrTy.getElementType(),
memrefAddrSpace),
allocatedPtr);

if (!typeConverter.useOpaquePointers())
allocatedPtr =
rewriter.create<LLVM::BitcastOp>(loc, elementPtrType, allocatedPtr);
return allocatedPtr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ transform::MemrefToLLVMTypeConverterOp::getTypeConverter() {
(getUseAlignedAlloc() ? LowerToLLVMOptions::AllocLowering::AlignedAlloc
: LowerToLLVMOptions::AllocLowering::Malloc);
options.useGenericFunctions = getUseGenericFunctions();
options.useOpaquePointers = getUseOpaquePointers();

if (getIndexBitwidth() != kDeriveIndexBitwidthFromDataLayout)
options.overrideIndexBitwidth(getIndexBitwidth());
Expand Down