• Home
Name Date Size #Lines LOC

..--

cmake/modules/03-May-2024-229191

docs/03-May-2024-14,05111,369

include/03-May-2024-28,59820,742

lib/03-May-2024-74,14261,858

module/03-May-2024-1,228917

runtime/03-May-2024-11,6379,508

test/03-May-2024-37,28518,844

tools/03-May-2024-1,8271,525

unittests/03-May-2024-4,9014,292

.clang-formatD03-May-2024559 2220

.clang-tidyD03-May-2024136 21

.drone.starD03-May-20242.9 KiB6155

.gitignoreD03-May-2024190 2221

CMakeLists.txtD03-May-202415.8 KiB463389

CODE_OWNERS.TXTD03-May-2024736 1915

LICENSE.txtD03-May-202412.8 KiB235196

README.mdD03-May-20248 KiB262200

README.md

1# Flang
2
3Flang is a ground-up implementation of a Fortran front end written in modern
4C++. It started off as the f18 project (https://github.com/flang-compiler/f18)
5with an aim to replace the previous flang project
6(https://github.com/flang-compiler/flang) and address its various deficiencies.
7F18 was subsequently accepted into the LLVM project and rechristened as Flang.
8
9## Getting Started
10
11Read more about flang in the [docs directory](docs).
12Start with the [compiler overview](docs/Overview.md).
13
14To better understand Fortran as a language
15and the specific grammar accepted by flang,
16read [Fortran For C Programmers](docs/FortranForCProgrammers.md)
17and
18flang's specifications of the [Fortran grammar](docs/f2018-grammar.md)
19and
20the [OpenMP grammar](docs/OpenMP-4.5-grammar.md).
21
22Treatment of language extensions is covered
23in [this document](docs/Extensions.md).
24
25To understand the compilers handling of intrinsics,
26see the [discussion of intrinsics](docs/Intrinsics.md).
27
28To understand how a flang program communicates with libraries at runtime,
29see the discussion of [runtime descriptors](docs/RuntimeDescriptor.md).
30
31If you're interested in contributing to the compiler,
32read the [style guide](docs/C++style.md)
33and
34also review [how flang uses modern C++ features](docs/C++17.md).
35
36If you are interested in writing new documentation, follow
37[markdown style guide from LLVM](https://github.com/llvm/llvm-project/blob/master/llvm/docs/MarkdownQuickstartTemplate.md).
38
39## Supported C++ compilers
40
41Flang is written in C++17.
42
43The code has been compiled and tested with
44GCC versions from 7.2.0 to 9.3.0.
45
46The code has been compiled and tested with
47clang version 7.0, 8.0, 9.0 and 10.0
48using either GNU's libstdc++ or LLVM's libc++.
49
50The code has been compiled on
51AArch64, x86\_64 and ppc64le servers
52with CentOS7, Ubuntu18.04, Rhel, MacOs, Mojave, XCode and
53Apple Clang version 10.0.1.
54
55The code does not compile with Windows and a compiler that does not have
56support for C++17.
57
58## Building Flang out of tree
59These instructions are for building Flang separately from LLVM; if you are
60building Flang alongside LLVM then follow the standard LLVM build instructions
61and add flang to `LLVM_ENABLE_PROJECTS` instead, as detailed there.
62
63### LLVM dependency
64
65The instructions to build LLVM can be found at
66https://llvm.org/docs/GettingStarted.html. If you are building flang as part
67of LLVM, follow those instructions and add flang to `LLVM_ENABLE_PROJECTS`.
68
69We highly recommend using the same compiler to compile both llvm and flang.
70
71The flang CMakeList.txt file uses
72the variable `LLVM_DIR` to find the installed LLVM components
73and
74the variable `MLIR_DIR` to find the installed MLIR components.
75
76To get the correct LLVM and MLIR libraries included in your flang build,
77define LLVM_DIR and MLIR_DIR on the cmake command line.
78```
79LLVM=<LLVM_BUILD_DIR>/lib/cmake/llvm \
80MLIR=<LLVM_BUILD_DIR>/lib/cmake/mlir \
81cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ...
82```
83where `LLVM_BUILD_DIR` is
84the top-level directory where LLVM was built.
85
86### Building flang with GCC
87
88By default,
89cmake will search for g++ on your PATH.
90The g++ version must be one of the supported versions
91in order to build flang.
92
93Or, cmake will use the variable CXX to find the C++ compiler. CXX should include
94the full path to the compiler or a name that will be found on your PATH, e.g.
95g++-8.3, assuming g++-8.3 is on your PATH.
96
97```
98export CXX=g++-8.3
99```
100or
101```
102CXX=/opt/gcc-8.3/bin/g++-8.3 cmake ...
103```
104
105### Building flang with clang
106
107To build flang with clang,
108cmake needs to know how to find clang++
109and the GCC library and tools that were used to build clang++.
110
111CXX should include the full path to clang++
112or clang++ should be found on your PATH.
113```
114export CXX=clang++
115```
116
117### Installation Directory
118
119To specify a custom install location,
120add
121`-DCMAKE_INSTALL_PREFIX=<INSTALL_PREFIX>`
122to the cmake command
123where `<INSTALL_PREFIX>`
124is the path where flang should be installed.
125
126### Build Types
127
128To create a debug build,
129add
130`-DCMAKE_BUILD_TYPE=Debug`
131to the cmake command.
132Debug builds execute slowly.
133
134To create a release build,
135add
136`-DCMAKE_BUILD_TYPE=Release`
137to the cmake command.
138Release builds execute quickly.
139
140### Build Flang out of tree
141```
142cd ~/flang/build
143cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/flang/src
144make
145```
146
147### Build The New Flang Driver
148The new Flang driver, `flang-new`, is currently under active development and
149should be considered as an experimental feature. For this reason it is disabled
150by default. This will change once the new driver replaces the _throwaway_
151driver, `flang`.
152
153In order to build the new driver, add `-DFLANG_BUILD_NEW_DRIVER=ON` to your
154CMake invocation line. Additionally, when building out-of-tree, use `CLANG_DIR`
155(similarly to `LLVM_DIR` and `MLIR_DIR`) to find the installed Clang
156components.
157
158**Note:** `CLANG_DIR` is only required when building the new Flang driver,
159which currently depends on Clang.
160
161# How to Run Tests
162
163Flang supports 2 different categories of tests
1641. Regression tests (https://www.llvm.org/docs/TestingGuide.html#regression-tests)
1652. Unit tests (https://www.llvm.org/docs/TestingGuide.html#unit-tests)
166
167## For out of tree builds
168To run all tests:
169```
170cd ~/flang/build
171cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/flang/src
172make test check-all
173```
174
175To run individual regression tests llvm-lit needs to know the lit
176configuration for flang. The parameters in charge of this are:
177flang_site_config and flang_config. And they can be set as shown below:
178```
179<path-to-llvm-lit>/llvm-lit \
180 --param flang_site_config=<path-to-flang-build>/test-lit/lit.site.cfg.py \
181 --param flang_config=<path-to-flang-build>/test-lit/lit.cfg.py \
182  <path-to-fortran-test>
183
184```
185
186Unit tests:
187
188If flang was built with `-DFLANG_INCLUDE_TESTS=On` (`ON` by default), it is possible to generate unittests.
189Note: Unit-tests will be skipped for LLVM install for an out-of-tree build as it does not include googletest related headers and libraries.
190
191There are various ways to run unit-tests.
192
193```
194
1951. make check-flang-unit
1962. make check-all or make check-flang
1973. <path-to-llvm-lit>/llvm-lit \
198        test/Unit
1994. Invoking tests from <out-of-tree flang build>/unittests/<respective unit test folder>
200
201```
202
203
204## For in tree builds
205If flang was built with `-DFLANG_INCLUDE_TESTS=On` (`On` by default), it is possible to
206generate unittests.
207
208To run all of the flang unit tests use the `check-flang-unit` target:
209```
210make check-flang-unit
211```
212To run all of the flang regression tests use the `check-flang` target:
213```
214make check-flang
215```
216
217# How to Generate Documentation
218
219## Generate FIR Documentation
220If flang was built with `-DLINK_WITH_FIR=On` (`On` by default), it is possible to
221generate FIR language documentation by running `make flang-doc`. This will
222create `docs/Dialect/FIRLangRef.md` in flang build directory.
223
224## Generate Doxygen-based Documentation
225To generate doxygen-style documentation from source code
226- Pass `-DLLVM_ENABLE_DOXYGEN=ON -DFLANG_INCLUDE_DOCS=ON` to the cmake command.
227
228```
229cd ~/llvm-project/build
230cmake -DLLVM_ENABLE_DOXYGEN=ON -DFLANG_INCLUDE_DOCS=ON ../llvm
231make doxygen-flang
232```
233
234It will generate html in
235
236```
237    <build-dir>/tools/flang/docs/doxygen/html # for flang docs
238```
239## Generate Sphinx-based Documentation
240<!TODO: Add webpage once we have a website.
241!>
242Flang documentation should preferably be written in `markdown(.md)` syntax (they can be in `reStructuredText(.rst)` format as well but markdown is recommended in first place), it
243is mostly meant to be processed by the Sphinx documentation generation
244system to create HTML pages which would be hosted on the webpage of flang and
245updated periodically.
246
247If you would like to generate and view the HTML locally:
248- Install [Sphinx](http://sphinx-doc.org/), including the [sphinx-markdown-tables](https://pypi.org/project/sphinx-markdown-tables/) extension.
249- Pass `-DLLVM_ENABLE_SPHINX=ON -DSPHINX_WARNINGS_AS_ERRORS=OFF` to the cmake command.
250
251```
252cd ~/llvm-project/build
253cmake -DLLVM_ENABLE_SPHINX=ON -DSPHINX_WARNINGS_AS_ERRORS=OFF ../llvm
254make docs-flang-html
255```
256
257It will generate html in
258
259```
260   $BROWSER <build-dir>/tools/flang/docs/html/
261```
262