This patch references code for translating memref.reinterpret_cast ops
to add translation rules for memref.reshape ops that have a static shape
argument. Since reshape ops don't have offsets, sizes, or strides, this
patch simply sets the allocated and aligned pointers of the MemRef
descriptor.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Since reshape ops don't have offsets, sizes, or strides, this
patch simply sets the allocated and aligned pointers of the MemRef
descriptor.
The convention is that the descriptor always contains the correct size and stride information even if the lowerings may chose to ignore it and use the information statically available from types. The reason for this is the descriptor being also used to interface with C code that does not have access to the information containing in the memref type. Leaving size/stride information uninitialized will lead to UB in such code.
set stride, offset, and size attributes of MemRefDescriptor
The code now uses getStridesAndOffset() on the result MemRefType to infer the
stride, offset, and size attributes.
Thanks for the suggestion. I've updated the code and test to set the offset, stride, and size. PTAL.
I left some comments but I am also pretty new to this. Hope someone who's expert on this help to take a look.
mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp | ||
---|---|---|
1126 | nit: could remove the auto successStrides and check if (failed(getStridesAndOffset...)) directly | |
1129 | My understanding is that it's still possible to get non static offset and strides for static shape memref so need to check all static before calling desc.setConstantXXX. |
Thanks @cathyzhyi! I've updated the code accordingly, but please let me know if I still got it wrong. Thanks!
mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp | ||
---|---|---|
1132 | Need to check for constant offset as well. |
LGTM! @ftynse could you help to double check because I am not super confident either.
mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp | ||
---|---|---|
1123 | Nit: do not specify the number of stack elements in SmallVector unless you have a strong reason to use a specific number. |
Nit: do not specify the number of stack elements in SmallVector unless you have a strong reason to use a specific number.