Commit Graph

4736 Commits

Author SHA1 Message Date
Valentin Clement 53804e426d
[flang][NFC] Make LEN parameters homogenous
This patch is part of the upstreaming effort from fir-dev branch.
This is the last patch for the upstreaming effort.

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-07-07 18:29:28 +02:00
Peter Klausler 7c708adb4a [flang][runtime] Trim FORMATs echoed to error messages
Since dynamic FORMAT strings usually come from blank-padded fixed-length
CHARACTER variables, trim leading and trailing blanks from them when they
are echoed to error messages for better readability.

Differential Revision: https://reviews.llvm.org/D129024
2022-07-06 18:55:03 -07:00
Peter Klausler ac77649951 [flang] Avoid spurious warnings in pedantic mode from FORMAT items
In free form source, pedantic mode will elicit portability warnings
about missing spaces when a token string ends with a character that
can be in an identifier and there is no space between that last token
character and a following character that can also be part of an identifier.

This behavior doesn't really work well for the token strings that are
parsed for edit descriptors in FORMAT statements.  For example, the
'F' in FORMAT(F7.3) is followed by a digit, but obviously no space is
necessary.  Free form or not, FORMATs are their own odd little world.

This patch adds trailing blanks to these FORMAT edit descriptor token
parsers to disable the missing space check, and extends the documentation
for token string parsing to explain why this technique works.

Differential Revision: https://reviews.llvm.org/D129023
2022-07-06 18:54:11 -07:00
Peter Klausler 6052025b58 [flang] Add IsElementalProcedure() predicate
Replace most tests of the explicit Attr::ELEMENTAL symbol flag with
a new predicate IsElementalProcedure() that works correctly for alternate
ENTRY points and does the right thing for procedure interfaces that
reference elemental intrinsic functions like SIN() whose elemental
nature does not propagate.

Differential Revision: https://reviews.llvm.org/D129022
2022-07-06 18:08:45 -07:00
Peter Klausler 061df07389 [flang][runtime] Fix directed UP/DOWN rounding edge case for Fw.d output
When Fw.d output editing takes place with directed rounding, make sure that
nonzero values that would normally be converted to zero round up (or down,
depending on the sign) to a scaled 1.

Differential Revision: https://reviews.llvm.org/D129021
2022-07-06 17:35:34 -07:00
Peter Klausler 715283aa17 [flang] Cope with overflow in real MOD/MODULO
In folding and in the runtime library for real MOD/MODULO(A,P),
detect overflow from the division A/P and return a properly signed
zero result.  (When A/P overflows and both A and P are finite numbers
with nonzero P, the quotient would be a large integer when rounded to
the precision of the floating-point representation.)

Differential Revision: https://reviews.llvm.org/D129020
2022-07-06 17:31:11 -07:00
Peter Klausler 0508fd5935 [flang][runtime] Make ENDFILE work after non-advancing READ
An ENDFILE statement executed when a non-advancing READ has
left the unit in the middle of a record must truncate the file
at that position.

Differential Revision: https://reviews.llvm.org/D129019
2022-07-06 17:30:33 -07:00
Naje George 9ad64cf020 [flang] Add semantics test for coshape function
Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D128957
2022-07-06 14:27:08 -07:00
Peter Klausler 23c2bedfd9 [flang] Establish a single source of target information for semantics
Create a TargetCharacteristics class to centralize the few items of
target specific information that are relevant to semantics.  Use the
new class for all target queries, including derived type component layout
modeling.

Future work will initialize this class with target information
provided or forwarded by the drivers, and use it to fold layout-dependent
intrinsic functions like TRANSFER().

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

Updates: Attempts to work around build issues on Windows.
2022-07-06 10:25:34 -07:00
Dominik Adamski 2c915e3b26 [mlir][OpenMP] Add if clause to OpenMP simd construct
This patch adds if clause to OpenMP TableGen for simd construct.

Reviewed By: peixin

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

Signed-off-by: Dominik Adamski <dominik.adamski@amd.com>
2022-07-06 07:24:48 -05:00
River Riddle ab9cdf09f4 [mlir:Parser] Don't use strings for the "ugly" form of Attribute/Type syntax
This commit refactors the syntax of "ugly" attribute/type formats to not use
strings for wrapping. This means that moving forward attirbutes and type formats
will always need to be in some recognizable form, i.e. if they use incompatible
characters they will need to manually wrap those in a string, the framework will
no longer do it automatically.

This has the benefit of greatly simplifying how parsing attributes/types work, given
that we currently rely on some extremely complicated nested parser logic which is
quite problematic for a myriad of reasons; unecessary complexity(we create a nested
source manager/lexer/etc.), diagnostic locations can be off/wrong given string escaping,
etc.

Differential Revision: https://reviews.llvm.org/D118505
2022-07-05 16:20:30 -07:00
Jean Perier b094c737cd [flang] Avoid opaque pointer issue with character array substring addressing
When addressing a substring of a character array, codegen emits two
GEPs: one for to compute the address of the base element, and a second
one to address the first characters from that element.

The first GEP still returns the LLVM array type (if the FIR array type could be
translated to an array type. Therefore) so zero
indexes must be added to the second GEP in this case to cover for the
Fortran array dimensions before inserting the susbtring offset index.

Surprisingly, the previous code worked ok when MLIR emits none opaque
pointers. But with opaque pointers, the two GEPs are folded in an
invalid GEP where the substring offset becomes an offset for the outer
array dimension.

Note that I tried to fix the issue by modifying the first GEP to return the
element type, but this still gave bad results (here something might be
wrong with opaque pointer in MLIR or LLVM).

Differential Revision: https://reviews.llvm.org/D129079
2022-07-05 09:13:54 +02:00
Valentin Clement 12d26ce9b0
[flang] Make code more homogenous in CodeGen
This patch just make the code more similar
in each conversion.

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

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D129071
2022-07-04 21:16:29 +02:00
Valentin Clement d7697c175d
[flang] Avoid segfault when defining op is not a fir::Convert
The previous code made the assumption that the defining
operation is a fir::ConvertOp without checking. This results in
segmentation fault in code like the added test.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D129077
2022-07-04 16:03:02 +02:00
Valentin Clement 740633ff08
[flang] Add TODO for derived types with final procedure
Finalization is F2003 and although the runtime supports it already,
lowering is not ensuring all the derived type are finalized properly
when they should. This will require surveying the places where lowering
needs to call it. Add a hard TODO for now.

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

Reviewed By: jeanPerier

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-07-04 13:05:14 +02:00
Valentin Clement b19cbda45a
[flang][NFC] Add embox test with character
This test is added to check for multidimensional descriptor of array
substring/derived type component array.

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

Reviewed By: jeanPerier

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-07-01 21:49:20 +02:00
Valentin Clement 8c44bef110
[flang] File omp_lib.f90 is not a standard intrinsic module
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-07-01 12:05:18 +02:00
Valentin Clement 0dd4fb0408
[flang] Fix for broken/degenerate forall case
Fix for broken/degenerate forall case where there is no assignment to an
array under the explicit iteration space. While this is a multiple
assignment, semantics only raises a warning.
The fix is to add a test that the explicit space has any sort of array
to be updated, and if not then the do_loop nest will not require a
terminator to forward array values to the next iteration.

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

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-07-01 10:37:15 +02:00
Valentin Clement df417c372f
[flang] Add correct number of args for wait
Add source coordinates to BeginWait and BeginWaitAll calls

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

Reviewed By: jeanPerier

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-07-01 10:16:36 +02:00
Valentin Clement 39377d5227
[flang] Fix APFloat conversion cases
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Peter Steinfeld <psteinfeld@nvidia.com>
2022-07-01 08:29:54 +02:00
Naje George e6d29161fb [flang] Expand semantics test coverage of collective subroutines
Add non-standard conforming calls that violate the intent(inout)
of errmsg argument for co_sum, co_max, co_min, and co_broadcast.
Add non-standard conforming calls that violate the argument
typing of errmsg argument for co_max, co_min, and co_broadcast.
Add standard conforming calls that reorder keyword arguments
for co_sum and co_reduce.

Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D128468
2022-06-30 14:30:44 -07:00
Naje George 4dc752e6ec [flang] Add new semantics test for team_number function
Add new semantics test for team_number and rename existing
team_number semantics test.

Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D128309
2022-06-30 14:05:11 -07:00
Katherine Rasmussen 06683d5f74 [flang] Add semantics test for `get_team`
Add a semantics test for the intrinsic function `get_team`.

Differential Revision: https://reviews.llvm.org/D128370
2022-06-30 10:54:05 -07:00
Valentin Clement 11c43cd2de
[flang] Fix "not yet implemented" message for CHARACTER MIN/MAX
The check to see if the arguments for the MIN/MAX intrinsics were of CHARACTER
type was not handling assumed length characters.  In this case, the FIR type is
"!fir.ref<!fir.char<1,?>>".

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Peter Steinfeld <psteinfeld@nvidia.com>
2022-06-30 18:13:22 +02:00
Peixin Qiao 13f9089ac9 [flang] Fix one corner case in reshape intrinsic
As Fortran 2018 16.9.163, the reshape is the only intrinsic which
requires the shape argument to be rank-one integer array and the SIZE
of it to be one constant expression. The current expression lowering
converts the shape expression with slice in intrinsic into one box value
with the box element type of unknown extent. However, the genReshape
requires the box element type to be constant size. So, convert the box
value into one with box element type of sequence of 1 x constant. This
corner case is found in cam4 in SPEC 2017
https://github.com/llvm/llvm-project/issues/56140.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D128597
2022-06-30 23:52:44 +08:00
Valentin Clement a19c213212
[flang][NFC] Fix warning 2022-06-30 16:56:49 +02:00
Valentin Clement 540a76f074
[flang] Convert assertion to a TODO
The original assertion is not necessarily correct since the shape
argument may involve a slice of an array (an expression) and not a whole
vector with constant length. In the presence of a slice operation, the
size must be computed (left as a TODO for now).

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

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-30 15:46:24 +02:00
Valentin Clement 411f839ae3
[flang] Fix for array upper bounds with *
Even though the array is declared with '*' upper bounds, it has an
initial value that has a statically known shape. Use the shape from
the type of the initializer when the declared size is '*'.

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

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-30 10:37:22 +02:00
Valentin Clement c628e9eb5e
[flang][NFC] Add FIR array test
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

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-06-30 10:36:18 +02:00
Valentin Clement 06d103ff95
[flang] Correct bug in literal CHARACTER constant names
The names of CHARACTER strings were being truncated leading to invalid
collisions and other failures. This change makes sure to use the entire
string as the seed for the unique name.

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

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-30 10:10:37 +02:00
Valentin Clement 1e55ec6666
[flang] SELECT CASE constructs with character selectors that require a temp
Here is a character SELECT CASE construct that requires a temp to hold the
result of the TRIM intrinsic call:

```
module m
      character(len=6) :: s
    contains
      subroutine sc
        n = 0
        if (lge(s,'00')) then
          select case(trim(s))
          case('11')
             n = 1
          case default
             continue
          case('22')
             n = 2
          case('33')
             n = 3
          case('44':'55','66':'77','88':)
             n = 4
          end select
        end if
        print*, n
      end subroutine
    end module m
```

This SELECT CASE construct is implemented as an IF/ELSE-IF/ELSE comparison
sequence.  The temp must be retained until some comparison is successful.
At that point the temp may be freed.  Generalize statement context processing
to allow multiple finalize calls to do this, such that the program always
executes exactly one freemem call.

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

Reviewed By: klausler, vdonaldson

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-06-30 09:04:27 +02:00
Valentin Clement ac1bda21c9
[flang] Fix error message in test 2022-06-30 09:01:58 +02:00
Valentin Clement 6c48700204
[flang][NFC] Revert message to not implemented yet 2022-06-30 08:36:10 +02:00
Fangrui Song 3f17dc89d3 [flang][test] Remove RUN COMMAND/EXPECTED OUTPUT/INPUT markers from other directories 2022-06-29 22:10:59 -07:00
Fangrui Song d5d420bb3b [flang][test] Remove RUN LINES?/EXPECTED OUTPUT.*/INPUT markers from test/Driver
Follow-up to D128763.
2022-06-29 22:08:02 -07:00
Peter Klausler 53dca2e6ec [flang][runtime] Emit "0.0E+0" for (1PG0.0) editing of 0.0
When a scale factor is in effect, respect it for G0.0 output editing.

Differential Revision: https://reviews.llvm.org/D128761
2022-06-29 11:42:39 -07:00
Peter Klausler f161964e1c [flang] Better error recovery for bad submodules
When a submodule appears in a source file and the compiler can't find the
named ancestor module (and submodule, if one appears), crashes may occur
later due to the absence of a scope.  For better resilience, a dummy
ancestral scope should be generated within which the submodule scope
can be created.

Differential Revision: https://reviews.llvm.org/D128760
2022-06-29 11:34:51 -07:00
Valentin Clement 649439e7ae
[flang] Fix lowering issue with character temp
- Add verifiers that determine if an Op requires type parameters or
  not and checks that the correct number of parameters is specified.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-29 20:06:54 +02:00
Peter Klausler b70f507c75 [flang] Fix folding of LEN(f(...))
LEN(f(...)), where "f" is a non-intrinsic function, should not be folded
to anything else unless the result is a known constant value.  While there
are conceivable cases in which we could do better (e.g., an internal function
whose length is a host-associated INTENT(IN) dummy argument), there are
other cases that we're getting wrong.

Differential Revision: https://reviews.llvm.org/D128759
2022-06-29 10:25:07 -07:00
Valentin Clement 62e907e9f9
[Flang] fix some types in error message 2022-06-29 14:55:53 +02:00
Valentin Clement be80c6d1b1
[flang][NFC] Cosmetic changes to make the file more homogenous
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D128799
2022-06-29 14:21:19 +02:00
Valentin Clement 7c65e62a51
[flang] Switch attr name to bindc_name
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-29 14:20:35 +02:00
Kiran Chandramohan 051dea8221 [Flang][OpenMP] Remove TODO for shared and two values of default clause
Shared is the default behaviour in the IR, so no handling is required.
Default clause with shared or none do not require any handling since
Shared is the default behaviour in the IR and None is only required
for semantic checks.

This patch is carved out from D123930 to remove couple of false TODOs.

Reviewed By: peixin, shraiysh

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

Co-authored-by: Nimish Mishra <neelam.nimish@gmail.com>
2022-06-29 12:09:03 +00:00
Valentin Clement feb44ccc91
[flang][NFC] Fix some typos 2022-06-29 12:35:58 +02:00
Fangrui Song 9d4a2baaa2 [flang][test] Remove RUN COMMANDS/EXPECTED OUTPUT/INPUT markers from test/Driver
Uses of these markers are contrary to all other llvm-project subprojects
and carry no information for people who know the basics of a lit test.

I understand that there is an argument "this makes beginners get started
quickly" but I am unsure whether this is strong enough to deviate from
all other projects. https://llvm.org/docs/TestingGuide.html covers the
basics. Actually, some contributors were confused by the markers.

Differential Revision: https://reviews.llvm.org/D128763
2022-06-29 01:06:01 -07:00
Andrzej Warzynski b405407a48 [clang][flang] Disable defaulting to `-fpie` for LLVM Flang
In, https://reviews.llvm.org/D120305, CLANG_DEFAULT_PIE_ON_LINUX was set
to `On` by default. However, neither `-fpie` nor `-fpic` are currently
supported in LLVM Flang. Hence, in this patch the behaviour controlled
with CLANG_DEFAULT_PIE_ON_LINUX is refined not to apply to Flang.

Another way to look at this is that CLANG_DEFAULT_PIE_ON_LINUX is
currently affecting both Clang and Flang. IIUC, the intention for this
CMake variable has always been to only affect Clang. This patch makes
sure that that's the case.

Without this change, you might see errors like this on X86_64:
```
/usr/bin/ld: main.o: relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC
```
I've not experienced any issues on AArch64. That's probably because on
AArch64 some object files happen to be position independent without
needing -fpie or -fpic.

Differential Revision: https://reviews.llvm.org/D128333
2022-06-29 07:53:06 +00:00
Peixin-Qiao 1795f8cd2e [NFC][OpenMP] Fix worksharing-loop
1. Remove the redundant collapse clause in MLIR OpenMP worksharing-loop
   operation.
2. Fix several typos.
3. Refactor the chunk size type conversion since CreateSExtOrTrunc has
   both type check and type conversion.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D128338
2022-06-29 12:20:03 +08:00
Peixin-Qiao 794b3bf776 [NFC][flang] Add the missed `constexpr`
Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D128598
2022-06-29 12:07:29 +08:00
Peixin-Qiao 779d2470a4 [flang] Support check for BIND statement entity
As Fortran 2018 8.6.4(1), the BIND statement specifies the BIND attribute
for a list of variables and common blocks.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D127120
2022-06-29 11:25:19 +08:00
Slava Zakharin 9f35657983 [flang] Lower Fortran math intrinsic operations into MLIR ops or libm calls.
Added new -lower-math-early option that defaults to 'true' that matches
the current math lowering scheme. If set to 'false', the intrinsic math
operations will be lowered to MLIR operations, which should potentially
enable more MLIR optimizations, or libm calls, if there is no corresponding
MLIR operation exists or if "precise" mode is requested.
The generated math MLIR operations are then converted to LLVM dialect
during codegen phase.

The -lower-math-early option is not exposed to users currently. I plan to
get rid of the "early" lowering completely, when "late" lowering
is robust enough to support all math intrinsics that are currently
supported via pgmath. So "late" mode will become default and -lower-math-early
option will not be needed. This will effectively eliminate the mandatory
dependency on pgmath in Fortran lowering, but this is WIP.

Differential Revision: https://reviews.llvm.org/D128385
2022-06-28 13:32:19 -07:00