[mlir] Handle different pointer sizes in unranked memref descriptors
authorKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Mon, 9 Jan 2023 15:56:22 +0000 (15:56 +0000)
committerKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Thu, 9 Feb 2023 19:14:58 +0000 (19:14 +0000)
commitd0f19ce774b0d3fa5cd3b22561cc75c7b38b290d
treef7c5b8566c0336ae9290a4e527fc664bf90c2971
parent90f4419a9c74ab713e2368675140ba63f1829f8d
[mlir] Handle different pointer sizes in unranked memref descriptors

The code for unranked memref descriptors assumed that
sizeof(!llvm.ptr) == lizeof(!llvm.ptr<N>) for all address spaces N.
This is not always true (ex. the AMDGPU compiler backend has
sizeof(!llvm.ptr) = 64 bits but sizeof(!llvm.ptr<5>) = 32 bits, where
address space 5 is used for stack allocations). While this is merely
an overallocation in the case where a non-0 address space has pointers
smaller than the default, the existing code could cause OOB memory
accesses when sizeof(!llvm.ptr<N>) > sizeof(!llvm.ptr).

So, add an address spaces parameter to computeSizes in order to
partially resolve this class of bugs. Note that the LLVM data layout
in the conversion passes is currently set to "" and not constructed
from the MLIR data layout or some other source, but this could change
in the future.

Depends on D142159

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D141293
mlir/include/mlir/Conversion/LLVMCommon/MemRefBuilder.h
mlir/include/mlir/Conversion/LLVMCommon/StructBuilder.h
mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
mlir/lib/Conversion/LLVMCommon/Pattern.cpp
mlir/lib/Conversion/LLVMCommon/StructBuilder.cpp
mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp
mlir/test/Conversion/FuncToLLVM/calling-convention.mlir
mlir/test/Conversion/MemRefToLLVM/convert-dynamic-memref-ops.mlir
mlir/test/Conversion/MemRefToLLVM/typed-pointers.mlir