RFC: Optimisation flags in `flang-new`

Hello everyone,

I’d like to add support for for optimisation flags in flang-new in the near future (e.g. -O1 or -O3). Below is a rough summary of the approach that I’d like to take. Please let me know whether this makes sense to you and meets your requirements.

  1. I would like to focus on LLVM’s middle-end and back-end optimisation first. I feel that we should wait a bit before discussing which MLIR/FIR optimisations to include.
  2. Similarly to Clang, I would like to re-use the definition of optimisation pipelines from LLVM (I’ve discussed them briefly here: https://discourse.llvm.org/t/optimisation-pipelines).
  3. In my initial implementation, I will skip LTO, sanitizers or anything that affects the meaning of these flags in Clang.

Essentially, the initial implementation will allow us to replace this:

flang-new -S -emit-llvm file.f90 -o - | clang -O3 -o file.o


flang-new -c -O3 file.f90 

The only real downside of this is that we will be enabling all LLVM optimisations that Clang does. I imagine that some of them might be irrelevant for Fortran (i.e. have been implemented with inputs from Clang in mind). But this will become more obvious once we have -O3 and can experiment.

Thanks for taking a look!



I believe starting with the options is a good idea. It will get you one step further. Designing a complete pipeline from FIR->MLIR->LLVM-> Isel will be a larger project.

1 Like

We discussed this in the call on Monday and folks seemed to be in favor of this approach. I have a rather long backlog of items to work on, but will aim for this to be available for LLVM 15.

Just to clarify, I will be introducing optimisation flags (e.g. -O3) and making them default to LLVM pipelines (which are also used in Clang).