Commit Graph

3703 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