[flang-commits] [flang] [flang][hlfir] Add MLIR op for `do concurrent` (PR #130893)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Wed Mar 12 21:49:37 PDT 2025


ergawy wrote:

> Thanks!
> 
> The approach looks good to me. A few questions:
> 
>     * Why HFLIR and not FIR?
> 
> 
> Putting it in HLFIR forces lowering it when moving from HLFIR to FIR, while it seems there is no deep requirement for this operation to be in HLFIR. The main reason for things to be in HLFIR is when they can manipulate hlfir.expr, which makes the so called "bufferization" the natural transition between FIR and HLFIR, and I am not sure it is best to correlate the hlfir.do_concurrent to xxx with bufferization (although I understand why you would want to run hlfir.do_concurrent to xxx early in the pipeline for some xxx, and that is OK, but I think it is best to give freedom to maintain fir.do_concurrent up to when we lower fir.do_loop).

Thanks for that context, very useful for me. This was suggested by @kiranchandramohan but it also made sense to me; since, in my mind, `hlfir.do_concurrent` is a high-level model of `do concurrent` loops that can be lowered to different targets including the lower level sibling `fir.do_loop`. Was HLFIR designed with the `hlfir.expr` and bufferization points being specifically in mind? Or is this just how the dialect has been used so far? If it is the latter, I think it won't be that bad to stretch the purpose/definition of the dialect to: "ops that are closer to Fortran source than the ones in FIR dialect". I am not too attached to that decision though, I think you guys will have better informed opinions here.

>     * What about locality specifiers?
> 
> 
> I think you mentioned in the [RFC](https://discourse.llvm.org/t/modeling-do-concurrent-loops-in-the-fir-dialect/84950/6) that you intend to add them later to these ops, I just want to check that I got that part right.

Yes, I want to reuse what we have in OpenMP regarding locality specifiers for the Fortran dialects as well. See: https://github.com/llvm/llvm-project/pull/128148. However, I am postponing this until I implement the `do_concurrent` op first. #128148 is just PoC, the final aim is to extract the OpenMP table-gen records used in the PoC into a "data environment dialect" used for OpenMP, Fortran, and maybe OpenACC as well. Since I did the PoC with `fir.do_loop` in mind, I will need to rethink it after finishing up `do_concurent`.

https://github.com/llvm/llvm-project/pull/130893


More information about the flang-commits mailing list