Commit Graph

3803 Commits

Author SHA1 Message Date
Peter Klausler 78d60094c7 [flang] Deal with negative character lengths in semantics
Fortran defines LEN(X) = 0 after CHARACTER(LEN=-1)::X so
apply MAX(0, ...) to character length expressions.

Differential Revision: https://reviews.llvm.org/D114030
2021-11-17 09:49:15 -08:00
Jean Perier 394d6fcf3e [flang] Check ArrayRef base for contiguity in IsSimplyContiguousHelper
Previous code was returning true for `x(:)` where x is a pointer without
the contiguous attribute.
In case the array ref is a whole array section, check the base for contiguity
to solve the issue.

Differential Revision: https://reviews.llvm.org/D114084
2021-11-17 18:18:58 +01:00
Valentin Clement 964536cf04
[fir] !fir.tdesc type conversion
Add !fir.tdesc type conversion.
!fir.tdesc is converted to a llvm.ptr<i8>.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-17 13:31:14 +01:00
Valentin Clement e38ef2ff71
[fir] Add fir.box_tdesc conversion
This patch adds the conversion pattern for
`fir.box_tdes`.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-17 12:02:48 +01:00
Valentin Clement 1ed5a90f70
[fir] Add conversion patterns for slice, shape, shapeshift and shift ops
The information in these perations is used by other operation.
At this point they should not have anymore uses.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-17 10:35:56 +01:00
Michael Kruse d2124bfccf [flang] Remove default argument from function template specialization. NFC.
Patch D113697 added default function arguments to template specializations of `ConvertToBinary`.

According to https://en.cppreference.com/w/cpp/language/template_specialization this not allowed:
> Default function arguments cannot be specified in explicit specializations of function templates, member function templates, and member functions of class templates when the class is implicitly instantiated.

It happens to compile with gcc, clang and msvc 14.30 (Visual Studio 2022), but not msvc 14.29 (Visual Studio 2020). Even for the compilers that syntactically accept it, the default argument will never be used (only the default argument of the template declaration). From https://en.cppreference.com/w/cpp/language/function_template
> Note that only non-template and primary template overloads participate in overload resolution.

That is, the explicit function template specialization is not added to the overload candidate set. Only after all the parameter types are known, are the explicit specializations chosen, at which point the default function argument is ignored.

Also see D85657.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D114032
2021-11-17 00:05:34 -06:00
Valentin Clement 1a2ec6670a
[fir] Add fir.string_lit conversion
This patch adds the conversion pattern for
the fir.string_lit operation.

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

Reviewed By: awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-16 21:13:45 +01:00
V Donaldson ea8cdf322f [flang] Fix a bug in INQUIRE(IOLENGTH=) output
The inquire by output list form of the INQUIRE statement calculates the
number of file storage units that would be required to store the data
of an output list in an unformatted file.  Currently, the result is
incorrectly multiplied by the number of bytes for a data type.  A query
for "INTEGER(KIND=4) A(10)" should be 40, not 160.

Update formatting.
2021-11-16 11:33:15 -08:00
William S. Moses 30d87d4a5d [MLIR][LLVM] Permit integer types in switch other than i32
LLVM switchop currently only permits i32. Both LLVM IR and MLIR Standard switch permit other integer types leading to an illegal state when lowering an i8 switch from MLIR standard

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D113955
2021-11-16 12:00:37 -05:00
Andrzej Warzynski 50acc6d0f7 [flang][fir] Add missing `HasParent` in `fir_DTEntryOp`
Differential Revision: https://reviews.llvm.org/D113674
2021-11-16 15:40:55 +00:00
Jean Perier 2e65c8e8db [flang] Allow write after non advancing read in IO runtime
1. To avoid overwriting the part of the record read in the non advancing read,
the furtherPositionInRecord field must be set to the max of the
furtherPositionInRecord and the positionInRecord at the beginning of the
IO write.

2. To allow any further read to succeed after the write, the unit
beganReadingRecord_ must be set to false when resetting the recordLength
during the write, otherwise, recordLength will not be computed in further
read and an assert is hit (at unit.cpp(398)).

The added unit test exercises both of these scenarios.

Differential Revision: https://reviews.llvm.org/D113740
2021-11-16 14:53:39 +01:00
Andrzej Warzynski 6c3d7fd4c5 [flang][CodeGen] Transform `fir.boxchar_len` to a sequence of LLVM MLIR
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.boxchar_len` to a sequence of LLVM MLIR
instructions.

This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

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

Originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-16 13:49:23 +00:00
Valentin Clement 3124618704
[fir] Add fir.gentypedesc conversion
Add conversion pattern for the GenTypeDescOp.
Convert to a global constant with an addressof.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-16 14:41:00 +01:00
Diana Picus f1dfc0275c [fir] Add fir.cmpc conversion
This patch adds the codegen for fir.cmpc. The real and imaginary parts
are extracted and compared separately. For the .EQ. predicate the
results are AND'd, for the .NE. predicate the results are OR'd, and for
other predicates we keep only the result on the real parts.

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-16 12:26:27 +00:00
Peter Steinfeld 4f11944652 [flang] Allow implicit procedure pointers to associate with explicit procedures
Section 10.2.2.4, paragraph 3 states that, for procedure pointer assignment:
  If the pointer object has an explicit interface, its characteristics shall be
  the same as the pointer target ...

Thus, it's illegal for a procedure pointer with an explicit interface to be
associated with a procedure whose interface is implicit.  However, there's no
prohibition that disallows a procedure pointer with an implicit interface from
being associated with a procedure whose interface is explicit.

We were incorrectly emitting an error message for this latter case.

We were also not covering the case of procedures with explicit
interfaces where calling them requires the use of a descriptor.  Such
procedures cannot be associated with procedure pointers with implicit
interfaces.

Differential Revision: https://reviews.llvm.org/D113706
2021-11-15 09:51:25 -08:00
Kiran Chandramohan 49c08a22ed [Flang] Add the FIR LLVMPointer Type
Add a fir.llvm_ptr type to allow any level of indirections

Currently, fir pointer types (fir.ref, fir.ptr, and fir.heap) carry
a special Fortran semantics, and cannot be freely combined/nested.

When implementing some features, lowering sometimes needs more liberty
regarding the number of indirection levels. Add a fir.llvm_ptr that has
no constraints.

Allow its usage in fir.coordinate_op, fir.load, and fir.store.

Convert the FIR LLVMPointer to an LLVMPointer in the LLVM dialect.

Reviewed By: clementval

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-15 15:57:59 +00:00
Valentin Clement 677df8c709
[fir] Add fir.global_len conversion placeholder
As for D113662, this patch just add a place holder for
the fir.global_len operation conversion. This operation
is part of F20xx and is not implemented yet.

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

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D113887
2021-11-15 16:47:20 +01:00
Andrzej Warzynski 14867ffc7c [flang][CodeGen] Transform `fir.unboxchar` to a sequence of LLVM MLIR
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.unboxchar` to a sequence of LLVM MLIR
instructions.

This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

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

Originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-15 15:34:55 +00:00
Valentin Clement 37c7211f11
[fir] Remove extra return in SelectTypeOpConversion
Extra commit after D113878
2021-11-15 16:20:53 +01:00
Valentin Clement 2a299e4f06
[fir] Add fir.select_type conversion placeholder
As for D113662, this patch just add a place holder for
the `fir.select_type` operation conversion. This operation
is part of F20xx and is not implemented yet.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D113878
2021-11-15 14:35:57 +01:00
Andrzej Warzynski 1e77b09538 [flang][CodeGen] Transform `fir.emboxchar` to a sequence of LLVM MLIR
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.emboxchar` to a sequence of LLVM MLIR
instructions.

This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-15 11:09:12 +00:00
Valentin Clement 6c8eecd676
[fir] Add !fir.len type conversion
This patch adds the !fir.len type conversion. The type is converted
to the a 32 bits integer.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D113658
2021-11-15 10:18:23 +01:00
Diana Picus faf869dc65 [Flang] Fixup some comments. NFC
Clarify some comments as discussed here:
https://github.com/flang-compiler/f18-llvm-project/pull/1210
2021-11-15 09:03:37 +00:00
Peter Klausler ece17064b5 [flang] Handle ENTRY names in IsPureProcedure() predicate
Fortran defines an ENTRY point name as being pure if its enclosing
subprogram scope defines a pure procedure.

Differential Revision: https://reviews.llvm.org/D113711
2021-11-12 13:21:18 -08:00
Peter Klausler da25f968a9 [flang] Runtime performance improvements to real formatted input
Profiling a basic internal real input read benchmark shows some
hot spots in the code used to prepare input for decimal-to-binary
conversion, which is of course where the time should be spent.
The library that implements decimal to/from binary conversions has
been optimized, but not the code in the Fortran runtime that calls it,
and there are some obvious light changes worth making here.

Move some member functions from *.cpp files into the class definitions
of Descriptor and IoStatementState to enable inlining and specialization.

Make GetNextInputBytes() the new basic input API within the
runtime, replacing GetCurrentChar() -- which is rewritten in terms of
GetNextInputBytes -- so that input routines can have the
ability to acquire more than one input character at a time
and amortize overhead.

These changes speed up the time to read 1M random reals
using internal I/O from a character array from 1.29s to 0.54s
on my machine, which on par with Intel Fortran and much faster than
GNU Fortran.

Differential Revision: https://reviews.llvm.org/D113697
2021-11-12 11:40:02 -08:00
Peter Klausler d1b09adeeb [flang] Fix rounding edge case in F output editing
When an Fw.d output edit descriptor has a "d" value exactly
equal to the number of zeroes after the decimal point for a value
(e.g., 0.07 with F5.1), the Fw.d output editing code needs to
do the rounding itself to either 0.0 or 0.1 after performing
a conversion without rounding (to avoid 0.04999 rounding up twice).

Differential Revision: https://reviews.llvm.org/D113698
2021-11-12 11:16:25 -08:00
Peter Klausler 4a0af824ee [flang] Respect NO_STOP_MESSAGE=1 in runtime
When an environment variable NO_STOP_MESSAGE=1 is set,
assume that STOP statements with a successful code
have QUIET=.TRUE.

Differential Revision: https://reviews.llvm.org/D113701
2021-11-12 10:50:36 -08:00
Peter Klausler 85ec449352 [flang] Fix ORDER= argument to RESHAPE
The ORDER= argument to the transformational intrinsic function RESHAPE
was being misinterpreted in an inverted way that could be detected only
with 3-d or higher rank array.  Fix in both folding and the runtime, and
extend tests.

Differential Revision: https://reviews.llvm.org/D113699
2021-11-12 10:25:00 -08:00
Kiran Chandramohan aa26119b82 [Flang] Add type conversion for FIR integer kind
Convert fir.int<kind> to their llvm equivalent type

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

Reviewed By: clementval, awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-12 10:15:21 +00:00
Kiran Chandramohan 2b247941ca [Flang] Add type conversion for FIR heap type
Convert fir.heap type to its llvm equivalent type (llvm.ptr)

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

Reviewed By: clementval

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-12 09:49:54 +00:00
Jean Perier 1fda7baf8a [flang] fix unused variable warning from D113659 2021-11-12 09:34:02 +01:00
Jean Perier 6544d9a4a0 [flang] Fix vector cshift runtime with non zero lower bounds
The source index should not be compared to zero after applying the
shift with the modulo, it must be compared to the lower bound.
Otherwise, the extent is not added in case it should and the computed
source index may be less than the lower bound, causing invalid results.

Differential Revision: https://reviews.llvm.org/D113659
2021-11-12 09:26:08 +01:00
Peter Klausler c3dddeeafb [flang] Allow exterior branch to outermost WHERE construct statement
The labels of WHERE constructs were being created within the scope of
the construct, not the scope of its parent, leading to incorrect error
messages for branches to that label.

Differential Revision: https://reviews.llvm.org/D113696
2021-11-11 13:14:42 -08:00
Andrzej Warzynski 420ad7ce7d [flang][CodeGen] Transform `IsPresentOpConversion` and `AbsentOpConversion`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding
hooks to transform `fir.is_present` and `fir.absent` to the LLVM dialect
of MLIR.

This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

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

Originally written by:
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 18:07:51 +00:00
Valentin Clement b67be52054
[fir] Add !fir.field type conversion
This patch adds conversion for !fir.field types.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 15:40:15 +01:00
Valentin Clement 39f4ef8146
[fir] Add fir.select_case conversion
The `fir.select_case` operation is converted to a if-then-else ladder.

Conversion of `fir.select_case` operation with character is not
implemented yet.

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

Reviewed By: kiranchandramohan, mehdi_amini

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 15:00:51 +01:00
Valentin Clement 9534e361ea
[fir] Add placeholder conversion pattern for disptach operations
`fir.dispatch`, `fir.dispatch_table` and `fir.dt_entry` are operations
for type-bound procedures. This patch just adds placeholder conversion
pattern that currently fails since F2003 is not implemented yet.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D113662
2021-11-11 13:58:59 +01:00
Diana Picus 1e6d9c06a5 [fir] Add !fir.alloca conversion
Convert !fir.alloca into !llvm.alloca.

This also contains a fix for verifyInType in FIROps.cpp, to make sure we
can handle a !fir.ptr<!fir.array<?xN>>.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-11 11:26:33 +00:00
Andrzej Warzynski bb2018261e [flang][codegen] Add type conversion for `fir.boxchar`
This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-11 10:28:40 +00:00
Valentin Clement afcacccd5a
[fir] Add !fir.vector type conversion
This patch adds the !fir.vector type conversion. The type is converted
to the builtin vector type.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 11:21:55 +01:00
Andrzej Warzynski f1a2b50789 [flang][nfc] Tidy up in CodeGen.cpp and TypeConverter.h
Some header `#include`s that belong in TypeConverter.h rather than in
CodeGen.cpp are moved accordingly. As TypeConverter.h is currently only
used in CodeGen.cpp, this wouldn't cause any build issues (ultimately,
all the required headers are included). However, this would become a problem
when including TypeConverter.h elsewhere.

Also, from [1], "(...) include all of the header files that you are
using ". This is currently not the case in TypeConverter.h and hence the
`#include`s should be moved.

I've also added missing namespace qualifiers in a few places in
TypeConverter.h

[1] https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible

Differential Revision: https://reviews.llvm.org/D113569
2021-11-11 10:08:55 +00:00
Valentin Clement b6e44ecd6e
[fir] Add fir.box_isarray, fir.box_isptr and fir.box_isalloc conversion.
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 10:41:06 +01:00
Mehdi Amini f97e72aaca Use base class AsmParser/AsmPrinter in Types and Attribute print/parse method (NFC)
This decouples the printing/parsing from the "context" in which the parsing occurs.
This will allow to invoke these methods directly using an OpAsmParser/OpAsmPrinter.

Differential Revision: https://reviews.llvm.org/D113637
2021-11-11 06:26:33 +00:00
Valentin Clement 92d205672a
[fir] Remove `fir.unbox` operation
`fir.unbox` operation is an old operation that is no longer required.
There are couple of other operations that can be used to extract
information from a `fir.box` such as `fir.box_rank`, `fir.box_addr`,
`fir.box_dims`.

This was found during the upstreaming process.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D113581
2021-11-10 20:30:10 +01:00
Valentin Clement df3b9810c7
[fir] Add fir.box_rank, fir.box_addr, fir.box_dims and fir.box_elesize conversion
This patch adds conversion for basic box operations that extract
information from the box.

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

Reviewed By: awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-10 15:35:19 +01:00
Valentin Clement 5eca6ad752
[fir] Use contralized values for indexing box
Add constant to index the different values in a box so that
they can be reused for the codegen part as well.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D113553
2021-11-10 15:35:19 +01:00
Diana Picus 81c99c5404 [fir] Fixup comment. NFC
Fixed comment as requested in https://reviews.llvm.org/D113560.
2021-11-10 12:49:31 +00:00
Diana Picus a343b74f85 [fir] Add !fir.char type conversion
This patch is part of the upstreaming effort from fir-dev.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-10 12:27:58 +00:00
Diana Picus deafc6fc6d [fir] Add !fir.ptr type conversion
This patch is part of the upstreaming effort for fir-dev.

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-10 12:27:39 +00:00
Mehdi Amini 18334a1c1a Fix flang following MLIR API change in f30a8a6f67
The printer for Attribute/Type does not need to include the mnemonic
anymore.
2021-11-10 01:25:36 +00:00
Andrzej Warzynski e3349fa1a3 [flang][CodeGen] Transform `fir.{store|load}` to `llvm.{store|load}`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.store`/`fir.load` to `llvm.store`/`fir.load`,
respectively.

This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-09 20:22:45 +00:00
Emil Kieri 384b4e0d33 [flang] Fix error in characteristics check at procedure pointer assignment
If the procedure pointer has an explicit interface, its characteristics must
equal the characteristics of its target, except that the target may be pure or
elemental also when the pointer is not (cf. F2018 10.2.2.4(3)). In the semantics
check for assignment of procedure pointers, the attributes of the procedures
were not checked correctly due to a typo. This caused some illegal
pointer-target-combinations to pass without raising an error. Fix this, and
expand the test case to improve the coverage of procedure pointer assignment
checks.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D113368
2021-11-09 18:46:54 +01:00
Valentin Clement 092cee5f7f
[fir] Add fir.convert op conversion from FIR to LLVM IR
Add conversion pattern for the `fir.convert` operation.

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

This patch was previously landed with a truncated version that
was failing the windows buildbot.

Reviewed By: rovka, awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-09 15:38:50 +01:00
Valentin Clement 9d9019c77c
Revert "[fir] Add fir.convert op conversion from FIR to LLVM IR"
This reverts commit 165879ec31.

Windows buildbot failure
2021-11-09 15:03:51 +01:00
Valentin Clement 165879ec31
[fir] Add fir.convert op conversion from FIR to LLVM IR
Add conversion pattern for the `fir.convert` operation.

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

Reviewed By: rovka, awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-09 14:55:24 +01:00
Valentin Clement fcb5a2b7d9
[fir] Force target for FIR to LLVM IR conversion 2021-11-09 14:26:40 +01:00
Valentin Clement 7b5132dae8
[fir] Add complex operations conversion from FIR LLVM IR
This patch add conversion for primitive operations on complex types.
- fir.addc
- fir.subc
- fir.mulc
- fir.divc
- fir.negc

This adds also the type conversion for !fir.complex<KIND> type.

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

This patch was updated to avoid failure on windows buildbot.
Flang codegen does not support windows target so we force the test
to use a known target instead.

Reviewed By: kiranchandramohan, rovka

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-09 14:17:34 +01:00
David Pagan b0de656bdf Initial parsing/sema for 'align' clause
Added basic parsing/sema/serialization support for 'align' clause for use with
'allocate' directive.
2021-11-09 07:34:18 -05:00
Valentin Clement 9b7c584ed8
Revert "[fir] Add complex operations conversion from FIR LLVM IR"
This reverts commit b9bc64ba14.

flang-x86_64-windows is failing with this patch
2021-11-09 13:07:36 +01:00
Valentin Clement b9bc64ba14
[fir] Add complex operations conversion from FIR LLVM IR
This patch add conversion for primitive operations on complex types.
- fir.addc
- fir.subc
- fir.mulc
- fir.divc
- fir.negc

This adds also the type conversion for !fir.complex<KIND> type.

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

Reviewed By: rovka

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-09 11:05:29 +01:00
Diana Picus 65431d3aeb [fir] TargetRewrite: Rewrite COMPLEX values
Rewrite function signatures and calls to functions that accept or return
COMPLEX values.

Also teach insert_value and extract_value about the MLIR ComplexType, by
adding AnyComplex to AnyCompositeLike.

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Tim Keith <tkeith@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-09 09:26:10 +00:00
Diana Picus 4c263ede54 [flang] Add TargetRewrite pass
This patch adds the basic infrastructure for the TargetRewrite pass,
which rewrites certain FIR dialect operations into target specific
forms. In particular, it converts boxchar function parameters, call
arguments and return values. Other convertions will be included in
future patches.

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Tim Keith <tkeith@nvidia.com>
2021-11-09 07:57:31 +00:00
Peter Klausler ca47447952 [flang] Don't reference non-invariant symbols in shape expressions
When an array's shape involves references to symbols that are not
invariant in a scope -- the classic example being a dummy array
with an explicit shape involving other dummy arguments -- the
compiler was creating shape expressions that referenced those
symbols.  This might be valid if those symbols are somehow
captured and copied at each entry point to a subprogram, and
the copies referenced in the shapes instead, but that's not
the case.

This patch introduces a new expression predicate IsScopeInvariantExpr(),
which defines a class of expressions that contains constant expressions
(in the sense that the standard uses that term) as well as references
to items that may be safely accessed in a context-free way throughout
their scopes.   This includes dummy arguments that are INTENT(IN)
and not VALUE, descriptor inquiries into descriptors that cannot
change, and bare LEN type parameters within the definitions of
derived types.  The new predicate is then used in shape analysis
to winnow out results that would have otherwise been contextual.

Differential Revision: https://reviews.llvm.org/D113309
2021-11-08 12:48:47 -08:00
peter klausler 6d44387e21 [flang] Make subscript list argument a nullable pointer
Component::CreatePointerDescriptor unconditionally expects a
vector of subscripts to be passed as an argument, but is called
from NAMELIST input with a null pointer.  Make that argument
a nullable pointer, move it to the end of the argument list,
and give it a default value of nullptr.

Differential Revision: https://reviews.llvm.org/D113312
2021-11-08 11:53:13 -08:00
Peter Klausler 80f0bb5971 [flang] Distinguish error/warning cases for bad jumps into constructs
Previously, jumps to labels in constructs from exterior statements
would elicit only a warning.  Upgrade these to errors unless the
branch into the construct would enter into only DO, IF, and SELECT CASE
constructs, whose interiors don't scope variables or have other
set-up/tear-down semantics.  Branches into these "safe" constructs
are still errors if they're nested in an unsafe construct that doesn't
also enclose the exterior branch statement.

Differential Revision: https://reviews.llvm.org/D113310
2021-11-08 11:52:01 -08:00
Peter Klausler f411c1dd95 [flang] Fix crash in semantic error recovery situation
A CHECK() in semantics is triggering when analyzing a program
with an undefined derived type pointer because the CHECK is
expecting a new error message to have been issued in a function
but not allowing for the case that a diagnostic could have been
produced earlier.  Adjust the predicate.

Differential Revision: https://reviews.llvm.org/D113307
2021-11-08 11:19:20 -08:00
Peter Klausler 333b419ad0 [flang] Fix folding of EPSILON()
The value of EPSILON() was off by one power of two due to my
misreading of the standard; this patch corrects it.
Confirmed by checking other Fortran compilers, which all agree.

Differential Revision: https://reviews.llvm.org/D113308
2021-11-08 10:50:28 -08:00
Peter Klausler e7823608bc [flang] Complete the fix for NAMELIST look-ahead case
When processing the devious NAMELIST input

  &group logarray = t t t
    = 666 /

for LOGICAL::logarray(3) and INTEGER::t, the runtime library
needs to do some look-ahead on the input stream to make sure
that the last "t" on the first line is a truth value rather than
an item name -- which in this case it is.  This look-ahead
was implemented in a previous patch but only worked for internal
input cases; this patch implements look-ahead capabilities for
input from an external file, too (and also adjusts repeated
list-directed input items to use this infrastructure, too).

Differential Revision: https://reviews.llvm.org/D113311
2021-11-08 10:01:16 -08:00
Andrzej Warzynski c4921663cf [Flang][driver] Update the docs
Please note that the updated documentation reflects the design that we are
working towards, but haven't implemented competely yet. We took this approach
in order to provide a more holisitic and complete overview of the design.

In particular, this document assumes that Flang's frontend and compiler
driver can already generate code. This is still work-in-progress and is
being developed on the `fir-dev` branch in the F18 repository [1].

[1] https://github.com/flang-compiler/f18-llvm-project/tree/fir-dev

Differential Revision: https://reviews.llvm.org/D111573
2021-11-08 17:54:46 +00:00
Valentin Clement 59a4bbe26c
[fir] Add !fir.logical type conversion
Add conversion from !fir.logical types to LLVM IR Dialect types.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-08 17:54:55 +01:00
Quinn Pham c3b15b71ce [NFC] Inclusive Language: change master to main for .chm files
[NFC] As part of using inclusive language within the llvm project,
this patch replaces master with main when referring to `.chm` files.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D113299
2021-11-08 08:23:04 -06:00
Valentin Clement 7e92b759ed
[fir] Add fir.box type conversion
This patch add the `!fir.box` type conversion to llvm.
`fir.box` is converted to the descriptor as defined in the ISO_Fortran_binding.h
and the addendum defined in descriptor.h.

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

Reviewed By: awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2021-11-08 14:18:11 +01:00
Andrzej Warzynski ddd11b9a4b [flang][CodeGen] Transform `fir.call` to `llvm.call`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.call` to `llvm.call`.

This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>

Differential Revision: https://reviews.llvm.org/D113278
2021-11-08 11:43:54 +00:00
Jean Perier 4375430689 [flang] Set the addendum when establishing pointer section in descriptor
If the source has an addendum, the descriptor that is being established
to describe a section over the source needs to copy the addendum so that
derived type information is correctly set in the descriptor being
established.

This allows namelist IO with derived type to work correctly.

Differential Revision: https://reviews.llvm.org/D113258
2021-11-08 11:05:31 +01:00
Valentin Clement 29abf2a4a4
[fir] Add test for FIR types conversion
Add a separate file to test FIR types conversion to LLVM types.
Conversion comes from `flang/lib/Optimizer/CodeGen/TypeConverter.h`

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

Reviewed By: kiranchandramohan, awarzynski

Differential Revision: https://reviews.llvm.org/D113283
2021-11-08 09:41:39 +01:00
Valentin Clement 54c563474a
[fir] Add fir.extract_value and fir.insert_value conversion
This patch add the conversion pattern for fir.extract_value
and fir.insert_value. fir.extract_value is lowered to llvm.extractvalue
anf fir.insert_value is lowered to llvm.insertvalue.
This patch also adds the type conversion for the BoxType and RecordType
needed to have some comprehensive tests.

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

This patch was landed and reverted once.
TypeBuilderFunc getModel<Fortran::ISO::CFI_index_t>() was clashing
with getModel<long long> on windows since they both are 64 bits
signed interger. On linux CFI_index_t is long. Change CFI_index_t
to getModel<long>.

Reviewed By: awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-07 21:59:01 +01:00
Valentin Clement 7a189fb267
Revert "[fir] Add fir.extract_value and fir.insert_value conversion"
This reverts commit ea55503d7c.
2021-11-05 22:16:37 +01:00
Valentin Clement d75ab7d548
[fir] Remove getModel<Fortran::ISO::CFI_dim_t> in DescriptorModel.h
A windows buildbot complains about previous definiton after D112961.

Remove the extra definition until we can figure out if really needed.
2021-11-05 20:49:17 +01:00
Valentin Clement ea55503d7c
[fir] Add fir.extract_value and fir.insert_value conversion
This patch add the conversion pattern for fir.extract_value
and fir.insert_value. fir.extract_value is lowered to llvm.extractvalue
anf fir.insert_value is lowered to llvm.insertvalue.
This patch also adds the type conversion for the BoxType and RecordType
needed to have some comprehensive tests.

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

Reviewed By: awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-05 15:53:42 +01:00
Valentin Clement 8c23990949
[fir] Add fir.select and fir.select_rank FIR to LLVM IR conversion patterns
The `fir.select` and `fir.select_rank` are lowered to llvm.switch.

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

Reviewed By: mehdi_amini

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-05 12:54:51 +01:00
Mike Rice 4eac7bcf1a [OpenMP] Add parsing/sema/serialization for 'bind' clause.
Differential Revision: https://reviews.llvm.org/D113154
2021-11-04 14:40:30 -07:00
Kiran Chandramohan 48dc5c8e73 [Flang][OpenMP] Use the ultimate symbol in a call to the IsPointer function
The IsPointer check currently fails for host-associated symbols in OpenMP
regions. This causes some failures in semantic checks for pointer association
in an OpenMP region. Fix is to use the ultimate symbol in the call to the
IsPointer function in CheckPointerAssignment function in
lib/Semantics/pointer-assignment.cpp.

Reviewed By: klausler, peixin

Differential Revision: https://reviews.llvm.org/D112876
2021-11-04 19:53:58 +00:00
Josh Mottley a0f29fec65 [flang][flang-omp-report] Add flang-omp-report summarising script
The flang plugin ``flang-omp-report`` takes one fortran file in and returns a
YAML report file of the input file. This becomes an issue when you want to
analyse an entire project into one final report.
The purpose of this Python script is to generate a final YAML
report from all of the files generated by ``flang-omp-report``. The report can
have (currently) 2 formats; summary and log. Summary focuses on "summarizing"
all constructs and there clauses from all YAML files with a corresponding "count"
for each. Log instead combines the generated YAML files into one report in a
"cleaner" format. (Pseudo) Examples can be found for both formats at the top of
the script.

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

Co-Authored by: Ivan Zhechev <ivan.zhechev@arm.com>
2021-11-04 17:43:17 +00:00
Josh Mottley 2aec2549e8 [flang][flang-omp-report] Remove the loop workarounds for nowait clause
In a "Worksharing-loop construct", one can add a nowait clause at the end
of the loop (i.e. at the loop tail). This clause wasn't associated with
the corresponding loop when originally worked on in flang-omp-report.
Note that this refers to parsing and parse-tree generation. To work
around it, it was needed to track such clauses and the loops.
This should no longer be required (and in fact no longer works) and so
was removed. This results in 'curLoopLogRecord' and 'loopLogRecordStack' and
all references to them being removed. This also allows for
'constructClauses' to be swapped from std::deque to llvm::SmallVector.
Lastly a new test has been added testing the "nowait" clauses in a
variety of ways.

Reviewed By: awarzynski, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D112217
2021-11-04 14:23:50 +00:00
Josh Mottley 0a95abb7dc [flang][flang-omp-report] Removed unnecessary comments in flang-omp-report plugin tests
This patch removes unnecessary comments in the flang-omp-report
plugin tests which can be implied from the file name and run command.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D112817
2021-11-04 13:46:19 +00:00
Valentin Clement 3ae8e44215
[fir] Add fir.insert_on_range conversion
Convert fir.insert_on_range operation to corresponding
llvm.insertvalue operations.

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

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D112896
2021-11-04 10:36:20 +01:00
Valentin Clement c86b4503a9
[fir] Restrict array type on fir.insert_on_range
Sequence type had no restriction on the insert_on_range operation.
This patch adds a restriction for the type to have constant shape
and size.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D113092
2021-11-04 08:54:09 +01:00
Valentin Clement 52d813edcc
[fir] Use notifyMatchFailure in fir.zero_bits conversion
Change emitOpError to notifyMatchFailure in conversion pattern.

Post-commit change after D113014

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D113091
2021-11-03 20:45:24 +01:00
Valentin Clement 3c7ff45cbb
[fir] Add substr information to fircg.ext_embox and fircg.ext_rebox operations
This patch adds the substring information to the fircg.ext_embox and
fircg.ext_rebox operations.

Substring is used for CHARACTER types.

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

Reviewed By: mehdi_amini

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-03 10:15:10 +01:00
Mehdi Amini ca0ed40e00 Remove builder that takes SSA value instead of Attribute on ExtractValueOp, InsetValueOp, and InsertOnRangeOp
This builder exposed a somehow "unsafe" API: it pretends we can
construct an InsertOnRangeOp from a range of SSA values, even though
this will crash if these aren't the result of `arith.constant` since
the operation actually needs attribute values (a build method can't
fail gracefully).
That means that the caller must check for the producer, at which
point they can just assemble the attribute array directly and call
the existing builder.

The existing call-sites were even in a worse state here: they would
actually create a constant operation that wouldn't be used and only
serve to carry the attribute through the builder API.

Differential Revision: https://reviews.llvm.org/D112946
2021-11-02 22:35:47 +00:00
Andrzej Warzynski 32e08248aa [flang][CodeGen] Transform `fir.unreachable` to `llvm.unreachable`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.unreachable` to `llvm.unreachable`.

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>

Differential Revision: https://reviews.llvm.org/D113023
2021-11-02 18:22:51 +00:00
Valentin Clement a7a6135925
[fir] Add fir.zero_bits conversion pattern to LLVM IR dialect
This patch adds the ZeroOpConversion pattern to LLVM IR dialect.
Conversion of aggregate types is not implemented yet and will trigger a
failure to legalize the operation. This is tested in the
convert-to-llvm-invalid.fir test file.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-02 16:54:34 +01:00
Valentin Clement 0c4a7a5263
[fir][NFC] Address post commit comments on D112845
Address some of the comments on D112845 after
it was committed.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D112918
2021-11-01 17:56:55 +01:00
Diana Picus 9df0ba599c [flang] Implement GET_ENVIRONMENT_VARIABLE(VALUE)
Implement the second entry point for GET_ENVIRONMENT_VARIABLE. Reuse
existing bits and pieces wherever possible.

This patch also increases CFI_* error codes in order to avoid conflicts.
GET_ENVIRONMENT_VARIABLE is required to return a status of 1 if an
environment variable does not exist and 2 if environment variables are
not supported. However, if we add status codes for that they will
conflict with CFI_ERROR_BASE_ADDR_NULL and CFI_ERROR_BASE_ADDR_NOT_NULL,
which are also 1 and 2 at the moment. We therefore move all CFI error
codes up (an arbitrary) 10 spots to make room. Hopefully this isn't
a problem, since we weren't matching the CFI error codes that gfortran
uses anyway. It may still be an issue if any other runtime functions
will need to return a status of 1 or 2, but we should probably deal with
that when/if it occurs.

Differential Revision: https://reviews.llvm.org/D112698
2021-11-01 09:19:20 +00:00
Valentin Clement 044d5b5dd1
[fir] Add base of the FIR to LLVM IR pass
This patch adds the base of the FIR to LLVM IR Dialect conversion pass.
It currently can convert the following operations:
 - fir.global
 - fir.has_value
 - fir.address_of
 - fir.undefined

This patch is part of the upstreaming effort from fir-dev branch. It does not
cover all FIR operations in order to have small patches. Several patches will
follow to convert other operations.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D112845
2021-10-29 23:21:43 +02:00
peter klausler f70343d926 [flang] Fix combined folding of FINDLOC/MAXLOC/MINLOC
The tests for folding these intrinsics neglected to name the
logical scalars with a leading "test_", so test failures caused
by recent work to implement a combined constant folding facility
for these intrinsics wasn't catching some bugs.  This patch fixes
the tests and the bugs.

Differential Revision: https://reviews.llvm.org/D112741
2021-10-29 11:00:11 -07:00
peter klausler d0ca0595b9 [flang] Fix crash on "call system_clock(count_max=j)"
An erroneous entry in the intrinsics table causes semantics to
crash on a call to system_clock if the optional "count_max="
argument appears and "count=" does not.

Differential Revision: https://reviews.llvm.org/D112738
2021-10-29 10:51:28 -07:00
Nimish Mishra 9faed889cf Fixed erring semantic errors arising from D108904 2021-10-30 03:44:59 +05:30
peter klausler a94b721d26 [flang] Improve error message for misuse of NULL(mold) as data statement constant
While "null()" is accepted as a data statement constant when it
corresponds to a pointer object, "null(mold=p)" and "null(p)"
are not allowed.  The current error messages simply complain
that null is not an array.  This patch adds a context-sensitive
message to the effect that a data statement constant followed
by non-empty parentheses must be an array or structure constructor.

(Note that f18 can't simply special-case the name "null" when parsing
data statement constants, since programs are free to repurpose that
name as an array or derived type.)

Differential Revision: https://reviews.llvm.org/D112740
2021-10-28 15:20:41 -07:00
Peter Klausler 8b5b38eb24 [flang] Revert new unintended runtime behavior
A recent change caused some variable-length sequential formatted
output statements with record positioning at the end of a FORMAT
(e.g., FORMAT('hi',10X) to append blanks at the end of the completed
record when emitting it.

Differential Revision: https://reviews.llvm.org/D112742
2021-10-28 14:11:06 -07:00
peter klausler d48236a51c [flang] Fold SPREAD
Implements constant folding of the transformational intrinsic
function SPREAD().

Differential Revision: https://reviews.llvm.org/D112739
2021-10-28 14:10:16 -07:00
Emil Kieri 848cca6c5b [flang] Checks for pointers to intrinsic functions
Check that when a procedure pointer is initialised or assigned with an intrinsic
function, or when its interface is being defined by one, that intrinsic function
is unrestricted specific (listed in Table 16.2 of F'2018).

Mark intrinsics LGE, LGT, LLE, and LLT as restricted specific. Getting their
classifications right helps in designing the tests.

Differential Revision: https://reviews.llvm.org/D112381
2021-10-28 12:30:29 +02:00
Diana Picus 824bf90819 [flang] runtime: Read environment variables directly
Add support for reading environment variables directly, via std::getenv.
This needs to allocate a C-style string to pass into std::getenv. If the
memory allocation for that fails, we terminate.

This also changes the interface for EnvVariableLength to receive the
source file and line so we can crash gracefully.

Note that we are now completely ignoring the envp pointer passed into
ProgramStart, since that could go stale if the environment is modified
during execution.

Differential Revision: https://reviews.llvm.org/D111785
2021-10-28 07:49:30 +00:00
Shraiysh Vaishay 9fb52cb3f1 [MLIR][OpenMP] Added omp.atomic.read and omp.atomic.write
This patch supports the atomic construct (read and write) following
section 2.17.7 of OpenMP 5.0 standard. Also added tests and
verifier for the same.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D111992
2021-10-27 14:05:44 +05:30
River Riddle 4283168603 Fix AffineDemotion pass after the DialectConversion change in D111620 2021-10-27 04:13:18 +00:00
Valentin Clement 9daec09551
[fir] Avoid slice with substr in fir.array_load, fir.array_coor and fir.array_merge_store
Substring information on slice operation has been added in D112441.
The operations fir.array_load, fir.array_coor and fir.array_merge_store can take
a slice but not with a substring. This patch add this check in their verifier.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D112568
2021-10-26 21:44:25 +02:00
Valentin Clement d43f779f82
[fir][NFC] Move RewritePatterns.td to CanonicalizationPatterns.td in Dialect
RewritePatterns.td/RewritePatterns.inc is used only by the
FIROps.cpp file. This patch move this file logically in the Dialect
folder together with FIRDialet, FIROps, FIRTypes ...
It also rename it to CanonicalizationPatterns.td.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D112522
2021-10-26 21:12:54 +02:00
Valentin Clement 1189d97d12
[fir][NFC] Fix indentation for fir.alloca builders 2021-10-26 14:55:47 +02:00
Valentin Clement 7812f510d2
[fir] Add substring to fir.slice operation
This patch adds the substriing information to the fir.slice
operation. This will be used by character operations in later
upstreaming patches.

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

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-26 10:33:40 +02:00
Mike Rice d8699391a4 [OPENMP51]Initial parsing/sema for append_args clause for 'declare variant'
Adds initial parsing and sema for the 'append_args' clause.

Note that an AST clause is not created as it instead adds its values
to the OMPDeclareVariantAttr.

Differential Revision: https://reviews.llvm.org/D111854
2021-10-25 09:38:50 -07:00
Valentin Clement 608eb3d9c2
[fir][NFC] Format and make FIROps.td homogenous
This patch has couple of small changes to clean-up FIROps.td.
- Wrap lines that are longer than 80.
- All parser, verifier and printer that are single line are wrapped with double
  quotes.
- Couple of small typos.

Reviewed By: AlexisPerry

Differential Revision: https://reviews.llvm.org/D112436
2021-10-25 18:36:38 +02:00
Valentin Clement 84486cb222
[fir][NFC] Move MLIR includes to FIRDialect.td
The fir_Dialect definition was coming silently through FIRTypes.td.
Make the include of flang/Optimizer/Dialect/FIRDialect.td explicit in
FIROps.td and move MLIR includes to FIRDialect.td.

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

Reviewed By: AlexisPerry

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-25 18:33:46 +02:00
peter klausler fc3f92a8f4 [flang] Fix buildbot (new warnings on old code)
The clang-aarch64-full-2stage buildbot is complaining about a
warning with three instances in f18 code (none modified recently).
The warning is for using the | bitwise OR operator on bool operands.

In one instance, the bitwise operator was being used instead of the
logical || operator in order to avoid short-circuting.  The fix
requires using some temporary variables.  In the other two instances,
the bitwise operator seemed more idiomatic in context, but can be
replaced without harm with the logical operator.

Pushing without review as confidence is high and nobody wants
a buildbot to stay sad for long.
2021-10-22 17:52:32 -07:00
peter klausler b83242e20e [flang] Support legacy usage of 'A' edit descriptors for integer & real
The 'A' edit descriptor once served as a form of raw I/O of bytes
to/from variables that weren't of type CHARACTER (which itself
didn't exist until F'77).  This usage was especially common for
output of numeric variables that had been initialized with Hollerith.

Differential Revision: https://reviews.llvm.org/D112346
2021-10-22 16:02:33 -07:00
peter klausler 89a927c678 [flang] Fix NAMELIST input bug with multiple subscript triplets
NAMELIST input can contain array subscripts with triplet notation.
The calculation of the default effective stride for the constructed
array descriptor was simply incorrect after the first dimension.

Differential Revision: https://reviews.llvm.org/D112347
2021-10-22 15:59:28 -07:00
peter klausler f6aac0dd4d [flang] Fix DOT_PRODUCT for logical
A build-time check in a template class instantiation was applying
a test that's meaningful only for numeric types.

Differential Revision: https://reviews.llvm.org/D112345
2021-10-22 15:56:20 -07:00
peter klausler fbb020fb48 [flang] Extension: allow tabs in output format strings
A CHARACTER variable used as an output format may contain
unquoted tab characters, which are treated as if they had
been quoted.  This is an extension supported by all other
Fortran compilers to which I have access.

Differential Revision: https://reviews.llvm.org/D112350
2021-10-22 15:53:29 -07:00
peter klausler ce71f8e017 [flang] Fix crash on empty formatted external READs
ExternalFileUnit::BeginReadingRecord() must be called at least once
during an external formatted READ statement before FinishReadingRecord().
In the case of a formatted external READ with no data items, the call
to finish processing of the format (which might have lingering control
items that need doing) was taking place before the call to BeginReadingRecord
from ExternalIoStatementState::EndIoStatement.  Add a call to
BeginReadingRecord on this path.

Differential Revision: https://reviews.llvm.org/D112351
2021-10-22 15:48:45 -07:00
Peter Klausler a5a493e192 [flang] Speed common runtime cases of DOT_PRODUCT & MATMUL
Look for contiguous numeric argument arrays at runtime and
use specialized code for them.

Differential Revision: https://reviews.llvm.org/D112239
2021-10-22 14:36:13 -07:00
peter klausler 14b90d1fe0 [flang] Fix generic resolution case
Don't try to convert INTEGER argument expressions to the kind of
the dummy argument when performing generic resolution; specific
procedures may be distinguished only by their kinds.

Differential Revision: https://reviews.llvm.org/D112240
2021-10-22 13:38:47 -07:00
peter klausler b8452dba28 [flang] Support NAMELIST input of short arrays
NAMELIST array input does not need to fully define an array.
If another input item begins after at least one element,
it ends input into the array and the remaining items are
not modified.

The tricky part of supporting this feature is that it's not
always easy to determine whether the next non-blank thing in
the input is a value or the next item's name, esp. in the case
of logical data where T and F can be names.  E.g.,

  &group logicalArray = t f f t
      = 1 /

should read three elements into "logicalArray" and then read
an integer or real variable named "t".

So the I/O runtime has to do some look-ahead to determine whether
the next thing in the input is a name followed by '=', '(', or '%'.
Since the '=' may be on a later record, possibly with intervening
NAMELIST comments, the runtime has to support a general form of
saving and restoring its current position.  The infrastructure
in the I/O runtime already has to support repositioning for
list-directed repetition, even on non-positionable input sources
like terminals and sockets; this patch adds an internal RAII API
to make it easier to save a position and then do arbitrary
look-ahead.

Differential Revision: https://reviews.llvm.org/D112245
2021-10-22 13:38:11 -07:00
peter klausler c4ba1108dd [flang] Extension to distinguish specific procedures
Allocatable dummy arguments can be used to distinguish
two specific procedures in a generic interface when
it is the case that exactly one of them is polymorphic
or exactly one of them is unlimited polymorphic.  The
standard requires that an actual argument corresponding
to an (unlimited) polymorphic allocatable dummy argument
must also be an (unlimited) polymorphic allocatable, so an
actual argument that's acceptable to one procedure must
necessarily be a bad match for the other.

Differential Revision: https://reviews.llvm.org/D112237
2021-10-22 12:38:21 -07:00
peter klausler f2360e1156 [flang] Enforce rest of semantic constraint C919
A reference to an allocatable or pointer component must be applied
to a scalar base object.  (This is the second part of constraint C919;
the first part is already checked.)

Differential Revision: https://reviews.llvm.org/D112241
2021-10-22 11:35:58 -07:00
peter klausler b03628d986 [flang] Emit unformatted headers & footers even with RECL=
The runtime library was emitting unformatted record headers and
footers when an external unit had no fixed RECL=.  This is wrong
for sequential files, which should have headers & footers even
with RECL.  Change to omit headers & footers from unformatted
I/O only for direct access files.

Differential Revision: https://reviews.llvm.org/D112243
2021-10-22 11:07:01 -07:00
peter klausler d5074c7166 [flang] Fix bogus folding error for ISHFT(x, negative)
Negative shift counts are of course valid for ISHFT when
shifting to the right.  This patch decouples the folding of
ISHFT from that of SHIFTA/L/R and adds tests.

Differential Revision: https://reviews.llvm.org/D112244
2021-10-22 10:38:27 -07:00
Andrzej Warzynski 3085e67851 [Flang][docs] Remove an out-dated section on the new driver
This section of the documentation should've been deleted in:
https://reviews.llvm.org/D105811

I am submitting this without a review as it's an obvious omission.
2021-10-22 14:44:24 +00:00
Valentin Clement a2e7af7516
[fir] Add utility function to FIRBuilder and MutableBox
This patch is extracted from D111337 to make is smaller.
It introduce utility functions to the FIRBuilder and add the MutableBox
files.

- genShape
- readCharLen
- getExtents

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-22 10:00:34 +02:00
Valentin Clement 0bf230d422
[fir] Remove unused function in CharacterTest 2021-10-22 00:25:59 +02:00
Valentin Clement 2ba572a82a
[fir] Remove createConcatenate test temporarily
This test is makeing one buildbot fail for unknown reason. Remove
it until we can investifate further.
2021-10-21 22:40:19 +02:00
Valentin Clement 13c31539f7
[fir] Add Character helper
This patch is extracted from D111337. It introduce the
CharacterExprHelper that helps dealing with character in FIR.

Reviewed By: schweitz, awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2021-10-21 18:45:32 +02:00
Valentin Clement 7bbd7e9c1d
Revert "[fir] Add Character helper"
This reverts commit e4ce92245c.

Buildbots not happy with the tests.
2021-10-21 11:36:10 +02:00
Valentin Clement e4ce92245c
[fir] Add Character helper
This patch is extracted from D111337. It introduce the
CharacterExprHelper that helps dealing with character in FIR.

Reviewed By: schweitz, awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2021-10-21 09:48:37 +02:00
Valentin Clement 676d091c63
Revert "[fir] Add Character helper"
This reverts commit 02d7089c23.
2021-10-20 22:43:13 +02:00
Valentin Clement 02d7089c23
[fir] Add Character helper
This patch is extracted from D111337. It introduce the
CharacterExprHelper that helps dealing with character in FIR.

Reviewed By: schweitz, awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2021-10-20 21:35:02 +02:00
Josh Mottley e9fe8ef4b0 [flang] flang-omp-report replace std::map with llvm::DenseMap
This patch replaces the uses of std::map with llvm::DenseMap in the
flang-omp-report plugin. It also removed the 'constructClauseCount' map
due to no longer being needed after the plugin was stripped down.
This is a one of several patches focusing on switching containers from STL to LLVM's ADT library.

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D111977
2021-10-20 07:57:04 +00:00
Josh Mottley 660c511e5b [Flang][flang-omp-report] Switch from std::string to StringRef (where possible)
This patch makes the following changes to flang-omp-report:
 - Update 'normalize_clause_name' parameter to use llvm::StringRef instead of
   std::sting.
 - Change usages of std::tolower to llvm::toLower from
   "ADT/StringExtras.h".
This is a one of several patches focusing on switching containers from STL to LLVM's ADT library.

Reviewed By: Leporacanthicus, clementval

Differential Revision: https://reviews.llvm.org/D111980
2021-10-20 07:55:44 +00:00
Valentin Clement c983aeddcf
[fir] Add character utility functions in FIRBuilder
Extract part of D111337 in order to mke it smaller
and easier to review. This patch add some utility
functions to the FIRBuilder.

Add the following utility functions:
- getCharacterLengthType
- createStringLiteral
- locationToFilename
- characterWithDynamicLen
- sequenceWithNonConstantShape
- hasDynamicSize

These bring up the BoxValue implementation together with it.

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

Reviewed By: AlexisPerry

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-19 22:34:21 +02:00
Valentin Clement 45503fc044
[fir] Add FIRBuilder utility functions
Extract some code from the big ptach D111337. This patch
contains some utility functions from the FIRBuidler.

List of utility functions added:
- getRegion
- getModule
- getKindMap
- getRefType
- getVarLenSeqTy
- getRealType
- createNullConstant
- createRealConstant
- createRealZeroConstant
- createGlobal
- createGlobalConstant
- createStringLitOp
- getNamedFunction
- getNamedGlobal
- createFunction
- addNamedFunction
- createBool

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-19 14:19:45 +02:00
peter klausler 2f80b73e0c [flang] Fold BTEST
Implements constant folding for BTEST intrinsic function.

Differential Revision: https://reviews.llvm.org/D111849
2021-10-18 13:46:46 -07:00
Valentin Clement f17f694a0f
[fir] Add IfBuilder and utility functions
In order to reduct the size of D111337. The IfBuilder and the two
utility functions genIsNotNull and genIsNull have been extracted in
a separate patch with dedicated unittests.

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

Reviewed By: Leporacanthicus

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-17 20:55:41 +02:00
PeixinQiao dd8c8d4b7c This patch supports the following checks for THREADPRIVATE Directive:
```
[5.1] 2.21.2 THREADPRIVATE Directive
A variable that appears in a threadprivate directive must be declared in
the scope of a module or have the SAVE attribute, either explicitly or
implicitly.
A variable that appears in a threadprivate directive must not be an
element of a common block or appear in an EQUIVALENCE statement.
```

This patch supports the following checks for DECLARE TARGET Directive:
```
[5.1] 2.14.7 Declare Target Directive
A variable that is part of another variable (as an array, structure
element or type parameter inquiry) cannot appear in a declare
target directive.
A variable that appears in a declare target directive must be declared
in the scope of a module or have the SAVE attribute, either explicitly
or implicitly.
A variable that appears in a declare target directive must not be an
element of a common block or appear in an EQUIVALENCE statement.
```

As Fortran 2018 standard [8.5.16] states, a variable, common block, or
procedure pointer declared in the scoping unit of a main program,
module, or submodule implicitly has the SAVE attribute, which may be
confirmed by explicit specification.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D109864
2021-10-17 22:08:02 +08:00
peter klausler 0fcda9ae57 [flang] Admit NULL() in generic procedure resolution cases
Semantics is rejecting valid programs with NULL() actual arguments
to generic interfaces, including user-defined operators.  Subclause
16.9.144(para 6) makes clear that NULL() can be a valid actual
argument to a generic interface so long as it does not produce
ambiguity.  This patch handles those cases, revises existing
tests, and adjust an error message about NULL() operands to
appear less like a blanket prohibition.

Differential Revision: https://reviews.llvm.org/D111850
2021-10-14 16:02:17 -07:00
peter klausler 6965a776ee [flang] Fold LGE/LGT/LLE/LLT intrinsic functions
Fold the legacy intrinsic functions LGE, LGT, LLE, & LLT
by rewriting them into character relational expressions and
then folding those.  Also fix folding of comparisons of
character values of distinct lengths: the shorter value must
be padded with blanks.  (This fix exposed some bad test cases,
which are also fixed.)

Differential Revision: https://reviews.llvm.org/D111843
2021-10-14 15:24:03 -07:00
peter klausler 1062f989af [flang] Expunge bogus semantic check for ELEMENTAL without dummies
Semantics refuses valid ELEMENTAL subprograms without dummy arguments,
but there's no such constraint in the standard; indeed, subclause
15.8.2 discusses the meaning of calls to ELEMENTAL functions with
arguments.  Remove the check and its test.

Differential Revision: https://reviews.llvm.org/D111832
2021-10-14 14:33:30 -07:00
Mogball cb3aa49ec0 [MLIR][arith] fix references to std.constant in comments
Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D111820
2021-10-14 20:38:47 +00:00
Josh Mottley 0b48b015b5 [Flang] flang-omp-report replace std::vector's with llvm::SmallVector
This patch replaces all uses of std::vector with llvm::SmallVector in the flang-omp-report plugin.
This is a one of several patches focusing on switching containers from STL to LLVM's ADT library.

Reviewed By: Leporacanthicus

Differential Revision: https://reviews.llvm.org/D111709
2021-10-14 11:05:24 +01:00
Valentin Clement 0fbd3aad75
[fir] Remove unused variable in FIRBuilder.h
Remove unsused variable that break Werror on some buildbots
2021-10-14 07:11:41 +02:00
Eric Schweitz bde89ac7f1
[fir] Add the DoLoopHelper
Add the DoLoopHelper. Some helpers functions
to create fir.do_loop operations.

This code was part of D111337 and was extracted in order to
make the patch easier to review.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-10-13 21:48:45 +02:00
Mike Rice fb4c451001 [OPENMP51]Initial parsing/sema for adjust_args clause for 'declare variant'
Adds initial parsing and sema for the 'adjust_args' clause.

Note that an AST clause is not created as it instead adds its expressions
to the OMPDeclareVariantAttr.

Differential Revision: https://reviews.llvm.org/D99905
2021-10-13 09:34:09 -07:00
Valentin Clement b2169992aa
[fir][NFC] Add disclaimer to affine promotion/demotion passes
AffinePromotion and AffineDemotion passes where upstreamed
in their current status from fir-dev. In order to make sure everybody
is on the same page, this patch add some comments to state that.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111629
2021-10-13 17:47:14 +02:00