-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[flang][driver] rename flang-new to flang #110023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c19e89f
[flang][driver] rename flang-new to flang
everythingfunctional fdd1196
[flang][driver] restore flang-new as symlink
everythingfunctional 48d19d7
[flang][driver] add version to flang executable
everythingfunctional 39fb4c7
[flang][driver] add warning when using openmp
everythingfunctional c4f8e70
[flang][doc] update note about CMake support
everythingfunctional 12c4645
[flang][test] fix tests broken by rename
everythingfunctional f2e919b
[flang][test] add check for OpenMP experimental warning
everythingfunctional File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
! Check that flang can handle mixed C and fortran inputs. | ||
|
||
! RUN: %clang --driver-mode=flang -### -fsyntax-only %S/Inputs/one.f90 %S/Inputs/other.c 2>&1 | FileCheck --check-prefixes=CHECK-SYNTAX-ONLY %s | ||
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang-new{{[^"/]*}}" "-fc1" | ||
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang{{[^"/]*}}" "-fc1" | ||
! CHECK-SYNTAX-ONLY: "{{[^"]*}}/Inputs/one.f90" | ||
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}clang{{[^"/]*}}" "-cc1" | ||
! CHECK-SYNTAX-ONLY: "{{[^"]*}}/Inputs/other.c" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
! Check that flang driver can handle multiple inputs at once. | ||
|
||
! RUN: %clang --driver-mode=flang -### -fsyntax-only %S/Inputs/one.f90 %S/Inputs/two.f90 2>&1 | FileCheck --check-prefixes=CHECK-SYNTAX-ONLY %s | ||
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang-new{{[^"/]*}}" "-fc1" | ||
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang{{[^"/]*}}" "-fc1" | ||
! CHECK-SYNTAX-ONLY: "{{[^"]*}}/Inputs/one.f90" | ||
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang-new{{[^"/]*}}" "-fc1" | ||
! CHECK-SYNTAX-ONLY-LABEL: "{{[^"]*}}flang{{[^"/]*}}" "-fc1" | ||
! CHECK-SYNTAX-ONLY: "{{[^"]*}}/Inputs/two.f90" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,17 +15,13 @@ local: | |
``` | ||
|
||
There are two main drivers in Flang: | ||
* the compiler driver, `flang-new` | ||
* the frontend driver, `flang-new -fc1` | ||
|
||
> **_NOTE:_** The diagrams in this document refer to `flang` as opposed to | ||
> `flang-new`. Eventually, `flang-new` will be renamed as `flang` and the | ||
> diagrams reflect the final design that we are still working towards. | ||
* the compiler driver, `flang` | ||
* the frontend driver, `flang -fc1` | ||
|
||
The **compiler driver** will allow you to control all compilation phases (e.g. | ||
preprocessing, semantic checks, code-generation, code-optimisation, lowering | ||
and linking). For frontend specific tasks, the compiler driver creates a | ||
Fortran compilation job and delegates it to `flang-new -fc1`, the frontend | ||
Fortran compilation job and delegates it to `flang -fc1`, the frontend | ||
driver. For linking, it creates a linker job and calls an external linker (e.g. | ||
LLVM's [`lld`](https://lld.llvm.org/)). It can also call other tools such as | ||
external assemblers (e.g. [`as`](https://www.gnu.org/software/binutils/)). In | ||
|
@@ -47,7 +43,7 @@ frontend. It uses MLIR and LLVM for code-generation and can be viewed as a | |
driver for Flang, LLVM and MLIR libraries. Contrary to the compiler driver, it | ||
is not capable of calling any external tools (including linkers). It is aware | ||
of all the frontend internals that are "hidden" from the compiler driver. It | ||
accepts many frontend-specific options not available in `flang-new` and as such | ||
accepts many frontend-specific options not available in `flang` and as such | ||
it provides a finer control over the frontend. Note that this tool is mostly | ||
intended for Flang developers. In particular, there are no guarantees about the | ||
stability of its interface and compiler developers can use it to experiment | ||
|
@@ -62,30 +58,30 @@ frontend specific flag from the _compiler_ directly to the _frontend_ driver, | |
e.g.: | ||
|
||
```bash | ||
flang-new -Xflang -fdebug-dump-parse-tree input.f95 | ||
flang -Xflang -fdebug-dump-parse-tree input.f95 | ||
``` | ||
|
||
In the invocation above, `-fdebug-dump-parse-tree` is forwarded to `flang-new | ||
In the invocation above, `-fdebug-dump-parse-tree` is forwarded to `flang | ||
-fc1`. Without the forwarding flag, `-Xflang`, you would see the following | ||
warning: | ||
|
||
```bash | ||
flang-new: warning: argument unused during compilation: | ||
flang: warning: argument unused during compilation: | ||
``` | ||
|
||
As `-fdebug-dump-parse-tree` is only supported by `flang-new -fc1`, `flang-new` | ||
As `-fdebug-dump-parse-tree` is only supported by `flang -fc1`, `flang` | ||
will ignore it when used without `Xflang`. | ||
|
||
## Why Do We Need Two Drivers? | ||
As hinted above, `flang-new` and `flang-new -fc1` are two separate tools. The | ||
fact that these tools are accessed through one binary, `flang-new`, is just an | ||
As hinted above, `flang` and `flang -fc1` are two separate tools. The | ||
fact that these tools are accessed through one binary, `flang`, is just an | ||
implementation detail. Each tool has a separate list of options, albeit defined | ||
in the same file: `clang/include/clang/Driver/Options.td`. | ||
|
||
The separation helps us split various tasks and allows us to implement more | ||
specialised tools. In particular, `flang-new` is not aware of various | ||
specialised tools. In particular, `flang` is not aware of various | ||
compilation phases within the frontend (e.g. scanning, parsing or semantic | ||
checks). It does not have to be. Conversely, the frontend driver, `flang-new | ||
checks). It does not have to be. Conversely, the frontend driver, `flang | ||
-fc1`, needs not to be concerned with linkers or other external tools like | ||
assemblers. Nor does it need to know where to look for various systems | ||
libraries, which is usually OS and platform specific. | ||
|
@@ -104,7 +100,7 @@ GCC](https://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Archi | |
In fact, Flang needs to adhere to this model in order to be able to re-use | ||
Clang's driver library. If you are more familiar with the [architecture of | ||
GFortran](https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gfortran/About-GNU-Fortran.html) | ||
than Clang, then `flang-new` corresponds to `gfortran` and `flang-new -fc1` to | ||
than Clang, then `flang` corresponds to `gfortran` and `flang -fc1` to | ||
`f951`. | ||
|
||
## Compiler Driver | ||
|
@@ -135,15 +131,15 @@ output from one action is the input for the subsequent one. You can use the | |
`-ccc-print-phases` flag to see the sequence of actions that the driver will | ||
create for your compiler invocation: | ||
```bash | ||
flang-new -ccc-print-phases -E file.f | ||
flang -ccc-print-phases -E file.f | ||
+- 0: input, "file.f", f95-cpp-input | ||
1: preprocessor, {0}, f95 | ||
``` | ||
As you can see, for `-E` the driver creates only two jobs and stops immediately | ||
after preprocessing. The first job simply prepares the input. For `-c`, the | ||
pipeline of the created jobs is more complex: | ||
```bash | ||
flang-new -ccc-print-phases -c file.f | ||
flang -ccc-print-phases -c file.f | ||
+- 0: input, "file.f", f95-cpp-input | ||
+- 1: preprocessor, {0}, f95 | ||
+- 2: compiler, {1}, ir | ||
|
@@ -158,7 +154,7 @@ command to call the frontend driver is generated (more specifically, an | |
instance of `clang::driver::Command`). Every command is bound to an instance of | ||
`clang::driver::Tool`. For Flang we introduced a specialisation of this class: | ||
`clang::driver::Flang`. This class implements the logic to either translate or | ||
forward compiler options to the frontend driver, `flang-new -fc1`. | ||
forward compiler options to the frontend driver, `flang -fc1`. | ||
|
||
You can read more on the design of `clangDriver` in Clang's [Driver Design & | ||
Internals](https://clang.llvm.org/docs/DriverInternals.html). | ||
|
@@ -232,12 +228,12 @@ driver, `clang -cc1` and consists of the following classes: | |
This list is not exhaustive and only covers the main classes that implement the | ||
driver. The main entry point for the frontend driver, `fc1_main`, is | ||
implemented in `flang/tools/flang-driver/driver.cpp`. It can be accessed by | ||
invoking the compiler driver, `flang-new`, with the `-fc1` flag. | ||
invoking the compiler driver, `flang`, with the `-fc1` flag. | ||
|
||
The frontend driver will only run one action at a time. If you specify multiple | ||
action flags, only the last one will be taken into account. The default action | ||
is `ParseSyntaxOnlyAction`, which corresponds to `-fsyntax-only`. In other | ||
words, `flang-new -fc1 <input-file>` is equivalent to `flang-new -fc1 -fsyntax-only | ||
words, `flang -fc1 <input-file>` is equivalent to `flang -fc1 -fsyntax-only | ||
<input-file>`. | ||
|
||
## Adding new Compiler Options | ||
|
@@ -262,8 +258,8 @@ similar semantics to your new option and start by copying that. | |
For every new option, you will also have to define the visibility of the new | ||
option. This is controlled through the `Visibility` field. You can use the | ||
following Flang specific visibility flags to control this: | ||
* `FlangOption` - this option will be available in the `flang-new` compiler driver, | ||
* `FC1Option` - this option will be available in the `flang-new -fc1` frontend driver, | ||
* `FlangOption` - this option will be available in the `flang` compiler driver, | ||
* `FC1Option` - this option will be available in the `flang -fc1` frontend driver, | ||
|
||
Options that are supported by clang should explicitly specify `ClangOption` in | ||
`Visibility`, and options that are only supported in Flang should not specify | ||
|
@@ -290,10 +286,10 @@ The parsing will depend on the semantics encoded in the TableGen definition. | |
|
||
When adding a compiler driver option (i.e. an option that contains | ||
`FlangOption` among in it's `Visibility`) that you also intend to be understood | ||
by the frontend, make sure that it is either forwarded to `flang-new -fc1` or | ||
by the frontend, make sure that it is either forwarded to `flang -fc1` or | ||
translated into some other option that is accepted by the frontend driver. In | ||
the case of options that contain both `FlangOption` and `FC1Option` among its | ||
flags, we usually just forward from `flang-new` to `flang-new -fc1`. This is | ||
flags, we usually just forward from `flang` to `flang -fc1`. This is | ||
then tested in `flang/test/Driver/frontend-forward.F90`. | ||
|
||
What follows is usually very dependant on the meaning of the corresponding | ||
|
@@ -339,11 +335,11 @@ just added using your new frontend option. | |
|
||
## CMake Support | ||
As of [#7246](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7246) | ||
(and soon to be released CMake 3.24.0), `cmake` can detect `flang-new` as a | ||
(CMake 3.28.0), `cmake` can detect `flang` as a | ||
Comment on lines
337
to
+338
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7246 pre-dates CMake 3.28.0 by quite a few releases, I would just remove the link. @DavidTruby what makes 3.28 special? Should 3.28 be marked as requirement? |
||
supported Fortran compiler. You can configure your CMake projects to use | ||
`flang-new` as follows: | ||
`flang` as follows: | ||
```bash | ||
cmake -DCMAKE_Fortran_COMPILER=<path/to/flang-new> <src/dir> | ||
cmake -DCMAKE_Fortran_COMPILER=<path/to/flang> <src/dir> | ||
``` | ||
You should see the following in the output: | ||
``` | ||
|
@@ -353,14 +349,14 @@ where `<version>` corresponds to the LLVM Flang version. | |
|
||
## Testing | ||
In LIT, we define two variables that you can use to invoke Flang's drivers: | ||
* `%flang` is expanded as `flang-new` (i.e. the compiler driver) | ||
* `%flang_fc1` is expanded as `flang-new -fc1` (i.e. the frontend driver) | ||
* `%flang` is expanded as `flang` (i.e. the compiler driver) | ||
* `%flang_fc1` is expanded as `flang -fc1` (i.e. the frontend driver) | ||
|
||
For most regression tests for the frontend, you will want to use `%flang_fc1`. | ||
In some cases, the observable behaviour will be identical regardless of whether | ||
`%flang` or `%flang_fc1` is used. However, when you are using `%flang` instead | ||
of `%flang_fc1`, the compiler driver will add extra flags to the frontend | ||
driver invocation (i.e. `flang-new -fc1 -<extra-flags>`). In some cases that might | ||
driver invocation (i.e. `flang -fc1 -<extra-flags>`). In some cases that might | ||
be exactly what you want to test. In fact, you can check these additional | ||
flags by using the `-###` compiler driver command line option. | ||
|
||
|
@@ -380,7 +376,7 @@ plugins. The process for using plugins includes: | |
* [Creating a plugin](#creating-a-plugin) | ||
* [Loading and running a plugin](#loading-and-running-a-plugin) | ||
|
||
Flang plugins are limited to `flang-new -fc1` and are currently only available / | ||
Flang plugins are limited to `flang -fc1` and are currently only available / | ||
been tested on Linux. | ||
|
||
### Creating a Plugin | ||
|
@@ -465,14 +461,14 @@ static FrontendPluginRegistry::Add<PrintFunctionNamesAction> X( | |
|
||
### Loading and Running a Plugin | ||
In order to use plugins, there are 2 command line options made available to the | ||
frontend driver, `flang-new -fc1`: | ||
frontend driver, `flang -fc1`: | ||
* [`-load <dsopath>`](#the--load-dsopath-option) for loading the dynamic shared | ||
object of the plugin | ||
* [`-plugin <name>`](#the--plugin-name-option) for calling the registered plugin | ||
|
||
Invocation of the example plugin is done through: | ||
```bash | ||
flang-new -fc1 -load flangPrintFunctionNames.so -plugin print-fns file.f90 | ||
flang -fc1 -load flangPrintFunctionNames.so -plugin print-fns file.f90 | ||
``` | ||
|
||
Both these options are parsed in `flang/lib/Frontend/CompilerInvocation.cpp` and | ||
|
@@ -493,7 +489,7 @@ reports an error diagnostic and returns `nullptr`. | |
|
||
### Enabling In-Tree Plugins | ||
For in-tree plugins, there is the CMake flag `FLANG_PLUGIN_SUPPORT`, enabled by | ||
default, that controls the exporting of executable symbols from `flang-new`, | ||
default, that controls the exporting of executable symbols from `flang`, | ||
which plugins need access to. Additionally, there is the CMake flag | ||
`LLVM_BUILD_EXAMPLES`, turned off by default, that is used to control if the | ||
example programs are built. This includes plugins that are in the | ||
|
@@ -526,7 +522,7 @@ invocations `invokeFIROptEarlyEPCallbacks`, `invokeFIRInlinerCallback`, and | |
`invokeFIROptLastEPCallbacks` for Flang drivers to be able to insert additonal | ||
passes at different points of the default pass pipeline. An example use of these | ||
extension point callbacks is shown in `registerDefaultInlinerPass` to invoke the | ||
default inliner pass in `flang-new`. | ||
default inliner pass in `flang`. | ||
|
||
## LLVM Pass Plugins | ||
|
||
|
@@ -539,15 +535,15 @@ documentation for | |
[`llvm::PassBuilder`](https://llvm.org/doxygen/classllvm_1_1PassBuilder.html) | ||
for details. | ||
|
||
The framework to enable pass plugins in `flang-new` uses the exact same | ||
The framework to enable pass plugins in `flang` uses the exact same | ||
machinery as that used by `clang` and thus has the same capabilities and | ||
limitations. | ||
|
||
In order to use a pass plugin, the pass(es) must be compiled into a dynamic | ||
shared object which is then loaded using the `-fpass-plugin` option. | ||
|
||
``` | ||
flang-new -fpass-plugin=/path/to/plugin.so <file.f90> | ||
flang -fpass-plugin=/path/to/plugin.so <file.f90> | ||
``` | ||
|
||
This option is available in both the compiler driver and the frontend driver. | ||
|
@@ -559,7 +555,7 @@ Pass extensions are similar to plugins, except that they can also be linked | |
statically. Setting `-DLLVM_${NAME}_LINK_INTO_TOOLS` to `ON` in the cmake | ||
command turns the project into a statically linked extension. An example would | ||
be Polly, e.g., using `-DLLVM_POLLY_LINK_INTO_TOOLS=ON` would link Polly passes | ||
into `flang-new` as built-in middle-end passes. | ||
into `flang` as built-in middle-end passes. | ||
|
||
See the | ||
[`WritingAnLLVMNewPMPass`](https://llvm.org/docs/WritingAnLLVMNewPMPass.html#id9) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.