-
Notifications
You must be signed in to change notification settings - Fork 15k
Open
Labels
Description
Lowering MemRef to LLVM dialect currently generates ptrtoint (getelementptr null, 1)
style sizeof expressions using this helper:
llvm-project/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
Lines 171 to 184 in cfb4dce
Value ConvertToLLVMPattern::getSizeInBytes( | |
Location loc, Type type, ConversionPatternRewriter &rewriter) const { | |
// Compute the size of an individual element. This emits the MLIR equivalent | |
// of the following sizeof(...) implementation in LLVM IR: | |
// %0 = getelementptr %elementType* null, %indexType 1 | |
// %1 = ptrtoint %elementType* %0 to %indexType | |
// which is a common pattern of getting the size of a type in bytes. | |
Type llvmType = typeConverter->convertType(type); | |
auto convertedPtrType = LLVM::LLVMPointerType::get(rewriter.getContext()); | |
auto nullPtr = rewriter.create<LLVM::ZeroOp>(loc, convertedPtrType); | |
auto gep = rewriter.create<LLVM::GEPOp>(loc, convertedPtrType, llvmType, | |
nullPtr, ArrayRef<LLVM::GEPArg>{1}); | |
return rewriter.create<LLVM::PtrToIntOp>(loc, getIndexType(), gep); | |
} |
These need to be replaced with an emission of a constant based on the DataLayout.
The ability to generate the expressions in this form will go away entirely with https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699 and causes problems for https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179 as well.