20 Commits

Author SHA1 Message Date
Michael Kruse
7341753a2e
[Flang-RT] Environment introspection for quadmath.h (#130411)
When compiling Flang-RT with Clang, query Clang for the GCC installation
it uses. If found, create `quadmath_wrapper.h` that points to the
`quadmath.h` of that GCC installation.

`quadmath.h` is only available when compiling with gcc, and Clang has no
equivalent even though gcc's version compiles fine with Clang (at least
up to and including gcc 13). It is still available into gcc's
installation resource dir (in constrast to a system-wide indirectory
such as `/usr/include` or `/usr/local/include`) and therefore not
available to any compiler other than the gcc of that installation.
quadmath may also be a different OS package than gcc itself, so it is
not necessarily presesent.
 
Clang actually already appropriates a GCC installation for its libraries
such that `libquadmath.a` is already found, but it does not do so for
the include paths. Because adding that directory to the header search
path may have wide-reaching consquences, we create only a wrapper header
that points to the real `quadmath.h` in the same GCC installation that
Clang uses.
2025-03-11 14:18:06 +01:00
مهدي شينون (Mehdi Chinoune)
cf5aa559a8
[flang] Don't redefine pid_t on MinGW-w64. (#130288) 2025-03-10 17:27:47 +00:00
Daniel Chen
78631ac51b
[Flang] explicitly link the pthread library when building shared flang-rt. (#129956)
This patch is to explicitly link the pthread library when building
shared flang-rt.
On AIX, for example, it needs to link in `libpthread.a` explicitly in
order to resolve the references to those `pthread_*` functions in
`include/flang-rt/runtime/lock.h`
2025-03-07 14:13:38 -05:00
Kelvin Li
a7a65a824e
[flang] explicitly cast the pointer to void* in std::memcpy calls (NFC) (#129946)
This patch is to add the explicit cast to the first argument of std::memcpy.
2025-03-06 16:09:16 -05:00
Valentin Clement (バレンタイン クレメン)
c8898b09f9
[flang][rt] Use allocator registry to allocate the pointer payload (#129992)
pointer allocation is done through `AllocateValidatedPointerPayload`.
This function was not updated to use the registered allocators in the
descriptor to perform the allocation. This patch makes use of the
allocator.
The footer word is not set and not checked for allocator other than the
default one. The support will likely come in a follow up patch but this
will necessitate more functions to be registered to be able to set and
get the footer value when the allocation in on the device.
2025-03-06 08:47:27 -08:00
Slava Zakharin
9b1604065e
[flang-rt] Move unit-map.cpp to host-only sources list. (#129763)
This file is not enabled for the offload builds.
This patch aligns the list with flang/runtime/CMakeLists.txt
(that is about to be removed).
2025-03-04 14:39:16 -08:00
Slava Zakharin
f44fb56f62
[flang-rt] Set CUDA_SEPARABLE_COMPILATION for PTX library. (#129563)
`CUDA_SEPARABLE_COMPILATION` adds `-rdc=true`, which is needed
for the PTX library build.
2025-03-03 17:10:35 -08:00
Valentin Clement (バレンタイン クレメン)
ae84717d11
[flang][cuda] Fix descriptor sync in data transfer (#129333)
The destination descriptor on the device needs to be sync with the
destination descriptor on the host, not the src one.
2025-02-28 14:52:33 -08:00
Peter Klausler
abe1ecff54
[flang][runtime] Detect byte order reversal problems (#129093)
When reading an unformatted sequential file with variable-length
records, detect byte order reversal problems with the first record's
header and footer words, and emit a more detailed error message.
2025-02-27 16:16:15 -08:00
Michał Górny
d254fa877f
[flang-rt] Make FLANG_RT_INSTALL_RESOURCE_PATH configurable (#128561)
Make it possible to change the path used to install flang-rt library.
This is particularly necessary for standalone builds, where the CMake
script currently hardwires the default clang install path, and therefore
is incorrect for distributions that override it. However, for
consistency I have made it configurable unconditionally, preserving the
current defaults.
2025-02-25 08:47:47 +00:00
Kelvin Li
7262a1ea31
[flang] Set compile definitions for flang-rt build on AIX (#127919)
After commit b55f751, the flang-rt build on AIX is missing `-D_LARGE_FILE_API 
-D_XOPEN_SOURCE=700` in compiling the source. This patch is to add the 
compile definitions.

---------

Co-authored-by: Michael Kruse <github@meinersbur.de>
2025-02-24 10:03:26 -05:00
Michael Kruse
7e4fef69f9 [flang-rt][NFC] Fix grammar 2025-02-21 19:41:12 +01:00
Tom Stellard
2b340c10a6
flang: Fix build with latest libc++ (#127362)
I think this first stopped working with
954836634abb446f18719b14120c386a929a42d1. This patch fixes the following
error:


/home/runner/work/llvm-project/llvm-project/flang/runtime/io-api-minimal.cpp:153:11:
error: '__libcpp_verbose_abort' is missing exception specification
'noexcept'
   153 | void std::__libcpp_verbose_abort(char const *format, ...) {
       |           ^
| noexcept
/mnt/build/bin/../include/c++/v1/__verbose_abort:30:28: note: previous
declaration is here
30 | __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format,
...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
       |                            ^
1 error generated.
2025-02-19 06:53:30 -08:00
Eugene Epshteyn
01f2f81f2b
[flang-rt] Fixed uninitialized class member variable (#127681)
valgrind complained that `OpenStatementState::pathLength_` was used
before it was initialized, when a file was opened with
`status='scratch'`. The code seems to expect that `pathLengh_` should be
initialized to 0, so added default initialization to the declaration.
2025-02-18 15:52:51 -05:00
Michael Kruse
4c4fc4650f
[Flang-RT] Build libflang_rt.so (#121782)
Under non-Windows platforms, also create a dynamic library version of
the runtime. Build of either version of the library can be switched on
using FLANG_RT_ENABLE_STATIC=ON respectively FLANG_RT_ENABLE_SHARED=ON.
Default is to build only the static library, consistent with previous
behaviour. This is because the way the flang driver invokes the linker,
most linkers choose the dynamic library by default, if available.
Building the dynamic library therefore causes flang-built executables to
depend on `libflang_rt.so`, unless explicitly told otherwise.
2025-02-17 12:53:12 +01:00
Michael Kruse
b55f7512a7
[Flang] LLVM_ENABLE_RUNTIMES=flang-rt (#110217)
Extract Flang's runtime library to use the LLVM_ENABLE_RUNTIME
mechanism. It will only become active when
`LLVM_ENABLE_RUNTIMES=flang-rt` is used, which also changes the
`FLANG_INCLUDE_RUNTIME` to `OFF` so the old runtime build rules do not
conflict. This also means that unless `LLVM_ENABLE_RUNTIMES=flang-rt` is
passed, nothing changes with the current build process.

Motivation:
* Consistency with LLVM's other runtime libraries (compiler-rt, libc,
libcxx, openmp offload, ...)
* Allows compiling the runtime for multiple targets at once using the
LLVM_RUNTIME_TARGETS configuration options
* Installs the runtime into the compiler's per-target resource directory
so it can be automatically found even when cross-compiling

Also see RFC discussion at
https://discourse.llvm.org/t/rfc-use-llvm-enable-runtimes-for-flangs-runtime/80826
2025-02-16 15:39:52 +01:00
Michael Kruse
81c85ea30f [flang-rt] Fix aarch64-libcxx build failure
There seems to be multiple declarations of __libcpp_verbose_abort, some
with noexcept and some without. Reverting to the previous
forward-declaration (without noexcept) which seemes to have worked
before.
2025-02-16 13:46:30 +01:00
Michael Kruse
54f37133b7
[Flang][NFC] Move runtime library files to flang-rt (#110298)
Mostly mechanical changes in preparation of extracting the Flang-RT
"subproject" in #110217. This PR intends to only move pre-existing files
to the new folder structure, with no behavioral change. Common files
(headers, testing, cmake) shared by Flang-RT and Flang remain in
`flang/`.

Some cosmetic changes and files paths were necessary:
* Relative paths to the new path for the source files and
`add_subdirectory`.
 * Add the new location's include directory to `include_directories`
* The unittest/Evaluate directory has unitests for flang-rt and Flang. A
new `CMakeLists.txt` was introduced for the flang-rt tests.
 * Change the `#include` paths relative to the include directive
 * clang-format on the `#include` directives
* Since the paths are part if the copyright header and include guards, a
script was used to canonicalize those
* `test/Runtime` and runtime tests in `test/Driver` are moved, but the
lit.cfg.py mechanism to execute the will only be added in #110217.
2025-02-16 13:25:31 +01:00
David Spickett
ffc67bb360 Revert "[Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration"
This reverts commit 6403287eff71a3d6f6c862346d6ed3f0f000eb70.

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