Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
563 changes: 459 additions & 104 deletions CMakeLists.txt

Large diffs are not rendered by default.

211 changes: 66 additions & 145 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,195 +6,116 @@

-->

# F18
# FIR

F18 is a ground-up implementation of a Fortran front end written in modern C++.
F18, when combined with LLVM, is intended to replace the Flang compiler.
Working branch for FIR development.

Flang is a Fortran compiler targeting LLVM.
Visit the [Flang wiki](https://github.com/flang-compiler/flang/wiki)
for more information about Flang.
## Monorepo now contains MLIR

## Getting Started
### In-tree build

Read more about f18 in the [documentation directory](documentation).
Start with the [compiler overview](documentation/Overview.md).
This is quite similar to the old way, but with a few subtle differences.

To better understand Fortran as a language
and the specific grammar accepted by f18,
read [Fortran For C Programmers](documentation/FortranForCProgrammers.md)
and
f18's specifications of the [Fortran grammar](documentation/f2018-grammar.txt)
and
the [OpenMP grammar](documentation/OpenMP-4.5-grammar.txt).
1. Get the stuff.

Treatment of language extensions is covered
in [this document](documentation/Extensions.md).

To understand the compilers handling of intrinsics,
see the [discussion of intrinsics](documentation/Intrinsics.md).

To understand how an f18 program communicates with libraries at runtime,
see the discussion of [runtime descriptors](documentation/RuntimeDescriptor.md).
```
git clone git@github.com:flang-compiler/f18-llvm-project.git
git clone git@github.com:schweitzpgi/f18.git
```

If you're interested in contributing to the compiler,
read the [style guide](documentation/C++style.md)
and
also review [how f18 uses modern C++ features](documentation/C++17.md).
2. Get "on" the right branches.

## Building F18
```
(cd f18-llvm-project ; git checkout mono)
(cd f18 ; git checkout mono)
```

3. Setup the LLVM space for in-tree builds.

```
(cd f18-llvm-project ; ln -s ../f18 flang)
```

### Get the Source Code
4. Create a build space for cmake and make (or ninja)

```
cd where/you/want/the/source
git clone https://github.com/flang-compiler/f18.git
mkdir build
cd build
cmake ../f18-llvm-project/llvm -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS="flang;mlir" -DCMAKE_CXX_STANDARD=17 -DLLVM_BUILD_TOOLS=On -DLLVM_INSTALL_UTILS=On <other-arguments>
```

### Supported C++ compilers
5. Build everything

F18 is written in C++17.
One can, for example, do this with make as follows.

The code has been compiled and tested with
GCC versions 7.2.0, 7.3.0, 8.1.0, and 8.2.0.
```
make <make-arguments>
```

The code has been compiled and tested with
clang version 7.0 and 8.0
using either GNU's libstdc++ or LLVM's libc++.
Or, of course, use their favorite build tool (such as ninja).

### LLVM dependency
### Out-of-tree build

F18 uses components from LLVM.
1. Get the stuff is the same as above. Get the code from the same repos.

The instructions to build LLVM can be found at
https://llvm.org/docs/GettingStarted.html.
2. Get on the right branches. Again, same as above.

We highly recommend using the same compiler to compile both llvm and f18.
3. SKIP step 3 above. We're not going to build `flang` yet.

The f18 CMakeList.txt file uses
the variable `LLVM_DIR` to find the installed components.
4. Create a build space for cmake and make (or ninja)

To get the correct LLVM libraries included in your f18 build,
define LLVM_DIR on the cmake command line.
```
LLVM=<LLVM_INSTALLATION_DIR>/lib/cmake/llvm cmake -DLLVM_DIR=$LLVM ...
mkdir build
cd build
export CC=<my-favorite-C-compiler>
export CXX=<my-favorite-C++-compiler>
cmake -GNinja ../f18-llvm-project/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS=mlir -DCMAKE_CXX_STANDARD=17 -DLLVM_BUILD_TOOLS=On -DLLVM_INSTALL_UTILS=On -DCMAKE_INSTALL_PREFIX=<install-llvm-here> <other-arguments>
```
where `LLVM_INSTALLATION_DIR` is
the top-level directory
where llvm is installed.

### LLVM dependency for lit Regression tests
5. Build and install

F18 has tests that use the lit framework, these tests rely on the
presence of llvm tools as llvm-lit, FileCheck, and others.
These tools are installed when LLVM build set:
```
LLVM_INSTALL_UTILS=On
ninja
ninja install
```
to run the regression tests on f18.

### Building f18 with GCC

By default,
cmake will search for g++ on your PATH.
The g++ version must be one of the supported versions
in order to build f18.
6. Add the new installation to your PATH

Or,
cmake will use the variable CXX to find the C++ compiler.
CXX should include the full path to the compiler
or a name that will be found on your PATH,
e.g. g++-7.2, assuming g++-7.2 is on your PATH.
```
export CXX=g++-7.2
PATH=<install-llvm-here>/bin:$PATH
```
or
```
CXX=/opt/gcc-7.2/bin/g++-7.2 cmake ...
```
There's a third option!
The CMakeList.txt file uses the variable GCC
as the path to the bin directory containing the C++ compiler.

GCC can be defined on the cmake command line
where `<GCC_DIRECTORY>` is the path to a GCC installation with bin, lib, etc:
7. Create a build space for another round of cmake and make (or ninja)

```
cmake -DGCC=<GCC_DIRECTORY> ...
mkdir build-flang
cd build-flang
cmake -GNinja ../f18 -DLLVM_DIR=<install-llvm-here> -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_CXX_STANDARD=17 -DLLVM_BUILD_TOOLS=On -DCMAKE_INSTALL_PREFIX=<install-flang-here> <other-arguments>
```
Note: if you plan on running lit regression tests, you should either:
- Use `-DLLVM_DIR=<build-llvm-here>` instead of `-DLLVM_DIR=<install-llvm-here>`
- Or, keep `-DLLVM_DIR=<install-llvm-here>` but add `-DLLVM_EXTERNAL_LIT=<path to llvm-lit>`.
A valid `llvm-lit` path is `<build-llvm-here>/bin/llvm-lit`.
Note that LLVM must also have been built with `-DLLVM_INSTALL_UTILS=On` so that tools required by tests like `FileCheck` are available in `<install-llvm-here>`.

### Building f18 with clang
8. Build and install

To build f18 with clang,
cmake needs to know how to find clang++
and the GCC library and tools that were used to build clang++.

The CMakeList.txt file expects either CXX or BUILD_WITH_CLANG to be set.

CXX should include the full path to clang++
or clang++ should be found on your PATH.
```
export CXX=clang++
```
BUILD_WITH_CLANG can be defined on the cmake command line
where `<CLANG_DIRECTORY>`
is the path to a clang installation with bin, lib, etc:
```
cmake -DBUILD_WITH_CLANG=<CLANG_DIRECTORY>
ninja
ninja install
```
Or GCC can be defined on the f18 cmake command line
where `<GCC_DIRECTORY>` is the path to a GCC installation with bin, lib, etc:
```
cmake -DGCC=<GCC_DIRECTORY> ...
```
To use f18 after it is built,
the environment variables PATH and LD_LIBRARY_PATH
must be set to use GCC and its associated libraries.

### Installation Directory

To specify a custom install location,
add
`-DCMAKE_INSTALL_PREFIX=<INSTALL_PREFIX>`
to the cmake command
where `<INSTALL_PREFIX>`
is the path where f18 should be installed.
### Running regression tests

### Build Types
Inside `build` for in-tree builds or inside `build-flang` for out-of-tree builds:

To create a debug build,
add
`-DCMAKE_BUILD_TYPE=Debug`
to the cmake command.
Debug builds execute slowly.

To create a release build,
add
`-DCMAKE_BUILD_TYPE=Release`
to the cmake command.
Release builds execute quickly.

### Build F18
```
cd ~/f18/build
cmake -DLLVM_DIR=$LLVM ~/f18/src
make
ninja check-flang
```

### How to Run the Regression Tests
Special CMake instructions given above are required while building out-of-tree so that lit regression tests can be run.

To run all tests:
```
cd ~/f18/build
cmake -DLLVM_DIR=$LLVM ~/f18/src
make check-all
```
### Problems

To run individual regression tests llvm-lit needs to know the lit
configuration for f18. The parameters in charge of this are:
flang_site_config and flang_config. And they can be set as shown bellow:
```
<path-to-llvm-lit>/llvm-lit \
--param flang_site_config=<path-to-f18-build>/test-lit/lit.site.cfg.py \
--param flang_config=<path-to-f18-build>/test-lit/lit.cfg.py \
<path-to-fortran-test>
```
Despite best efforts, there may be situations where the above repos will
get out of sync, and the build will fail.
Loading