505 Commits

Author SHA1 Message Date
Slava Zakharin
3f6ae3f0a8
[flang] Added driver options for arrays repacking. (#134002)
Added options:
  * -f[no-]repack-arrays
  * -f[no-]stack-repack-arrays
  * -frepack-arrays-contiguity=whole/innermost
2025-04-03 10:43:28 -07:00
Tom Eccles
9b2fd1a6ec
[flang][OpenMP] Bump default OpenMP version to 3.1 (#133745)
Precise OpenMP standards support information is being documented in
#132707

Flang now has good support for OpenMP Version 3.1 and earlier.
2025-04-02 10:43:48 +01:00
Kareem Ergawy
5d364481e3
[flang][OpenMP] Upstream first part of do concurrent mapping (#126026)
This PR starts the effort to upstream AMD's internal implementation of
`do concurrent` to OpenMP mapping. This replaces #77285 since we
extended this WIP quite a bit on our fork over the past year.

An important part of this PR is a document that describes the current
status downstream, the upstreaming status, and next steps to make this
pass much more useful.

In addition to this document, this PR also contains the skeleton of the
pass (no useful transformations are done yet) and some testing for the
added command line options.

This looks like a huge PR but a lot of the added stuff is documentation.

It is also worth noting that the downstream pass has been validated on
https://github.com/BerkeleyLab/fiats. For the CPU mapping, this achived
performance speed-ups that match pure OpenMP, for GPU mapping we are
still working on extending our support for implicit memory mapping and
locality specifiers.

PR stack:
- https://github.com/llvm/llvm-project/pull/126026 (this PR)
- https://github.com/llvm/llvm-project/pull/127595
- https://github.com/llvm/llvm-project/pull/127633
- https://github.com/llvm/llvm-project/pull/127634
- https://github.com/llvm/llvm-project/pull/127635
2025-04-02 09:24:38 +02:00
Michael Kruse
27539c3f90 Revert "[Flang] Remove FLANG_INCLUDE_RUNTIME (#124126)"
The production buildbot master apparently has not yet been restarted
since https://github.com/llvm/llvm-zorg/pull/393 landed.

This reverts commit 96d1baedefc3581b53bc4389bb171760bec6f191.
2025-03-26 19:02:13 +01:00
Michael Kruse
96d1baedef
[Flang] Remove FLANG_INCLUDE_RUNTIME (#124126)
Remove the FLANG_INCLUDE_RUNTIME option which was replaced by
LLVM_ENABLE_RUNTIMES=flang-rt.

The FLANG_INCLUDE_RUNTIME option was added in #122336 which disables the
non-runtimes build instructions for the Flang runtime so they do not
conflict with the LLVM_ENABLE_RUNTIMES=flang-rt option added in #110217.
In order to not maintain multiple build instructions for the same thing,
this PR completely removes the old build instructions (effectively
forcing FLANG_INCLUDE_RUNTIME=OFF).

As per discussion in
https://discourse.llvm.org/t/buildbot-changes-with-llvm-enable-runtimes-flang-rt/83571/2
we now implicitly add LLVM_ENABLE_RUNTIMES=flang-rt whenever Flang is
compiled in a bootstrapping (non-standalone) build. Because it is
possible to build Flang-RT separately, this behavior can be disabled
using `-DFLANG_ENABLE_FLANG_RT=OFF`. Also see the discussion an
implicitly adding runtimes/projects in #123964.
2025-03-26 18:50:41 +01:00
Kelvin Li
cf6c451a38
[flang] set the paths for the symbol extracting tool (#131375)
This patch is to set the paths for tools used in the
`export_executable_symbols` function in standalone build and set the
necessary macros for compiling the runtime source.
2025-03-21 16:18:16 -04:00
Slava Zakharin
fd0e20a64b
[flang] Generate fir.pack/unpack_array in Lowering. (#131704)
Basic generation of array repacking operations in Lowering.
2025-03-18 21:26:33 -07:00
Michael Kruse
bddf24ddbd
[Flang] Add omp_lib dependency to check-flang (#130975)
With `LLVM_ENABLE_RUNTIMES=openmp`, flang enables the OpenMP regression
tests, but `check-flang` was not ensuring that the OpenMP requirements
are built first. Fix by adding a `libomp-mod` to `flang-test-depends`.

Adding `libomp-mod` to extra_targets is necessary because there is no
target from openmp/ that is reachable from the parent
bootstrapping-build. `ninja openmp` fails because openmp/ has no
`openmp` target. `check-openmp` would also run the OpenMP tests and does
not even build `omp_lib.mod`. `runtimes` would build all the runtimes,
not just OpenMP.

Also fix the misleading CMake configure status messages that suggest the
only way to build omp_lib.mod/.h is `LLVM_ENABLE_PROJECTS=openmp`.
2025-03-14 09:24:28 +01:00
Nikita Popov
f137c3d592
[TargetRegistry] Accept Triple in createTargetMachine() (NFC) (#130940)
This avoids doing a Triple -> std::string -> Triple round trip in lots
of places, now that the Module stores a Triple.
2025-03-12 17:35:09 +01: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
e6e8ac59ba
[Flang] Optionally do not compile the runtime in-tree (#122336)
Introduce the CMake switch FLANG_INCLUDE_RUNTIME. When set to off, do
not add build instructions for the runtime.

This is required for Flang-RT (#110217) and the current runtime CMake
code to co-exist. When using `LLVM_ENABLE_RUNTIME=flang-rt`, the in-tree
build instructions are in conflict and must be disabled.
2025-02-08 01:06:27 +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
Nikita Popov
f9af5c145f
[flang][cmake] Fix bcc dependencies (#125822)
The Fortran libraries are not part of MLIR, so they should use
target_link_libraries() rather than mlir_target_link_libraries().

This fixes an issue introduced in
https://github.com/llvm/llvm-project/pull/120966.
2025-02-05 11:58:44 +01:00
Kiran Chandramohan
ce32625966
Reland "[Flang][Driver] Add a flag to control zero initialization" (#123606)
Reverts llvm/llvm-project#123330
2025-01-21 07:57:44 +00:00
Kiran Chandramohan
8a229f595a
Revert "Revert "Revert "[Flang][Driver] Add a flag to control zero initializa…" (#123330)
Reverts llvm/llvm-project#123097

Reverting due to buildbot failure
https://lab.llvm.org/buildbot/#/builders/89/builds/14577.
2025-01-17 12:27:58 +00:00
Kiran Chandramohan
8c63648117
Revert "Revert "[Flang][Driver] Add a flag to control zero initializa… (#123097)
…tion of global v…" (#123067)"

This reverts commit 44ba43aa2b740878d83a9d6f1d52a333c0d48c22.

Adds the flag to bbc as well.
2025-01-17 12:14:20 +00:00
Michał Górny
6a2cc12229
[flang] Support linking to MLIR dylib (#120966)
Introduce a new `MLIR_LIBS` argument to `add_flang_library`, that uses
`mlir_target_link_libraries` to link the MLIR dylib alterantively to the
component libraries. Use it, along with a few inline
`mlir_target_link_libraries` in tools, to support linking Flang to MLIR
dylib rather than the static libraries.

With these changes, the vast majority of Flang can be linked
dynamically. The only parts still using static libraries are these
requiring MLIR test libraries, that are not included in the dylib.
2025-01-16 13:35:26 +00:00
Razvan Lupusoru
11758f9ceb
[flang][acc] Add missing dependency to bbc tool (#122960)
The LLVM build here:

https://lab.llvm.org/buildbot/#/builders/89/builds/14359/steps/5/logs/stdio
is failing with error:
/usr/bin/ld: tools/flang/tools/bbc/CMakeFiles/bbc.dir/bbc.cpp.o:
undefined reference to symbol
'_ZN3fir3acc25registerOpenACCExtensionsERN4mlir15DialectRegistryE

Add missing dependency.
2025-01-14 12:01:43 -08:00
Razvan Lupusoru
01a0d212a6
[flang][acc] Implement MappableType interfaces for fir.box and fir.array (#122495)
The newly introduced MappableType interface in `acc` dialect was
primarily intended to allow variables with non-materialized storage to
be used in acc data clauses (previously everything was required to be
`pointer-like`). One motivator for this was `fir.box` since it is
possible to be passed to functions without a wrapping `fir.ref` and also
it can be generated directly via operations like `fir.embox` - and
unlike other variable representations in FIR, the underlying storage for
it does not get materialized until LLVM codegen.

The new interface is being attached to both `fir.box` and `fir.array`.
Strictly speaking, attaching to the latter is primarily for consistency
since the MappableType interface requires implementation of utilities to
compute byte size - and it made sense that a
`fir.box<fir.array<10xi32>>` and `fir.array<10xi32>` would have a
consistently computable size. This decision may be revisited as
MappableType interface evolves.

The new interface attachments are made in a new library named
`FIROpenACCSupport`. The reason for this is to avoid circular
dependencies since the implementation of this library is reusing code
from lowering of OpenACC. More specifically, the types are defined in
`FIRDialect` and `FortranLower` depends on it. Thus we cannot attach
these interfaces in `FIRDialect`.
2025-01-14 10:42:57 -08:00
Valentin Clement (バレンタイン クレメン)
c701c18bed
[flang][cuda] Move interface to __cuda_device (#122771) 2025-01-13 17:28:34 -08:00
Slava Zakharin
9d33874936
[flang] Support -f[no-]realloc-lhs. (#120165)
-frealloc-lhs is the default.
If -fno-realloc-lhs is specified, then an allocatable on the left
side of an intrinsic assignment is not implicitly (re)allocated
to conform with the right hand side. Fortran runtime will issue
an error if there is a mismatch in shape/type/allocation-status.
2024-12-17 09:06:05 -08:00
Yusuke MINATO
a88677edc0
Reland "[flang] Integrate the option -flang-experimental-integer-overflow into -fno-wrapv" (#118933)
This relands #110063.
The performance issue on 503.bwaves_r is found not to be related to the
patch, and is resolved by fbd89bcc when LTO is enabled.
2024-12-10 16:26:53 +09:00
Tarun Prabhu
4ab5e90c9c
[flang][Driver] Add correct libraries to driver
A recent commit (23d7a6cedb519853508) introduced a dependency on
libLLVMMC.so. This is to handle the `-print-supported-cpus` option which
uses `llvm/MC/SubtargetInfo`. It requires libLLVMMC to be linked into
the flang-driver which the previous commit did not do. This fixes that
issue.
2024-11-22 14:20:19 -07:00
Tarun Prabhu
23d7a6cedb
[flang][Driver] Support -print-supported-cpus and associated aliases (#117199)
The aliases are -mcpu=help and -mtune=help. There is still an issue with
the output which prints an example line that references clang. That is
not fixed here because it is printed in llvm/MC/SubtargetInfo.cpp. Some
more thought is needed to determine how best to handle this.

Fixes #117010
2024-11-22 11:57:03 -07:00
Ivan R. Ivanov
e7e5541616
[flang] Lower omp.workshare to other omp constructs (#101446)
Add a new pass that lowers an `omp.workshare` with its binding `omp.workshare.loop_wrapper` loop nests into other OpenMP constructs that can be lowered to LLVM.

More specifically, in order to preserve the sequential execution semantics of the code contained, it wraps portions that needs to be executed on a single thread in `omp.single` blocks, converts code that must be parallelized into `omp.wsloop` nests and inserts the appropriate synchronization.
2024-11-19 17:02:16 +09:00
David Truby
dda20ea73d
[flang] Add fir-lsp-server (#114059)
This patch adds a fir-lsp-server tool for editor support for editing fir
files, using the existing MLIR lsp server support.

See https://mlir.llvm.org/docs/Tools/MLIRLSP/ for more information.
2024-10-30 15:05:18 +00:00
Yusuke MINATO
bd6ab32e6e
Revert "[flang] Integrate the option -flang-experimental-integer-overflow into -fno-wrapv" (#113901)
Reverts llvm/llvm-project#110063 due to the performance regression on
503.bwaves_r in SPEC2017.
2024-10-28 14:19:20 +00:00
Yusuke MINATO
96bb375f5c
[flang] Integrate the option -flang-experimental-integer-overflow into -fno-wrapv (#110063)
nsw is now added to do-variable increment when -fno-wrapv is enabled as
GFortran seems to do.
That means the option introduced by #91579 isn't necessary any more.

Note that the feature of -flang-experimental-integer-overflow is enabled
by default.
2024-10-25 15:20:23 +09:00
Valentin Clement (バレンタイン クレメン)
4e40b71c51
[flang][cuda] Add specialized gpu.launch_func conversion (#113493) 2024-10-23 15:28:51 -07:00
Valentin Clement (バレンタイン クレメン)
7e72e5ba86
Reland '[flang][cuda] Add cuf.register_kernel operation' (#112389)
The operation will be used in the CUF constructor to register the kernel
functions. This allow to delay this until codegen when the gpu.binary
will be available.

Reland of #112268 with correct shared library build support.
2024-10-15 11:12:03 -07:00
Valentin Clement (バレンタイン クレメン)
2a68f82989
Revert "[flang][cuda] Add cuf.register_kernel operation" (#112306)
Reverts llvm/llvm-project#112268
2024-10-14 21:06:59 -07:00
Valentin Clement (バレンタイン クレメン)
cbe76a2ac3
[flang][cuda] Add cuf.register_kernel operation (#112268)
The operation will be used in the CUF constructor to register the kernel
functions. This allow to delay this until codegen when the gpu.binary
will be available.
2024-10-14 20:57:21 -07:00
Tarun Prabhu
839344f025
[clang][flang][mlir] Reapply "Support -frecord-command-line option (#102975)"
The underlying issue was caused by a file included in two different
places which resulted in duplicate definition errors when linking
individual shared libraries. This was fixed in c3201ddaeac02a2c86a38b
[#109874].
2024-10-14 08:44:24 -06:00
Brad Richardson
06eb10dadf
[flang][driver] rename flang-new to flang (#110023)
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>
2024-10-10 09:26:04 +01:00
Yusuke MINATO
b91a25ef58
[flang] add nsw to operations in subscripts (#110060)
This patch adds nsw to operations when lowering subscripts.

See also the discussion in the following discourse post.
https://discourse.llvm.org/t/rfc-add-nsw-flags-to-arithmetic-integer-operations-using-the-option-fno-wrapv/77584/9
2024-10-03 10:56:01 +09:00
Krzysztof Parzyszek
3b20a833cb
[flang][Semantics] Add LangOptions to SemanticsContext (#110013)
The motivation for this is to make OpenMP settings visible in the
semantic checks (OpenMP version in particular).
2024-09-26 08:56:22 -05:00
Tarun Prabhu
c3201ddaea
[flang][NFC] Refactor to remove .inc file containing shared code (#109874)
Remove flang/include/flang/Tools/CLOptions.inc - which was included as
is in - several places. Move the code in it to header and source files
which are used used in the "standard" way. Some minor cleanup such as
removing trailing whitespace and excessive newlines and reordering
entries alphabetically for files that were modified along the way.
Update the documentation that referenced CLOptions.inc.
2024-09-25 14:04:38 -06:00
David Spickett
737c414e1d Revert "[clang][flang][mlir] Support -frecord-command-line option (#102975)"
This reverts commit b3533a156da92262eb19429d8c12f53e87f5ccec.

It caused test failures in shared library builds:
https://lab.llvm.org/buildbot/#/builders/80/builds/3854
2024-09-20 11:30:50 +00:00
Tarun Prabhu
b3533a156d
[clang][flang][mlir] Support -frecord-command-line option (#102975)
Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object
file. This behavior is also supported in clang. Some refactoring of the
code in flang to handle these command line options was carried out. The
corresponding -grecord-command-line option which saves the command line
in the debug information has not yet been enabled for flang.
2024-09-19 18:28:50 -06:00
Peter Klausler
c5711130be
[flang] Fix cycle of build dependencies (#108132)
While trying to fix one build problem, I made things worse. This should
clear things up.
2024-09-10 19:00:32 -07:00
Peter Klausler
901006f238
[flang] Make flang module hidden dependency explicit to correct build… (#108129)
… failure

Any flang module with a derived type definition implicitly depends on
flang/module/__fortran_type_info.f90. Make this dependency explicit so
that an unlucky build order doesn't cause a crash.
2024-09-10 18:45:06 -07:00
Tom Eccles
3b19e480c0
[flang] Warn when F128 is unsupported (#102147) (#106957)
This generates `warning: REAL(KIND=16) is not an enabled type for this
target` if that type is used in a build not correctly configured to
support this type. Uses of `selected_real_kind(30)` return -1.

Relanding #102147 because the test errors turned out to be specific to a
downstream configuration.
2024-09-05 15:59:36 +01:00
Renaud Kauffmann
697bc748f9
Allow disabling of types from the command line (#107126)
Adding hidden options to disable types through the
`TargetCharacteristics`. I am seeing issues when I do this
programmatically and would like, for anyone, to have the ability to
reproduce them for development and testing purposes.

I am planning to file a couple of issues following this patch.
2024-09-04 08:59:55 -07:00
Tom Eccles
8ae877a089
Revert "[flang] Warn when F128 is unsupported" (#106561)
Reverts llvm/llvm-project#102147

It seems some systems which should support F128 are wrongly detected as
not supporting.

This might be due to checking `LDBL_MANT_DIG` instead of
`__LDBL_MANT_DIG__`. I will investigate.
2024-08-29 15:37:59 +01:00
Tom Eccles
114ff99e93
[flang] Warn when F128 is unsupported (#102147)
This generates `warning: REAL(KIND=16) is not an enabled type for this
target` if that type is used in a build not correctly configured to
support this type. Uses of `selected_real_kind(30)` return -1.
2024-08-28 16:33:39 +01:00
Ivan R. Ivanov
65f66d2c60 [flang][NFC] Move OpenMP related passes into a separate directory (#104732)
Reapplied with fixed library dependencies for shared lib build
2024-08-22 11:23:21 +09:00
Ivan Radanov Ivanov
bccb227093 Revert "[flang][NFC] Move OpenMP related passes into a separate directory (#104732)"
This reverts commit 87eeed1f0ebe57abffde560c25dd9829dc6038f3.
2024-08-21 23:16:52 +09:00
Ivan R. Ivanov
87eeed1f0e
[flang][NFC] Move OpenMP related passes into a separate directory (#104732) 2024-08-21 22:59:11 +09:00
Steven Wu
b8c560f159
[CMake] Remove EXPORT_SYMBOLS_FOR_PLUGINS from #102138 (#102396)
Partially remove some of the changes from #102138 as
EXPORT_SYMBOLS_FOR_PLUGINS doesn't work on all the configurations.
2024-08-08 06:00:11 -07:00
Steven Wu
01b488faab
Reapply "[CMake] Fold export_executable_symbols_* into function args. (#101741)" (#102138)
Fix the builds with LLVM_TOOL_LLVM_DRIVER_BUILD enabled.

LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES is not completely
compatible with export_executable_symbols as the later will be ignored
if the previous is set to NO.

Fix the issue by passing if symbols need to be exported to
llvm_add_exectuable so the link flag can be determined directly
without calling export_executable_symbols_* later.
2024-08-07 09:12:15 -07:00