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/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 Flang support in LLVM (FLANG)
Linaro Windows on Arm (WOA) project page Windows On Arm (WOA)
WoA Flang component page Fortran
CMak'e Flang CI information page https://linaro.atlassian.net/wiki/spaces/TCWG/pages/28782756056
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: https://linaro.atlassian.net/wiki/spaces/TCWG/pages/22395192116
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. https://linaro.atlassian.net/wiki/spaces/TCWG/pages/22348008450 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 https://github.com/llvm/llvm-project/tree/main/flang#building-flang-in-tree has instructions on how to build and test Flang.
A good LLVM developers guide can be found at https://llvm.org/docs/GettingStarted.html
https://llvm.org/docs/GettingStartedVS.htmlis targeted for LLVM development on windows.
For introduction to various LLVM CMake options use information provided at https://llvm.org/docs/CMake.html
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
https://github.com/llvm/llvm-project/blob/main/flang/README.md#getting-started
Windows 10 on Arm
How to setup Windows 10 on Arm for llvm development
Windows 11 on Arm
https://linaro.atlassian.net/wiki/spaces/TCWGPUB/pages/28809266294
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 https://linaro.atlassian.net/wiki/spaces/TCWG/pages/22256026123
Linaro’s LLVM buildbot monitor page
http://llvm.validation.linaro.org/
Linaro LLVM buildbot maintenance information pages
Linux Arm/AArch64 https://linaro.atlassian.net/wiki/spaces/TCWG/pages/22343946024
Windows 10 on Arm https://linaro.atlassian.net/wiki/spaces/TCWGPUB/pages/25310167965
Windows 11 on Arm https://linaro.atlassian.net/l/cp/RKj14KFf
Talks and Tutorials
Flang
MLIR
https://www.youtube.com/watch?v=ff3ngdvUang
LLVM
https://resources.linaro.org/en/resource/8SXVuHd5EVVERgLrwvqDb6
MISC
https://www.youtube.com/watch?v=hlBOFmFHfhw&list=PL2OGy94bULInJyLISlZzZc0p0ELevyoSV&index=2
Â
https://www.youtube.com/watch?v=Np7Fy2F71lU
Â