This is the first patch in a series of patches part of this RFC: https://discourse.llvm.org/t/rfc-switching-the-llvm-dialect-and-dialect-lowerings-to-opaque-pointers/68179
This patch adds the ability to lower the memref dialect to the LLVM Dialect with the use of opaque pointers instead of typed pointers. The latter are being phased out of LLVM and this patch is part of an effort to phase them out of MLIR as well. To do this, we'll need to support both typed and opaque pointers in lowering passes, to allow downstream projects to change without breakage.
The gist of changes required to change a conversion pass are:
- Change any LLVM::LLVMPointerType::get calls to NOT use an element type if opaque pointers are to be used.
- Use the build method of llvm.load with the explicit result type. Since the pointer does not have an element type anymore it has to be specified explicitly.
- Use the build method of llvm.getelementptr with the explicit basePtrType. Ditto to above, we have to now specify what the element type is so that GEP can do its indexing calculations
- Use the build method of llvm.alloca with the explicit elementType. Ditto to the above, alloca needs to know how many bytes to allocate through the element type.
- Get rid of any llvm.bitcasts
- Adapt the tests to the above. Note that llvm.store changes syntax as well when using opaque pointers
I'd like to note that the 3 build method changes work for both opaque and typed pointers, so unconditionally using the explicit element type form is always correct.
For the testsuite a practical approach suggested by @ftynse was taken: I created a separate test file for testing the typed pointer lowering of Ops. This mostly comes down to checking that bitcasts have been created at the appropiate places, since these are required for typed pointer support.