Commit Graph

391 Commits

Author SHA1 Message Date
Joseph Huber
f2a87b07e7 [OpenMP] Use loaded offloading toolchains to add libraries (#87108)
Summary:
We want to pass these GPU libraries by default if a certain offloading
toolchain is loaded for OpenMP. Previously I parsed this from the
arguments because it's only available in the compilation. This doesn't
really work for `native` and it's extra effort, so this patch just
passes in the `Compilation` as an extr argument and uses that. Tests
should be unaffected.
2024-04-01 17:26:20 -05:00
Fangrui Song
f18600c874 [Driver] Avoid repeated ToolChain.getTriple() calls. NFC 2024-03-27 13:50:17 -07:00
Joseph Huber
d03f470cbd [Clang] Make '-frtlib-add-rpath' include the standard library directory (#86217)
Summary:
The original intention of the `openmp-add-rpath` option was to add the
rpath to the language runtime directory. However, the current
implementation only adds it to the compiler's resource directory. This
patch adds support for appending the `-rpath` to the compiler's standard
library directory as well. Currently this is `<exe>/../lib/<triple>`.
2024-03-22 06:54:33 -05:00
Yaxun (Sam) Liu
e7175b0704 [HIP] do not link runtime for -r (#85675)
since it will cause duplicate symbols when the partially linked object
is linked again.
2024-03-19 23:03:57 -04:00
Phoebe Wang
f4676b6be6 [X86] Add Support for X86 TLSDESC Relocations (#83136) 2024-03-15 22:09:56 +08:00
Yaxun (Sam) Liu
124d0b787b [HIP] add --offload-compression-level= option (#83605)
Added --offload-compression-level= option to clang and
-compression-level=
option to clang-offload-bundler for controlling compression level.

Added support of long distance matching (LDM) for llvm::zstd which is
off
by default. Enable it for clang-offload-bundler by default since it
improves compression rate in general.

Change default compression level to 3 for zstd for clang-offload-bundler
since it works well for bundle entry size from 1KB to 32MB, which should
cover most of the clang-offload-bundler usage. Users can still specify
compression level by -compression-level= option if necessary.
2024-03-09 09:45:48 -05:00
Joseph Huber
b92c3fe027 [OpenMP] Fix test after updating library search paths (#83573)
Summary:
We still use this bitcode library in one case, the NVPTX non-LTO build.
The patch updated the search paths to treat it the same as other
libraries, which unintentionally prioritized system paths over
LIBRARY_PATH which is generally not correct. Also we had a test that
relied on system state so remove that.
2024-03-01 09:48:14 -06:00
Joseph Huber
1977404d20 [OpenMP] Respect LLVM per-target install directories (#83282)
Summary:
One recurring problem we have with the OpenMP libraries is that they are
potentially conflicting with ones found on the system, this occurs when
there are two copies and one is used for linking that it not attached to
the correspoding clang compiler. LLVM already uses target specific
directories for this, like with libc++, which are always searched first.
This patch changes the install directory to be
`lib/x86_64-unknown-linux-gnu` for example.

Notable changes would be that users will need to change their
LD_LIBRARY_PATH settings optionally, or use default rt-rpath options.
This should fix problems were users are linking the wrong versions of
static libraries
2024-02-28 15:39:27 -06: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
47b7c91abe [libc] Rework the GPU build to be a regular target (#81921)
Summary:
This is a massive patch because it reworks the entire build and
everything that depends on it. This is not split up because various bots
would fail otherwise. I will attempt to describe the necessary changes
here.

This patch completely reworks how the GPU build is built and targeted.
Previously, we used a standard runtimes build and handled both NVPTX and
AMDGPU in a single build via multi-targeting. This added a lot of
divergence in the build system and prevented us from doing various
things like building for the CPU / GPU at the same time, or exporting
the startup libraries or running tests without a full rebuild.

The new appraoch is to handle the GPU builds as strict cross-compiling
runtimes. The first step required
https://github.com/llvm/llvm-project/pull/81557 to allow the `LIBC`
target to build for the GPU without touching the other targets. This
means that the GPU uses all the same handling as the other builds in
`libc`.

The new expected way to build the GPU libc is with
`LLVM_LIBC_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda`.

The second step was reworking how we generated the embedded GPU library
by moving it into the library install step. Where we previously had one
`libcgpu.a` we now have `libcgpu-amdgpu.a` and `libcgpu-nvptx.a`. This
patch includes the necessary clang / OpenMP changes to make that not
break the bots when this lands.

We unfortunately still require that the NVPTX target has an `internal`
target for tests. This is because the NVPTX target needs to do LTO for
the provided version (The offloading toolchain can handle it) but cannot
use it for the native toolchain which is used for making tests.

This approach is vastly superior in every way, allowing us to treat the
GPU as a standard cross-compiling target. We can now install the GPU
utilities to do things like use the offload tests and other fun things.

Some certain utilities need to be built with 
`--target=${LLVM_HOST_TRIPLE}` as well. I think this is a fine
workaround as we
will always assume that the GPU `libc` is a cross-build with a
functioning host.

Depends on https://github.com/llvm/llvm-project/pull/81557
2024-02-22 15:29:29 -06:00
Slava Zakharin
a468d02fe9 [flang][runtime] Add FortranFloat128Math wrapper library. (#81971)
Implemented few entry points for REAL(16) math in FortranF128Math
static library. It is a thin wrapper around GNU libquadmath.
Flang driver can always link it, and the dependencies will
be brought in as needed.
The final Fortran program/library that uses any of the entry points
will depend on the underlying third-party library - this dependency
has to be resolved somehow. I added FLANG_RUNTIME_F128_MATH_LIB
CMake control so that the compiler driver and the runtime library
can be built using the same third-party library: this way the linker
knows which dependency to link in (under --as-needed).
The compiler distribution should specify which third-party library
is required for linking/running the apps that use REAL(16).
The compiler package may provide a version of the third-party library
or at least a stub library that can be used for linking, but
the final program execution will still require the actual library.
2024-02-20 12:33:08 -08: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
Pierre van Houtryve
500846d2f5 [AMDGPU] Introduce Code Object V6 (#76954)
Introduce Code Object V6 in Clang, LLD, Flang and LLVM. This is the same
as V5 except a new "generic version" flag can be present in EFLAGS. This
is related to new generic targets that'll be added in a follow-up patch.
It's also likely V6 will have new changes (possibly new metadata
entries) added later.

Docs change are part of the follow-up patch #76955
2024-02-05 08:19:53 +01:00
Fangrui Song
36b4a9ccd9 [Driver,CodeGen] Support -mtls-dialect= (#79256)
GCC supports -mtls-dialect= for several architectures to select TLSDESC.
This patch supports the following values

* x86: "gnu". "gnu2" (TLSDESC) is not supported yet.
* RISC-V: "trad" (general dynamic), "desc" (TLSDESC, see #66915)

AArch64 toolchains seem to support TLSDESC from the beginning, and the
general dynamic model has poor support. Nobody seems to use the option
-mtls-dialect= at all, so we don't bother with it.
There also seems very little interest in AArch32's TLSDESC support.

TLSDESC does not change IR, but affects object file generation. Without
a backend option the option is a no-op for in-process ThinLTO.

There seems no motivation to have fine-grained control mixing trad/desc
for TLS, so we just pass -mllvm, and don't bother with a modules flag
metadata or function attribute.

Co-authored-by: Paul Kirth <paulkirth@google.com>
2024-01-26 09:25:38 -08:00
Paschalis Mpeis
03cf0e9354 [LTO] Fix Veclib flags correctly pass to LTO flags (#78749)
Flags `-fveclib=name` were not passed to LTO flags.
This pass fixes that by converting the `-fveclib` flags to their
relevant names for opt's `-vector-lib=name` flags.

For example:
`-fveclib=SLEEF` would become `-vector-library=sleefgnuabi` and passed
through the `-plugin-opt` flag.
2024-01-25 09:29:46 +00:00
Kazu Hirata
5404a3792e [Driver] Use StringRef::consume_front (NFC) 2024-01-24 00:27:33 -08:00
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
Matthew Voss
f626b1f4ca [clang][FatLTO][UnifiedLTO] Pass -enable-matrix to the LTO driver
Unified LTO and Fat LTO do not use the regular LTO prelink pipeline when
-flto/-flto=full is specified on the command line, thus they require
LowerMatrixIntrinsicsPass to be run during the link stage. To enable
this, we pass -enable-matrix to the LTO driver, replicating ThinLTO
behavior. This fix was applied to ThinLTO in https://reviews.llvm.org/D153583.

This fixes #77621.
2024-01-11 16:52:35 -08:00
Kazu Hirata
68f832f56d [clang] Use StringRef::consume_front (NFC) 2023-12-25 12:54:35 -08: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
Colin Cross
d9d20bd81f Honor -fno-sanitize-link-runtime for libclang_rt.asan_static (#66414)
https://reviews.llvm.org/D122407 added a static link against
libclang_rt.asan_static whenever ASAN is linked, but ignored the
-fno-sanitize-link-runtime flag. Every other conditional in
collectSanitizerRuntimes is already checking for SanArgs.linkRuntimes(),
move it to the top of the function so that newly added conditionals
don't need to remember to check it.
2023-12-18 17:15:41 -08:00
Andrzej Warzyński
76041a45bb [flang][nfc] Refactor linker invocation logic (#75648)
Refactor how the Fortran runtime libs are added to the linker
invocation. This is a non-functional change.

This is an updated version of #75534. This iteration makes sure that
FortranMain.a comes before FortranRuntme.a (the former depends on the
latter).
2023-12-16 11:13:20 +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
Kazu Hirata
f3dcc2351c [clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 08:54:13 -08:00
Michael Klemm
50a5f5c183 [flang][driver] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (#74139)
This PR adds the `-fno-fortran-main` command line option to remove
`Fortran_main.a` from the link and to allow for linking Fortran code w/o
program unit with C/C++ translation units that provide the `main()`
entrypoint.

When linking Fortran code with C/C++ code (Fortran calling into C/C++),
PR #73124 introduced a proper error message that would prevent
successful linkage, if there was a program unit from Fortran *and*
`main()` function coming from C/C++. Alas, this caused some breakage of
code that would call Fortran code from C/C++ and rightfully provided the
`main()` entrypoint. Classic Flang had the command-line option
`-fno-fortran-main` to then remove the entrypoints for the Fortran
program unit from the linker stage.

This PR is related to PR #74120 and (merged) PR #73124.

---------

Co-authored-by: Andrzej Warzyński <andrzej.warzynski@gmail.com>
2023-12-11 13:35:27 +01:00
dong jianqiang
b499466361 [Driver][MachineOutliner] Support -moutline option for aarch64_be (#73223)
This patch propagates the -moutline flag when target is aarch64_be, 
fix warning: 'aarch64_be' does not support '-moutline'; flag ignored
[-Woption-ignored]
2023-12-07 16:47:41 +08:00
Radu Salavat
ea4eb691f4 [Flang][Clang] Add support for frame pointers in Flang 2023-12-01 17:09:59 +00:00
Michael Klemm
17feb330aa [flang][Driver] Let the linker fail on multiple definitions of main() (#73124)
The flang driver was silently ignoring the `main()` function in
`Fortran_main.a` for entry into the Fortran program unit if an external
`main()` as supplied (e.g., via cross-language linkage with Fortran and
C/C++). This PR fixes this by making sure that the linker always pulls
in the `main()` definition from `Fortran_main.a` and consequently fails
due to multiple definitions of the same symbol if another object file
also has a definition of `main()`.
2023-11-28 14:20:30 -06:00
David Truby
0bc7cd4d51 [flang] Add runtimes using --dependent-lib on MSVC targets (#72519)
This patch uses the added --dependent-lib support to add the relevant
runtimes on MSVC targets as `/DEFAULTLIB:` sections in the object file
rather than on the link line. This should help CMake support for flang
on Windows.

Fixes #63741 
Fixes #68017
2023-11-23 14:19:57 +00:00
Brad Smith
4d5a8ccf25 [Driver] Add LTO support for Haiku and OpenBSD (#72047) 2023-11-13 02:42:14 -05:00
David Truby
cf1e3420b0 [flang][windows] Add option to link against specific MSVC CRT (#70833)
Currently flang's runtime libraries are only built for the specific CRT
that LLVM itself was built against. This patch adds the cmake logic for
building a separate runtime for each CRT configuration and adds a flag
for selecting a CRT configuration to link against.
2023-11-10 16:13:49 +00:00
Pierre van Houtryve
4428b01faa Reland: [AMDGPU] Remove Code Object V3 (#67118)
V3 has been deprecated for a while as well, so it can safely be removed
like V2 was removed.

- [Clang] Set minimum code object version to 4
- [lld] Fix tests using code object v3
- Remove code object V3 from the AMDGPU backend, and delete or port v3
tests to v4.
- Update docs to make it clear V3 can no longer be emitted.
2023-11-07 12:23:03 +01:00
Juan Manuel MARTINEZ CAAMAÑO
6687c5725c [NFC][Clang] Make GetSDLFromOffloadArchive return void 2023-10-25 15:57:22 +02:00
Juan Manuel MARTINEZ CAAMAÑO
7c946031b2 [NFC][Clang] Make read-only arguments of GetSDLFromOffloadArchive and SDLSearch read-only references instead of copying them 2023-10-25 15:57:22 +02:00
Juan Manuel Martinez Caamaño
6c0ceaeccc [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch static (#70201)
Make GetSDLFromOffloadArchive and SDLSearch functions static since they
are used only in the file where they are defined. The aim is to ease
refactoring/modifying the declarations of these functions in the future.
2023-10-25 15:31:04 +02:00
Juan Manuel MARTINEZ CAAMAÑO
16fe53c47e [NFC][Clang] Remove unused variable "AOBFileNames" 2023-10-24 18:28:33 +02:00
Min-Yih Hsu
ebf4c698c3 [Clang][LTO][GISel] Propagate -fglobal-siel to LTO (#69747)
Translate `-fglobal-isel` to `-plugin-opt=-global-isel=1`.
2023-10-24 09:13:01 -07:00
Juan Manuel Martinez Caamaño
f2801a5f5d [Clang][OpenMP] Check if value is contained in array, not if it's contained in the first element (#69462) 2023-10-20 18:51:22 +02:00
pvanhout
868abf0961 Revert "[AMDGPU] Remove Code Object V3 (#67118)"
This reverts commit 544d91280c.
2023-10-18 12:55:36 +02:00
Pierre van Houtryve
544d91280c [AMDGPU] Remove Code Object V3 (#67118)
V3 has been deprecated for a while as well, so it can safely be removed
like V2 was removed.

- [Clang] Set minimum code object version to 4
- [lld] Fix tests using code object v3
- Remove code object V3 from the AMDGPU backend, and delete or port v3
tests to v4.
- Update docs to make it clear V3 can no longer be emitted.
2023-10-16 08:21:48 +02:00
Dhanrajbir-Hira
0bb4b24ca3 [clang][AIX]Fix -flto-jobs for AIX. (#67853)
Currently using the `-flto-jobs=N` option passes `-bplugin_opt:jobs=N`
to the AIX linker which is not a valid option. This PR seeks to change
this behaviour to instead pass `-bplugin_opt:-threads=N` to control the
level of concurrency during LTO builds.
2023-10-03 09:18:21 -04:00
David Spickett
ffc67bb360 Revert "[Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration"
This reverts commit 6403287eff.

This is failing on all but 1 of Linaro's flang builders.
CMake Error at /home/tcwg-buildbot/worker/clang-aarch64-full-2stage/llvm/flang-rt/unittests/CMakeLists.txt:37 (message):
  Target llvm_gtest not found.
2023-10-02 09:02:05 +00:00
Paul Scoropan
6403287eff [Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration
See discourse thread https://discourse.llvm.org/t/rfc-support-cmake-option-to-control-link-type-built-for-flang-runtime-libraries/71602/18 for full details.

Flang-rt is the new library target for the flang runtime libraries. It builds the Flang-rt library (which contains the sources of FortranRuntime and FortranDecimal) and the Fortran_main library. See documentation in this patch for detailed description (flang-rt/docs/GettingStarted.md).

This patch aims to:
- integrate Flang's runtime into existing llvm infrasturcture so that Flang's runtime can be built similarly to other runtimes via the runtimes target or via the llvm target as an enabled runtime
- decouple the FortranDecimal library sources that were used by both compiler and runtime so that different build configurations can be applied for compiler vs runtime
- add support for running flang-rt testsuites, which were created by migrating relevant tests from `flang/test` and `flang/unittest` to `flang-rt/test` and `flang-rt/unittest`, using a new `check-flang-rt` target.
- provide documentation on how to build and use the new FlangRT runtime

Reviewed By: DanielCChen

Differential Revision: https://reviews.llvm.org/D154869
2023-09-30 12:35:33 -04:00
Kazushi Marukawa
1e00423788 [Clang][VE] Correct rpath handling on VE (#67671)
Add rpath for libc++ libraries in order to not specify rpath by user
each time. Disable -frthlib-add-ppath by default for VE similar to other
architectures. Update regression tests to check modifications.
2023-09-29 17:47:15 +09:00
Joseph Huber
381cc48a8e [OpenMP] Implicitly include the 'cgpu' and 'mgpu' libraries for OpenMP (#67557)
Summary:
[The LLVM C library for GPUs](https://libc.llvm.org/gpu/) supports
standard function calls on the GPU that users are familiar with.
Currently, this requires that users include these manually. The support
for this library is dependent upon whether or not associated LLVM build
was built with the GPU C library support. This patch implicitly adds
these for an OpenMP offloading compilation if we find that the toolchain
contains the GPU declarations that allow us to use this.

I do not know how to test this, given that it requires information from
the resource directory in the install. That means it won't be present
for any internal tests. It works when I test it and the idea is simple
enough so it should be simple enough.
2023-09-27 16:18:55 -05:00
Joseph Huber
c1afed9f48 [Clang][HIP] Remove 'clangPostLink' from SDL handling (#67366)
Summary:
This feature is not needed anymore and is replaced by different
implementations. The code guarded by this flag also causes us to emit an
invalid argument to `-mlink-builtin-bitcode` that will cause errors if
ever actually executed. Remove this feature.
2023-09-26 11:27:38 -05:00
Pierre van Houtryve
fe2f67e4ba [AMDGPU] Remove Code Object V2 (#65715)
Code Object V2 has been deprecated for more than a year now. We can
safely remove it from LLVM.

- [clang] Remove support for the `-mcode-object-version=2` option.
- [lld] Remove/refactor tests that were still using COV2
- [llvm] Update AMDGPUUsage.rst
- Code Object V2 docs are left for informational purposes because those
code objects may still be supported by the runtime/loaders for a while.
- [AMDGPU] Remove COV2 emission capabilities.
- [AMDGPU] Remove `MetadataStreamerYamlV2` which was only used by COV2
- [AMDGPU] Update all tests that were still using COV2 - They are either
deleted or ported directly to code object v4 (as v3 is also planned to
be removed soon).
2023-09-21 12:00:45 +02:00