Commit Graph

4272 Commits

Author SHA1 Message Date
PeixinQiao fbdcb3ce6b [flang] Add one semantic check for allocatable/pointer argument association
The actual argument shall have deferred the same type parameters as
the dummy argument if the argument is allocatable or pointer variable.
Currently programs not following this get one crash during execution.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D122779
2022-04-04 23:16:30 +08:00
Andrzej Warzynski 03efa5a362 [flang] Update the conversion code for fir.coordinate_of
These are mostly small changes to make the code a bit clearer and more
consistent. Summary of changes:
  * add missing namespace qualifiers (that's the preference in Flang)
  * replace const member methods with static methods (to avoid passing
    the *this pointer unnecessarily)
  * rename `currentObjTy` (current object type) as `cpnTy` (component
    type) - the latter feels more fitting
  * remove redundant `return failure();` calls (` return
    mlir::emitError` gives the same result)
  * updated a few comments

Differential Revision: https://reviews.llvm.org/D122799
2022-04-04 10:15:14 +00:00
Valentin Clement d333b38270
[flang][NFC] Add tests for array-value-copy pass with array with pointers
This patch adds tests for the array-value-copy pass with array assignment
involving Fortran pointers.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D122878
2022-04-04 10:45:45 +02:00
Jean Perier b8e8f62d5e [flang] Fold instantiated PDT character component length when needed
In case a character component PDT length only depends on kind parameters,
fold it while instantiating the PDT. This is especially important if the
component has an initializer because later semantic phases (offset
computation or runtime type info generation) might get confused and
generate offset/type info that will lead to crashes in lowering.

Differential Revision: https://reviews.llvm.org/D122938
2022-04-04 09:47:15 +02:00
Valentin Clement 7dc492ed34
[flang][NFC] Add tests for fir.address_of
This patch adds FIR to LLVM test for fir.address_of.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D122889

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-04-04 09:28:44 +02:00
Kiran Chandramohan 0000030b18 Revert "[Flang][OpenMP] Add semantic check for OpenMP Private, Firstprivate and Lastprivate clauses."
This reverts commit a2ca6bbda6.

D93213 performs some checks to ensure that variables that appear in
statement functions are not in privatisation clauses. The point at
which this check is currently performed, there can be misparses that
cause more constructs to be identified as statement functions. This
can lead to various kinds of errors, hence reverting.

This revert hopefully fixes:
https://github.com/llvm/llvm-project/issues/54477
https://github.com/llvm/llvm-project/issues/54161
https://github.com/llvm/llvm-project/issues/54163

Reviewed By: shraiysh

Differential Revision: https://reviews.llvm.org/D122650
2022-04-03 15:54:02 +00:00
Valentin Clement 3bcc928b1b
[flang][NFC] Add tests for fir.array_modify in array-value-copy pass
This patch adds some test for the `fir.array_modify` operation
in the array-value-copy pass

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D122809

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-04-03 15:26:14 +02:00
Valentin Clement 0371f3e232
[flang][NFC] Add more test cases for the array-value-copy pass
This patch adds some test cases for the array-value-copy pass with slices.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D122807

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-04-03 15:25:10 +02:00
Valentin Clement 602dd6bd32
[flang][NFC] Add tests for fir.is_present
This patch adds tests for the `fir.is_present`
translation.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D122813

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-04-03 15:22:33 +02:00
Valentin Clement e0c782bdc0
[flang] Add global and global box initialization tests
This patch addes some global initialization and global
box initialization tests.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D122881

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-04-03 15:20:55 +02:00
Valentin Clement 2fb57d628c
[flang][NFC] Add tests for select constructs
Add tests for fir.select_rank and
fir.select_case.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D122888

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-04-03 15:18:57 +02:00
Jean Perier 7c158e3e55 [flang] add evaluate::IsAllocatableDesignator helper
Previously, some semantic checks that are checking if an entity is an
allocatable were relying on the expression being a designator whose
last symbol has the allocatable attribute.

This is wrong since this was considering substrings and array sections of
allocatables as being allocatable. This is wrong (see NOTE 2 in
Fortran 2018 section 9.5.3.1).

Add evaluate::IsAllocatableDesignator to correctly test this.
Also add some semantic tests for ALLOCATED to test the newly added helper.
Note that ifort and nag are rejecting coindexed-named-object in
ALLOCATED (`allocated(coarray_scalar_alloc[2])`).
I think it is wrong given allocated argument is intent(in) as per
16.2.1 point 3.
So 15.5.2.6 point 4 regarding allocatable dummy is not violated (If the actual
argument is a coindexed object, the dummy argument shall have the INTENT (IN)
attribute.) and I think this is valid. gfortran accepts it.

The need for this helper was exposed in https://reviews.llvm.org/D122779.

Differential Revision: https://reviews.llvm.org/D122899

Co-authored-by: Peixin-Qiao <qiaopeixin@huawei.com>
2022-04-01 22:34:19 +02:00
Mehdi Amini ba43d6f85c Revert "[GreedPatternRewriter] Preprocess constants while building worklist when not processing top down"
This reverts commit 59bbc7a085.

This exposes an issue breaking the contract of
`applyPatternsAndFoldGreedily` where we "converge" without applying
remaining patterns.
2022-04-01 06:16:55 +00:00
Valentin Clement 868c212f42
[flang] Keep fully qualified !fir.heap type for fir.freemem op
Re-introduce a fully qualified type on teh fir.freemem operation.
Since this is the only operation where the prefix gets elided in fir, this
patch make it fully qualified so the dialect syntax feels more consistent.

Reviewed By: vdonaldson

Differential Revision: https://reviews.llvm.org/D122839
2022-03-31 21:37:21 +02:00
River Riddle 59bbc7a085 [GreedPatternRewriter] Preprocess constants while building worklist when not processing top down
This avoids accidentally reversing the order of constants during successive
application, e.g. when running the canonicalizer. This helps reduce the number
of iterations, and also avoids unnecessary changes to input IR.

Fixes #51892

Differential Revision: https://reviews.llvm.org/D122692
2022-03-31 12:08:55 -07:00
Jean Perier 88d4b85f59 [flang] Allow user to recover from bad edit descriptor with INTEGER
Runtime was crashing when an INTEGER passed in formatted output with
a bad edit descriptor even when the user did provide IOSTAT. Flang
is already signaling an error when facing similar error with other
types. Do the same with INTEGERs.

The input case is already signaling an error in the related input error
case.

Differential Revision: https://reviews.llvm.org/D122749
2022-03-31 10:57:13 +02:00
Jean Perier 14c7754a35 [flang] Skip `D` when including D debug line
When including debug lines as code, the `D` should be considered as
a white space. Currently an error was raised about bad labels because
it the `D` remained a `D` when considering the source line as code.

Differential Revision: https://reviews.llvm.org/D122711
2022-03-31 10:56:25 +02:00
V Donaldson 09b1a6d673 [flang] Correct a typo when parsing format token white space
A format such as "( D   C, X6. 2  )" is parsed the same as "(DC,X6.2)".
2022-03-30 18:56:09 -07:00
serge-sans-paille c531171d99 Fix invalid overflow check in flang
Statically checking for overflow with

    if constexpr (sizeof(std::size_t) <= sizeof(std::int64_t)) {
         return static_cast<std::int64_t>(length);
    }

Doesn't work if `sizeof(std::size_t) == sizeof(std::int64_t)` because std::size_t
is unsigned.

if `length == std::numeric_limits<size_t>` casting it to `int64_t` is going to overflow.

This code would be much simpler if returning a `uint64_t` instead of a signed
value...

Differential Revision: https://reviews.llvm.org/D122705
2022-03-30 16:47:33 +02:00
Jean Perier ec13942e71 [flang] prevent undefined behavior in character MAXLOC folding
When folding MAXLOC/MINLOC, the current element being compared was moved twice
in row in case it became the new extremum. With numeric and logical types, it
made no difference (std::move is a no-op for them), but for characters
where the string storage is actually moved, it caused the new extremum to
be set to the empty string, leading to wrong results.

Note: I could have left the first std::move relating to logical Findloc, but it
brings nothing and makes the code less auditable, so I also removed it.

Differential Revision: https://reviews.llvm.org/D122590
2022-03-29 09:34:09 +02:00
Shraiysh Vaishay 1fe4b968c5 [flang][OpenMP] Added parallel sections translation
This patch adds translation for parallel sections from PFT to MLIR.

Reviewed By: kiranchandramohan, NimishMishra

Differential Revision: https://reviews.llvm.org/D122464
2022-03-29 11:16:38 +05:30
Emil Kieri 577827cbbf [flang][driver] Make --version and -version consistent with clang
This patch makes -version valid, and --version invalid, for
flang-new -fc1. The invocation
  flang-new --version
remains valid. This behaviour is consistent with clang
(and with clang -cc1 and clang -cc1as).

Previously, flang-new -fc1 accepted --version (as per Options.td), but
the frontend driver acutally checks for -version. As a result,
  flang-new -fc1 --version
triggered no action, emitted no message, and stalled waiting for
standard input.

Fixes #51438

Reviewed By: PeteSteinfeld, awarzynski

Differential Revision: https://reviews.llvm.org/D122542
2022-03-28 22:53:17 +02:00
Peter Klausler e619c07d16 [flang] Fold NEAREST() and its relatives
Implement constant folding for the intrinsic function NEAREST()
and the related functions IEEE_NEXT_AFTER(), IEEE_NEXT_UP(), and
IEEE_NEXT_DOWN().

Differential Revision: https://reviews.llvm.org/D122510
2022-03-28 11:33:40 -07:00
Mogball e51652f9bf [mlir] Simplify LoopLikeOpInterface
- Adds default implementations of `isDefinedOutsideOfLoop` and `moveOutOfLoop` since 99% of all implementations of these functions were identical
- `moveOutOfLoop` takes one operation and doesn't return anything anymore. 100% of all implementations of this function would always return `success` and uses would either respond with a pass failure or an `llvm_unreachable`.
2022-03-28 18:10:04 +00:00
Kiran Chandramohan c49af35a3d [Flang] Options to lower math intrinsics to relaxed, precise variants
Enable lowering to the relaxed and precise variants in the pgmath
library.

This is part of the upstreaming effort from the fir-dev branch in [1].
[1] https://github.com/flang-compiler/f18-llvm-project

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Peter Klausler <pklausler@nvidia.com>

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D122484
2022-03-28 17:17:51 +00:00
Valentin Clement 534b228313
[flang] Lower some coarray statements to their runtime functions
This patch adds the lowering of coarray statements to the runtime
functions. The runtime functions are currently not implemented.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D122466
2022-03-28 13:36:32 +02:00
Andrzej Warzynski 4ca111d4cb Revert "[flang] Add & use a better visit()"
This reverts commit 2ab9990c9e. It has
caused multiple build failures:
*  https://lab.llvm.org/buildbot/#/builders/177/builds/4346
*  https://lab.llvm.org/buildbot/#/builders/180/builds/3803
*  https://lab.llvm.org/buildbot/#/builders/175/builds/10419
*  https://lab.llvm.org/buildbot/#/builders/191/builds/4318
*  https://lab.llvm.org/buildbot/#/builders/173/builds/4274
*  https://lab.llvm.org/buildbot/#/builders/181/builds/4297

All these bots failed with a time-out:
```
command timed out: 1200 seconds without output running [b'ninja', b'-j', b'32'], attempting to kill
```
I'm guessing that that's due to template instantiations failing at some
point (https://reviews.llvm.org/D122441 introduced a custom
implementation of std::visit). Everything seems fine when either:
* building on X86 with GCC or Clang (tested with GCC 9.3 and Clang 12)
* building on AArch64 with GCC (tested with GCC 11)
2022-03-28 10:46:47 +00:00
Shraiysh Vaishay fcbf00f098 [mlir][OpenMP] Added ReductionClauseInterface
This patch adds the ReductionClauseInterface and also adds reduction
support for `omp.parallel` operation.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D122402
2022-03-28 14:24:28 +05:30
Jean Perier 479eed1850 [flang][runtime] Ensure PointerDeallocate actually deallocate pointers
PointerDeallocate was silently doing nothing because it relied on
Destroy that doe not do anything for Pointers. Add an option to Destroy
in order to destroy pointers.

Add a unit test for PointerDeallocate.

Differential Revision: https://reviews.llvm.org/D122492
2022-03-28 10:22:08 +02:00
Peter Klausler 435641bc3d [flang] Catch bad OPEN(STATUS=) cases
STATUS='NEW' and 'REPLACE' require FILE= to be present.
STATUS='SCRATCH' may not appear with FILE=.

These errors are caught at compilation time when constant character
strings are used in an OPEN statement, but the runtime needs
to enforce them as well to catch errors in OPEN statements
with character variables and expressions.

Differential Revision: https://reviews.llvm.org/D122509
2022-03-25 18:24:50 -07:00
Peter Klausler 5c116d50e4 [flang] Mark C_ASSOCIATED specific procedures as PURE
The interfaces to C_ASSOCIATED()'s specific procedures must be
PURE so that they are accepted for use in specification expressions.

Differential Revision: https://reviews.llvm.org/D122438
2022-03-25 15:04:26 -07:00
Peter Klausler 2ab9990c9e [flang] Add & use a better visit()
Adds flang/include/flang/Common/visit.h, which defines
a Fortran::common::visit() template function that is a drop-in
replacement for std::visit().  Modifies most use sites in
the front-end and runtime to use common::visit().

The C++ standard mandates that std::visit() have O(1) execution
time, which forces implementations to build dispatch tables.
This new common::visit() is O(log2 N) in the number of alternatives
in a variant<>, but that N tends to be small and so this change
produces a fairly significant improvement in compiler build
memory requirements, a 5-10% improvement in compiler build time,
and a small improvement in compiler execution time.

Building with -DFLANG_USE_STD_VISIT causes common::visit()
to be an alias for std::visit().

Calls to common::visit() with multiple variant arguments
are referred to std::visit(), pending further work.

Differential Revision: https://reviews.llvm.org/D122441
2022-03-25 13:15:20 -07:00
Peter Klausler 0363a164b6 [flang] Fix bogus error from assignment to CLASS(*)
Assignment semantics was coughing up bad errors and crashes for
intrinsic assignments to unlimited polymorphic entities while
looking for any (impossible) user defined ASSIGNMENT(=) generic
or intrinsic type conversion.

Differential Revision: https://reviews.llvm.org/D122440
2022-03-25 11:17:01 -07:00
Jean Perier 5bc9ee1b78 [flang][lowering] Handle zero extent case in LBOUND
Follow up of https://reviews.llvm.org/D121488. Ensure lower bounds
are `1` when the related dimension extent is zero. Note that lower
bounds from descriptors are now guaranteed to fulfill this property
after the runtime/codegen patches.

Also fixes explicit shape array extent lowering when instantiating
variables to deal with negative extent cases (issue found while testing
LBOUND edge case). This notably caused allocation crashes when dealing
with automatic arrays with reversed bounds or negative size
specification expression. The standard specifies that the extent of such
arrays is zero. This change has some ripple effect in the current lit
tests.

Add move two helpers as part of this change:
- Add a helper to tell if a fir::ExtendedValue describes an assumed size
  array (last dimension extent is unknown to the compiler, both at compile
  time and runtime).

- Move and share getIntIfConstant from Character.cpp so that it can be
  used elsewhere (NFC).

Differential Revision: https://reviews.llvm.org/D122467
2022-03-25 18:05:54 +01:00
Peter Klausler 174cabeda5 [flang] Fix cycle-catcher in procedure characterization
The "seenProcs" sets passed as arguments to the procedure and dummy
procedure characterization routines need to be passed by value so that
local updates to those sets do not become permanent.  They are
presently passed by reference and that has led to bogus errors about
recursively defined procedures in testing.

(It might be faster to pass the sets by reference and undo those local
updates in these functions, but that's error-prone, and the performance
difference is not expected to be detectable in practice.)

Differential Revision: https://reviews.llvm.org/D122439
2022-03-25 09:49:55 -07:00
Kiran Chandramohan 7babc8e6cd [Flang] Lower achar intrinsic
The intrinsic returns the character located at the position requested
in the ASCII sequence. The intrinsic is lowered to inline FIR code.

This is part of the upstreaming effort from the fir-dev branch in [1].
[1] https://github.com/flang-compiler/f18-llvm-project

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D122480

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-25 14:23:32 +00:00
Jean Perier 6daa206b5d [flang][NFC] fix comment typo in SetLowerBound description 2022-03-25 01:32:57 -07:00
Jean Perier d3bc3a0400 [flang][codegen] ensure descriptor lower bounds are LBOUND compliant
Follow-up of https://reviews.llvm.org/D121488 to ensure all descriptors
created inline complies with LBOUND requirement that the lower bound is
`1` when the related dimension extent is zero.

Both fir.xrebox and fir.xembox codegen is updated to enforce this
constraint.

Also upstream the "normalized lower bound" attribute that was added in fir-dev
since embox codegen was upstreamed, it is conflicting with this patch
otherwise.

Differential Revision: https://reviews.llvm.org/D122419
2022-03-25 09:02:57 +01:00
Jean Perier 7f1adbaba9 [flang] Fix LBOUND rewrite on descriptor components
GetLowerBoundHelper rewrite in https://reviews.llvm.org/D121488 was
incorrect with POINTER/ALLOCATABLE components. The rewrite created a
descriptor inquiry to the component symbol only instead of the whole
named entity. The base information was lost, and not retrievable.
LBOUND(a(10)%p) became LBOUND(p).

Fix this regression, and also update DescriptorInquiry unparsing to
carry the kind information. DescriptorInquiries are KIND 8 expressions,
while LBOUND/SIZE/RANK, %LEN are default kind expressions.
This caused `print *,lbound(x,kind=8)` to unparse as `print*,lbound(x)` which is not
semantically the same (this unparsing issue was not an issue for
lowering, but I noticed it while writing my regression test).

Differential Revision: https://reviews.llvm.org/D122406
2022-03-25 09:00:56 +01:00
Valentin Clement 50354558a7
[flang] Lower mvbits intrinsic
This patch adds the lowering for the `mvbits`
intrinsic.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122412

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-03-25 08:01:27 +01:00
Peter Steinfeld df209b8038 [flang] Make not yet implemented messages more consistent
To make it easier to find things that are not yet implemented, I'm changing the
messages that appear in the compiler's output to all have the string "not yet
implemented:".

These changes apply to files in the front end.  I have another set of changes
to files in the lowering code.

Differential Revision: https://reviews.llvm.org/D122355
2022-03-24 15:19:40 -07:00
Valentin Clement a80bf18565
[flang][NFC] Remove unused variable 2022-03-24 20:43:11 +01:00
Valentin Clement 44b0ea44f2
[flang[OpenACC] Lower wait directive
This patch adds lowering for the `!$acc wait` directive
from the PFT to OpenACC dialect.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122399
2022-03-24 17:15:27 +01:00
Valentin Clement 5ee88e0ba5
[flang[OpenACC] Lower data directive
This patch adds lowering for the `!$acc data`
from the PFT to OpenACC dialect.

This patch is part of the upstreaming effort from fir-dev branch.

Depends on D122384

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122398
2022-03-24 15:30:31 +01:00
Valentin Clement c6a9ce2b6b
[flang][OpenACC] Lower update directive
This patch adds lowering for the `!$acc update`
from the PFT to OpenACC dialect.

This patch is part of the upstreaming effort from fir-dev branch.

Depends on D122387

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122396
2022-03-24 15:19:05 +01:00
Valentin Clement 39157b98fd
[flang][OpenACC] Lower init/shutdown directive
This patch adds lowering for the `!$acc init` and `!$acc shutdown`
from the PFT to OpenACC dialect.

This patch is part of the upstreaming effort from fir-dev branch.

Depends on D122384

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122387
2022-03-24 15:18:09 +01:00
Valentin Clement 67defe5067
[flang][OpenACC] Lower exit data directive
This patch adds lowering for the `!$acc exit data` directive
from the PFT to OpenACC dialect.

This patch is part of the upstreaming effort from fir-dev branch.

Depends on D122384

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122386
2022-03-24 15:15:56 +01:00
Valentin Clement 12d22cea73
[flang][OpenACC] Lower enter data directive
This patch adds lowering for the `!$acc enter data` directive
from the PFT to OpenACC dialect.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122384
2022-03-24 15:01:05 +01:00
Valentin Clement 30b4421a74
[flang][NFC] Add lowering test for array expression
This patches adds lowering tests for some array
expressions use cases.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D122380

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-24 14:59:33 +01:00
Peixin-Qiao 6ce82eae1f [NFC][flang] Remove unused code in lowerExplicitLowerBounds
There is no need to lower the implicit lower bounds for assumed-shape
array in lowerExplicitLowerBounds. Remove the unused code.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D122280
2022-03-24 16:50:38 +08:00