Commit Graph

308 Commits

Author SHA1 Message Date
Arthur Eubanks
be10070f91 Revert "[Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin"
This reverts commit ccdebbae4d.

Causes test failures in the presence of Android runtime libraries in resource-dir.
See comments on https://github.com/llvm/llvm-project/pull/87866.
2024-04-10 23:41:51 +00:00
Daniel Chen
8136ac1c42 [Flang] Define c_int_fast16_t and c_int_fast32_t for PowerPC. (#88292)
On Linux, PowerPC defines `int_fast16_t` and `int_fast32_t` as `long`.
Need to update the corresponding type, `c_int_fast16_t` and
`c_int_fast32_t` in `iso_c_binding` module so they are interoparable.
2024-04-10 19:22:38 -04:00
Krzysztof Parzyszek
7d60232b38 [flang][Frontend] Implement printing defined macros via -dM (#87627)
This should work the same way as in clang.
2024-04-10 10:41:20 -05:00
Fangrui Song
ccdebbae4d [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin
Follow-up to #81037.

ToolChain::LibraryPaths holds the new compiler-rt library directory
(e.g. `/tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu`). However,
it might be empty when the directory does not exist (due to the `if
(getVFS().exists(P))` change in https://reviews.llvm.org/D158475).

If neither the old/new compiler-rt library directories exists, we would
suggest the undesired old compiler-rt file name:

```
% /tmp/Debug/bin/clang++ a.cc -fsanitize=memory -o a
ld.lld: error: cannot open /tmp/Debug/lib/clang/19/lib/linux/libclang_rt.msan-x86_64.a: No such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```

With this change, we will correctly suggest the new compiler-rt file name.

Fix #87150

Pull Request: https://github.com/llvm/llvm-project/pull/87866
2024-04-08 16:51:34 -07:00
Mats Petersson
6d2f57d2c4 [FLANG] allow -fopenmp= (#86816)
This enables the -fopenmp=<library> option to the set of options
supported by flang.

The generated arguments for the FC1 compilation will appear in a
slightly different order, so one test had to be updated to be less
sensitive to order of the arguments.
2024-04-05 13:48:43 +01:00
David Spickett
aff197ff21 Reland "[flang][clang] Add Visibility specific help text for options (#81869)"
This reverts commit 67d20412b4.

This includes fixes for clanginstallapi.
2024-04-05 08:27:59 +00:00
David Spickett
67d20412b4 Revert "[flang][clang] Add Visibility specific help text for options (#81869)"
This reverts commit 7e958f64ef.

Failing on multiple bots.
2024-04-05 08:15:35 +00:00
David Spickett
7e958f64ef [flang][clang] Add Visibility specific help text for options (#81869)
And use it to print the correct default OpenMP version for flang and
flang -fc1.

This change adds an optional `HelpTextsForVariants` to options. This
allows you to change the help text that gets shown in documentation and
`--help` based on the program its being generated for.

As `OptTable` needs to be constexpr compatible, I have used a std::array
of help text variants. Each entry is:
(list of visibilities) - > help text string

So for the OpenMP version we have (flang, fc1) -> "OpenMP version for
flang is...".

So you can have multiple visibilities use the same string. The number of
entries is currently set to 1, and the number of visibilities per entry
is 2, because that's the maximum we need for now. The code is written so
we can increase these numbers later, and the unused elements will be initialised.

I have not applied this to group descriptions just because I don't know
of one that needs changing. It could easily be enabled for those too if
needed. There are minor changes to them just to get it all to compile.

This approach of storing many help strings per option in the 1 driver
library seemed preferable to making a whole new library for Flang (even
if that would mostly be including stuff from Clang).
2024-04-05 09:03:16 +01:00
Michael Kruse
75e7e7d327 [flang] Add --gcc-toolchain and --gcc-install-dir options to flang. (#87360)
The `--gcc-toolchain` and `--gcc-install-dir` option were previously only visible to the Clang driver, but not Flang. These determine which assembler, linker, and libraries to use, e.g. for cross-compiling, and therefore are relevant for Flang as well.

Tests are implemented using a mock GCC installation in `basic_cross_linux_tree` copied over from Clang's tests. The Clang driver already contains tests with `--driver-mode=flang` but `flang-new` is an entirely different executable (containing the `-fc1` stage) that should be tested as well. While not all files in `basic_cross_linux_tree` are strictly needed for testing those two driver flags, they will be necessarily needed for future added flags such as `--rtlib`.
 
Also remove the entry `*.o` in flang's `.gitignore` since `crt*.o` files are needed in the GCC mock installation.

Fixes #86729
2024-04-05 00:02:06 +02:00
Michael Klemm
fb5fd2d82f [flang][OpenMP] Compile proper omp_lib.mod from the openmp/src/include sources (#80874)
This PR changes the build system to use use the sources for the module
`omp_lib` and the `omp_lib.h` include file from the `openmp` runtime
project and not from a separate copy of these files. This will greatly
reduce potential for inconsistencies when adding features to the OpenMP
runtime implementation.

When the OpenMP subproject is not configured, this PR also disables the
corresponding LIT tests with a "REQUIRES" directive at the beginning of
the OpenMP test files.

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
2024-03-20 13:47:26 +01:00
Sergio Afonso
d84252e064 [MLIR][OpenMP] NFC: Uniformize OpenMP ops names (#85393)
This patch proposes the renaming of certain OpenMP dialect operations with the
goal of improving readability and following a uniform naming convention for
MLIR operations and associated classes. In particular, the following operations
are renamed:

- `omp.map_info` -> `omp.map.info`
- `omp.target_update_data` -> `omp.target_update`
- `omp.ordered_region` -> `omp.ordered.region`
- `omp.cancellationpoint` -> `omp.cancellation_point`
- `omp.bounds` -> `omp.map.bounds`
- `omp.reduction.declare` -> `omp.declare_reduction`

Also, the following MLIR operation classes have been renamed:

- `omp::TaskLoopOp` -> `omp::TaskloopOp`
- `omp::TaskGroupOp` -> `omp::TaskgroupOp`
- `omp::DataBoundsOp` -> `omp::MapBoundsOp`
- `omp::DataOp` -> `omp::TargetDataOp`
- `omp::EnterDataOp` -> `omp::TargetEnterDataOp`
- `omp::ExitDataOp` -> `omp::TargetExitDataOp`
- `omp::UpdateDataOp` -> `omp::TargetUpdateOp`
- `omp::ReductionDeclareOp` -> `omp::DeclareReductionOp`
- `omp::WsLoopOp` -> `omp::WsloopOp`
2024-03-20 11:19:38 +00:00
Tom Eccles
1f1e0948f2 [flang] run CFG conversion on omp reduction declare ops (#84953)
Most FIR passes only look for FIR operations inside of functions (either
because they run only on func.func or they run on the module but iterate
over functions internally). But there can also be FIR operations inside
of fir.global, some OpenMP and OpenACC container operations.

This has worked so far for fir.global and OpenMP reductions because they
only contained very simple FIR code which doesn't need most passes to be
lowered into LLVM IR. I am not sure how OpenACC works.

In the long run, I hope to see a more systematic approach to making sure
that every pass runs on all of these container operations. I will write
an RFC for this soon.

In the meantime, this pass duplicates the CFG conversion pass to also
run on omp reduction operations. This is similar to how the
AbstractResult pass is already duplicated for fir.global operations.

OpenMP array reductions 2/6
Previous PR: https://github.com/llvm/llvm-project/pull/84952
Next PR: https://github.com/llvm/llvm-project/pull/84954

---------

Co-authored-by: Mats Petersson <mats.petersson@arm.com>
2024-03-20 09:47:49 +00:00
Stephen Tozer
885f93d62a Reapply "[flang] Fix cuda-option test on Darwin (#85687)"
This commit was mistakenly reverted in place of the actual failing
commit prior; reapplying.

This reverts commit db4170a4f3.
2024-03-19 14:40:46 +00:00
Stephen Tozer
db4170a4f3 Revert "[flang] Fix cuda-option test on Darwin (#85687)"
Reverted due to buildbot failures:
https://lab.llvm.org/buildbot/#/builders/139/builds/61717/

This reverts commit b4b7d988bd.
2024-03-19 14:37:30 +00:00
Leandro Lupori
b4b7d988bd [flang] Fix cuda-option test on Darwin (#85687)
On Darwin, -isysroot is needed and is automatically appended to
%flang and %flang_fc1, so use %flang_fc1 instead to have both -fc1
and -isysroot in the expected positions and avoid errors.
2024-03-19 11:35:52 -03:00
jeanPerier
d0829fbded [flang] Enable polymorphic lowering by default (#83285)
Polymorphic entity lowering status is good. The main remaining TODO is
to allow lowering of vector subscripted polymorphic entity, but this
does not deserve blocking all application using polymorphism.

Remove experimental option and enable lowering of polymorphic entity by
default.
2024-03-19 11:45:31 +01:00
Valentin Clement (バレンタイン クレメン)
8a8ef1cacf [flang][cuda] Enable cuda with -x cuda option (#84944)
Flang driver was already able to enable the CUDA language feature base
on the file extension but there was no command line option. This PR adds
one.
2024-03-13 09:14:40 -07:00
jeanPerier
325f512372 [flang] Set polymorphic entity lowering option on by default (#83308)
Preliminary patch for https://github.com/llvm/llvm-project/pull/83285 to
turn polymorphism on by default.

Will give a few days warning for people to remove the flag from their
workflow using flang-new.

Also easier to revert if issues with the gfortran test suites.
2024-02-29 09:47:06 +01:00
Slava Zakharin
6398baa425 [flang] Fixes for LIT testing of FLANG_RUNTIME_F128_MATH_LIB build. (#82832)
Follow-up for #81971 to fix the disabled LIT test and add
LIT tests for lowering of the added math intrinsics.
2024-02-26 10:54:08 -08:00
Joseph Huber
018c992879 [Flang] Fix the test ordering of the GPU libraries
Summary:
Turns out these are out of order
2024-02-22 16:29:24 -06:00
Joseph Huber
3ed4b95bcf [Flang] Fix test not updated after 'clang' case change
Summary:
The shared 'clang' code changed this slightly but did not update the
flang test.
2024-02-22 15:37:48 -06:00
Daniel Chen
987258f5c7 [Flang] Add __powerpc__ macro to set c_intmax_t to c_int64_t rather than c_int128_t as PowerPC only supports up to c_int64_t. (#81222)
PowerPC only supports up to `c_int64_t`. Add macro `__powerpc__` and
preprocess it for setting `c_intmax_t` in `iso_c_binding` intrinsic
module.
2024-02-13 11:03:54 -05:00
David Spickett
9ca1a1575a [flang][Driver] Add -masm option to flang (#81490)
The motivation here was a suggestion over in Compiler Explorer. You can
use `-mllvm` already to do this but since gfortran supports `-masm`, I
figured I'd try to add it.

This is done by flang expanding `-masm` into `-mllvm x86-asm-syntax=`,
then passing that to fc1. Which then collects all the `-mllvm` options
and forwards them on.

The code to expand it comes from clang `Clang::AddX86TargetArgs` (there
are some other places doing the same thing too). However I've removed
the `-inline-asm` that clang adds, as fortran doesn't have inline
assembly.

So `-masm` for flang purely changes the style of assembly output.

```
$ ./bin/flang-new /tmp/test.f90 -o - -S -target x86_64-linux-gnu
<...>
        pushq   %rbp
$ ./bin/flang-new /tmp/test.f90 -o - -S -target x86_64-linux-gnu -masm=att
<...>
        pushq   %rbp
$ ./bin/flang-new /tmp/test.f90 -o - -S -target x86_64-linux-gnu -masm=intel
<...>
        push    rbp
```

The test is adapted from `clang/test/Driver/masm.c` by removing the
clang-cl related lines and changing the 32 bit triples to 64 bit triples
since flang doesn't support 32 bit targets.
2024-02-13 10:38:38 +00:00
Fangrui Song
3a3302ef7b [flang][test] Update driver-help*.f90 after 9397d23671 2024-02-09 16:10:11 -08:00
Alex Bradbury
22544e2a54 [flang] Set fast math related function attributes for -Ofast/-ffast-math (#79301)
The implemented logic matches the logic used for Clang in emitting these
attributes. Although it's hoped that function attributes won't be needed
in the future (vs using fast math flags in individual IR instructions),
there are codegen differences currently with/without these attributes,
as can be seen in issues like #79257 or by hacking Clang to avoid
producing these attributes and observing codegen changes.
2024-02-05 19:39:12 +00:00
Mats Petersson
214536b0d8 Fix broken ARM processor features test (#80717)
This should fix failed build bots, so pushing before Windows build is done.
2024-02-05 18:35:45 +00:00
Mats Petersson
992d852758 [flang]Add support for -moutline-atomics and -mno-outline-atomics (#78755)
This adds the support to add the target-feature to outline atomic operations (calling the
runtime library instead).
2024-02-05 13:54:12 +00:00
Peter Klausler
60860079ec [flang][preprocessor] Replace macros in some #include directives (#80039)
Ensure that #include FOO undergoes macro replacement. But, as is the
case with C/C++, continue to not perform macro replacement in a #include
directive with <angled brackets>.
2024-01-31 11:50:51 -08:00
Sergio Afonso
837bff11cb [Flang][Lower] Attach target_cpu and target_features attributes to MLIR functions (#78289)
This patch forwards the target CPU and features information from the
Flang frontend to MLIR func.func operation attributes, which are later
used to populate the target_cpu and target_features llvm.func
attributes.

This is achieved in two stages:

1. Introduce the `fir.target_cpu` and `fir.target_features` module
attributes with information from the target machine immediately after
the initial creation of the MLIR module in the lowering bridge.

2. Update the target rewrite flang pass to get this information from the
module and pass it along to all func.func MLIR operations, respectively
as attributes named `target_cpu` and `target_features`. These attributes
will be automatically picked up during Func to LLVM dialect lowering and
used to initialize the corresponding llvm.func named attributes.

The target rewrite and FIR to LLVM lowering passes are updated with the
ability to override these module attributes, and the `CodeGenSpecifics`
optimizer class is augmented to make this information available to
target-specific MLIR transformations.

This completes a full flow by which target CPU and features make it all
the way from compiler options to LLVM IR function attributes.
2024-01-30 13:45:56 +00:00
Saiyedul Islam
082f87c9d4 [AMDGPU] Change default AMDHSA Code Object version to 5 (#79038)
Also update LIT tests and docs.
For more details, see
https://llvm.org/docs/AMDGPUUsage.html#code-object-v5-metadata

Corresponding llvm-objdump AMDGPU lit tests are updated
in a follow-up PR.
2024-01-23 17:08:18 +05:30
Tom Eccles
d37d1c8dea [flang][driver] deprecate manual usage of -lFortran_main (#79016)
Intended to warn users of the 18.x release not to do this.

A better solution should be found for the 19.x release. See discussion
in https://github.com/llvm/llvm-project/pull/78152.

Unfortunately there is no warning on Windows currently. I am rushing to
get this landed before 18.x branches.
2024-01-22 23:14:09 +00:00
Leandro Lupori
07abde2717 [flang][driver] Fix Driver/isysroot.f90 test (#78478)
Check for DEFAULT_SYSROOT, because when it is set -isysroot has no
effect.
2024-01-18 11:21:57 -03:00
ostannard
13e977d173 [AArch64][Driver] Better handling of target feature dependencies (#78270)
Currently there are several bits of code in the AArch64 driver which
attempt to enforce dependencies between optional features in the -march=
and -mcpu= options. However, these are based on the list of feature
names being enabled/disabled, so they have a lot of logic to consider
the order in which features were turned on and off, which doesn't scale
well as dependency chains get longer.

This patch moves the code handling these dependencies to TargetParser,
and changes them to use a Bitset of enabled features. This makes it easy
to check which features are enabled, and is converted back to a list of
LLVM feature names once all of the command-line options are parsed.

The motivating example for this was the -mcpu=cortex-r82+nofp option.
Previously, the code handling the dependency between the fp16 and
fp16fml extensions did not consider the nofp modifier, so it added
+fullfp16 to the feature list. This should have been disabled by the
+nofp modifier, and also the backend did follow the dependency between
fullfp16 and fp, resulting in fp being turned back on in the backend.

Most of the dependencies added to AArch64TargetParser.h weren't known
about by clang before, I built that list by checking what the backend
thinks the dependencies between SubtargetFeatures are.
2024-01-17 16:20:34 +00:00
Tarun Prabhu
aa440aae36 [flang][Driver] Support -pthread in the frontend (#77360)
The -pthread option seems to be extensively tested for various platforms by
clang. Since flang uses those parts of the clang driver, the only test added
is to ensure that the option is recognized by the frontend.
2024-01-16 08:25:36 -07:00
Andrzej Warzyński
8cac995ead [flang][driver] Limit the usage of -mvscale-max and -mvscale-min (#77905)
Make sure that `-mvscale-max` and `-mvscale-min` are only available for
targets that are known to support vscale and scalable vectors.

Also fix capitalization of function variables.
2024-01-15 08:49:58 +00:00
Kelvin Li
99b7c770c2 [flang] Allow different linker name (#77849)
The linker name is different if the `lld` project is enabled
`-DLLVM_ENABLE_PROJECTS="...;lld"`.

---------

Co-authored-by: Leandro Lupori <leandro.lupori@gmail.com>
2024-01-12 22:32:33 -05:00
Leandro Lupori
31ce0f1dda [flang][driver] Fix exec.f90 test with shared libs 2024-01-11 15:52:20 +00:00
Leandro Lupori
f1c88d7c6f [flang] Fix fveclib on Darwin (#77605)
Fixes fveclib.f90 and fveclib-codegen.f90 tests, that were failing
on Darwin.
2024-01-11 10:39:53 -03:00
Leandro Lupori
9edcf7a28e [flang][driver] Add support for -isysroot in the frontend (#77365)
If DEFAULT_SYSROOT is not specfied when building flang, then the
-isysroot flag is needed to link binaries against system libraries
on Darwin. It's also needed when linking against a non-default
sysroot.
2024-01-11 10:37:58 -03:00
Luke Lau
2c60d59864 [Flang] Support -mrvv-vector-bits flag (#77588)
This patch adds support for the -mrvv-vector-bits flag in the Flang
driver, and
translates them to -mvscale-min/-mvscale-max.

The code was copied from the Clang toolchain (similarly to what was done
for
AArch64's -msve-vector-bits flag) so it also supports the same
-mrvv-vector-bits=zvl mode.

Note that Flang doesn't yet define the __riscv_v_fixed_vlen macro, so
the help
text has been updated to highlight that it's only defined for Clang.
2024-01-11 00:37:01 +07:00
Dominik Adamski
f443fbc49b [Flang][OpenMP][MLIR] Add support for -nogpulib option (#71045)
If -nogpulib option is passed by the user, then the OpenMP device
runtime is not used and we should not emit globals to configure
debugging at compile-time for the device runtime.

Link to -nogpulib flag implementation for Clang:
https://reviews.llvm.org/D125314
2024-01-10 09:38:58 +01:00
agozillon
d9710d7624 [Flang][Driver] Enable gpulibc/nogpulibc options for Flang, which allows linking of GPU LIBC for the fortran and OpenMP runtime (#77135)
This patch seeks to add the -gpulibc and -nogpulibc for Flang, which
allows the linking of the GPU libc library, this allows the use of
memcpy and other useful library functions for GPU.

In particular, this allows the Fortran runtime (written in C++) to be
compiled for offload and then linked against the GPU LIBC library via
this option to resolve memcpy and other C library functions that the
fortran runtime depends on for AMD GPU devices (and likely other GPU
devices).

This is the current method I've tested and found to be able to utilise
the Fortran runtime when compiled for AMD GPU, albeit it requires
compiling libc for GPU and then the Fortran runtime for GPU, so not
particularly straight forward or user friendly yet.

Activating this option will allow the subset of C functions to also be
utilised for GPU in other C/C++ based Fortran libraries if any are made
when linking against GPU libc.
2024-01-09 13:54:44 +01:00
Andrzej Warzynski
c7c912cff9 [flang][nfc] Add missing REQUIRES directive in a test
Failing bot:
  * https://lab.llvm.org/buildbot/#/builders/21/builds/88731

Failing test was introduced in:
  * https://github.com/llvm/llvm-project/pull/74598

Sending without a review as the fix is straightforward and I want to
prioritize fixing the broken bot and unblocking everyone who's been
affected.
2023-12-31 10:55:56 +00:00
Radu Salavat
0487377382 [flang] Pass to add frame pointer attribute (#74598)
Pass to add frame pointer attribute in Flang
2023-12-28 15:41:27 +00:00
Michael Klemm
9d6837d595 [flang][driver] Remove Fortain_main static library from linking stages (#75816)
At present, when building static or shared libraries, Flang adds
`-lFortran_main.a` (or `/WHOLEARCHIVE:Fortran.*.lib` pon Windows) to the
link line. This leads to the problem that `_QQmain` and
`_QQEnvironmentDefaults` (as of the time of this PR) are symbols marked
as used, while `main` is being defined. This should not happen and this
PR fixes this by detecting if `-shared` or `-static` is used on the
Flang command line and removing the static `Fortran_main` library.

---------

Co-authored-by: kkwli <kkwli@users.noreply.github.com>
2023-12-25 19:15:00 +01:00
madanial0
6b505406a3 [Flang] remove whole-archive option for AIX linker (#76039)
The AIX linker does not support the `--whole-archive` option, removing
the option if the OS is AIX.

---------

Co-authored-by: Mark Danial <mark.danial@ibm.com>
2023-12-21 10:22:30 -05:00
Radu Salavat
3107f313f1 [Flang, Clang] Enable and test 'rdynamic' flag (#75598)
Enable and test 'rdynamic' flag
2023-12-21 14:37:51 +00:00
Philip Reames
0b7dda3d4c Revert "[flang][nfc] Refactor linker invocation logic (#75534)"
This reverts commit 71bbfabd08.  Breaks check-flang on x86_64 host.
2023-12-15 11:08:09 -08:00
Andrzej Warzyński
71bbfabd08 [flang][nfc] Refactor linker invocation logic (#75534)
Refactor how the Fortran runtime libs are added to the linker
invocation. This is a non-functional change.
2023-12-15 15:04:37 +00:00
Andrzej Warzyński
1b6c8280b9 [flang][driver] Don't use -whole-archive on Darwin (#75393)
Direct follow-up of #73124 - the linker on Darwin does not support
`-whole-archive`, so that needs to be removed from the linker
invocation.

For context:
  * https://github.com/llvm/llvm-project/pull/73124
2023-12-14 21:11:25 +00:00