9783 Commits

Author SHA1 Message Date
lorenzo chelini
c1a2292526
[MLIR][NFC] Retire let constructor for passes in Conversion directory (part1) (#127403)
`let constructor` is deprecated since the table gen backend emits most
of the glue logic to build a pass. This PR retires the td method for
most (I need another pass) passes in the Conversion directory.
2025-02-17 10:55:27 +01:00
Florian Mayer
a7a02083ac
[flang] Assert the Options fit into the storage bits (#126169) 2025-02-16 15:03:59 -08: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
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
Michał Górny
07b0665d28
[Flang] Support overriding LLVM_LIT_ARGS in standalone builds (#127340)
Declare `LLVM_LIT_ARGS` as a cache variable in standalone builds to
permit overriding it. This mirrors the logic used in Clang.
2025-02-15 19:50:14 +00:00
Michał Górny
948e97a40e
[flang] Revert MLIR_MAIN_SRC_DIR override (#127337)
This change is no longer necessary after #125842. Thanks to @nikic for
letting me know.
2025-02-15 18:36:20 +00:00
Michał Górny
c30a7f4594
[flang] Fix standalone builds against installed MLIR (#126387)
1. Add a new `MLIR_DEPS` argument group to `flang_add_library()`, and
move MLIR-specific dependencies to that group. These dependencies are
added as usual in regular builds, and are skipped in standalone builds,
since MLIR targets are not visible there (and were already built and
installed).
2. Fix the value of `MLIR_MAIN_SRC_DIR` to refer to the current source
directory rather than the directory written into MLIR CMake files. The
latter refers to the directory used to build the MLIR package, and is no
longer valid.
3. Fix non-dylib friendly linking of `LLVMTargetParser` in `Optimizer`
unittests.

With these changes, I can successfully run Flang's regression tests.
2025-02-15 07:15:00 +00:00
Valentin Clement (バレンタイン クレメン)
004afcbfb4
[flang][cuda] Set cudadevice interfaces as public by default (#127229)
Remove the PRIVATE statement from cudadevice as it hides any interfaces
from the used __cuda_device module.
2025-02-14 10:16:16 -08:00
Sergio Afonso
8a3d7cedb7
[Flang][OpenMP] Per-sym checks to introduce barriers (#127074)
Whenever there is a `lastprivate` variable and another unrelated
variable sets the `mightHaveReadHostSym` flag during Flang lowering
privatization, this will result in the insertion of a barrier.

This patch modifies this behavior such that this barrier will not be
inserted unless the same symbol both sets the flag and has
`lastprivate`.
2025-02-14 12:24:16 +00:00
Valentin Clement (バレンタイン クレメン)
910be4ff90
[flang][cuda] Lower clock64 to nvvm intrinsic (#127155) 2025-02-13 18:59:24 -08:00
Joel E. Denny
eb8ffd617a
[flang] AliasAnalysis: Handle fir.load on fir.alloca (#117785)
For example, determine that the address in p below cannot alias the
address of v:

```
subroutine test()
  real, pointer :: p
  real, target :: t
  real :: v
  p => t
  v = p
end subroutine test
```
2025-02-13 12:40:03 -05: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
Craig Topper
8da8ff8768
[flang][RISCV] Add target-abi ModuleFlag. (#126188)
This is needed to generate proper ABI flags in the ELF header for LTO
builds. If these flags aren't set correctly, we can't link with objects
that were built with the correct flags.

For non-LTO builds the mcpu/mattr in the TargetMachine will cause the
backend to infer an ABI. For LTO builds the mcpu/mattr aren't set.

I've only added lp64, lp64f, and lp64d ABIs. ilp32* requires riscv32
which is not yet supported in flang. lp64e requires a different
DataLayout string and would need additional plumbing.

Fixes #115679
2025-02-13 08:08:09 -08:00
Joseph Huber
c4ed95c85b [Flang] Fix leftover use of 'OPT_nogpulib'
Summary:
This didn't show up as a failure in precommit and I don't build flang so
this slipped by.
2025-02-13 08:14:12 -06:00
Jan Leyonberg
f63e3b15f9
[Flang] Generate math ops for non-precise calls to acosh, asin, asinh and atanh intrinsic calls (#126932)
This patch changes the codegen for non-precise acosh, asin, asinh and
atanh calls to generate math ops instead. This wasn't done before
because the math dialect did not have the corresponding operations at
the time.
2025-02-13 09:10:46 -05:00
Leandro Lupori
46ffacc2dd
[flang][OpenMP] Skip invalid conditional compilation sentinels (#126282)
In fixed form, an initial line can have an OpenMP conditional
compilation sentinel only if columns 3 through 5 have only
white space or numbers.

Fixes https://github.com/llvm/llvm-project/issues/89560
2025-02-13 09:36:04 -03:00
Abid Qadeer
bfd3e25fdd
[flang][debug] Allow variable from non-entry blocks. (#125692)
We currently drop the `DeclareOp` which are not in the entry block of
the function. This was done to side step a problem with the variables in
OpenMP target region. Now that issue has been addressed in #118314 so we
can lift this restriction as well.
2025-02-13 11:20:45 +00:00
Nikita Popov
3bf425764e [flang] Update f128 tests
Update test that require flang-supports-f128-math after #126929.
2025-02-13 09:24:38 +01:00
Nikita Popov
75c356c488
[MLIR][LLVMIR] Always use TargetFolder in IRBuilder (#126929)
This is a followup to https://github.com/llvm/llvm-project/pull/126745,
generalizing it to always use TargetFolder, including inside function
bodies.

This avoids generating non-canonical constant expressions that can be
folded away.
2025-02-13 08:53:59 +01:00
Razvan Lupusoru
7b473dfe84
[flang][acc] Implement type categorization for FIR types (#126964)
The OpenACC type interfaces have been updated to require that a type
self-identify which type category it belongs to. Ensure that FIR types
are able to provide this self identification.

In addition to implementing the new API, the PointerLikeType interface
attachment was moved to FIROpenACCSupport library like MappableType to
ensure all type interfaces and their implementation are now in the same
spot.
2025-02-12 21:09:59 -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
jeanPerier
5836d91845
[flang] add ABI argument attributes in indirect calls (#126896)
Last piece that implements the TODO for sret and byval setting on
indirect calls.

This includes a fix to the codegen last patch. I thought types in in
type attributes were automatically converted in dialect conversion
passes, but that is not the case. The sret and byval type needs to be
converted to llvm types in codegen (mlir FuncOp conversion is doing a
similar conversion).
2025-02-12 17:31:34 +01:00
Sergio Afonso
f13aea1d87
[Flang][OpenMP] Update semantics checks for 'teams' nesting (#126922)
This patch introduces a directive set for combined constructs where
`teams` is the last leaf. This is used in a couple places to simplify
checks, which is NFC, but it also replaces two incorrect uses of
`topTeamsSet`.

Before, these checks would incorrectly skip combined constructs where
`teams` was the last leaf construct when checking for allowed nested
constructs inside of a `teams` region. Similarly, it would also
incorrectly perform these checks whenever a compound `teams` construct
where `teams` was the first leaf construct was found.
2025-02-12 15:24:31 +00:00
Scott Manley
830a2911ee
[Flang] fix initializer with empty string to fix aarch64 build (#126918)
After tuneCPU was changed to std::string in
c8376a93bb9853cbcedeb22d80a9b200060eaf85 the flang builds broke, due to
a missing initializer.

If we want to add tuneCPU to the MLIRToLLVMPassPipelineConfig, we might
want to tackle that separately after the build is restored. This should
be no different than the previous behaviour.
2025-02-12 08:56:02 -06:00
Scott Manley
cbe879d685
[Flang] Fix options for FunctionAttr pass (#126819)
For non-basic types GenericOptionParser::findArgStrForValue will return
null, ultimately an llvm_unreachable, when the specific values are not
found. Add the enum, much like the debug-level option in AddDebugInfo to
resolve this problem. Also change tuneCPU to be std::string or it will
also fail.
2025-02-12 08:17:07 -06:00
Kareem Ergawy
32faf43878
[flang][OpenMP] Handle fixed length charaters in delayed privatization (#126704)
We currently handle sequences of fixed-length arrays properly by **not**
emitting length parameters for `embox` ops inside the `omp.private` op.
However, we do not handle the scalar case. This PR extends
`getLengthParameters` defined in `PrivateReductionUtils.cpp` to handle
such cases.

Fixes issue reported in #125732.
2025-02-12 11:04:26 +01:00
Nikita Popov
c03325cead
[MLIR][LLVMIR] Use TargetFolder when creating globals (#126745)
The LLVM dialect lowers globals using IRBuilder, relying on it creating
constant expressions where possible. As we remove support for more
constant expressions (per
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179),
this can cause issues for cases where the constant expression is no
longer supported, and the operation cannot be constant folded without
DataLayout being available. In particular, I ran into this issue with
flang and the removal of mul constant expressions.

Address this by using TargetFolder when creating globals, which will
perform DL-aware constant folding. I think it would make sense to also
do this in general, but I'm starting with globals where not doing this
can result in translation failures.

Ideally, globals with these problematic expressions would never be
generated in the first place, but there has been little movement on
fixing this (https://github.com/llvm/llvm-project/issues/96047).
2025-02-12 10:14:00 +01:00
jeanPerier
65075a863b
[flang][FIR] handle argument attributes in fir.call (#126711)
Add pretty printer/parser for fir.call argument/result attributes and
propagate them to llvm.call.

This will allow implementing the TODO about ABI relevant argument
attribute in indirect calls.
2025-02-12 09:49:52 +01: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
Renaud Kauffmann
9d7177a2d7
[flang][NFCI] Stop tracking memory source after a load in a more explicit manner. (#126156)
Typically, we do not track memory sources after a load because of the
dynamic nature of the load and the fact that the alias analysis is a
simple static analysis.

However, the code is written in a way that makes it seem like we are
continuing to track memory but in reality we are only doing so when we
know that the tracked memory is a leaf and therefore when there will
only be one more iteration through the switch statement. In other words,
we are iterating one more time, to gather data about a box, anticipating
that this will be the last time. This is a hack that helped avoid
cut-and-paste from other case statements but gives the wrong impression
about the intention of the code and makes it confusing.

To make it clear that there is no more tracking, we gather all the
necessary data from the memref of the load, in the case statement for
the load, and exit the loop. I am also limiting this data gathering for
the case when we load a box reference while we were actually following
data, as tests have shows, is the only case when we need it for. Other
cases will be handled conservatively, but this can change in the future,
on a case-by-case basis.

---------

Co-authored-by: Joel E. Denny <jdenny.ornl@gmail.com>
2025-02-11 10:47:38 -08:00
Razvan Lupusoru
c3d8c625af
[flang][acc] Fill-in name for privatized loop iv (#126601)
When the loop induction variable implicit private clause was being
generated, the name was left empty. The intent is that the data clause
operation holds the source language variable name. Thus, add the missing
name now.
2025-02-11 09:16:59 -08:00
Nikita Popov
82bd148a3f
[mlir][cmake] Do not export MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR (#125842)
MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR point to the source directory,
which is not installed. As such, the installed MLIRConfig.cmake also
should not reference it.

The comment indicates that these are needed for mlir_tablegen(), but I
don't see any related uses.

The motivation for this is the use in flang, where we end up inheriting
a meaningless MLIR_MAIN_SRC_DIR from a previous MLIR build, whose source
directory doesn't exist anymore, and that cannot be overridden with the
correct path, because it's not a cached variable.

Instead do what all the other projects do for LLVM_MAIN_SRC_DIR and
initialize MLIR_MAIN_SRC_DIR to CMAKE_CURRENT_SOURCE_DIR/../mlir.

For MLIR_INCLUDE_DIR there already is an exported MLIR_INCLUDE_DIRS,
which can be used instead.
2025-02-11 14:32:30 +01:00
jeanPerier
06f4fe3317
[flang][NFC] fix rewrite-out_of_range.F90 tests (#126699)
There was a typo in the target, and REAL(16) parts needed to be
protected too.
2025-02-11 11:49:32 +01:00
Slava Zakharin
754d896ca7
[flang] Propagate fast-math flags to FIROpBuilder. (#126316)
One constructor was missing to propagate fast-math flags
from an operation to the builder. It is fixed now.
And the builder creation in one opt-bufferization case should take
the rewriter, I think.
2025-02-10 15:23:34 -08:00
Razvan Lupusoru
83edbd4958
[flang][acc] Ensure data exit action is generated for present & nocreate (#126560)
The acc.delete operation has semantics of decrementing present counter
and deleting the data when the counter reaches zero. Since both
acc.present and acc.nocreate are both intended to increment present
counter, this matching exit action must be inserted.

This is also what was specified in OpenACC dialect documentation:
https://mlir.llvm.org/docs/Dialects/OpenACCDialect/#operation-categories
2025-02-10 13:04:10 -08:00
Asher Mancinelli
6b52fb25b9
[flang] Correctly handle !dir$ unroll with unrolling factors of 0 and 1 (#126170)
https://github.com/llvm/llvm-project/pull/123331 added support for the
unrolling directive. In the presence of an explicit unrolling factor,
that unrolling factor would be unconditionally passed into the metadata
even when it was 1 or 0. These special cases should instead disable
unrolling. Adding an explicit unrolling factor of 0 triggered this
assertion which is fixed by this patch:

```
unsigned int unrollCountPragmaValue(const llvm::Loop*):
Assertion `Count >= 1 && "Unroll count must be positive."' failed.
```

Updated tests and documentation.
2025-02-10 08:21:22 -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
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
Kelvin Li
4c7cbb9478
[flang] update PPC vector tests (NFC) (#126256)
Replace 'undef' with 'poison' based on commit f4e3b87
2025-02-07 11:23:09 -05:00
vdonaldson
79e9887a0f
[flang] test fix (#126251) 2025-02-07 09:55:10 -05:00
vdonaldson
b51fc2ac60
[flang] Modifications to ieee_support_standard (#125967)
The result of a call to ieee_support_halting is one of the components
that affect the result of a call to ieee_support_standard.
2025-02-07 08:49:12 -05: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
(b75a3c9f31c1ffdc9856aee32991d8129b372ee7) which is undocumented, the
logic to link against the various versions of Microsofts runtime library
(#70833), and avoiding dependency on the C++ runtime
(7783bba22c7add678d796741d30669c73159b3d8).
2025-02-07 11:43:31 +01:00
Valentin Clement (バレンタイン クレメン)
070c888292
[flang][cuda] Lower syncwarp to NVVM intrinsic (#126164) 2025-02-06 19:43:21 -08:00
Valentin Clement (バレンタイン クレメン)
b00b193728
[flang][cuda] Allow POINTER component to have device attribute (#126116) 2025-02-06 19:43:04 -08:00
David Pagan
8fb1b3f4b2
[flang][OpenMP] 'no_openmp_constructs' added to clang broke flang build (#126145)
Adding 'no_openmp_constructs' assumption clause to clang broke the flang
build. Adding to flang so it builds.

Testing
- Build
- Testing: check-all
2025-02-06 15:00:47 -08:00
Valentin Clement (バレンタイン クレメン)
98752ef893
[flang][cuda] Add interface for sinpi, cospi and sincospi (#126123)
Add interface for `sinpi`, `cospi` and `sincospi` and also expose
`sincosf`
2025-02-06 13:12:41 -08:00
Michael Kruse
02fa340711
[Flang] Promote FortranEvaluateTesting library (#124417)
The non-GTest library will be shared by unittests of Flang and Flang-RT.
Promote it as a regular library for use by both projects.

In the long term, we may want to convert these to regular GTest checks
to avoid having multiple testing frameworks.
2025-02-06 21:45:51 +01:00
Renaud Kauffmann
6dc41a6393
[flang][NFC] Moving alias analysis utilities utilities together. Adding new utility. (#125925)
1. Our static functions are a bit spread out in this file. I am
gathering them in an anonymous namespace
2. Moving the code to get the `target` attribute on a `fir.global` into
its own utility.
2025-02-06 12:18:51 -08:00
Kareem Ergawy
dcb124e820
[flang][OpenMP] Enable delayed privatization by default omp.wsloop (#125732)
Reapplies #122471

This is based on https://github.com/llvm/llvm-project/pull/125699, only
the latest commit is relevant.

With changes in this PR and the parent one, the previously reported
failures in the Fujitsu(*) test suite should hopefully be resolved (I
verified all the 14 reported failures and they pass now).

(*) https://linaro.atlassian.net/browse/LLVM-1521
2025-02-06 19:11:04 +01:00
Renaud Kauffmann
8d5f280559
[flang] Adding a couple of tests to the alias analysis (#125917)
To establish a baseline for new tests mentioned in
https://github.com/llvm/llvm-project/pull/117785, adding them here
independently.
2025-02-06 09:55:49 -08:00