Commit Graph

925 Commits

Author SHA1 Message Date
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
Slava Zakharin
660cdace55 [flang] Fixed write past allocated descriptor in PointerAssociateRemapping. (#127000)
The pointer descriptor might be smaller than the target descriptor,
so `operator=` would write beyound the pointer descriptor.
2025-02-13 09:39:36 -08:00
Michał Górny
c665480694 [flang] [runtime] Explicitly disable EH & RTTI (#126920)
Explicitly disable EH & RTTI when building Flang runtime library. This
fixes the runtime built when Flang is built standalone against system
LLVM that was compiled with EH & RTTI enabled.

I think this change may be sufficient to lift the top-level
`LLVM_ENABLE_EH` restriction from Flang. However, I'd prefer if somebody
more knowledgeable decided on that.
2025-02-12 18:03:04 +00:00
Valentin Clement (バレンタイン クレメン)
401f4b828c [flang][rt] Add decimal files to device runtime (#126778)
The library FortranDecimal is not used anymore with the runtime but its
files are now integrated. Add the files for the device build as well.
2025-02-11 12:03:19 -08:00
Michael Kruse
5c8c2b3db5 [Flang] Rename libFortranRuntime.a to libflang_rt.runtime.a (#122341)
Following the conclusion of the
[RFC](https://discourse.llvm.org/t/rfc-names-for-flang-rt-libraries/84321),
rename Flang's runtime libraries as follows:

 * libFortranRuntime.(a|so) to libflang_rt.runtime.(a|so)
 * libFortranFloat128Math.a to libflang_rt.quadmath.a
* libCufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR}.(a|so) to
libflang_rt.cuda_${CUDAToolkit_VERSION_MAJOR}.(a|so)

This follows the same naming scheme as Compiler-RT libraries
(`libclang_rt.${component}.(a|so)`). It provides some consistency
between Flang's runtime libraries for current and potential future
library components.
2025-02-08 18:02:54 +01:00
Michael Kruse
98e118ca43 [Flang] Don't use FortranDecimal for runtime (#121997)
Avoid using the same library for runtime and compiler. `FortranDecimal`
was used in two ways:

1. As an auxiliary library needed for `libFortranRuntime.a`. This patch
adds the two source files of FortranDecimal directly into
FortranRuntime, so `FortranRuntime` is not used anymore.
 
2. As a library used by the Flang compiler. As the only remaining use of
the library, extra CMake code to make it compatible with the runtime can
be removed.

Before this PR, `enable_cuda_compilation` is applied to `FortranDecimal`
which causes everything that links to it, including flang (the
compiler), to depend on libcudart when CUDA support is enabled.

Having two runtime library just makes everything more complicated while
the user ideally should not be concerned with how the runtime is
structured internally. Some logic was copied for FortranDecimal because
of this, such as the ability to be compiled out-of tree
(b75a3c9f31) which is undocumented, the
logic to link against the various versions of Microsofts runtime library
(#70833), and avoiding dependency on the C++ runtime
(7783bba22c).
2025-02-07 11:43:31 +01:00
Michael Kruse
b815a3942a [Flang] Move non-common headers to FortranSupport (#124416)
Move non-common files from FortranCommon to FortranSupport (analogous to
LLVMSupport) such that

* declarations and definitions that are only used by the Flang compiler,
but not by the runtime, are moved to FortranSupport

* declarations and definitions that are used by both ("common"), the
compiler and the runtime, remain in FortranCommon

* generic STL-like/ADT/utility classes and algorithms remain in
FortranCommon

This allows a for cleaner separation between compiler and runtime
components, which are compiled differently. For instance, runtime
sources must not use STL's `<optional>` which causes problems with CUDA
support. Instead, the surrogate header `flang/Common/optional.h` must be
used. This PR fixes this for `fast-int-sel.h`.

Declarations in include/Runtime are also used by both, but are
header-only. `ISO_Fortran_binding_wrapper.h`, a header used by compiler
and runtime, is also moved into FortranCommon.
2025-02-06 15:29:10 +01:00
Brad Smith
cb2598dda1 [flang][runtime] Make sure to link libexecinfo if it exists (#125344)
Fixes building the backtrace support on FreeBSD/NetBSD/OpenBSD/DragonFly and musl
libc with libexecinfo.
2025-02-03 10:03:59 -05:00
Valentin Clement (バレンタイン クレメン)
f1b075df2e [flang][cuda] Pass the pinned variable in allocate calls (#125310) 2025-02-02 18:05:59 -08:00
Peter Klausler
8d8a821b78 [flang] Support OPEN(..., FORM="BINARY") (#124657)
... as a legacy spelling for OPEN(..., FORM="UNFORMATTED",
ACCESS="STREAM").
2025-01-31 10:51:16 -08:00
Brad Smith
e31c6c97b7 [flang] Fix building on aarch64 *BSD and musl libc after 9d8dc45d17 (#125183)
The fpu_control.h header appears to be GLIBC specific.
2025-01-31 11:49:28 -05:00
vdonaldson
7fa1257c35 [flang] Build fix (#125087)
Reinstate a preprocessor define for a nonstandard exception.


[124978](https://github.com/llvm/llvm-project/issues/124978#event-16113621403)
2025-01-30 15:15:52 -05:00
Jean-Didier PAILLEUX
ecc71de53f [flang] Implement IERRNO intrinsic (#124281)
Add the implementation of the IERRNO intrinsic to get the last system
error number, as given by the C errno variable.
This intrinsic is also used in RAMSES
(https://github.com/ramses-organisation/ramses/).
2025-01-29 12:01:07 +01:00
Jean-Didier PAILLEUX
5a34e6fdce [flang] Implement CHDIR intrinsic (#124280)
This intrinsic is a gnu extension
(https://gcc.gnu.org/onlinedocs/gfortran/CHDIR.html) and is used in
FLEUR (https://github.com/JuDFTteam/FLEUR).
2025-01-29 09:44:58 +01:00
Valentin Clement (バレンタイン クレメン)
654b76321a [flang][cuda] Allow to set the stack limit size (#124859)
This patch adds a call to the CUFInit function just after `ProgramStart`
when CUDA Fortran is enabled to initialize the CUDA context. This allows
us to set up some context information like the stack limit that can be
defined by an environment variable `ACC_OFFLOAD_STACKSIZE=<value>`.
2025-01-28 20:57:33 -08:00
vdonaldson
9d8dc45d17 [flang] IEEE underflow control for Arm (#124807)
Update IEEE_SUPPORT_UNDERFLOW_CONTROL, IEEE_GET_UNDERFLOW_MODE, and
IEEE_SET_UNDERFLOW_MODE code for Arm.
2025-01-28 15:41:04 -05:00
Muhammad Omair Javaid
c0861e9cbb Revert "[flang] IEEE underflow control for Arm (#124617)"
This reverts commit c4c76eabb8.

This breaks LLVM build on Windows:
https://lab.llvm.org/buildbot/#/builders/161/builds/4322
2025-01-28 17:32:45 +05:00
vdonaldson
c4c76eabb8 [flang] IEEE underflow control for Arm (#124617)
Update IEEE_SUPPORT_UNDERFLOW_CONTROL, IEEE_GET_UNDERFLOW_MODE, and
IEEE_SET_UNDERFLOW_MODE code for Arm.
2025-01-27 15:11:24 -05:00
Peter Klausler
fee393e4ea [flang][runtime] Don't crash on ASYNCHRONOUS='NO' in child I/O (#124208)
When ASYNCHRONOUS='NO' appears in a data transfer statement control item
list, don't crash if it isn't appropriate for the kind of I/O under way
(such as child I/O).

Fixes https://github.com/llvm/llvm-project/issues/124135.
2025-01-27 08:59:15 -08:00
vdonaldson
3322ba493a Revert "[flang] IEEE underflow control for Arm" (#124570)
Reverts llvm/llvm-project#124170
2025-01-27 10:40:23 -05:00
vdonaldson
20f72d19fc Revert "[flang] arm build fix" (#124569)
Reverts llvm/llvm-project#124562
2025-01-27 10:38:42 -05:00
vdonaldson
1eb4e9f88b [flang] arm build fix (#124562) 2025-01-27 10:32:13 -05:00
vdonaldson
3684ec4259 [flang] IEEE underflow control for Arm (#124170)
Update IEEE_SUPPORT_UNDERFLOW_CONTROL, IEEE_GET_UNDERFLOW_MODE, and
IEEE_SET_UNDERFLOW_MODE code for Arm.
2025-01-27 09:18:47 -05:00
Valentin Clement (バレンタイン クレメン)
48657bf29b [flang][cuda] Handle launch of cooperative kernel (#124362)
Add `CUFLaunchCooperativeKernel` entry points and lower gpu.launch_func
with grid_global attribute to this entry point.
2025-01-24 15:52:05 -08:00
Slava Zakharin
3da7de34a2 [flang][runtime] Disable optimization for traceback related functions. (#124172)
The backtrace may at least print the backtrace name in the call stack,
but this does not happen with the release builds of the runtime.
Surprisingly, specifying "no-omit-frame-pointer" did not work
with GCC, so I decided to fall back to -O0 for these functions.
2025-01-24 08:49:35 -08:00
Valentin Clement (バレンタイン クレメン)
67a8857989 [flang][cuda] Handle pointer allocation with double descriptors (#124183) 2025-01-23 15:54:22 -08:00
Valentin Clement (バレンタイン クレメン)
8c138bee6e [flang][cuda] Handle pointer allocation with source (#124070) 2025-01-23 09:24:06 -08:00
Valentin Clement (バレンタイン クレメン)
6e498bc2cd [flang][cuda] Handle simple device pointer allocation (#123996) 2025-01-22 15:59:32 -08:00
macurtis-amd
c25bd6e351 [flang][runtime] Teach ApplyType to handle TypeCategory::Unsigned (#123058) 2025-01-16 05:08:49 -06:00
vdonaldson
ff862d6de9 [flang] Modifications to ieee floating point environment procedures (#121949)
Intrinsic module procedures ieee_get_modes, ieee_set_modes,
ieee_get_status, and ieee_set_status store and retrieve opaque data
values whose size varies by machine and OS environment. These data
values are usually, but not always small. Their sizes are not directly
known in a cross compilation environment. Address this issue by
implementing two mechanisms for processing these data values.
Environments that use typical small data sizes can access storage
defined at compile time. When this is not valid, data storage of any
size can be allocated at runtime.
2025-01-15 10:55:09 -05:00
Peter Klausler
874a3ba868 [flang][runtime] Don't buffer unit 0 (#122614)
Always assume that predefined unit 0 is a terminal, so that output to it
is never buffered.
2025-01-14 12:58:42 -08:00
Peter Klausler
bf95854e9a [flang] EOF goes to ERR= in READ(..., REC=) (#122608)
A direct access READ that tries to read past the end of the file must
recover the error via an ERR= label, not an END= label (which is not
allowed to be present).

Fixes https://github.com/llvm/llvm-project/issues/122150.
2025-01-14 12:58:16 -08:00
Peter Klausler
7463b46a34 [flang][runtime] Fix use of empty optional in BOZ input (#120789)
Slava reported a valgrind result showing the use of uninitialized data
due to an unconditional dereference of an optional in BOZ formatted
input editing; fix.
2025-01-08 13:12:25 -08:00
Leandro Lupori
5130a4ea12 [flang][OpenMP] Handle pointers and allocatables in clone init (#121824)
InitializeClone(), implemented in #120295, was not handling top
level pointers and allocatables correctly.
Pointers and unallocated variables must be skipped.

This caused some regressions in the Fujitsu testsuite:
https://linaro.atlassian.net/browse/LLVM-1488
2025-01-07 14:00:39 -03:00
Valentin Clement (バレンタイン クレメン)
6dcd2b035d [flang][cuda] Convert cuf.sync_descriptor to runtime call (#121524)
Convert the op to a new entry point in the runtime
`CUFSyncGlobalDescriptor`
2025-01-02 17:02:59 -08:00
Brooks Davis
7326e903d7 flang: fix backtrace build on FreeBSD (#120297)
FreeBSD's libexecinfo defines backtrace with a size_t for the size
argument and return type. This almost certainly doesn't make sense, but
what's done is done so cast the output to allow compilation. Otherwise
we get:

.../flang/runtime/stop.cpp:165:13: error: non-constant-expression cannot
be narrowed from type 'size_t' (aka 'unsigned long') to 'int' in
initializer list [-Wc++11-narrowing]
  165 |   int nptrs{backtrace(buffer, MAX_CALL_STACK)};
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-01-02 12:06:29 -05:00
vdonaldson
df12983610 [flang] build fix (#121032)
Place floating point environment calls under '#ifdef __USE_GNU'.
2024-12-24 03:19:29 -05:00
Valentin Clement (バレンタイン クレメン)
4cb2a519db Revert "Reland '[flang] Allow to pass an async id to allocate the descriptor (#118713)' and #118733" (#121029)
This still cause issue for device runtime build.
2024-12-23 21:27:34 -08:00
khaki3
7d166fa384 [flang][cuda] Correct the number of blocks when setting the grid to * (#121000)
We set the `gridX` argument of `_FortranACUFLaunchKernel` to `-1` when
`*` is passed to the grid parameter. We store it in one of `dim3`
members. However, `dim3` members are unsigned, so positive-value checks
we use later, such as `gridDim.x > 0`, are invalid. This PR utilizes the
original gird-size arguments to compute the number of blocks.
2024-12-23 17:14:38 -08:00
Valentin Clement (バレンタイン クレメン)
5b74fb75d9 Reland '[flang] Allow to pass an async id to allocate the descriptor (#118713)' and #118733 (#120997)
Device runtime build have been fixed. Attempt to re-land these patches
that have been approved before.

https://github.com/llvm/llvm-project/pull/118713
https://github.com/llvm/llvm-project/pull/118733
2024-12-23 12:13:56 -08:00
vdonaldson
dcb7f44cd6 [flang] Modifications to ieee_support_halting (#120976)
The F23 standard requires that a call to intrinsic module procedure
ieee_support_halting be foldable to a constant at compile time in some
contexts. See for example F23 Clause 10.1.11 [Specification expression]
list item (13), Clause 1.1.12 [Constant expression] list item (11), and
references to specification and constant expressions elsewhere, such as
constraints C1012, C853, and C704.

Some Arm processors allow a user to control processor behavior when an
arithmetic exception is signaled, and some Arm processors do not have
this capability. An Arm executable will run on either type of processor,
so it is effectively unknown at compile time whether or not this support
will be available at runtime. This is in conflict with the standard
requirement.

This patch addresses this conflict by implementing ieee_support_halting
calls on Arm processors to check if this capability is present at
runtime. A call to ieee_support_halting in a constant context, such as
in the specification part of a program unit, will generate a compile
time "cannot be computed as a constant value" error. The expectation is
that such calls are unlikely to appear in production code.

Code generation for other processors will continue to generate a compile
time constant result for ieee_support_halting calls.
2024-12-23 11:07:20 -05:00
vdonaldson
c28a7c1efd [flang] Modifications to ieee_support_halting (#120747)
The F23 standard requires that a call to intrinsic module procedure
ieee_support_halting be foldable to a constant at compile time in some
contexts. See for example F23 Clause 10.1.11 [Specification expression]
list item (13), Clause 1.1.12 [Constant expression] list item (11), and
references to specification and constant expressions elsewhere, such as
constraints C1012, C853, and C704.

Some Arm processors allow a user to control processor behavior when an
arithmetic exception is signaled, and some Arm processors do not have
this capability. An Arm executable will run on either type of processor,
so it is effectively unknown at compile time whether or not this support
will be available at runtime. This in conflict with the standard
requirement.

This patch addresses this conflict by implementing ieee_support_halting
calls on Arm processors to check if this capability is present at
runtime. A call to ieee_support_halting in a constant context, such as
in the specification part of a program unit, will generate a compile
time "cannot be computed as a constant value" error. The expectation is
that such calls are unlikely to appear in production code.

Code generation for other processors will continue to generate a compile
time constant result for ieee_support_halting calls.
2024-12-23 09:30:45 -05:00
Valentin Clement (バレンタイン クレメン)
415cfaf339 [flang][cuda][NFC] Fix type in CUFFreeDescriptor (#120799) 2024-12-20 14:43:12 -08:00
Valentin Clement (バレンタイン クレメン)
e650ac1654 [flang][cuda][NFC] Fix typo in CUFAllocDescriptor (#120797)
Missing `r` in the function name.
2024-12-20 13:57:47 -08:00
Leandro Lupori
1fcb6a9754 [flang][OpenMP] Initialize allocatable members of derived types (#120295)
Allocatable members of privatized derived types must be allocated,
with the same bounds as the original object, whenever that member
is also allocated in it, but Flang was not performing such
initialization.

The `Initialize` runtime function can't perform this task unless
its signature is changed to receive an additional parameter, the
original object, that is needed to find out which allocatable
members, with their bounds, must also be allocated in the clone.
As `Initialize` is used not only for privatization, sometimes this
other object won't even exist, so this new parameter would need
to be optional.
Because of this, it seemed better to add a new runtime function:
`InitializeClone`.
To avoid unnecessary calls, lowering inserts a call to it only for
privatized items that are derived types with allocatable members.

Fixes https://github.com/llvm/llvm-project/issues/114888
Fixes https://github.com/llvm/llvm-project/issues/114889
2024-12-19 17:26:50 -03:00
Peter Klausler
9f3a611480 [flang] Don't needlessly instantiate distinct UNSIGNED cases for FINDLOC (#120471)
The FINDLOC runtime doesn't need to distinguish between INTEGER and
UNSIGNED data, so use the code for INTEGER also for UNSIGNED.
2024-12-18 11:37:26 -08:00
Peter Klausler
fc97d2e68b [flang] Add UNSIGNED (#113504)
Implement the UNSIGNED extension type and operations under control of a
language feature flag (-funsigned).

This is nearly identical to the UNSIGNED feature that has been available
in Sun Fortran for years, and now implemented in GNU Fortran for
gfortran 15, and proposed for ISO standardization in J3/24-116.txt.

See the new documentation for details; but in short, this is C's
unsigned type, with guaranteed modular arithmetic for +, -, and *, and
the related transformational intrinsic functions SUM & al.
2024-12-18 07:02:37 -08:00
执着
e8baa792e7 Backtrace support for flang (#118179)
Fixed build failures in old PRs due to missing files
2024-12-10 10:31:48 +00:00
Valentin Clement (バレンタイン クレメン)
16c2a1016e Revert "[flang] Allow to pass an async id to allocate the descriptor (#118713)" (#119109)
This reverts commit 7d1c661381.

This commit breaks some device runtime builds. Need time to investigate.
2024-12-07 19:55:12 -08:00
jeanPerier
d6ec7c82f3 [flang][CUF] fix missing header after #112188 (#118993)
Otherwise, builds with `-DFLANG_CUF_RUNTIME` hits:

```
runtime/CUDA/descriptor.cpp:44:24: error: invalid use of incomplete type 'const class Fortran::runtime::Descriptor'
   44 |   std::size_t count{src->SizeInBytes()};
```
2024-12-06 17:22:47 +01:00