[CIR][ThroughMLIR] Lower pointers to memref<?xType> #2069
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello, I attempted to resolve the #1729, as I have been compiling some simple OpenCL kernels similar to @mahmood82.
According to the @felixdaas's suggestion of using the 'polygeist way', I have changed the default type conversion of cir.ptr to memref<?xType>.
To make the intermediate legalization work, this also changes the lowering of AllocaOp and GlobalOp to generate memref<1xType> followed by a CastOp to memref<?xType>. CastOp is later eliminated in Load/Store-lowering. Load/Store-lowering's findBaseAndIndices was then adjusted to generate op with zero indices in case a non-indexed op is performed.
I added a testcase ptr-arg.cir, with example code similar to one in #1729
I also had to touch the loop lowering to SCF, since the alloca-change affected the 'canonical-loop recognition'.
I also had to change all the ThroughMLIR tests to work with the alloca of memref<1xType>.
Additionally, the ptr.dialect based lowering by @terapines-osc-cir is now basically dead code, as the ptrstride-ptr.cir-test they added is now lowered directly to memref-ops. So probably a new, more complex testcase would be needed to also test it, and to change the ptrstrideop-lowering to still take that path in the more complex cases.