Skip to content

Commit

Permalink
[flang][driver] rename flang-new to flang (#110023)
Browse files Browse the repository at this point in the history
This does a global rename from `flang-new` to `flang`. I also
removed/changed any TODOs that I found related to making this change.

---------

Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
  • Loading branch information
3 people authored Oct 10, 2024
1 parent f1eac77 commit 06eb10d
Show file tree
Hide file tree
Showing 70 changed files with 249 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ jobs:
run: |
# Build some of the mlir tools that take a long time to link
if [ "${{ needs.prepare.outputs.build-flang }}" = "true" ]; then
ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/ -j2 flang-new bbc
ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/ -j2 flang bbc
fi
ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/ \
mlir-bytecode-parser-fuzzer \
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def warn_drv_unsupported_option_for_processor : Warning<
def warn_drv_unsupported_openmp_library : Warning<
"the library '%0=%1' is not supported, OpenMP will not be enabled">,
InGroup<OptionIgnored>;
def warn_openmp_experimental : Warning<
"OpenMP support in flang is still experimental">,
InGroup<ExperimentalOption>;

def err_drv_invalid_thread_model_for_target : Error<
"invalid thread model '%0' in '%1' for this target">;
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1583,3 +1583,7 @@ def ExtractAPIMisuse : DiagGroup<"extractapi-misuse">;
// Warnings about using the non-standard extension having an explicit specialization
// with a storage class specifier.
def ExplicitSpecializationStorageClass : DiagGroup<"explicit-specialization-storage-class">;

// A warning for options that enable a feature that is not yet complete
def ExperimentalOption : DiagGroup<"experimental-option">;

4 changes: 2 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -6077,7 +6077,7 @@ def _sysroot_EQ : Joined<["--"], "sysroot=">, Visibility<[ClangOption, FlangOpti
def _sysroot : Separate<["--"], "sysroot">, Alias<_sysroot_EQ>;

//===----------------------------------------------------------------------===//
// pie/pic options (clang + flang-new)
// pie/pic options (clang + flang)
//===----------------------------------------------------------------------===//
let Visibility = [ClangOption, FlangOption] in {

Expand All @@ -6093,7 +6093,7 @@ def fno_pie : Flag<["-"], "fno-pie">, Group<f_Group>;
} // let Vis = [Default, FlangOption]

//===----------------------------------------------------------------------===//
// Target Options (clang + flang-new)
// Target Options (clang + flang)
//===----------------------------------------------------------------------===//
let Flags = [TargetSpecific] in {
let Visibility = [ClangOption, FlangOption] in {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ void Driver::PrintHelp(bool ShowHidden) const {

void Driver::PrintVersion(const Compilation &C, raw_ostream &OS) const {
if (IsFlangMode()) {
OS << getClangToolFullVersion("flang-new") << '\n';
OS << getClangToolFullVersion("flang") << '\n';
} else {
// FIXME: The following handlers should use a callback mechanism, we don't
// know what the client would like to do.
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ static const DriverSuffix *FindDriverSuffix(StringRef ProgName, size_t &Pos) {
{"cl", "--driver-mode=cl"},
{"++", "--driver-mode=g++"},
{"flang", "--driver-mode=flang"},
// For backwards compatibility, we create a symlink for `flang` called
// `flang-new`. This will be removed in the future.
{"flang-new", "--driver-mode=flang"},
{"clang-dxc", "--driver-mode=dxc"},
};

Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,

if (Args.hasArg(options::OPT_fopenmp_force_usm))
CmdArgs.push_back("-fopenmp-force-usm");
// TODO: OpenMP support isn't "done" yet, so for now we warn that it
// is experimental.
D.Diag(diag::warn_openmp_experimental);

// FIXME: Clang supports a whole bunch more flags here.
break;
Expand Down Expand Up @@ -881,14 +884,12 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,

CmdArgs.push_back(Input.getFilename());

// TODO: Replace flang-new with flang once the new driver replaces the
// throwaway driver
const char *Exec = Args.MakeArgString(D.GetProgramPath("flang-new", TC));
const char *Exec = Args.MakeArgString(D.GetProgramPath("flang", TC));
C.addCommand(std::make_unique<Command>(JA, *this,
ResponseFileSupport::AtFileUTF8(),
Exec, CmdArgs, Inputs, Output));
}

Flang::Flang(const ToolChain &TC) : Tool("flang-new", "flang frontend", TC) {}
Flang::Flang(const ToolChain &TC) : Tool("flang", "flang frontend", TC) {}

Flang::~Flang() {}
2 changes: 1 addition & 1 deletion clang/test/Driver/flang/flang.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
! * (no type specified, resulting in an object file)

! All invocations should begin with flang -fc1, consume up to here.
! ALL-LABEL: "{{[^"]*}}flang-new{{[^"/]*}}" "-fc1"
! ALL-LABEL: "{{[^"]*}}flang{{[^"/]*}}" "-fc1"

! Check that f90 files are not treated as "previously preprocessed"
! ... in --driver-mode=flang.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/flang/flang_ucase.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
! * (no type specified, resulting in an object file)

! All invocations should begin with flang -fc1, consume up to here.
! ALL-LABEL: "{{[^"]*}}flang-new{{[^"/]*}}" "-fc1"
! ALL-LABEL: "{{[^"]*}}flang{{[^"/]*}}" "-fc1"

! Check that f90 files are not treated as "previously preprocessed"
! ... in --driver-mode=flang.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/flang/multiple-inputs-mixed.f90
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"
4 changes: 2 additions & 2 deletions clang/test/Driver/flang/multiple-inputs.f90
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"
76 changes: 36 additions & 40 deletions flang/docs/FlangDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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).
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
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:
```
Expand All @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions flang/docs/ImplementingASemanticCheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ of the call to `intentOutFunc()`:

I also used this program to produce a parse tree for the program using the command:
```bash
flang-new -fc1 -fdebug-dump-parse-tree testfun.f90
flang -fc1 -fdebug-dump-parse-tree testfun.f90
```

Here's the relevant fragment of the parse tree produced by the compiler:
Expand Down Expand Up @@ -296,7 +296,7 @@ In `lib/Semantics/check-do.cpp`, I added an (almost empty) implementation:
I then built the compiler with these changes and ran it on my test program.
This time, I made sure to invoke semantic checking. Here's the command I used:
```bash
flang-new -fc1 -fdebug-unparse-with-symbols testfun.f90
flang -fc1 -fdebug-unparse-with-symbols testfun.f90
```

This produced the output:
Expand Down
Loading

0 comments on commit 06eb10d

Please sign in to comment.