Commit Graph

10524 Commits

Author SHA1 Message Date
David Truby
049d61ad65 [flang][AArch64] Always link compiler-rt to flang after libgcc (#144710)
This patch fixes an issue where the __trampoline_setup symbol is missing
with some programs compiled with flang. This symbol is present only in
compiler-rt and not in libgcc. This patch adds compiler-rt to the link
line after libgcc if libgcc is being used, so that only this symbol will
be picked from compiler-rt.

Fixes #141147
2025-06-24 11:08:13 +01:00
antoine moynault
5fa55b2dfc Revert "[flang][OpenMP] Skip runtime mapping with no offload targets (#144534)" (#145478)
And also revert 6ba1955 "[flang][OpenMP] Fix ignore-target-data.f90 test"

As it causes several bot failures
https://github.com/llvm/llvm-project/pull/144534#issuecomment-2995303224
2025-06-24 10:51:26 +02:00
Paul Osmialowski
4b9f7cd856 [flang] flang manpage overhaul (#144948)
Make the flang man page look more like the one clang is having.
2025-06-24 00:07:10 +01:00
Lei Huang
d715ecba79 Revert "[flang][fir] Add fir.if -> scf.if and add filecheck test … (#142965)" (#145345)
This reverts commit 823750d873.

Test causes segfault on aix flang builder.
2025-06-23 16:46:47 -04:00
Sam James
117e51de8a [flang][cmake] Don't pass -fno-strict-aliasing for GCC either
This is the same as 4ed10db859 with the
same rationale, but for Flang, I strongly suspect it was just pulled in
from Clang, see https://github.com/flang-compiler/f18/pull/6#issuecomment-364155817.
2025-06-23 14:24:50 +01:00
Krzysztof Parzyszek
fb209929e1 [flang][OpenMP] Set isNewBlock directly on OpenMP constructs (#144593)
When the PFT builder decides that an evaluation needs a new block it
checks if the evaluation has nested evaluations. In such case it sets
the flag on the first nested evaluation. This works under the assuption
that such an evaluation only serves as a container, and does not, by
itself, generate any code.

This fails for OpenMP constructs that contain nested evaluations because
the top-level evaluation does generate code that wraps the code from the
nested evaluations. In such cases, the code for the top-level evaluation
may be emitted in a wrong place.

When setting the `isNewBlock` flag, recognize OpenMP directives, and
treat them accordingly.

This fixes https://github.com/llvm/llvm-project/issues/139071
2025-06-23 08:09:50 -05:00
Krzysztof Parzyszek
925dbc7988 [flang][OpenMP] Fix namespace nesting after PR144960
Newly introduced Atomic.cpp fails to compile on its own, but somehow
compiles fine in the build. Maybe it's because PCH, but it needs to be
fixed nevertheless.
2025-06-20 13:22:58 -05:00
Krzysztof Parzyszek
6ba1955ba2 [flang][OpenMP] Fix ignore-target-data.f90 test
Allow the function definition line to match with and without attrbute
set number.

This fixes build break after PR144534:
https://lab.llvm.org/buildbot/#/builders/157/builds/31331

Also move the test to the OpenMP subdirectory where it should have
been from the beginning.
2025-06-20 11:09:07 -05:00
Krzysztof Parzyszek
349f8d67d4 [flang][OpenMP] Skip runtime mapping with no offload targets (#144534)
When no offload targets are specified flang will ignore "target"
constructs, but not "target data" constructs. This patch makes the
behavior consistent across all offload-related operations.

While ignoring "target" may produce semantically incorrect code, it may
still be a useful debugging tool.
2025-06-20 08:09:36 -05:00
NimishMishra
e970f59e6b [flang][OpenMP] Reintroduce TODO for FIR lowering of linear clause (#144883)
Current design of the linear clause lowering and translation shifts all
responsibility for handling the clause (like privatisation, linear
stepping, finalisation, and emission of synchronisation barriers) to the
IRBuilder. However in certain corner cases (like associated loops in or
before OpenMP version 4.5), variables are are implicitly linear. This
currently causes a problem with the existing linear clause
implementation. Hence, re-introduce TODO on the linear clause until the
linear clause lowering/translation are robust enough to handle such
cases as well.

Fixes https://github.com/llvm/llvm-project/issues/142935
2025-06-20 04:53:00 -07:00
NimishMishra
8650c80138 [flang][OpenMP] Do not skip privatization of linear variable if it is OmpPreDetermined (#144315)
Current implementation of linear clause skips privatisation of all
linear variables during the FIR generation phase, since linear variables
are handled in their entirety by the OpenMP IRBuilder. However,
"implicit" linear variables (like OmpPreDetermined) cannot be skipped,
since FIR generation requires privatized symbols. This patch adds checks
to skip the same.


Fixes https://github.com/llvm/llvm-project/issues/142935
2025-06-20 04:52:40 -07:00
Krzysztof Parzyszek
e5559ca45f [flang][OpenMP] Move lowering of ATOMIC to separate file, NFC (#144960) 2025-06-20 06:44:14 -05:00
Peter Klausler
9fd22cb56d [flang][NFC] Move new code to right place (#144551)
Some new code was added to flang/Semantics that only depends on
facilities in flang/Evaluate. Move it into Evaluate and clean up some
minor stylistic problems.
2025-06-19 13:42:46 -07:00
Slava Zakharin
28808dda2c [flang] Fixed test added in #144830. 2025-06-19 13:02:30 -07:00
Slava Zakharin
8631b4f1b4 [flang] Set low probability for array repacking code. (#144830)
This allows LLVM to place the most probably cold blocks
that do the repacking out of the line of the potentially hot code.
2025-06-19 12:12:04 -07:00
Jack Styles
89efae916a [Flang][OpenMP] Update default MapType for Map Clauses and OpenMP 5.2 (#144715)
In OpenMP 5.2, the `target enter data` and `target exit data` constructs
now have default map types if the user does not define them in the Map
clause. For `target enter data`, this is `to` and `target exit data`
this is `from`. This behaviour is now enabled when OpenMP 5.2 or greater
is used when compiling. To enable this, the default value is now set in
the `processMap` clause, with any previous behaviour being maintained
for either older versions of OpenMP or other directives.

See also #110008
2025-06-19 15:32:27 +01:00
Krzysztof Parzyszek
936c5566db [flang][OpenMP] Handle REQUIRES ADMO in lowering (#144362)
The previous approach rewrote the atomic constructs in the AST based on
the REQUIRES ATOMIC_DEFAULT_MEM_ORDER directives. The new approach
checks for incorrect uses of REQUIRED ADMO in the semantic analysis, and
applies it in lowering, eliminating the need for a separate
tree-rewriting procedure.
2025-06-19 07:18:21 -05:00
Andre Kuhlenschmidt
17f5b8b52a [flang][driver] add ability to look up feature flags without setting them (#144559)
This just adds some convenience methods to feature control and rewrites
old code in terms of those methods. Also cleans up some names that I
just realize were overloads of another method.
2025-06-18 11:21:35 -07:00
Krzysztof Parzyszek
4084ffcf1e [flang] Show types in DumpEvExpr (#143743)
When dumping evaluate::Expr, show type names which contain a lot of
useful information.

For example show
```
expr <Fortran::evaluate::SomeType> {
  expr <Fortran::evaluate::SomeKind<Fortran::common::TypeCategory::Integer>> {
    expr <Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 4>> {
      ...
```
instead of
```
expr T {
  expr T {
    expr T {
      ...
```
2025-06-18 11:31:03 -05:00
Krzysztof Parzyszek
5d502aeddf [flang][OpenMP] Clarify confusing error message (#144707)
The message "The atomic variable x should occur exactly once among the
arguments of the top-level [...] operator" was intended to convey that
(1) an atomic variable should be an argument, and (2) it should be
exactly one of the arguments. However, the wording turned out to be
sowing confusion instead.

Rework the corresponding check, and emit an individual error message for
each problematic situation:
- "atomic variable cannot be a proper subexpression of an argument",
- "atomic variable should appear as an argument",
- "atomic variable should be exactly one of the arguments".

Fixes https://github.com/llvm/llvm-project/issues/144599
2025-06-18 10:42:39 -05:00
Jack Styles
671caef379 [Flang][OpenMP] Update relevant warnings to emit when OMP >= v5.2 (#144492)
There has been a number of deprecation warnings that have been added to
Flang, however these features are only deprecated when the OpenMP
Version being used is 5.2 or later. Previously, flang did not consider
the version with the warnings so would always be emitted.

Flang now ensures warnings are emitted for the appropriate version of
OpenMP, and tests are updated to reflect this change.
2025-06-18 14:35:53 +01:00
Tom Eccles
a83d3362f6 [flang][OpenMP] Don't allow DO CONCURRENT inside of a loop nest (#144506)
I don't think DO CONCURRENT fits the definition of a Canonical Loop Nest
(OpenMP 6.0 section 6.4.1).
It is however explicitly allowed for the LOOP construct (6.0 section
13.8).

There's some obscure language in OpenMP 6.0 for the LOOP construct:

> If the collapsed loop is a DO CONCURRENT loop, neither the
> data-sharing attribute clauses nor the collapse clause may be
specified.

From the surrounding context, I think "collapsed loop" just means the
loop that the LOOP construct applies to. So I will interpret this to
mean that DO CONCURRENT can only be used with the LOOP construct if it
does not contain the COLLAPSE clause.

This also fixes a bug where the associated clause was never cleared
after it was set.

Fixes #144178
2025-06-18 14:02:11 +01:00
Krzysztof Parzyszek
4b2ab1494b [flang][OpenMP] Don't crash on iterator modifier in declare mapper (#144359)
Both the declare mapper directive argument, and the iterator modifier
can contain declaration-type-spec, so make sure that the processing of
one ends before processing of the other begins in semantic analysis.
2025-06-18 07:46:49 -05:00
Kareem Ergawy
59d6fbb8ff [flang][fir] Provide allocation block for fir.local when required (#144521)
Extends `fir::FirOpBuilder::getAllocaBlock()` to support `fir.local`.
This allows us to retrieve an allocation block when needed for
`fir.local`.
2025-06-18 10:24:08 +02:00
Slava Zakharin
70343c8d44 [mlir][flang] Added Weighted[Region]BranchOpInterface's. (#142079)
The new interfaces provide getters and setters for the weight
information about the branches of BranchOpInterface and
RegionBranchOpInterface operations.

These interfaces are done the same way as LLVM dialect's
BranchWeightOpInterface.

The plan is to produce this information in Flang, e.g. mark
most probably "cold" code as such and allow LLVM to order
basic blocks accordingly. An example of such a code is
copy loops generated for arrays repacking - we can mark it
as "cold" assuming that the copy will not happen dynamically.
If the copy actually happens the overhead of the copy is probably high
enough so that we may not care about the little overhead
of jumping to the "cold" code and fetching it.
2025-06-17 16:14:13 -07:00
Tom Eccles
cf637b7e35 [flang][OpenMP] Fix goto within SECTION (#144502)
Previously we didn't push any context for SECTION and they are not
modelled with differing scopes and so goto detection couldn't tell that
GOTOs between two SECTIONs were between constructs rather than just
staying inside of the parent SECTIONS construct.

Fixes #143231
2025-06-17 16:57:32 +01:00
Slava Zakharin
cd4e384339 [flang][test] Removed temporary workaround for buildbots. 2025-06-17 08:55:18 -07:00
Kajetan Puchalski
4cfe0d7f4c [flang][OpenMP] Support using copyprivate with fir.boxchar arguments (#144092)
Implement the lowering for passing a fir.boxchar argument to the
copyprivate clause.

Resolves https://github.com/llvm/llvm-project/issues/142123.

---------

Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-06-17 15:32:23 +01:00
Krzysztof Parzyszek
5f841a6284 [flang][OpenMP] Set _OPENMP macro for version 6.0 (#144410) 2025-06-17 07:41:20 -05:00
Kareem Ergawy
97e17e1595 Revert "[flang] Enable delayed localization by default for do concurrent (#144074)" (#144476)
This reverts commit b5dbf8210a.

Reverting again due to gfortran failure:
https://lab.llvm.org/buildbot/#/builders/17/builds/8868
2025-06-17 11:34:05 +02:00
Jack Styles
cb355def95 [Flang][OpenMP] Add Parsing support for Indirect Clause (#143505)
As part of OpenMP Version 5.1, support for the `indirect` clause was
added for the `declare target` directive. This clause should follow an
`enter` clause, and allows procedure calls to be done indirectly through
OpenMP.

This adds Parsing support for the clause, along with semantics checks.
Currently, lowering for the clause is not supported so a TODO message
will be outputted to the user. It also performs version checking as
`indirect` is only support in OpenMP 5.1 or greater.

See also: #110008
2025-06-17 09:05:36 +01:00
Kareem Ergawy
2dc58e02cb [flang][OpenMP] Add symbol table scopes for teams and parallel (#144015)
Adds symbol map scopes for standalone `teams` and `parallel` constructs.
This is required to properly bind the privatized symbols in both
constructs so that nested constructs can find them.

Resolves https://github.com/llvm/llvm-project/issues/116428.
2025-06-17 07:01:53 +02:00
Kareem Ergawy
b5dbf8210a [flang] Enable delayed localization by default for do concurrent (#144074)
Reintroduces changes from
https://github.com/llvm/llvm-project/issues/143897. A fix for the
reported problem in https://github.com/llvm/llvm-project/issues/143897
is hopefully resolved in
https://github.com/llvm/llvm-project/pull/144027.

This PR aims to make it easier and more self-contained to revert the
switch/flag if we discover any problems with enabling it by default.
2025-06-17 06:08:38 +02:00
Kareem Ergawy
7caeec5999 [NFC][flang][OpenMP] Unify genSectionsOp's prototype to match other genXXXOp functions (#144013)
Unifies the prototype of `genSectionsOp` to match other ops generators.
Doing so, we are able to call `genSectionsOp` directtly from
`genOMPDispatch` instead of the special handling needed now to pass the
section blocks. This is useful because now we can handle symbol mapping
scopes easier for nested OpenMP directives. See

https://github.com/llvm/llvm-project/pull/143706#issuecomment-2965344723
and the following discussion for more info.
2025-06-17 06:08:15 +02:00
Slava Zakharin
ab7aaaca93 [flang][tests] Remove stale module files to fix buildbots. 2025-06-16 19:50:43 -07:00
Slava Zakharin
ac7af53d05 [flang] Fixed LIT tests to create modfiles in a temp dir. (#144448) 2025-06-16 16:26:03 -07:00
Peter Klausler
2bf3ccabfa [flang] Restructure runtime to avoid recursion (relanding) (#143993)
Recursion, both direct and indirect, prevents accurate stack size
calculation at link time for GPU device code. Restructure these
recursive (often mutually so) routines in the Fortran runtime with new
implementations based on an iterative work queue with
suspendable/resumable work tickets: Assign, Initialize, initializeClone,
Finalize, and Destroy.

Default derived type I/O is also recursive, but already disabled. It can
be added to this new framework later if the overall approach succeeds.

Note that derived type FINAL subroutine calls, defined assignments, and
defined I/O procedures all perform callbacks into user code, which may
well reenter the runtime library. This kind of recursion is not handled
by this change, although it may be possible to do so in the future using
thread-local work queues.

(Relanding this patch after reverting initial attempt due to some test
failures that needed some time to analyze and fix.)

Fixes https://github.com/llvm/llvm-project/issues/142481.
2025-06-16 14:37:01 -07:00
Peter Klausler
65b06cd983 [flang][runtime] Check SOURCE= conformability on ALLOCATE (#144113)
The SOURCE= expression of an ALLOCATE statement, when present and not
scalar, must conform to the shape of the allocated objects. Check this
at runtime, and return a recoverable error, or crash, when appropriate.

Fixes https://github.com/llvm/llvm-project/issues/143900.
2025-06-16 14:36:35 -07:00
Peter Klausler
9c25ca78f9 [flang] Don't generate module file for hermetic USE'd dependency (#144143)
It's possible for the module file generation code to think that it needs
to (re)generate a module file for a dependent module read from a
hermetic module file, if it defines contains a procedure imported via
renaming due to a name clash. Adjust the logic that determines whether a
module file should be written to include a check for having originated
in a module file.
2025-06-16 14:36:13 -07:00
Leandro Lupori
1bd4f9719f [flang][OpenMP] Put taskgroup in a new scope (#144122)
Although taskgroup is a privatizing construct, because of
task_reduction clause, a new scope was not being created for it.
This could cause an extra privatization of variables when
taskgroup was lowered, because its scope would be the same as of
the parent privatizing construct.

This fixes regressions in tests 1052_0201 and 1052_0205, from
Fujitsu testsuite.

This issue didn't happen before because implicit symbols were
being created in a different way before #142154.
2025-06-16 13:20:30 -03:00
Kiran Chandramohan
dfb14b65bc [Flang] NFC: Update test to work on Mac (#144253)
`%flang` expands to `flang -isysroot <SDK location>` in Mac and probably
other OS as well. `fc1` is only accepted as the first argument and hence
in this case it fails.

Use the `%flang_fc1` option to correctly expand to `flang -fc1 -isysroot
<SDK location>`.
2025-06-16 16:55:40 +01:00
Kiran Chandramohan
01f9dff61f [Flang] Add llvm-profdata to list of tools to be built (#144325)
Fixes #144179
2025-06-16 13:10:45 +01:00
FYK
52d34865b9 Fix and reapply IR PGO support for Flang (#142892)
This PR resubmits the changes from #136098, which was previously
reverted due to a build failure during the linking stage:

```
undefined reference to `llvm::DebugInfoCorrelate'  
undefined reference to `llvm::ProfileCorrelate'
```

The root cause was that `llvm/lib/Frontend/Driver/CodeGenOptions.cpp`
references symbols from the `Instrumentation` component, but the
`LINK_COMPONENTS` in the `llvm/lib/Frontend/CMakeLists.txt` for
`LLVMFrontendDriver` did not include it. As a result, linking failed in
configurations where these components were not transitively linked.

### Fix:

This updated patch explicitly adds `Instrumentation` to
`LINK_COMPONENTS` in the relevant `llvm/lib/Frontend/CMakeLists.txt`
file to ensure the required symbols are properly resolved.

---------

Co-authored-by: ict-ql <168183727+ict-ql@users.noreply.github.com>
Co-authored-by: Chyaka <52224511+liliumshade@users.noreply.github.com>
Co-authored-by: Tarun Prabhu <tarunprabhu@gmail.com>
2025-06-13 12:05:16 -06:00
Krzysztof Parzyszek
eba63cd76f [flang][OpenMP] Improve handling of REQUIRES ATOMIC_DEFAULT_MEM_ORDER (#143917)
According to OpenMP 5.0 rules, the ACQ_REL ordering coming from a
REQUIRES directive may need to be replaced with ACQUIRE or RELEASE
depending on the directive in the ATOMIC construct. This was not done,
leading to an incorrect "memory-order" clause appearing in the generated
HLFIR.

This may need to be relaxed a bit to fully comply with later spec
versions, that will be done in a future PR.
2025-06-13 10:29:31 -05:00
Kareem Ergawy
7e0bb2b0b9 [flang][fir] Extend locality specs lowering to support init and dealloc regions (#144027)
Extending `fir.do_concurrent` to `fir.do_loop ... unordered` lowering by
adding support for lowring/inlining non-empty `init` and `dealloc`
regions.

Resolves https://github.com/llvm/llvm-project/issues/143897 (actually
handles the todo).
2025-06-13 15:21:23 +02:00
Tom Eccles
6ca31ad720 [flang][OpenMP] improve semantic check for invalid goto (#144040)
Fixes #143229
2025-06-13 14:17:39 +01:00
Tom Eccles
4a47634a00 [flang][OpenMP] Support substrings and complex part refs for DEPEND (#143907)
Fixes #142404

The parser can't tell the difference between array indexing and a
substring: that has to be done in semantics once we have types.
Substrings can only be in the form string([lower]:[higher]) not
string(index) or string(lower:higher:step). I added semantic checks to
catch this for the DEPEND clause.

This patch also adds lowering for correct substrings and for complex
part references.
2025-06-13 14:16:58 +01:00
Thirumalai Shaktivel
4268360003 [Flang] [OpenMP] Allow any type as argument to the FlushOp (#143844)
Fixes: #143842
2025-06-13 09:35:48 +05:30
Valentin Clement (バレンタイン クレメン)
9992668404 [flang][cuda] Add runtime check for passing device arrays (#144003) 2025-06-12 20:47:58 -07:00
Zhen Wang
3ddd137332 [flang] [cuda] Move SetImplicityCUDADevice after symbols in block construct are converted to objects (#143791)
`SetImplicitCUDADevice` looks for `symbol.has<ObjectEntityDetails>()` to
set the device attribute before symbols inside block constructs are
converted to ObjectEntity. Fix is to move the call to
`SetImplicitCUDADevice` after those symbols are converted.
2025-06-12 17:08:49 -07:00