@@ -15,13 +15,17 @@ local:
15
15
```
16
16
17
17
There are two main drivers in Flang:
18
- * the compiler driver, ` flang `
19
- * the frontend driver, ` flang -fc1 `
18
+ * the compiler driver, ` flang-new `
19
+ * the frontend driver, ` flang-new -fc1 `
20
+
21
+ > ** _ NOTE:_ ** The diagrams in this document refer to ` flang ` as opposed to
22
+ > ` flang-new ` . Eventually, ` flang-new ` will be renamed as ` flang ` and the
23
+ > diagrams reflect the final design that we are still working towards.
20
24
21
25
The ** compiler driver** will allow you to control all compilation phases (e.g.
22
26
preprocessing, semantic checks, code-generation, code-optimisation, lowering
23
27
and linking). For frontend specific tasks, the compiler driver creates a
24
- Fortran compilation job and delegates it to ` flang -fc1 ` , the frontend
28
+ Fortran compilation job and delegates it to ` flang-new -fc1 ` , the frontend
25
29
driver. For linking, it creates a linker job and calls an external linker (e.g.
26
30
LLVM's [ ` lld ` ] ( https://lld.llvm.org/ ) ). It can also call other tools such as
27
31
external assemblers (e.g. [ ` as ` ] ( https://www.gnu.org/software/binutils/ ) ). In
@@ -43,7 +47,7 @@ frontend. It uses MLIR and LLVM for code-generation and can be viewed as a
43
47
driver for Flang, LLVM and MLIR libraries. Contrary to the compiler driver, it
44
48
is not capable of calling any external tools (including linkers). It is aware
45
49
of all the frontend internals that are "hidden" from the compiler driver. It
46
- accepts many frontend-specific options not available in ` flang ` and as such
50
+ accepts many frontend-specific options not available in ` flang-new ` and as such
47
51
it provides a finer control over the frontend. Note that this tool is mostly
48
52
intended for Flang developers. In particular, there are no guarantees about the
49
53
stability of its interface and compiler developers can use it to experiment
@@ -58,30 +62,30 @@ frontend specific flag from the _compiler_ directly to the _frontend_ driver,
58
62
e.g.:
59
63
60
64
``` bash
61
- flang -Xflang -fdebug-dump-parse-tree input.f95
65
+ flang-new -Xflang -fdebug-dump-parse-tree input.f95
62
66
```
63
67
64
- In the invocation above, ` -fdebug-dump-parse-tree ` is forwarded to `flang
68
+ In the invocation above, ` -fdebug-dump-parse-tree ` is forwarded to `flang-new
65
69
-fc1` . Without the forwarding flag, ` -Xflang`, you would see the following
66
70
warning:
67
71
68
72
``` bash
69
- flang: warning: argument unused during compilation:
73
+ flang-new : warning: argument unused during compilation:
70
74
```
71
75
72
- As ` -fdebug-dump-parse-tree ` is only supported by ` flang -fc1 ` , ` flang `
76
+ As ` -fdebug-dump-parse-tree ` is only supported by ` flang-new -fc1 ` , ` flang-new `
73
77
will ignore it when used without ` Xflang ` .
74
78
75
79
## Why Do We Need Two Drivers?
76
- As hinted above, ` flang ` and ` flang -fc1 ` are two separate tools. The
77
- fact that these tools are accessed through one binary, ` flang ` , is just an
80
+ As hinted above, ` flang-new ` and ` flang-new -fc1 ` are two separate tools. The
81
+ fact that these tools are accessed through one binary, ` flang-new ` , is just an
78
82
implementation detail. Each tool has a separate list of options, albeit defined
79
83
in the same file: ` clang/include/clang/Driver/Options.td ` .
80
84
81
85
The separation helps us split various tasks and allows us to implement more
82
- specialised tools. In particular, ` flang ` is not aware of various
86
+ specialised tools. In particular, ` flang-new ` is not aware of various
83
87
compilation phases within the frontend (e.g. scanning, parsing or semantic
84
- checks). It does not have to be. Conversely, the frontend driver, `flang
88
+ checks). It does not have to be. Conversely, the frontend driver, `flang-new
85
89
-fc1`, needs not to be concerned with linkers or other external tools like
86
90
assemblers. Nor does it need to know where to look for various systems
87
91
libraries, which is usually OS and platform specific.
@@ -100,7 +104,7 @@ GCC](https://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Archi
100
104
In fact, Flang needs to adhere to this model in order to be able to re-use
101
105
Clang's driver library. If you are more familiar with the [ architecture of
102
106
GFortran] ( https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gfortran/About-GNU-Fortran.html )
103
- than Clang, then ` flang ` corresponds to ` gfortran ` and ` flang -fc1 ` to
107
+ than Clang, then ` flang-new ` corresponds to ` gfortran ` and ` flang-new -fc1 ` to
104
108
` f951 ` .
105
109
106
110
## Compiler Driver
@@ -131,15 +135,15 @@ output from one action is the input for the subsequent one. You can use the
131
135
` -ccc-print-phases ` flag to see the sequence of actions that the driver will
132
136
create for your compiler invocation:
133
137
``` bash
134
- flang -ccc-print-phases -E file.f
138
+ flang-new -ccc-print-phases -E file.f
135
139
+- 0: input, " file.f" , f95-cpp-input
136
140
1: preprocessor, {0}, f95
137
141
```
138
142
As you can see, for ` -E ` the driver creates only two jobs and stops immediately
139
143
after preprocessing. The first job simply prepares the input. For ` -c ` , the
140
144
pipeline of the created jobs is more complex:
141
145
``` bash
142
- flang -ccc-print-phases -c file.f
146
+ flang-new -ccc-print-phases -c file.f
143
147
+- 0: input, " file.f" , f95-cpp-input
144
148
+- 1: preprocessor, {0}, f95
145
149
+- 2: compiler, {1}, ir
@@ -154,7 +158,7 @@ command to call the frontend driver is generated (more specifically, an
154
158
instance of ` clang::driver::Command ` ). Every command is bound to an instance of
155
159
` clang::driver::Tool ` . For Flang we introduced a specialisation of this class:
156
160
` clang::driver::Flang ` . This class implements the logic to either translate or
157
- forward compiler options to the frontend driver, ` flang -fc1 ` .
161
+ forward compiler options to the frontend driver, ` flang-new -fc1 ` .
158
162
159
163
You can read more on the design of ` clangDriver ` in Clang's [ Driver Design &
160
164
Internals] ( https://clang.llvm.org/docs/DriverInternals.html ) .
@@ -228,12 +232,12 @@ driver, `clang -cc1` and consists of the following classes:
228
232
This list is not exhaustive and only covers the main classes that implement the
229
233
driver. The main entry point for the frontend driver, ` fc1_main ` , is
230
234
implemented in ` flang/tools/flang-driver/driver.cpp ` . It can be accessed by
231
- invoking the compiler driver, ` flang ` , with the ` -fc1 ` flag.
235
+ invoking the compiler driver, ` flang-new ` , with the ` -fc1 ` flag.
232
236
233
237
The frontend driver will only run one action at a time. If you specify multiple
234
238
action flags, only the last one will be taken into account. The default action
235
239
is ` ParseSyntaxOnlyAction ` , which corresponds to ` -fsyntax-only ` . In other
236
- words, ` flang -fc1 <input-file> ` is equivalent to `flang -fc1 -fsyntax-only
240
+ words, ` flang-new -fc1 <input-file> ` is equivalent to `flang-new -fc1 -fsyntax-only
237
241
<input-file >`.
238
242
239
243
## Adding new Compiler Options
@@ -258,8 +262,8 @@ similar semantics to your new option and start by copying that.
258
262
For every new option, you will also have to define the visibility of the new
259
263
option. This is controlled through the ` Visibility ` field. You can use the
260
264
following Flang specific visibility flags to control this:
261
- * ` FlangOption ` - this option will be available in the ` flang ` compiler driver,
262
- * ` FC1Option ` - this option will be available in the ` flang -fc1 ` frontend driver,
265
+ * ` FlangOption ` - this option will be available in the ` flang-new ` compiler driver,
266
+ * ` FC1Option ` - this option will be available in the ` flang-new -fc1 ` frontend driver,
263
267
264
268
Options that are supported by clang should explicitly specify ` ClangOption ` in
265
269
` Visibility ` , and options that are only supported in Flang should not specify
@@ -286,10 +290,10 @@ The parsing will depend on the semantics encoded in the TableGen definition.
286
290
287
291
When adding a compiler driver option (i.e. an option that contains
288
292
` FlangOption ` among in it's ` Visibility ` ) that you also intend to be understood
289
- by the frontend, make sure that it is either forwarded to ` flang -fc1 ` or
293
+ by the frontend, make sure that it is either forwarded to ` flang-new -fc1 ` or
290
294
translated into some other option that is accepted by the frontend driver. In
291
295
the case of options that contain both ` FlangOption ` and ` FC1Option ` among its
292
- flags, we usually just forward from ` flang ` to ` flang -fc1 ` . This is
296
+ flags, we usually just forward from ` flang-new ` to ` flang-new -fc1 ` . This is
293
297
then tested in ` flang/test/Driver/frontend-forward.F90 ` .
294
298
295
299
What follows is usually very dependant on the meaning of the corresponding
@@ -335,11 +339,11 @@ just added using your new frontend option.
335
339
336
340
## CMake Support
337
341
As of [ #7246 ] ( https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7246 )
338
- (CMake 3.28 .0 ), `cmake` can detect `flang` as a
342
+ (and soon to be released CMake 3.24 .0 ), `cmake` can detect `flang- new ` as a
339
343
supported Fortran compiler. You can configure your CMake projects to use
340
- `flang` as follows:
344
+ `flang- new ` as follows:
341
345
```bash
342
- cmake -DCMAKE_Fortran_COMPILER=<path/to/flang> <src/dir>
346
+ cmake -DCMAKE_Fortran_COMPILER=<path/to/flang- new > <src/dir>
343
347
```
344
348
You should see the following in the output:
345
349
```
@@ -349,14 +353,14 @@ where `<version>` corresponds to the LLVM Flang version.
349
353
350
354
## Testing
351
355
In LIT, we define two variables that you can use to invoke Flang's drivers:
352
- * ` %flang ` is expanded as ` flang ` (i.e. the compiler driver)
353
- * ` %flang_fc1 ` is expanded as ` flang -fc1 ` (i.e. the frontend driver)
356
+ * ` %flang ` is expanded as ` flang-new ` (i.e. the compiler driver)
357
+ * ` %flang_fc1 ` is expanded as ` flang-new -fc1 ` (i.e. the frontend driver)
354
358
355
359
For most regression tests for the frontend, you will want to use ` %flang_fc1 ` .
356
360
In some cases, the observable behaviour will be identical regardless of whether
357
361
` %flang ` or ` %flang_fc1 ` is used. However, when you are using ` %flang ` instead
358
362
of ` %flang_fc1 ` , the compiler driver will add extra flags to the frontend
359
- driver invocation (i.e. ` flang -fc1 -<extra-flags> ` ). In some cases that might
363
+ driver invocation (i.e. ` flang-new -fc1 -<extra-flags> ` ). In some cases that might
360
364
be exactly what you want to test. In fact, you can check these additional
361
365
flags by using the ` -### ` compiler driver command line option.
362
366
@@ -376,7 +380,7 @@ plugins. The process for using plugins includes:
376
380
* [ Creating a plugin] ( #creating-a-plugin )
377
381
* [ Loading and running a plugin] ( #loading-and-running-a-plugin )
378
382
379
- Flang plugins are limited to ` flang -fc1 ` and are currently only available /
383
+ Flang plugins are limited to ` flang-new -fc1 ` and are currently only available /
380
384
been tested on Linux.
381
385
382
386
### Creating a Plugin
@@ -461,14 +465,14 @@ static FrontendPluginRegistry::Add<PrintFunctionNamesAction> X(
461
465
462
466
### Loading and Running a Plugin
463
467
In order to use plugins, there are 2 command line options made available to the
464
- frontend driver, ` flang -fc1 ` :
468
+ frontend driver, ` flang-new -fc1 ` :
465
469
* [ ` -load <dsopath> ` ] ( #the--load-dsopath-option ) for loading the dynamic shared
466
470
object of the plugin
467
471
* [ ` -plugin <name> ` ] ( #the--plugin-name-option ) for calling the registered plugin
468
472
469
473
Invocation of the example plugin is done through:
470
474
``` bash
471
- flang -fc1 -load flangPrintFunctionNames.so -plugin print-fns file.f90
475
+ flang-new -fc1 -load flangPrintFunctionNames.so -plugin print-fns file.f90
472
476
```
473
477
474
478
Both these options are parsed in ` flang/lib/Frontend/CompilerInvocation.cpp ` and
@@ -489,7 +493,7 @@ reports an error diagnostic and returns `nullptr`.
489
493
490
494
### Enabling In-Tree Plugins
491
495
For in-tree plugins, there is the CMake flag ` FLANG_PLUGIN_SUPPORT ` , enabled by
492
- default, that controls the exporting of executable symbols from ` flang ` ,
496
+ default, that controls the exporting of executable symbols from ` flang-new ` ,
493
497
which plugins need access to. Additionally, there is the CMake flag
494
498
` LLVM_BUILD_EXAMPLES ` , turned off by default, that is used to control if the
495
499
example programs are built. This includes plugins that are in the
@@ -522,7 +526,7 @@ invocations `invokeFIROptEarlyEPCallbacks`, `invokeFIRInlinerCallback`, and
522
526
`invokeFIROptLastEPCallbacks` for Flang drivers to be able to insert additonal
523
527
passes at different points of the default pass pipeline. An example use of these
524
528
extension point callbacks is shown in `registerDefaultInlinerPass` to invoke the
525
- default inliner pass in `flang`.
529
+ default inliner pass in `flang- new `.
526
530
527
531
## LLVM Pass Plugins
528
532
@@ -535,15 +539,15 @@ documentation for
535
539
[`llvm::PassBuilder`](https:// llvm.org/doxygen/classllvm_1_1PassBuilder.html)
536
540
for details.
537
541
538
- The framework to enable pass plugins in `flang` uses the exact same
542
+ The framework to enable pass plugins in `flang- new ` uses the exact same
539
543
machinery as that used by `clang` and thus has the same capabilities and
540
544
limitations.
541
545
542
546
In order to use a pass plugin, the pass (es) must be compiled into a dynamic
543
547
shared object which is then loaded using the ` -fpass-plugin ` option.
544
548
545
549
```
546
- flang -fpass-plugin=/path/to/plugin.so <file.f90>
550
+ flang-new -fpass-plugin=/path/to/plugin.so <file.f90>
547
551
```
548
552
549
553
This option is available in both the compiler driver and the frontend driver.
@@ -555,7 +559,7 @@ Pass extensions are similar to plugins, except that they can also be linked
555
559
statically. Setting ` -DLLVM_${NAME}_LINK_INTO_TOOLS ` to ` ON ` in the cmake
556
560
command turns the project into a statically linked extension. An example would
557
561
be Polly, e.g., using ` -DLLVM_POLLY_LINK_INTO_TOOLS=ON ` would link Polly passes
558
- into ` flang ` as built-in middle-end passes.
562
+ into ` flang-new ` as built-in middle-end passes.
559
563
560
564
See the
561
565
[ ` WritingAnLLVMNewPMPass ` ] ( https://llvm.org/docs/WritingAnLLVMNewPMPass.html#id9 )
0 commit comments