I’m very interested in advanced optimizations for Fortran in MLIR. Currently, the FIR dialect is directly lowered to the LLVM dialect. We can first convert the FIR dialect to the Affine dialect, perform optimizations on top of it, and then lower it to the FIR dialect. I have successfully established an initial optimization pipeline that can automatically apply OpenMP parallelization to Fortran loops. The optimization passes are currently experimental, so it’s important to actively identify and address issues.
PR: [flang][fir] Add affine optimization pass pipeline. by NexMing · Pull Request #138627 · llvm/llvm-project · GitHub
Hello @yanming,
Thanks for this RFC.
Can you join one of the biweekly Flang calls (on Wednesday 7th May or Monday 12th May) to share your plans? The calls are usually at 4.30 pm BST/8.30 am PT/
See details of the calls in the link below.
My spoken English is poor, so I’m not able to participate in a conference call.
Can we discuss this on the forum instead?
Sure, that is alright. Thanks.
Is it the FIR → Affine → SCF → OpenMP flow that you are primarily interested in? Or are you also working on loop transformations (tiling, vectorization, fission, fusion etc) in Affine/SCF? Do you have a productisation plan for this FIR to OpenMP transformation or will this be available only under a flag (-mllvm --enable-affine-opt
)?
A related question will be, would it be more natural to convert HLFIR operations to Affine rather than do this at the FIR level?
FYI: @bob.belcher is working on converting do-concurrent loops to OpenMP when a flag is used.
My main interest is in performing advanced optimizations on Affine. OpenMP is just one example to demonstrate the effectiveness of this approach.
Currently, some passes are still under development(like affine-promotion
pass). The goal is to gradually fix these passes and eventually remove --enable-affine-opt
flag.
I’m also very interested in performing various loop optimizations or even polyhedral optimizations in Affine. The top priority is to enable the conversion of as many loop forms in Fortran as possible into Affine.
Enabling all of these optimizations by default (removing the flag) is likely to be quite challenging. For example, I expect it will not be possible to do the lowering to OpenMP by default because (if I understand correctly) this could involve parallelizing loops which the programmer has not requested to be run in parallel. If the Fortran standard even allows that, it would put all of the correctness requirements on the compiler. I think it could be difficult to inspect a loop and determine at compile time if it is safe and profitable to parallelize without any assurance form the programmer.
However, contributing this upstream behind a flag is very welcome (at least from me). And hopefully some polyhedral optimizations could be safe to enable by default if they prove profitable.