-
Notifications
You must be signed in to change notification settings - Fork 139
Building Flang
We build Flang on Intel x86-64 and OpenPOWER hardware running either Ubuntu or Red Hat.
Building LLVM requires a fairly modern compiler toolchain and CMake, check Getting started with LLVM and Building LLVM with CMake for the full list of tools required to build flang.
Flang depends on forks of clang and llvm.
The clang fork, flang-compiler/flang-driver, has been modified to support compilation of Fortran files, Fortran-specific command-line options, and the flang toolchain.
The llvm fork, flang-compiler/llvm, has been extended to support enhanced debug metadata specific to Fortran. It also has bug fixes that have been exposed by flang but have not yet been fixed in the llvm repository.
The latest supported LLVM version is 6.0. Flang also supports LLVM version 5.0.
To use 5.0, substitute 50 for 60 in the build instructions.
Flang is built outside of the llvm source tree.
The Linux command-line examples below will install everything into the default system location unless you set a custom install location.
When building flang, your PATH must include the install bin directory.
To specify a custom install location, in each step below
add -DCMAKE_INSTALL_PREFIX=<INSTALL_PREFIX>
to every CMake command.
If you use CMAKE_INSTALL_PREFIX
in any step, you must use the same
CMAKE_INSTALL_PREFIX
in every step.
When using a custom install location, you must make sure that the bin directory is on your PATH when building and running flang.
If you use CMAKE_INSTALL_PREFIX
and <INSTALL_PREFIX>/bin
is not in your path,
you need to add several additional command-line arguments for CMake:
-DLLVM_CONFIG=<INSTALL_PREFIX>/bin/llvm-config
-DCMAKE_CXX_COMPILER=<INSTALL_PREFIX>/bin/clang++
-DCMAKE_C_COMPILER=<INSTALL_PREFIX>/bin/clang
-DCMAKE_Fortran_COMPILER=<INSTALL_PREFIX>/bin/flang)
-
Get Flang LLVM, build and install it according to instructions
cd where/you/want/to/build git clone https://github.com/flang-compiler/llvm.git cd llvm git checkout release_60 mkdir build && cd build cmake <your custom options> .. make sudo make install
-
Get the flang driver, build and install it
cd where/you/want/to/build git clone https://github.com/flang-compiler/flang-driver.git cd flang-driver git checkout release_60 mkdir build && cd build cmake <your custom options> .. make sudo make install
If you use
CMAKE_INSTALL_PREFIX
in Step 1 and<INSTALL_PREFIX>/bin
is not in your path, you need to add-DLLVM_CONFIG=<INSTALL_PREFIX>/bin/llvm-config
when invoking CMake, otherwise you will encounter an error related toLLVMConfig.cmake
not being found. -
Get the OpenMP runtime library, build and install it
cd where/you/want/to/build git clone https://github.com/llvm-mirror/openmp.git cd openmp/runtime git checkout release_60 mkdir build && cd build cmake <your custom options> ../.. make sudo make install
-
Get the flang source code
cd where/you/want/to/build
git clone https://github.com/flang-compiler/flang.git
-
Build libpgmath and install it
Note that libpgmath on x86 requires a toolchain that understands AVX-512 instructions, such as gcc 7.2.
For example, you might add custom options similar to these:
-DCMAKE_CXX_COMPILER=<GCC_PREFIX>/bin/g++ -DCMAKE_C_COMPILER=<GCC_PREFIX>/bin/gcc
The source for libpgmath is in flang/runtime/libpgmath.
cd where/you/want/to/build cd flang/runtime/libpgmath mkdir build && cd build cmake <your custom options> .. make sudo make install
-
Built flang and install it
cd where/you/want/to/build git clone https://github.com/flang-compiler/flang.git cd flang mkdir build && cd build cmake <your custom options> .. make sudo make install
Spack is a flexible package manager for HPC system and can be used to build flang and its dependencies.
-
Get Spack
git clone https://github.com/llnl/spack.git
On bash:
source spack/share/spack/setup-env.sh
or tcsh:
source spack/share/spack/setup-env.csh
-
Build Flang and its dependencies:
spack install flang
watch out for the installation path, the flang wrapper script in there is ready to use.
-
(optional) setup Flang as a compiler inside spack if you want to build spack package with flang:
spack compiler add path/to/flang/bin
Now you might want to edit your
~/.spack/*/compilers.yaml
to combineflang
with any c compiler of your choice.
To test your installation, create a simple "hello world" program, like the following:
program hello
print *, 'hello world'
end
Next, compile the program in the following manner. We will assume the program is called hello.f90
% flang hello.f90
If the build succeeds, then you can execute the program in the following manner:
% ./a.out