Getting started with LLVM Flang development

Fortran is a language popular with the Scientific and HPC community. Flang is LLVM's Fortran frontend and it is important component for LLVM to be successful in HPC. Linaro and Linaro’s Members are working on Flang development targeting AArch64 on Linux and Windows.

This page is collection of necessary developer information that is required to get started with Flang development.

LLVM wiki pages on LLVM and flang

LLVM wiki pages below provide good documentation and have the information about how to get involved with the Flang community. Please feel free to join the Flang biweekly calls, mailing list and the slack channels for discussions related to development of Flang.

https://flang.llvm.org/docs/

https://flang.llvm.org/docs/GettingInvolved.html

https://flang.llvm.org/docs/FIRLangRef.html

Fortran 2018 standard

Fortran’s official standards aren’t free. But many use the latest working draft instead, that is very close to the final version. Flang’s code and community often references Fortran 2018 standard.

F2018 Interpretation Document: https://j3-fortran.org/doc/year/18/18-007r1.pdf

Linaro wiki pages on LLVM Flang

LLVM Flang is a sub-project (JIRA component) within LLVM toolchain project at Linaro. Windows on Arm specific work is being tracked by Windows on Arm project at Linaro. List of pages given below provide information on Linaro’s LLVM Flang development activities.

  • LLVM Flang Linaro’s project page

  • Linaro Windows on Arm (WOA) project page

    • WoA Flang component page

  • CMak'e Flang CI information page

Accessing a development machines or container

Linaro Lab hosts development machines that can be remotely accessed for various day to day development activities.

Windows on Arm development is done on Microsoft Surface X Pro machines. More information about accessing these machines can be found here:

There are various different machines hosted for Linux x64/Arm/AArch64 development which are mostly managed by Docker virtualisation and can be accessed as docker containers by developers. page has information on how to set up access to Linux development machines and containers.

How to build Flang and LLVM:

LLVM wiki has a lot of good resources on how to get started with LLVM development.

Flang’s GitHub README at has instructions on how to build and test Flang.

A good LLVM developers guide can be found at

is targeted for LLVM development on windows.

For introduction to various LLVM CMake options use information provided at

Building Fortran programs with Flang

As Flang’s code generation support is still in experimental stage, in order to build binaries with flang-new an undocumented flag needs to be used: -flang-experimental-exec.

Debugging Flang

Running Flang under gdb can help in the process of understanding how each part of the code works and in locating which part may be misbehaving. The first step is to make a debug build. The following cmake flags can help in speeding up the build and gdb load times:

LLVM_USE_SPLIT_DWARF=ON LLVM_USE_LINKER=lld LLVM_OPTIMIZED_TABLEGEN=ON

It’s also a good idea to limit the number of parallel link jobs with LLVM_PARALLEL_LINK_JOBS and the number of build threads to avoid running out of memory.

To debug issues with the frontend, first get its invocation command line with flang-new -v -c <file> and then use that with gdb instead, to avoid having to handle forks when debugging.

Testing IR generation

The bbc tool is very useful to test IR generation and compiler passes.

Some examples are:

  • Emit FIR: bbc --emit-fir <source>

  • Emit HLFIR: bbc --emit-fir --hlfir <source>

  • Dump IR before each pass: bbc --mlir-print-ir-before-all <source>

LLVM Flang developer guides

Linux Arm/AArch64

Windows 10 on Arm

Windows 11 on Arm

Flang buildbot maintenance

For about last 10 years or so Linaro toolchain team has been maintaining and monitoring a series of LLVM buildbots to make sure that the quality of the code produced by LLVM doesn't regress on ARM. We have hosted LLVM Flang buildbots as well.

More information about Linaro’s LLVM buildbots can be found at

Linaro’s LLVM buildbot monitor page

http://llvm.validation.linaro.org/

Linaro LLVM buildbot maintenance information pages

  • Linux Arm/AArch64

  • Windows 10 on Arm

  • Windows 11 on Arm

Talks and Tutorials

Flang

MLIR

LLVM

MISC