3292 Commits

Author SHA1 Message Date
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
Victor Kingi
f04ccadf35 [Flang] Add support for fsave-optimization-record
Add support for generating and saving the optimization record.
Optimization record lists the optimizations performed by LLVM.

This patch enables the flag in Flang. Clang handles this functionality
using the BackendConsumer which Flang doesn't have, hence, was
implemented in CodeGenAction::executeAction

FlangOption added to all variants of fsave-optimization-record in
clang/include/clang/Driver/Options.td . Clang handles it the
same way.

opt_record_file, opt_record_passes and opt_record_format flags
in Options.td were moved out of the group [CC1Option, NoDriverOption]
to allow flang -fc1 support.

The renderRemarksOptions and willEmitRemarks functions in
clang/lib/Driver/ToolChains/Flang.cpp follow same syntax as clang.
In flang/lib/Frontend/CompilerInvocation.cpp we update the field
OptRecordFile with the provided optimization file value. Clang
doesn't do this as it processes the Options.td, mapping the
OptRecordFile earlier on.

Reviewed By: awarzynski, tblah

Differential Revision: https://reviews.llvm.org/D155452
2023-07-28 09:26:40 +00:00
Slava Zakharin
fb7366cab1 [flang] Fixed shape computation for elementals with optional dummys.
It looks like a regression after D151737: shape of the elemental
call became rank-0.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D156386
2023-07-27 13:56:13 -07:00
Valentin Clement
a2b92017d3
[flang][openacc] Lower acc declare link for module variable
This patch adds support to lower the link clause on OpenACC
declare construct in module declaration.

Depends on D156463

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156464
2023-07-27 13:04:00 -07:00
Valentin Clement
bbd214d997
[flang][openacc] Lower acc declare device_resident for module variable
This patch adds support to lower the device_resident clause on OpenACC
declare construct in module declaration.

Depends on D156457

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156463
2023-07-27 13:01:22 -07:00
Valentin Clement
5f2c585b10
[flang][openacc] Lower acc declare copyin for module variable
This patch adds support to lower the copyin clause on OpenACC
declare construct in module declaration.

Depends on D156353

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156457
2023-07-27 13:00:20 -07:00
Valentin Clement
e25d7f1688
[flang][openacc] Add global destructor for acc declare construct
Add the acc.global_dtor when lowering the OpenACC declare
construct.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156353
2023-07-27 12:59:01 -07:00
Kelvin Li
2c2d427ca3 [flang] Add a subset of PowerPC MMA (Matrix Multiply Accelerate) intrinsics
This patch includes the a subset of MMA intrinsics that are included in
the mma intrinsic module:

mma_assemble_acc
mma_assemble_pair
mma_build_acc
mma_disassemble_acc
mma_disassemble_pair

Submit on behalf of Daniel Chen <cdchen@ca.ibm.com>

Differential Revision: https://reviews.llvm.org/D155725
2023-07-27 14:30:06 -04:00
Valentin Clement
c217ff8794
[flang][openacc] Add basic lowering for OpenACC declare construct in module
This patch adds the skeleton and the basic lowering for OpenACC declare
construct when located in the module declaration. This patch just lower the
create clause with or without modifier. Other clause and global descrutor
lowering will come in follow up patches to keep this one small enough for
review.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156266
2023-07-26 09:56:19 -07:00
V Donaldson
7ba2ac2828 [flang] test update 2023-07-25 11:27:51 -07:00
V Donaldson
f1ada999e2 [flang] build test failure 2023-07-25 11:08:34 -07:00
V Donaldson
ba531a55c6 [flang] Implement procedure IEEE_COPY_SIGN with mlir::math::CopySignOp 2023-07-25 10:52:48 -07:00
Kelvin Li
447c3a358d [flang] Add PowerPC vec_abs, vec_nmadd, vec_msub and vec_sel intrinsics
Co-authored-by: Paul Scoropan <1paulscoropan@gmail.com>

Differential Revision: https://reviews.llvm.org/D154985
2023-07-24 14:03:50 -04:00
Slava Zakharin
60f02aa7f7 [flang][hlfir] Fixed KindMapping for HLFIR intrinsics lowering.
hlfir.count lowering was using incorrect default integer kind
by ignoring the kind specified in the ModuleOp.

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D156017
2023-07-24 10:12:39 -07:00
Slava Zakharin
3eedff3c04 [flang][hlfir] Inherit constant length for the result of hlfir.transpose.
Character length may be unknown for the type of Fortran::evaluate::FunctionRef
expression, but we can try to propagate it from the argument of
TRANSPOSE if it is known constant. Alternatively, we could relax
hlfir.transpose verification (i.e. allow character types mismatch
for the argument and the result).

Depends on D155912

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D155913
2023-07-24 10:12:39 -07:00
Valentin Clement
be5ac66643
[flang][openacc] Keep original array size in reduction init region with slice
Keep the original array size when materializing the private copy.

Depends on D155882

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D155893
2023-07-24 09:34:31 -07:00
Valentin Clement
9d8e4759a8
[flang][openacc] Update materialization recipe for private copy in reduction init region
Update the code generated in the init region to materialize the private
copy.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D155882
2023-07-24 09:33:39 -07:00