[Mlir-commits] [flang] [mlir] [flang] Introduce omp_target_allocmem and omp_target_freemem fir ops. (PR #145464)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 3 08:59:08 PDT 2025
skc7 wrote:
> Thanks @skc7 for the PR! I have a few concerns about this approach, please let me know if I am missing anything:
>
> 1. I am bit skeptical about leaking OpenMP specific ops to the `fir` dialect. The reason I see we have to do that is that we need to return a `fir_HeapType` from the `omp_target_allocmem` op, right? If there are not other reasons, why don't we introduce the op in the OpenMP dialect where it naturally fits, let it return an `Int64` type and use `fir.convert` to the target type?
> 2. In general though, why are we introducing a new op for the runtime API? Can't we directly emit these as call ops instead of having to introduce an op and then lower the op to a call? Are we planning to use these ops later somehow in some other way than lowering to the target call?
>
> I am probably missing some context here though so my question might not be totally informed.
Hi @ergawy
For implementing workdistribute lowering, in a new pass "lower-workdistribute" : [LINK](https://github.com/llvm/llvm-project/pull/140523), Need to move fir.allocmem nested in omp.target outside it (or hoist it outside omp.target)
Have updated the PR to implement the approach 1, to introduce omp.target_alloc_mem and omp.target_free_mem in openMP dialect. Also, their conversion to llvm ir has been implemented.
But, inorder to properly calculate the size of allocation of fir types, had to implement TargetAllocMemOpConversion in CodeGenOpenMP, to lower omp.target_alloc_mem to LLVM dialect callOp of "omp_target_alloc".
Approach 2, is to directly lower to a LLVM dialect, call to "omp_target_alloc".
Call to "omp_target_alloc" is to be made directly in the pass. It requires to calculate the actual size of allocation for fir type when it is lowered to llvm ir in the pass itself, which I think is bit complicated since it requires to move the utilities of size calculation (from Codegen fir to llvm) to with in the pass.
So, went ahead with approach 1. Please let me know your comments on this.
https://github.com/llvm/llvm-project/pull/145464
More information about the Mlir-commits
mailing list