|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | 13-Mar-2025 | - |
| cmake/modules/ | H | 13-Mar-2025 | - | 214 | 176 |
| docs/ | H | 13-Mar-2025 | - | 15,614 | 12,692 |
| examples/ | H | 13-Mar-2025 | - | 856 | 669 |
| include/ | H | 13-Mar-2025 | - | 42,106 | 29,060 |
| lib/ | H | 13-Mar-2025 | - | 127,741 | 105,153 |
| module/ | H | 13-Mar-2025 | - | 1,684 | 1,219 |
| runtime/ | H | 13-Mar-2025 | - | 20,894 | 17,688 |
| test/ | H | 13-Mar-2025 | - | 112,952 | 46,067 |
| tools/ | H | 13-Mar-2025 | - | 2,033 | 1,474 |
| unittests/ | H | 13-Mar-2025 | - | 11,576 | 9,577 |
| .clang-format | H A D | 13-Mar-2025 | 559 | 22 | 20 |
| .clang-tidy | H A D | 13-Mar-2025 | 144 | 3 | 2 |
| .drone.star | H A D | 13-Mar-2025 | 2.9 KiB | 61 | 55 |
| .gitignore | H A D | 13-Mar-2025 | 190 | 22 | 21 |
| CMakeLists.txt | H A D | 13-Mar-2025 | 16.3 KiB | 483 | 404 |
| CODE_OWNERS.TXT | H A D | 13-Mar-2025 | 736 | 19 | 15 |
| LICENSE.TXT | H A D | 13-Mar-2025 | 12.8 KiB | 235 | 196 |
| README.md | H A D | 13-Mar-2025 | 9.1 KiB | 308 | 242 |
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[LLVM's Markdown style guide](https://github.com/llvm/llvm-project/blob/main/llvm/docs/MarkdownQuickstartTemplate.md).
38
39## Building flang
40There are two ways to build flang. The first method is to build it at the same
41time that you build all of the projects on which it depends. This is called
42building in tree. The second method is to first do an in tree build to create
43all of the projects on which flang depends, and then only build the flang code
44itself. This is called building standalone. Building standalone has the
45advantage of being smaller and faster. Once you create the base build and base
46install areas, you can create multiple standalone builds using them.
47
48Note that instructions for building LLVM can be found at
49https://llvm.org/docs/GettingStarted.html.
50
51### Building flang in tree
52Building flang in tree means building flang along with all of the projects on
53which it depends. These projects include mlir, clang, flang, and compiler-rt.
54Note that compiler-rt is only needed to access libraries that support 16 bit
55floating point numbers. It's not needed to run the automated tests.
56
57Here's a complete set of commands to clone all of the necessary source and do
58the build.
59
60First clone the source:
61```bash
62git clone https://github.com/llvm/llvm-project.git my-project
63```
64Once the clone is complete, execute the following commands:
65```bash
66cd my-project
67
68rm -rf build
69mkdir -p build
70
71cd build
72
73cmake \
74 -G Ninja \
75 ../llvm \
76 -DCMAKE_BUILD_TYPE=Release \
77 -DFLANG_ENABLE_WERROR=On \
78 -DLLVM_ENABLE_ASSERTIONS=ON \
79 -DLLVM_TARGETS_TO_BUILD=host \
80 -DCMAKE_INSTALL_PREFIX=$INSTALLDIR
81 -DLLVM_LIT_ARGS=-v \
82 -DLLVM_ENABLE_PROJECTS="clang;mlir;flang" \
83 -DLLVM_ENABLE_RUNTIMES="compiler-rt"
84
85ninja
86```
87
88To run the flang tests on this build, execute the command in the "build"
89directory:
90```bash
91ninja check-flang
92```
93
94Note that these instructions specify flang as one of the projects to build in
95the in tree build. This is not strictly necessary for subsequent standalone
96builds, but doing so lets you run the flang tests to verify that the source
97code is in good shape.
98### Building flang standalone
99To do the standalone build, start by building flang in tree as described above.
100This build is base build for subsequent standalone builds. Start each
101standalone build the same way by cloning the source for llvm-project:
102```bash
103git clone https://github.com/llvm/llvm-project.git standalone
104```
105Once the clone is complete, execute the following commands:
106```bash
107cd standalone
108base=<directory that contains the in tree build>
109
110cd flang
111rm -rf build
112mkdir build
113cd build
114
115cmake \
116 -G Ninja \
117 -DCMAKE_BUILD_TYPE=Release \
118 -DFLANG_ENABLE_WERROR=On \
119 -DLLVM_TARGETS_TO_BUILD=host \
120 -DLLVM_ENABLE_ASSERTIONS=On \
121 -DLLVM_BUILD_MAIN_SRC_DIR=$base/build/lib/cmake/llvm \
122 -DLLVM_LIT_ARGS=-v \
123 -DLLVM_DIR=$base/build/lib/cmake/llvm \
124 -DCLANG_DIR=$base/build/lib/cmake/clang \
125 -DMLIR_DIR=$base/build/lib/cmake/mlir \
126 ..
127
128ninja
129```
130
131To run the flang tests on this build, execute the command in the "flang/build"
132directory:
133```bash
134ninja check-flang
135```
136
137## Supported C++ compilers
138
139Flang is written in C++17.
140
141The code has been compiled and tested with
142GCC versions from 7.2.0 to 9.3.0.
143
144The code has been compiled and tested with
145clang version 7.0, 8.0, 9.0 and 10.0
146using either GNU's libstdc++ or LLVM's libc++.
147
148The code has been compiled on
149AArch64, x86\_64 and ppc64le servers
150with CentOS7, Ubuntu18.04, Rhel, MacOs, Mojave, XCode and
151Apple Clang version 10.0.1.
152
153### Building flang with GCC
154
155By default,
156cmake will search for g++ on your PATH.
157The g++ version must be one of the supported versions
158in order to build flang.
159
160Or, cmake will use the variable CXX to find the C++ compiler. CXX should include
161the full path to the compiler or a name that will be found on your PATH, e.g.
162g++-8.3, assuming g++-8.3 is on your PATH.
163
164```bash
165export CXX=g++-8.3
166```
167or
168```bash
169CXX=/opt/gcc-8.3/bin/g++-8.3 cmake ...
170```
171
172### Building flang with clang
173
174To build flang with clang,
175cmake needs to know how to find clang++
176and the GCC library and tools that were used to build clang++.
177
178CXX should include the full path to clang++
179or clang++ should be found on your PATH.
180```bash
181export CXX=clang++
182```
183
184### Installation Directory
185
186To specify a custom install location,
187add
188`-DCMAKE_INSTALL_PREFIX=<INSTALL_PREFIX>`
189to the cmake command
190where `<INSTALL_PREFIX>`
191is the path where flang should be installed.
192
193### Build Types
194
195To create a debug build,
196add
197`-DCMAKE_BUILD_TYPE=Debug`
198to the cmake command.
199Debug builds execute slowly.
200
201To create a release build,
202add
203`-DCMAKE_BUILD_TYPE=Release`
204to the cmake command.
205Release builds execute quickly.
206
207# How to Run Tests
208
209Flang supports 2 different categories of tests
2101. Regression tests (https://www.llvm.org/docs/TestingGuide.html#regression-tests)
2112. Unit tests (https://www.llvm.org/docs/TestingGuide.html#unit-tests)
212
213## For standalone builds
214To run all tests:
215```bash
216cd ~/flang/build
217cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/flang/src
218ninja check-all
219```
220
221To run individual regression tests llvm-lit needs to know the lit
222configuration for flang. The parameters in charge of this are:
223flang_site_config and flang_config. And they can be set as shown below:
224```bash
225<path-to-llvm-lit>/llvm-lit \
226 --param flang_site_config=<path-to-flang-build>/test-lit/lit.site.cfg.py \
227 --param flang_config=<path-to-flang-build>/test-lit/lit.cfg.py \
228 <path-to-fortran-test>
229
230```
231
232Unit tests:
233
234If flang was built with `-DFLANG_INCLUDE_TESTS=On` (`ON` by default), it is possible to generate unittests.
235Note: Unit-tests will be skipped for LLVM install for an standalone build as it does not include googletest related headers and libraries.
236
237There are various ways to run unit-tests.
238
239```
240
2411. ninja check-flang-unit
2422. ninja check-all or ninja check-flang
2433. <path-to-llvm-lit>/llvm-lit \
244 test/Unit
2454. Invoking tests from <standalone flang build>/unittests/<respective unit test folder>
246
247```
248
249
250## For in tree builds
251If flang was built with `-DFLANG_INCLUDE_TESTS=On` (`On` by default), it is possible to
252generate unittests.
253
254To run all of the flang unit tests use the `check-flang-unit` target:
255```bash
256ninja check-flang-unit
257```
258To run all of the flang regression tests use the `check-flang` target:
259```bash
260ninja check-flang
261```
262
263# How to Generate Documentation
264
265## Generate FIR Documentation
266If flang was built with `-DLINK_WITH_FIR=On` (`On` by default), it is possible to
267generate FIR language documentation by running `ninja flang-doc`. This will
268create `docs/Dialect/FIRLangRef.md` in flang build directory.
269
270## Generate Doxygen-based Documentation
271To generate doxygen-style documentation from source code
272- Pass `-DLLVM_ENABLE_DOXYGEN=ON -DFLANG_INCLUDE_DOCS=ON` to the cmake command.
273
274```bash
275cd ~/llvm-project/build
276cmake -DLLVM_ENABLE_DOXYGEN=ON -DFLANG_INCLUDE_DOCS=ON ../llvm
277ninja doxygen-flang
278```
279
280It will generate html in
281
282```bash
283 <build-dir>/tools/flang/docs/doxygen/html # for flang docs
284```
285## Generate Sphinx-based Documentation
286<!TODO: Add webpage once we have a website.
287!>
288Flang 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
289is mostly meant to be processed by the Sphinx documentation generation
290system to create HTML pages which would be hosted on the webpage of flang and
291updated periodically.
292
293If you would like to generate and view the HTML locally:
294- Install [Sphinx](http://sphinx-doc.org/), including the [sphinx-markdown-tables](https://pypi.org/project/sphinx-markdown-tables/) extension.
295- Pass `-DLLVM_ENABLE_SPHINX=ON -DSPHINX_WARNINGS_AS_ERRORS=OFF` to the cmake command.
296
297```bash
298cd ~/llvm-project/build
299cmake -DLLVM_ENABLE_SPHINX=ON -DSPHINX_WARNINGS_AS_ERRORS=OFF ../llvm
300ninja docs-flang-html
301```
302
303It will generate html in
304
305```bash
306 $BROWSER <build-dir>/tools/flang/docs/html/
307```
308