3308 Commits

Author SHA1 Message Date
Tom Eccles
4492ec775c Revert "[flang] support (hl)fir.declare in alias analysis"
Reverting because of buildbot failure

This reverts commit c732a452ea15d4b7b682b35a72f78c1cdc13f60b.
2023-08-08 10:11:23 +00:00
Tom Eccles
c732a452ea [flang] support (hl)fir.declare in alias analysis
Differential Revision: https://reviews.llvm.org/D157106
2023-08-08 09:44:06 +00:00
Valentin Clement
5cb48f7543
[flang][openacc] Add lowering support for device_resident clause on OpenACC declare
Depends on D156828

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156829
2023-08-07 10:16:32 -07:00
Valentin Clement
a749b32a11
[flang][openacc] Support readonly modifier for declare copyin in module file
Distinguish between copyin and copyin with the readonly modifier.

Depends on D157121

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157125
2023-08-07 09:53:09 -07:00
Kelvin Li
00769d69fb [flang] Add -fppc-native-vector-element-order option to control the element order in PowerPC vector types
This patch also adds a LIT test for the vec_cvf intrinsic that
can be affected by the option.

Co-authored-by: Mark Danial <Mark.Danial@ibm.com>
Co-authored-by: Daniel Chen <cdchen@ca.ibm.com>

Differential Revision: https://reviews.llvm.org/D155852
2023-08-04 17:11:30 -04:00
Valentin Clement
22f63b5c73
[flang][openacc] Retain the declare information in module file declaration
F18 produce a module file with a declaration part. This patch
propagates the OpenACC declare information in the module file along the variable
declaration.

Depends on D157042

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157121
2023-08-04 14:03:16 -07:00
Valentin Clement
ebf5f37130
[flang][openacc] Make sure the correct flags are set for symbol in acc declare
Flags were not correctly set for symbols appearing in the OpenACC declare
directive in module declaration part.

Also some missing flags for OpenACC are added. This makes the Flags enum
> 64 and then the implementation switch to std::bitset as defined in
`flang/include/flang/Common/enum-set.h`. Therefore, `constexpr` cannot be
used for set of flags in `flang/lib/Semantics/resolve-directives.cpp`.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157042
2023-08-04 13:08:47 -07:00
Slava Zakharin
7095a86fc3 [flang][hlfir] Fixed where/elsewhere mask saving in case of conflicts.
The assignments inside where/elsewhere may affect variables participating
in the mask expression, but execution of the assignments must not affect
the established control mask(s) (F'18 10.2.3.2 p. 13).

The following example must print all 42's:
```
program test
  integer c(3)
  logical :: mask(3) = .true.
  where (mask)
     c = f()
  end where
  print *, c
contains
  integer function f()
    mask = .false.
    f = 42
  end function f
end program test
```

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D156959
2023-08-04 09:19:43 -07:00
Sergio Afonso
65e80d6dfd
[Flang][OpenMP] Improve support for if clause on combined constructs
This patch adds support for matching multiple OpenMP `if` clauses to their
specified directive in a combined construct. It also enables this clause to be
attached by name to `simd` and `teams` directives, in addition to the others
that were already supported.

This patch on its own cannot yet be tested because there is currently no
lowering to MLIR support for any combined construct containing two or more
OpenMP directives that can have an `if` clause attached.

Depends on D155981.

Differential Revision: https://reviews.llvm.org/D156313
2023-08-04 10:43:12 +01:00
Raghu Maddhipatla
71d763b88d [OpenMP] [Semantics] [Flang] Adding more semantic checks for USE_DEVICE_PTR and USE_DEVICE_ADDR clauses.
The following restrictions for USE_DEVICE_PTR and USE_DEVICE_ADDR clauses on OMP TARGET DATA directive are implemented in this patch.

  - A list item may not be specified more than once in use_device_ptr clauses that appear on the directive.
  - A list item may not be specified more than once in use_device_addr clauses that appear on the directive.
  - A list item may not be specified in both a use_device_addr clause and a use_device_ptr clause on the directive.
  - A list item that appears in a use_device_ptr or use_device_addr clause must not be a structure element.
  - A list item that appears in a use_device_ptr must be of type C_PTR.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D155133
2023-08-04 00:19:36 -05:00
Zhen Wang
c5abddbf29 Enable CUDA Fortran for bbc 2023-08-03 14:04:03 -07:00
Kiran Chandramohan
93b0d0f6b5 [Flang][OpenMP] Add TODO message for copyprivate clause
The copyprivate clause is not yet implemented. Provide a TODO
error message when this clause is seen.

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D155596
2023-08-03 18:51:27 +00:00
Valentin Clement
b82c259370
[flang][openacc] Add lowering support for the link clause on OpenACC declare
Lower link clause with data entry operation.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156913
2023-08-03 10:22:32 -07:00
Kiran Chandramohan
067ecad620 [Flang][OpenMP] Convert elementTypeAttr for AtomicRead Op
Convert the elementTypeAttr of AtomicRead Op for LLVMConversion.
This is required when the elementType is non-integer, non-real.

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D155817
2023-08-03 11:49:26 +00:00
Valentin Clement
c988e78f8e
[flang][openacc] Enforce restriction on declare directive
Enforce the following restriction specified in 2.13
A var may appear at most once in all the clauses of declare directives for a
function, subroutine, program, or module.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156945
2023-08-02 21:27:00 -07:00
Valentin Clement
07000998e4
[flang][openacc] Add lowering support for deviceptr clause on OpenACC declare
Lower the deviceptr clause for the OpenACC declare directive.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156828
2023-08-02 21:04:21 -07:00
Valentin Clement
34e53bf1cb
[flang][openacc] Add lowering support for copyout clause on OpenACC declare
Lower the copyout clause for the OpenACC declare directive

Depends on D156738

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156824
2023-08-02 15:54:49 -07:00
Valentin Clement
b1f3667a60
[flang][openacc] Disallow the zero modifier on the copyout clause with the declare directive
The OpenACC 3.3 specification does not allow the `zero` modifier
on the `copyout` clause used with the declare directive.

This is similar to D156703 for the create clause.

This might be missing piece in the spec but we disallow it until proven otherwise.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156825
2023-08-02 15:52:14 -07:00
Justin Bogner
7ef1718c4d [Driver] Don't try to spell check unsupported options
We currently spell check options that are listed as unsupported, but
this doesn't make much sense. If an option is explicitly unsupported
why would one that's spelled similarly be useful?

It looks like the reason this was added was that we explicitly mark
all `--something` flags as Unsupported rather than just leaving them
undefined and treating them as unknown. Drop that handling so that we
don't regress on things like misspelling `--help`.

Differential Revision: https://reviews.llvm.org/D156925
2023-08-02 14:23:14 -07:00
Ethan Luis McDonough
7f0d54b429
[flang][openmp] Allocators construct semantic checks
This patch applies the semantic checks for executable allocation directives to the new allocators construct.  It also introduces a new check that ensures all items in the list appear in the corresponding Fortran allocate statement.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D150428
2023-08-02 12:59:06 -05:00
Slava Zakharin
315939fd61 [flang] Fixed slice offset computation in XEmbox codegen.
For character type with unknown length we end up generating
a GEP with the base type `llvm.ptr<i[width]>`. The GEP produces
the address of the first element of the slice, and it should be
using the offset computed in the number of characters, while we were
providing the offset in bytes.

Simple reproducer fails with and w/o HLFIR:
```
program test
  integer,parameter :: ck = 4
  character(:,ck),allocatable :: res(:,:)
  allocate(character(3,ck) :: res(2,2))
  res(1,1) = ck_'111'
  res(1,2) = ck_'222'
  res(2,1) = ck_'333'
  res(2,2) = ck_'444'
  call check(res)
contains
  subroutine check(res)
    character(:,ck),allocatable :: res(:,:)
    print *, res(2,:)
  end subroutine check
end program test
```

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D156849
2023-08-02 10:45:00 -07:00
Slava Zakharin
449823e202 [flang] Fixed IsContiguous check for slices of parameter arrays.
A section of a parameter array may be non-contiguous,
so the current !IsVariable(expr) check is too optimistic
to claim contiguity.

This patch fixes issues with incorrect hlfir.designate op generated
during lowering: the lowering queries IsContiguous to decide whether
to use fir.box<fir.array> or plain fir.ref<fir.array> to represent
the designator result.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D156494
2023-08-02 10:45:00 -07:00
Krzysztof Drewniak
7c349c3698 [mlir][Arith] Add arith.is_nan and arith.is_inf predicates
Both LLVM and SPIR-V have some form of "is this float a NaN/Inf"
operation (though LLVM's uses the rather opaque "is.fpclass"
intrinsic), which is not exposed in MLIR.

This has lead to awkward workarounds in -arith-expands-ops where a NaN
test was performed by comparing an operation to itself. This commit
resolves that issue.

Reviewed By: dcaballe, kuhar

Differential Revision: https://reviews.llvm.org/D156169
2023-08-02 14:42:25 +00:00
Leandro Lupori
5bbfbd9a1c [flang][OpenMP] Fix parallel do with integer*1 var
Temporaries created to store worksharing loop index values were
using different types than that of the original index variables.
This caused invalid IR to be produced when an index variable was
used in binary operations which expected its original type.

Fix this by creating temporaries with the types of their original
variables and converting the loop values, that continue to use
the types that OpenMP runtime expects, to them.

Fixes https://github.com/llvm/llvm-project/issues/60870

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D156803
2023-08-02 10:16:16 -03:00
Kiran Chandramohan
2f0047aad1 [MLIR][OpenMP] Allow map operands to be not specified
This patch permits map operands to be not specified for the target
data operation. Also emit an error if none of the map, use_device_addr,
or use_device_ptr operands are specified.

Reviewed By: TIFitis

Differential Revision: https://reviews.llvm.org/D156170
2023-08-02 12:04:36 +00:00
Valentin Clement
0058c92609
[flang][openacc] Add lowering support for copyin clause on OpenACC declare
Depends on D156721

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156738
2023-08-01 14:15:38 -07:00
Valentin Clement
392203d8ac
[flang][openacc] Add lowering support for present clause on OpenACC declare
Lower the present clause on the OpenACC declare construct in
function/subroutine.

Depends on D156572

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156721
2023-08-01 14:14:48 -07:00
Valentin Clement
29851f48fa
[flang][openacc] Add lowering support for create clause on OpenACC declare
Lower the create clause on the OpenACC declare construct in
function/subroutine.

Depends on D156568

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156572
2023-08-01 14:12:40 -07:00
Valentin Clement
14741ef88f
[flang][openacc] Lower the exit part for OpenACC declare in function/subroutine
This patch adds lowering for the exit part of the OpenACC declare construct
in function/subroutine.

Depends on D156560

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156568
2023-08-01 14:10:33 -07:00
Valentin Clement
ba2082cdff
[flang][openacc] Lower the entry part for OpenACC declare in function/subroutine
This patch adds lowering for the entry part of the OpenACC declare construct
in function/subroutine. The exit part will come as a follow up patch.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156560
2023-08-01 14:04:30 -07:00
Peter Klausler
b21c24c308
[flang][runtime] Recognize and handle FINAL subroutines with contiguous dummy arrays when data are not so
When a FINAL subroutine is being invoked for a discontiguous array, which can
happen for INTENT(OUT) dummy arguments and for some left-hand side variables
in intrinsic assignment statements, it may be the case that the subroutine
being called was defined with a dummy argument that requires contiguous data.

Extend the derived type descriptions used by the runtime to signify when
a special procedure binding requires contiguity; set the flags accordingly;
check them in the runtime support library, and, when necessary, use a
temporary shallow copy of the finalized array data in the call to the
final subroutine.

Differential Revision: https://reviews.llvm.org/D156760
2023-08-01 13:46:45 -07:00
Peter Klausler
5718a4256b
[flang] Catch insufficient actual elements/characters associated with longer dummy argument
Check for cases of storage sequence association in which an element or
substring is an actual argument associated with a dummy argument array
that can be detected as being larger than the remaining elements or characters
in the actual argument's storage sequence.

Differential Revision: https://reviews.llvm.org/D156757
2023-08-01 13:31:45 -07:00
Fangrui Song
f39c399d9d [Driver] -###: exit with code 1 if hasErrorOccurred
The exit code for -### is inconsistent. Unrecognized options lead to
exit code 1, as expected. However, most others errors (including invalid
option value) lead to exit code 0, differing from GCC and most utilities.

This is a longstanding quirk of -###, and we didn't fix it because many
driver tests need adjustment.

Change -### to be similar to -fdriver-only -v and exit with code 1.

This requires fixing many driver tests, but the end result gives us
stronger tests.

* Existing `RUN: %clang -### ...` tests usually don't use `CHECK-NOT: error:` or `--implicit-check-not=error:`.
  If a change introduces an error, such a change usually cannot be detected.
* Many folks contributing new tests don't know `-fdriver-only -v`.
  To test no driver error/warning for new tests, they can use the familiar `-### -Werror`
  instead of `-fdriver-only -v -Werror`.

An incomplete list of prerequisite test improvement:

* 2f79bb10461d114783a1548201928549ace09755: add -nogpulib to some AMDGPU tests
* 9155e517e6e1cda474d0d0fa82f71696c325bc10: add --cuda-path= (test w/ and w/o /usr/local/cuda)
* 80765ede5bbcca1364c2d4ae06127011eaba6389: -mcpu=native may return either 0 or 1, depending on whether `--target=` specifies a native target
* abae53f43f0d1da8d8e421f4a628d7ec64d6e365: fix -fuse-ld=lld misuses (test w/o and w/o /usr/local/bin/ld.lld)
* ab68df505e5bb8808ee44f53044b50ca7575098e: add -resource-dir= and -fvisibility=hidden
 to some -fsanitize=cfi tests
* d5ca1602f64114f612ad5630f04e4aa90591c78d: --rtlib=platform without --unwindlib= may fail if CLANG_DEFAULT_UNWINDLIB=unwindlib

Reviewed By: jhuber6, yaxunl, dblaikie

Differential Revision: https://reviews.llvm.org/D156363
2023-08-01 13:23:51 -07:00
Peter Klausler
2734f15437
[flang][openmp] Handle !$INCLUDE "foo" (bug #64128)
Detect and process INCLUDE lines that are guarded by OpenMP conditional
compilation markers (!$), when enabled.

Fixes https://github.com/llvm/llvm-project/issues/64128.

Differential Revision: https://reviews.llvm.org/D156759
2023-08-01 11:35:23 -07:00
Peter Klausler
f9fdd4fdba
[flang] Don't emit false errors on LBOUND/UBOUND of assumed-rank arrays
Folding of LBOUND/UBOUND on assumed-rank arrays could lead to bogus errors
later.  This is a regression from a recent change intended to ensure that
patently bad DIM= arguments were caught even in the case of assumed-rank.
Rearrange the order of checks so that those bad DIM= argument values are
caught but otherwise defer LBOUND/UBOUND of assumed-rank arguments to
run time.  (It was tempting to always fold LBOUND(ar,DIM=n) to 1, but
that would obscure the run time error required when 'n' is out of bounds,
including the case of a scalar 'ar'.)

Differential Revision: https://reviews.llvm.org/D156755
2023-08-01 11:02:58 -07:00
Anton Rydahl
2301e13269 [Clang][Frontend] Change help text for --offload-host-device
I believe the help text for the flag `--offload-host-device` is wrong. Currently, the help text says "Only compile for the offloading host." but the flag alias with `--cuda-compile-host-device` which
has the help text "Compile CUDA code for both host and device (default). Has no effect on non-CUDA compilations."

Fixes https://github.com/llvm/llvm-project/issues/64243

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D156641
2023-08-01 10:24:09 -07:00
Peter Klausler
16c4b320fe
[flang] Correct handling of non-default lower bounds in ASSOCIATE with named constants
Work through several issues with LBOUND() and UBOUND() of ASSOCIATE
construct entities that have been associated with named constants or
subobjects of named constants that are sporting non-default lower bounds.
Sometimes the non-default lower bounds matter, sometimes they don't.
Add a fairly exhaustive test to work through the possibilities.

Differential Revision: https://reviews.llvm.org/D156756
2023-08-01 09:54:31 -07:00
Peter Klausler
4f1eec1fc6
[flang] Fix crash in folding of DPROD() with non-scalar arguments
DPROD(x,y) is defined as DBLE(x)*DBLE(y) and that's exactly how
the implementation of its rewriting and possible folding should
be implemented, instead of the current code that only works when
both arguments are scalar and crashes otherwise.

Fixes https://github.com/llvm/llvm-project/issues/63991.

Differential Revision: https://reviews.llvm.org/D156754
2023-08-01 09:26:34 -07:00
Peter Klausler
9c446da556
[flang] More compile-time error checking for null implied DO loops in array constructors
An implied DO loop in an array constructor may not have a type (explicit
or otherwise) with a character length that depends on a value of an
implied DO index or a non-constant expression if the implied DO loop
executes no iterations.  When the iteration count can be known to be
zero at compilation time, catch the case of a non-constant length
expression correctly.

Differential Revision: https://reviews.llvm.org/D156753
2023-08-01 09:05:41 -07:00
Kiran Chandramohan
980808dc5b [Flang][OpenMP] Fix loop index privatisation with HLFIR
Loop index variables are privatised for a worksharing loop.
The alloca ops of the privatised index are hoisted to the
entry block of the outlineable region or parent function.
With HLFIR, the hlfir.declare should be created in the same
place as the alloca op. To achieve this the alloc and the
hflir.declare should be created in the same place. A new
function is created in OpenMP.cpp for this purpose.

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D156719
2023-08-01 14:45:52 +00:00
Valentin Clement
887b69c1f1
[flang][openacc] Disallow the zero modifier on the create clause with the declare directive
The OpenACC 3.3 specification does not allow the `zero` modifier
on the `create` clause used with the declare directive.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156703
2023-07-31 14:29:56 -07:00
Peter Klausler
6fac3f7b2e
[flang] Stricter "implicit continuation" in preprocessing
The prescanner performs implicit line continuation when it looks
like the parenthesized arguments of a call to a function-like macro
may span multiple lines.  In an attempt to work more like a
Fortran-oblivious C preprocessor, the prescanner will act as if
the following lines had been continuations so that the function-like
macro could be invoked.

This still seems like a good idea, but a recent bug report on
LLVM's GitHub issue tracker shows one way in which it could trigger
inadvertently and mess up a program.  So this patch makes the
conditions for implicit line continuation much more strict.

First, the leading parenthesis has to have been preceded by an
identifier that's known to be a macro name.  (It doesn't have to
be a function-like macro, since it's possible for a keyword-like
macro to expand to the name of a function-like macro.)  Second,
no macro definition can ever have had unbalanced parentheses in
its replacement text.

Also cleans up some parenthesis recognition code to fix some
issues found in testing, so that a token with leading or trailing
spaces can still be recognized as a parenthesis or comma.

Fixes https://github.com/llvm/llvm-project/issues/63844.

Differential Revision: https://reviews.llvm.org/D155499
2023-07-31 14:22:43 -07:00
cabreraam
a033bf242f [flang][hlfir] work towards handling char_convert in hlfir
This patch aims to address the TODO for handling character conversion in HLFIR found [here](1defa78124/flang/lib/Lower/ConvertExprToHLFIR.cpp (L1388)) using [this similar operation but for FIR as inspiration](3ea673a97b/flang/lib/Lower/ConvertExpr.cpp (L1212-L1271)).

Reviewed By: vzakhari, tblah

Differential Revision: https://reviews.llvm.org/D155650
2023-07-31 10:45:10 -04:00
Nimish Mishra
f752265231 [flang][OpenMP] Support for privatization in common block
This patch provides support for usage of common block
in private/firstprivate and lastprivate clauses.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D156120
2023-07-31 16:46:18 +05:30
Peixin Qiao
b4c54b2027 [flang][OpenMP] Support common block in OpenMP private clause
This supports the common block in OpenMP privat clause by making
each common block member host-associated privatization and
adds the test case.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D127215
2023-07-31 16:24:12 +05:30
Fangrui Song
beb89e7fc0 Revert "[flang][test] Update %flang tests after D156363"
This reverts commit 7141c5b113a0c4e06aed3451ec83e984b1cb2f18
after the base commit D156363 was reverted.
2023-07-30 20:16:56 -07:00
Fangrui Song
7141c5b113 [flang][test] Update %flang tests after D156363 2023-07-29 20:37:39 -07:00
Valentin Clement
b5f7852c22
[flang][openacc] Fix acc-declare test 2023-07-28 10:17:28 -07:00
Valentin Clement
27f39ad499
[flang][openacc] Set structured to false for entry operation in declare ctor
Fix the value of the structured attribute for entry operation in the
global constructor noted in D156353.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156481
2023-07-28 09:48:14 -07:00
Andrzej Warzynski
e88ff8a79b [flang][nfc] Simplify option forwarding
Use `AddAllArgs` to keep the implementation succinct. Also adds missing
'-flang-experimental-hlfir` in "frontend-forwarding.f90"

Differential Revision: https://reviews.llvm.org/D156524
2023-07-28 14:23:58 +00:00