Commit Graph

6776 Commits

Author SHA1 Message Date
Renaud Kauffmann
b9978f8c77 [flang][cuda] Adding variable registration in constructor (#113976)
1) Adding variable registration in constructor
2) Applying feedback from PR
https://github.com/llvm/llvm-project/pull/112989
2024-10-29 11:48:48 -07:00
Kelvin Li
8e14c6c172 [flang] Support -mabi=vec-extabi and -mabi=vec-default on AIX (#113215)
This option is to enable the AIX extended and default vector ABIs.
2024-10-29 14:20:11 -04:00
Valentin Clement (バレンタイン クレメン)
b05fec97d5 [flang][cuda] Convert gpu.launch_func to CUFLaunchClusterKernel when cluster dims are present (#113959)
Kernel launch in CUF are converted to `gpu.launch_func`. When the kernel
has `cluster_dims` specified these get carried over to the
`gpu.launch_func` operation. This patch updates the special conversion
of `gpu.launch_func` when cluster dims are present to the newly added
entry point.
2024-10-29 10:02:08 -07:00
Krzysztof Parzyszek
d48c849ea9 [flang][OpenMP] Parsing support for iterator in DEPEND clause (#113622)
Warn about use of iterators OpenMP versions that didn't have them
(support added in 5.0). Emit a TODO error in lowering.
2024-10-29 08:00:44 -05:00
Abid Qadeer
8239ea3918 [flang][debug] Support IndexType. (#113921) 2024-10-29 12:22:43 +00:00
Krzysztof Parzyszek
46944d1f95 [flang][OpenMP] Extract OMP version hint into helper functions, NFC (#113621) 2024-10-29 06:43:40 -05:00
Renaud Kauffmann
0eb5c9d2ef [flang][cuda] Copying device globals in the gpu module (#113955) 2024-10-28 15:34:27 -07:00
Krzysztof Parzyszek
09a4bcf1a5 [flang][OpenMP] Update handling of DEPEND clause (#113620)
Parse the locator list in OmpDependClause as an OmpObjectList (instead
of a list of Designators). When a common block appears in the locator
list, show an informative message.
Implement resolving symbols in DependSinkVec in a dedicated visitor
instead of having a visitor for OmpDependClause.
Resolve unresolved names common blocks in OmpObjectList.

Minor changes to the code organization:
- rename OmpDependenceType to OmpTaskDependenceType (to follow 5.2
terminology),
- rename Depend::WithLocators to Depend::DepType,
- add comments with more detailed spec references to parse-tree.h.

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2024-10-28 16:06:22 -05: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
Kiran Chandramohan
5621929f7f [Flang][OpenMP] Add parser support for grainsize and num_tasks clause (#113136)
These clauses are applicable only for the taskloop directive. Since the
directive has a TODO error, skipping the addition of TODOs for these
clauses.
2024-10-27 20:16:24 +00:00
Kiran Chandramohan
eef3766ae5 Assumed-size arrays are shared and cannot be privatized (#112963)
Do not error out if default(none) is specified and the region has an
assumed-size array.

Fixes #110442
2024-10-27 18:58:47 +00:00
jeanPerier
64d7e45c40 Revert "[flang][debug] Support mlir::NoneType." (#113769)
Reverts llvm/llvm-project#113550

It turns out this causes compiler crashes with assumed-type arrays and -g.
See https://github.com/llvm/llvm-project/pull/113769 for a reproducer.
2024-10-26 21:38:54 +02:00
Renaud Kauffmann
3acf856b50 Adding CUFCommon.{h,cpp} for CUF utilities (#113740) 2024-10-25 16:08:45 -07:00
Kiran Chandramohan
843c2fbe7f Add parser+semantics support for scope construct (#113700)
Test parsing, semantics and a couple of basic semantic checks for
block/worksharing constructs.
Add TODO message in lowering.
2024-10-25 18:57:01 +01:00
Abid Qadeer
85af1926f7 [flang][debug] Support mlir::NoneType. (#113550) 2024-10-25 11:43:25 +01: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
Krzysztof Parzyszek
e2e7d565bf [flang][OpenMP] Make Symbol::OmpFlagToClauseName static (#113586)
It doesn't need the Symbol object for anything.
2024-10-24 12:10:18 -05:00
Abid Qadeer
37832d5de2 [flang][debug] Support fir.vector type. (#112951)
This PR converts the `fir.vector<>` to
`DICompositeTypeAttr(DW_TAG_array_type)` with `vector` flag set.
2024-10-24 13:37:32 +01:00
Abid Qadeer
47c1abf4af [flang][debug] Fix array lower bounds in derived type members. (#113183)
The lower bound information for the array members of a derived type
can't be obtained from the `DeclareOp`. It has to be extracted from the
`TypeInfoOp`. That was left as FIXME in the code. This PR adds the
missing functionality to fix the issue.

I tried the following approaches before settling on the current one that
is to generate `DITypeAttr` for array members right where the components
are being processed.

1. Generate a temp XDeclareOp with the shift information obtained from
the `TypeInfoOp`. This caused a few issues mostly related to
`unrealized_conversion_cast`.

2. Change the shift operands in the `declOp` that was passed in the
function before calling `convertType`. The code can be seen in the
abcf031a8e5a02f0081e7f293858302e7bf47bec. It essentially looked like the
following. It works correctly but I was not sure if temporarily changing
the `declOp` is the safe thing to do.

```
mlir::OperandRange originalShift = declOp.getShift();
mlir::MutableOperandRange mutableOpRange = declOp.getShiftMutable();
mutableOpRange.assign(shiftOpers);
elemTy = convertType(fieldTy, fileAttr, scope, declOp);
mutableOpRange.assign(originalShift);
```

Fixes #113178.
2024-10-24 13:22:28 +01:00
Krzysztof Parzyszek
ea3534b385 [flang][OpenMP] Parse AFFINITY clause, lowering not supported yet (#113485)
Implement parsing of the AFFINITY clause on TASK construct, conversion
from the parser class to omp::Clause.
Lowering to HLFIR is unsupported, a TODO message is displayed.
2024-10-24 05:54:35 -05:00
Abid Qadeer
c07abf7272 [flang][debug] Support fir::ReferenceType. (#113480) 2024-10-24 11:38:17 +01:00
Valentin Clement (バレンタイン クレメン)
4e40b71c51 [flang][cuda] Add specialized gpu.launch_func conversion (#113493) 2024-10-23 15:28:51 -07:00
Valentin Clement (バレンタイン クレメン)
60105ac6ba [flang][cuda] Fix kernel registration (#113372)
The registration needs the fct pointer and the name. This patch updates
the entry point with an extra arg and the translation as well.
2024-10-23 11:25:58 -07:00
Krzysztof Parzyszek
973fa983af [flang][OpenMP] Parse iterators, add to MAP clause, TODO for lowering (#113167)
Define `OmpIteratorSpecifier` and `OmpIteratorModifier` parser classes,
and add parsing for them. Those are reusable between any clauses that
use iterator modifiers.

Add support for iterator modifiers to the MAP clause up to lowering,
where a TODO message is emitted.
2024-10-23 08:31:53 -05:00
jeanPerier
a59f712434 [flang][hlfir] do not consider local temps as conflicting in assignment (#113330)
Last patch required to avoid creating a temporary for the LHS when
dealing with `x([a,b]) = y`.

The code dealing with "ordered assignments" (where, forall, user and
vector subscripted assignments) is saving the evaluated RHS/LHS and
masks if they have write effects because this write effects should not
be evaluated when they affect entities that may be written to in other
contexts after the evaluation and before the re-evaluation.

But when dealing with write to storage allocated in the region for the
expression being evluated, there is no problem to re-evaluate the write:
it has no effect outside of the expression evaluation that owns the
allocation.

In the case of `x([a,b]) = y`, the temporary is created for the vector
subscript. Raising the HLFIR abstraction for simple array constructors
may be a good idea, but local temps are created in other contexts, so
this fix is more generic.
2024-10-23 12:34:13 +02:00
jeanPerier
d89c1dbaf5 [flang][hlfir] refine hlfir.assign side effects (#113319)
hlfir.assign currently has the `MemoryEffects<[MemWrite]` which makes it
look like it can write to anything. This is good for some cases where
the assign effect cannot be precisely described through the MLIR side
effect API (e.g., when the LHS is a descriptor and it is not possible to
get an OpOperand describing the data address, or when derived type are
involved and finalization could be called, or user defined assignment
for some components). For the most common case of hlfir.assign on
intrinsic types without whole allocatable LHS, this is pessimistic.

This patch implements a finer description of the side effects when
possible, and also adds the proper read/allocate/free effects when
relevant.

The ultimate goal is to suppress the generation of temporary for the LHS
address when dealing with an assignment to a vector subscripted LHS
where the vector subscript is an array constructor that does not refer
to the LHS (as in `x([a,b]) = y`).

Two more patches will follow to enable this.
2024-10-23 12:33:14 +02:00
NimishMishra
1cbc015551 [flang][OpenMP] Error out when CHARACTER type is used in atomic constructs (#113045)
According to OpenMPv5.2 1.2.6, "For Fortran, a scalar variable with
intrinsic type, as defined by the base language, excluding character
type.". Likewise, section 4.3.1.3 states that atomic operations are on
"scalar variables of intrinsic type". This PR hence introduces a check
to error out when CHARACTER type is used in atomic operations.

Fixes https://github.com/llvm/llvm-project/issues/112918
2024-10-22 19:29:21 -07:00
Krzysztof Parzyszek
a8d506b320 [flang][OpenMP] Rename enum OmpxHold to Ompx_Hold in parser (#113366)
The convention is to use enum names that match the source spelling (up
to upper/lower case), including names with underscores.

Remove the special case from unparser, update tests.
2024-10-22 16:24:17 -05:00
Renaud Kauffmann
f1e59dcb45 Renaming Cuf passes to CUF (#113351)
For consistency with other dialects and other CUF passes and files, this
patch renames passes CufOpConversion to CUFOpConversion,
CufImplicitDeviceGlobal to CUFDeviceGlobal.
It also renames the file.
2024-10-22 12:50:31 -07:00
Sergio Afonso
c44860c8d2 [Flang][OpenMP] Disable lowering of omp.simd reductions in composites (#112686)
Currently, the `omp.simd` operation is ignored during MLIR to LLVM IR
translation when it takes part in a composite construct. One consequence
of this limitation is that any entry block arguments defined by that
operation will trigger a compiler crash if they are used anywhere, as
they are not bound to an LLVM IR value.

A previous PR introducing support for the `reduction` clause resulted in
the creation and use of entry block arguments attached to the `omp.simd`
operation, causing compiler crashes on 'do simd reduction(...)'
constructs.

This patch disables Flang lowering of simd reductions in 'do simd'
constructs to avoid triggering these errors while translation to LLVM IR
is still incomplete.
2024-10-21 14:32:21 +01:00
Abid Qadeer
95b4128c6a [flang][debug] Don't generate debug for compiler-generated variables (#112423)
Flang generates many globals to handle derived types. There was a check
in debug info to filter them based on the information that their names
start with a period. This changed since PR#104859 where 'X' is being
used instead of '.'.

This PR fixes this issue by also adding 'X' in that list. As user
variables gets lower cased by the NameUniquer, there is no risk that
those will be filtered out. I added a test for that to be sure.
2024-10-21 11:27:34 +01:00
Thirumalai Shaktivel
9b49392d6e [Flang] Handle the source (scopes) for some OpenMP constructs (#109097)
Fixes: https://github.com/llvm/llvm-project/issues/82943
Fixes: https://github.com/llvm/llvm-project/issues/82942
Fixes: https://github.com/llvm/llvm-project/issues/85593
2024-10-21 13:07:48 +05:30
Pranav Bhandarkar
11dad2fa51 [flang][OpenMP] - Add MapInfoOp instances for target private variables when needed (#109862)
This PR adds an OpenMP dialect related pass for FIR/HLFIR which creates
`MapInfoOp` instances for certain privatized symbols. For example, if an
allocatable variable is used in a private clause attached to a
`omp.target` op, then the allocatable variable's descriptor will be
needed on the device (e.g. GPU). This descriptor needs to be separately
mapped onto the device. This pass creates the necessary `omp.map.info`
ops for this.
2024-10-20 01:01:39 -05:00
Valentin Clement (バレンタイン クレメン)
d37bc32a65 [flang][cuda] Translate cuf.register_kernel and cuf.register_module (#112972)
Add LLVM IR Translation for `cuf.register_module` and
`cuf.register_kernel`. These are lowered to function call to the CUF
runtime entries.
2024-10-18 21:31:47 -07:00
Valentin Clement (バレンタイン クレメン)
5406834cda [flang][cuda] Add cuf.register_module operation (#112971)
Add a new operation to register the fatbin and pass it to
`cuf.register_kernel`
2024-10-18 21:30:38 -07:00
Renaud Kauffmann
864902e9b4 [flang][cuda] Call CUFGetDeviceAddress to get global device address from host address (#112989) 2024-10-18 17:35:38 -07:00
Jay Foad
922992a22f Fix typo "instrinsic" (#112899) 2024-10-18 15:58:33 +01:00
Krzysztof Parzyszek
852e4779ba [flang][OpenMP] Add Id function to OmpClause to return clause id,… (#112712)
… NFC

This replaces the two instances of `GetClauseKindForParserClass` with a
localized member function.
2024-10-18 07:17:01 -05:00
Yusuke MINATO
9698e57548 [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (#110061)
This patch introduces the options for integer overflow flags into Flang.
The behavior is similar to that of Clang.
2024-10-18 16:30:23 +09:00
Scott Manley
e6a4346b5a [flang] add getElementType() to fir::SquenceType and fir::VectorType (#112770)
getElementType() was missing from Sequence and Vector types. Did a
replace of the obvious places getEleTy() was used for these two types
and updated to use this name instead.

Co-authored-by: Scott Manley <scmanley@nvidia.com>
2024-10-18 09:29:25 +02:00
Thirumalai Shaktivel
e6321d94de [Flang][Semantics] Add a semantic check for simd construct (#109089)
Add missing semantic check for the SAFELEN clause in the SIMD Order
construct
2024-10-18 10:13:49 +05:30
Thirumalai Shaktivel
252645528e [Flang][OpenMP] Add semantic checks for Worshare construct (#111358)
Add missing semantic checks for the Workshare construct:
OpenMP 5.2: 11.4 Workshare Construct
- The construct must not contain any user-defined function calls unless
either the function is pure and elemental or the function call is
contained inside a parallel construct that is nested inside the
workshare construct. (Flang-new used to check only the elemental function, 
but now it needs to be an impure elemental function)
- At most one NoWait clause can appear in the Workshare construct.
- Add tests for the same.
2024-10-18 10:11:59 +05:30
Valentin Clement (バレンタイン クレメン)
834d001e10 [flang][cuda] Relax the verifier for cuf.register_kernel op (#112585)
Relax the verifier since the `gpu.func` might be converted to
`llvm.func` before `cuf.register_kernel` is converted.
2024-10-17 08:30:13 -07:00
Leandro Lupori
a1ac5a57ae [flang] Allow OpenMP declarations before type declarations (#112414)
Skip resolving implicit types for OpenMP declarative directives, to
allow them to appear before type declarations, which is supported
by several compilers. This was discussed in

https://discourse.llvm.org/t/rfc-openmp-should-type-declaration-be-allowed-after-threadprivate/81345.

This fixes the semantic errors of
https://github.com/llvm/llvm-project/issues/106021.
2024-10-17 11:32:21 -03:00
jeanPerier
2f0b4f43fc [flang][extension] support concatenation with absent optional (#112678)
Fix #112593 by adding support in lowering to concatenation with an
absent optional _assumed length_ dummy argument because:
1. Most compilers seem to support it (most likely by accident).
2. This actually makes the compiler codegen simpler. Codegen was going
out of its way to poke the LLVM optimizer bear by producing an undef
argument for the length.

I insist on the fact that no compiler support this with _explicit
length_ optional arguments and the executable will segfault and I would
discourage users from using that "feature" because runtime checks for
bad optional dereference will kick when used (For instance, "nagfor
-C=present" will produce an executable that abort with an error message
. Flang does not have such runtime check option so far).

Hence, I am not updating the Extensions.md document because this is not
something I think we should advertise.
2024-10-17 13:25:09 +02:00
David Truby
91b5bef358 [flang] Tighten requirements on some glibc float128 functions (#110651)
j0l, j1l, jnl, y0l, y1l and ynl are glibc extensions rather than
standard POSIX functions, and so are not available in every Linux libc.
This patch checks if `__GLIBC__` and `_GNU_SOURCE` are defined before
using
these functions.

This patch allows the float128 runtime to build with musl libc on Linux.
2024-10-16 14:49:30 +01:00
Sergio Afonso
15d85769f1 [Flang][OpenMP] Support lowering of simd reductions (#112194)
This patch enables lowering to MLIR of the reduction clause of `simd`
constructs. Lowering from MLIR to LLVM IR remains unimplemented, so at
that stage it will result in errors being emitted rather than silently
ignoring it as it is currently done.

On composite `do simd` constructs, this lowering error will remain
untriggered, as the `omp.simd` operation in that case is currently
ignored. The MLIR representation, however, will now contain `reduction`
information.
2024-10-16 10:27:50 +01:00
Peter Klausler
7cbb365903 [flang] Fix broken shared library build (#112444)
I just introduced a dependency from the Evaluate library to the
Semantics library, which is circular in a shared library build.
Rearrange the code a little to ensure that the dependence is only on a
header.
2024-10-15 15:11:25 -07:00
Peter Klausler
9fb2db1e1f [flang] Retain spaces when preprocessing fixed-form source (#112417)
When running fixed-form source through the compiler under -E, don't
aggressively remove space characters, since the parser won't be parsing
the result and some tools might need to see the spaces in the -E
preprocessed output.

Fixes https://github.com/llvm/llvm-project/issues/112279.
2024-10-15 14:23:45 -07:00
Peter Klausler
38b9dd7a7f [flang] Fold ERFC_SCALED (#112287)
Move the ErfcScaled template function from the runtime into a new header
file in flang/include/Common, then use it in constant folding to
implement folding for the erfc_scaled() intrinsic function.
2024-10-15 14:23:15 -07:00