9304 Commits

Author SHA1 Message Date
Krzysztof Parzyszek
2d90af5908
[flang][OpenMP] Add unparsing of BIND clause argument (#117776)
Currently the argument of the BIND clause is not printed. This is likely
an omission in the original implementation.
2024-11-26 16:17:41 -06:00
NimishMishra
b9e3a769b9
[flang][mlir][llvm][OpenMP] Add lowering and translation support for mergeable clause on task (#114662)
Add FIR generation and LLVMIR translation support for mergeable clause
on task construct. If mergeable clause is present on a task, the
relevant flag in `ompt_task_flag_t` is set and passed to
`__kmpc_omp_task_alloc`.
2024-11-26 02:40:26 -08:00
Tom Eccles
c0192a008c
[flang] implement function form of SYSTEM intrinsic (#117585)
SYSTEM is a gfortran extension which we already supported in subroutine
form. Gfortran also allows it to be called as a function, which was
requested by a user

https://discourse.llvm.org/t/unresolved-externals-with-appendend-underscore/83305/4
2024-11-26 10:18:44 +00:00
Tom Eccles
ad7bb652d6
[flang] Implement non-standard LNBLNK intrinsic (#117589)
This is defined here
https://gcc.gnu.org/onlinedocs/gfortran/LNBLNK.html. It is just an alias
to LEN_TRIM.

This was requested by a user:

https://discourse.llvm.org/t/unresolved-externals-with-appendend-underscore/83305
2024-11-26 10:18:34 +00:00
jeanPerier
cf602b95d1
[flang] handle fir.call in AliasAnalysis::getModRef (#117164)
fir.call side effects are hard to describe in a useful way using
`MemoryEffectOpInterface` because it is impossible to list which memory
location a user procedure read/write without doing a data flow analysis
of its body (even PURE procedures may read from any module variable,
Fortran SIMPLE procedure from F2023 will allow that, but they are far
from common at that point).

Fortran language specifications allow the compiler to deduce
that a procedure call cannot access a variable in many cases 
This patch leverages this to extend `fir::AliasAnalysis::getModRef` to
deal with fir.call.

This will allow implementing "array = array_function()" optimization in
a future patch.
2024-11-26 11:17:33 +01:00
jeanPerier
bb8bf858e8
[flang] add internal_assoc flag to mark variable captured in internal procedure (#117161)
This patch adds a flag to mark hlfir.declare of host variables that are
captured in some internal procedure.

It enables implementing a simple fir.call handling in
fir::AliasAnalysis::getModRef leveraging Fortran language specifications
and without a data flow analysis.

This will allow implementing an optimization for "array =
array_function()" where array storage is passed directly into the hidden
result argument to "array_function" when it can be proven that
arraY_function does not reference "array".

Captured host variables are very tricky because they may be accessed
indirectly in any calls if the internal procedure address was captured
via some global procedure pointer. Without flagging them, there is no
way around doing a complex inter procedural data flow analysis:
- checking that the call is not made to an internal procedure is not
enough because of the possibility of indirect calls made to internal
procedures inside the callee.
- checking that the current func.func has no internal procedure is not
enough because this would be invalid with inlining when an procedure
with internal procedures is inlined inside a procedure without internal
procedure.
2024-11-26 09:21:13 +01:00
Valentin Clement (バレンタイン クレメン)
eb5cda480d
[flang][cuda] cuf.allocate: Carry over stream to the runtime call (#117631)
- Update the runtime entry points to accept a stream information
- Update the conversion of `cuf.allocate` to pass correctly the stream
information when present.

Note that the stream is not currently used in the runtime. This will be
done in a separate patch as a design/solution needs to be down together
with the allocators.
2024-11-25 20:46:24 -08:00
Ivan R. Ivanov
2ed8c5de58
[flang][OpenMP] Fix handling of nested loop wrappers in LowerWorkshare (#117275) 2024-11-26 09:30:27 +09:00
Valentin Clement (バレンタイン クレメン)
deab4e9ab2
[flang][cuda][NFC] Add missing default values (#117610)
Make it homogenous with other runtime entry points.
2024-11-25 12:57:31 -08:00
Tarun Prabhu
b872c4c993
[flang][Driver] Fix incorrect condition in test
The conditions in a test did not match the target that was being
requested. This resulted in a test failure when building with
-DTARGETS_TO_BUILD=X86. This is now fixed.
2024-11-25 09:37:16 -07:00
David Truby
2d62daab49
[flang] AArch64 support for BIND(C) derived return types (#114051)
This patch adds support for BIND(C) derived types as return values
matching the AArch64 Procedure Call Standard for C.

Support for BIND(C) derived types as value parameters will be in a
separate patch.
2024-11-25 14:36:53 +00:00
Krzysztof Parzyszek
52755ac253
[flang][OpenMP] Use new modifier infrastructure for MAP/FROM/TO clauses (#117447)
This removes the specialized parsers and helper classes for these
clauses, namely ConcatSeparated, MapModifiers, and MotionModifiers. Map
and the motion clauses are now handled in the same way as all other
clauses with modifiers, with one exception: the commas separating their
modifiers are optional. This syntax is deprecated in OpenMP 5.2.

Implement version checks for modifiers: for a given modifier on a given
clause, check if that modifier is allowed on this clause in the
specified OpenMP version. This replaced several individual checks.

Add a testcase for handling map modifiers in a different order, and for
diagnosing an ultimate modifier out of position.
2024-11-25 07:38:12 -06:00
ShashwathiNavada
612f8ec7ac
seq_cst is allowed in Flush since OpenMP 5.1. (#114072)
This PR adds support seq_cst (sequential consistency) clause for the
flush directive in OpenMP. The seq_cst clause enforces a stricter memory
ordering, ensuring that all threads observe the memory effects of the
flush in the same order, improving consistency in memory operations
across threads.

---------

Co-authored-by: Shashwathi N <nshashwa@pe28vega.hpc.amslabs.hpecorp.net>
Co-authored-by: CHANDRA GHALE <chandra.nitdgp@gmail.com>
2024-11-25 16:08:39 +05:30
Krzysztof Parzyszek
b0e7383e59
Reapply [flang][OpenMP] Avoid early returns, NFC #117231 (#117325)
Two PRs were merged at the same time: one that modified `maybeApplyToV`
function, and shortly afterwards, this (the reverted) one that had the
old definition.

During the merge both definitions were retained leading to compilation
errors.

Reapply the reverted PR (1a08b15589) with the duplicate removed.
2024-11-23 10:29:52 -06:00
Valentin Clement (バレンタイン クレメン)
5802367ddb
[flang][cuda] Add support for allocate with source (#117388)
Add support for allocate statement with CUDA device variable and a
source.
2024-11-22 16:55:26 -08: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
Raghu Maddhipatla
556ea5265a
[Flang] [Semantics] [OpenMP] Added missing semantic check with nested target region. (#115344)
Issue semantic warning for any combination of nested OMP TARGET
directives inside another OMP TARGET region.

This change would not affect OMP TARGET inside an OMP TARGET DATA.
However, it issues warning for OMP TARGET DATA inside an OMP TARGET
region.
2024-11-22 08:24:08 -06:00
Kazu Hirata
764cfd7d09 Revert "[flang][OpenMP] Avoid early returns, NFC (#117231)"
This reverts commit 1a08b155899ee3ed6a6c441799991a8be5df801e.

Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/157/builds/13427
2024-11-21 19:16:36 -08:00
Krzysztof Parzyszek
1a08b15589
[flang][OpenMP] Avoid early returns, NFC (#117231)
Frontend code is generally nested.
Follow-up to https://github.com/llvm/llvm-project/pull/116658.
2024-11-21 17:51:01 -06:00
Krzysztof Parzyszek
e79cd24676
[flang][OpenMP] Use new modifier code in ORDER and SCHEDULE clauses (#117081)
This actually simplifies the AST node for the schedule clause: the two
allowed modifiers can be easily classified as the ordering-modifier and
the chunk-modifier during parsing without the need to create additional
classes.
2024-11-21 17:50:37 -06:00
Krzysztof Parzyszek
4fc1141e76
[flang][OpenMP] Apply modifier representation to semantic checks (#116658)
Also, define helper macros in parse-tree.h.

Apply the new modifier representation to the DEFAULTMAP and REDUCTION
clauses, with testcases utilizing the new modifier validation.

OpenMP modifier overhaul: #3/3
2024-11-21 13:18:01 -06:00
Peter Klausler
bb23ac65a1
[flang] Don't tokenize an exponent that isn't one (#117061)
The character 'e' or 'd' (either case) shouldn't be tokenized as part of
a real literal during preprocessing if it is not followed by an
optionally-signed digit string. Doing so prevents it from being
recognized as a macro name, or as the start of one.

Fixes https://github.com/llvm/llvm-project/issues/115676.
2024-11-21 10:48:53 -08:00
Peter Klausler
bde2f39ae0
[flang] Don't check fixed form label field too early (#117040)
When a fixed form source line begins with the name of a macro, don't
emit the usual warning message about a non-decimal character in the
label field. (The check for a macro was only being applied to free form
source lines, and the label field checking was unconditional).

Fixes https://github.com/llvm/llvm-project/issues/116914.
2024-11-21 10:48:36 -08:00
Peter Klausler
be6bc6a1e5
[flang] Better recovery from errors in a loop control (#117025)
When there's an error in a DO statement loop control, error recovery
isn't great. A bare "DO" is a valid statement, so a failure to parse its
loop control doesn't fail on the whole statement. Its partial parse ends
after the keyword, and as some other statement parsers can get further
into the input before failing, errors in the loop control can lead to
confusing error messages about bad pointer assignment statements and
others. So just check that a bare "DO" is followed by the end of the
statement.
2024-11-21 10:47:42 -08:00
Peter Klausler
3f594741cf
[flang] Fix implementation of Kahan summation (#116897)
In the runtime's implementation of floating-point SUM, the
implementation of Kahan's algorithm for increased precision is
incorrect. The running correction factor should be subtracted from each
new data item, not added to it. This fix ensures that the sum of 100M
random default real values between 0. and 1. is close to 5.E7.

See https://en.wikipedia.org/wiki/Kahan_summation_algorithm.
2024-11-21 10:47:21 -08:00
Valentin Clement (バレンタイン クレメン)
a76609dd72
[flang][cuda] Avoid intrinsics simplification in device context (#117026) 2024-11-21 10:37:38 -08:00
Ivan R. Ivanov
5d38e6e42a [flang] Introduce hlfir.elemental lowerings to omp.workshare_loop_nest (#104748)
This patch adds parallelization support for the following expression in OpenMP
workshare constructs:

* Elemental procedures in array expressions

(reapplied with linking fix)
2024-11-21 11:14:21 +09:00
Valentin Clement (バレンタイン クレメン)
ecda14069f
[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039) 2024-11-20 15:30:05 -08:00
Kazu Hirata
ae023f3499 [flang] Fix a warning
This patch fixes:

  flang/include/flang/Semantics/openmp-modifiers.h:45:69: error: extra
  ';' outside of a function is incompatible with C++98
  [-Werror,-Wc++98-compat-extra-semi]
2024-11-20 09:05:34 -08:00
Krzysztof Parzyszek
fb4ecada81
[flang][OpenMP] Change clause modifier representation in parser (#116656)
The main issue to solve is that OpenMP modifiers can be specified in any
order, so the parser cannot expect any specific modifier at a given
position. To solve that, define modifier to be a union of all allowable
specific modifiers for a given clause.

Additionally, implement modifier descriptors: for each modifier the
corresponding descriptor contains a set of properties of the modifier
that allow a common set of semantic checks. Start with the syntactic
properties defined in the spec: Required, Unique, Exclusive, Ultimate,
and implement common checks to verify each of them.

OpenMP modifier overhaul: #2/3
2024-11-20 10:38:06 -06:00
Krzysztof Parzyszek
cfd67c2149
[flang][OpenMP] Normalize clause modifiers that exist on their own (#116655)
This is the first part of the effort to make parsing of clause modifiers
more uniform and robust. Currently, when multiple modifiers are allowed,
the parser will expect them to appear in a hard-coded order.
Additionally, modifier properties (such as "ultimate") are checked
separately for each case.

The overall plan is
1. Extract all modifiers into their own top-level classes, and then
equip them with sets of common properties that will allow performing the
property checks generically, without refering to the specific kind of
the modifier.
2. Define a parser (as a separate class) for each modifier.
3. For each clause define a union (std::variant) of all allowable
modifiers, and parse the modifiers as a list of these unions.

The intent is also to isolate parts of the code that could eventually be
auto-generated.

OpenMP modifier overhaul: #1/3
2024-11-20 08:33:17 -06:00
Mats Petersson
b7ddb97ac2
[flang][OpenMP]Add TODO checking for scope allocate and firstprivate (#116801)
For the situation where scope is implemented to 5.1 standard, check that
the 5.2 are still "not yet implemented" (or some other partial
implementation).
2024-11-20 09:24:00 +00:00
Mats Petersson
92604d7c80
[flang][OpenMP]Add parsing support for MAP(MAPPER(name) ...) (#116274)
This prepares for using the DECLARE MAPPER construct.

A check in lowering will say "Not implemented" when trying to use a
mapper as some code is required to tie the mapper to the declared one.

Senantics check for the symbol generated.
2024-11-20 09:23:41 +00:00
David Spickett
9111d531d8
[flang] Rename Code Owners to Maintainers (#116009)
https://llvm.org/docs/DeveloperPolicy.html#maintainers
2024-11-20 09:21:07 +00:00
Ivan Radanov Ivanov
fa22100d57 Revert "[flang] Introduce hlfir.elemental lowerings to omp.workshare_loop_nest (#104748)"
This reverts commit 40c8938ff8447fc46bd2aa1605e3147cc38ffb8d.

Linking errors in buildbot build
2024-11-20 10:56:55 +09:00
Ivan R. Ivanov
40c8938ff8
[flang] Introduce hlfir.elemental lowerings to omp.workshare_loop_nest (#104748)
This patch adds parallelization support for the following expression in OpenMP
workshare constructs:

* Elemental procedures in array expressions
2024-11-20 10:49:34 +09:00
Valentin Clement
58280c0e97 [flang][cuda] Update test after #116882 2024-11-19 17:11:27 -08:00
Valentin Clement (バレンタイン クレメン)
01cd7ad2ba
[flang][cuda] Do not generate NVVM target attribute when creating the module (#116882)
Leave it to the `NVVMAttachTargetPass` so we can set compute capability
and features.
2024-11-19 16:55:34 -08:00
Peter Klausler
a54e8b2cc4
[flang] Silence bogus error about insufficiently defined interfaces (#116694)
The interfaces of separate module procedures are sufficiently well
defined in a submodule to be used in a local generic interface; the
compiler just needed to work a little harder to find them.

Fixes https://github.com/llvm/llvm-project/issues/116567.
2024-11-19 16:20:23 -08:00
Peter Klausler
d20f55fbd5
[flang] Silence bogus error on local proc pointer initializer (#116663)
A procedure pointer is allowed to be initialized with the subprogram in
which it is local, assuming that other requirements are satisfied.

Add a good test for local procedure pointer initialization, as no test
existed for the error message in question.

Fixes https://github.com/llvm/llvm-project/issues/116566.
2024-11-19 16:20:08 -08:00
Peter Klausler
300370c27b
[flang] Catch I/O statement error (#116647)
Fortran doesn't have unformatted internal I/O, so catch attempts to use
internal units without a format or namelist specifier.

Fixes https://github.com/llvm/llvm-project/issues/116586.
2024-11-19 16:19:48 -08:00
Peter Klausler
73216cd712
[flang] Rework CUDA kernel DO host array check (#116301)
Don't worry about derived type components unless they are pointers or
allocatables.
2024-11-19 16:19:32 -08:00
Valentin Clement (バレンタイン クレメン)
4d7df40c08
[flang][cuda] Materialize constant src in memory (#116851)
When the src of the data transfer is a constant, it needs to be
materialized in memory to be able to perform a data transfer.

```
subroutine sub1()
  real, device :: a(10)
  integer :: I

  do i = 5, 10
    a(i) = -4.0
  end do
end
```
2024-11-19 14:11:20 -08:00
Valentin Clement (バレンタイン クレメン)
ca79e12648
[flang][cuda] Handle implicit global in cuf kernel and nested statement (#116846)
Update the implicit global detection by looking for them in the CUF
kernel and also update to a walk so nested `fir.address_of` in nested
statement are also accounted for.
2024-11-19 12:38:18 -08:00
Zhaoxin Yang
b24acc06e1
[Flang][LoongArch] Add sign extension for i32 arguments and returns in function signatures. (#116146)
In loongarch64 LP64D ABI, `unsigned 32-bit` types, such as unsigned int,
are stored in general-purpose registers as proper sign extensions of
their 32-bit values. Therefore, Flang also follows it if a function
needs to be interoperable with C.

Reference:

https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc#Fundamental-types
2024-11-19 19:58:20 +08: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
Ivan R. Ivanov
8bb21ae6c9
[flang] Introduce custom loop nest generation for loops in workshare construct (#101445)
This alternative loop nest generation is used to generate an OpenMP loop nest instead of fir loops to facilitate parallelizing statements in an OpenMP `workshare` construct.
2024-11-19 17:00:04 +09:00
Ivan R. Ivanov
7d6713db60
[flang][omp] Emit omp.workshare in frontend (#101444)
Emit the contents of OpenMP workshare constructs in `omp.workshare`.
2024-11-19 16:58:30 +09:00
David Truby
5d33010f5e
[NFC][flang] Fix driver linker tests on Windows (#116667) 2024-11-18 23:25:45 +00:00