Commit Graph

491 Commits

Author SHA1 Message Date
Jean Perier a398981fb0 [flang] Add fir.declare operation
Add fir.declare operation whose purpose was described in https://reviews.llvm.org/D134285.
It uses the FortranVariableInterfaceOp for most of its logic (including the verifier).
The rational is that all these aspects/logic will be shared by hlfir.designate and
hlfir.associate.

Its codegen and lowering will be added in later patches.

Differential Revision: https://reviews.llvm.org/D136181
2022-10-19 11:06:58 +02:00
Valentin Clement 6e85b8807f
[flang] Add fir.dispatch code generation
fir.dispatch code generation uses the binding table stored in the
type descriptor. There is no runtime call involved. The binding table
is always build from the parent type so the index of a specific binding
is the same in the parent derived-type or in the extended type.

Follow-up patches will deal cases not present here such as allocatable
polymorphic entities or pointers.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D136189
2022-10-19 09:41:47 +02:00
Jean Perier 875fd9df76 [flang] Introduce FortranVariableOpInterface for ops creating variable
HLFIR will rely on certain operations to create SSA memory values
that correspond to a Fortran variable. They will hold bounds and type
parameters information as well as metadata (like Fortran attributes).

This patch adds an interface that for such operations so that Fortran
variable can be stored, manipulated, and queried regardless of what
created them. This is so far intended for fir.declare, hlfir.designate
and hlfir.associate operations.
It is added to FIR and not HLFIR because fir.declare needs it and it
does not itself needs any HLFIR concepts.

Unit tests for the interface methods will be added alongside
fir.declare in the next patch.

Differential Revision: https://reviews.llvm.org/D136151
2022-10-19 08:56:47 +02:00
Valentin Clement 87b2d1d04e
[flang] Add getTypeDescriptorBindingTableName function
Type descriptor and its binding table are defined as fir.global in FIR.
Their names are derived from the derived-type name. This patch adds a new
function `getTypeDescriptorBindingTableName` in the NameUniquer and
refactor the `GetTypeDescriptorName` function to reuse the same code.
This will be used in the fir.dispatch code generation.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D136167
2022-10-18 19:55:55 +02:00
Valentin Clement faf0e1fbf9
[flang] Reconstruct binding tables for fir.dispatch codegen
Binding tables are needed to perform the fir.dispatch code generation.
The binding tables are defined as fir.global from the initial lowering.
This patch adds the ability to reconstruct the binding tables information
and store the procedure name and binding index for later use by the
fir.dispatch code generation.
Tests will come with follow up patch that makes full use of this information.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D136141
2022-10-18 12:12:32 +02:00
Jean Perier c4331358fb [flang] Add an enum attribute to carry Fortran attributes
Currently, Fortran attributes are mostly represented via the presence of
named attribute with special names (fir.target, fir.contiguous,
fir.optional...).

Create an enum so that these attributes can be more easily and safely
manipulated in FIR.

This patch does not add usages for it yet. It is planned to use in it in
the future HLFIR and fir.declare operations. This is added to FIR and
not HLFIR because it is intended to be used on fir.declare that will
be part of FIR, and seems also usefull for FIR operations.

Differential Revision: https://reviews.llvm.org/D135961
2022-10-17 15:42:42 +02:00
Valentin Clement 4265f78dd7
[flang] Lower tbp dispatch calls for polymorphic array element
When calling a type-bound procedure from a polymoprhic array element,
the dynamic type needs to be extracted from the array descriptor
and passed to the embox operation for the pass-object.

Depends on D135809

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D135856
2022-10-13 14:48:42 +02:00
Valentin Clement 3d9653bc2f
[flang] Add optional tdesc operand to fir.embox for polymorphic entities
In some cases, it is useful to be able to embox a polymorphic entity
together with its dynamic type. This patch adds an optional tdesc operand
to fir.embox so the dynamic type can be provided while emboxing the entity.
This will be used in follow-up patch that lowers tbp calls for element of
polymorphic entities array.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D135809
2022-10-13 11:41:15 +02:00
Valentin Clement 89c923655a
[flang] Embox derived-type directly to fir.class without fir.convert
non-polymorphic derived-type can call type-bound procedure with passed-object.
In that case, the derived-type is emboxed in order to be passed to the call.
Until now the emboxing was done to a fir.box followed by a fir.convert.
This patch update the createBox function so that we can directly embox to
a fir.class and avoid the extra fir.convert.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D135790
2022-10-13 10:39:59 +02:00
Jonathon Penix 0ec3ac9b7f [Flang] Add -fconvert option to swap endianness for unformatted files.
To accomplish this, this patch creates an optional list of environment
variable default values to be set by the runtime to allow directly using
the existing runtime implementation of FORT_CONVERT for I/O conversions.
2022-10-12 16:57:37 -07:00
Valentin Clement 0ff137c1ef
[flang] Use fir.rebox for tbp fir.dispatch call with allocatable or pointer
Polymorphic entities with allocatable or pointer attribute cannot be passed
directly as passed-object when the type-bound procedure is expecting a
simply dummy polymorphic entity. Use fir.rebox to adapt the fir.class box
to the tbp type.

Depends on D135649

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D135654
2022-10-12 16:19:03 +02:00
Valentin Clement 7883900c04
[flang] Lower type-bound procedure call needing dynamic dispatch to fir.dispatch
Lower call with polymorphic entities to fir.dispatch operation. This patch only
focus one lowering with simple scalar polymorphic entities. A follow-up patch
will deal with allocatble, pointer and array of polymorphic entities as they
require box manipulation for the passed-object.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D135649
2022-10-12 15:24:49 +02:00
David Truby d983f5f39e [flang] Add cpowi function to runtime and use instead of pgmath
This patch adds a cpowi function to the flang runtime, and switches
to using that function instead of pgmath for complex number to
integer power operations.

Differential Revision: https://reviews.llvm.org/D134889
2022-10-11 12:34:58 +00:00
Slava Zakharin 9f6aae4606 [flang] Add type-specific runtime entries for Minloc/Maxloc.
We used to have a big switch statement over the type categories and kinds
inside Minloc/Maxloc. After D133051 the switch grew bigger, and this
changed inlining decisions made by GCC (the build compiler). Some of the
simple methods stopped being inlined, and this caused slight performance
regression in Polyhedron/gas_dyn2. This change adds separate entries
for real/integer data types to let them be optimized separately.

Differential Revision: https://reviews.llvm.org/D135610
2022-10-10 16:58:33 -07:00
Valentin Clement 0cf70a33f2
[flang] Allow conversion from boxed derived type to fir.class
This patch updates the fir.convert operation's verifier to allow
conversion from !fir.box<!fir.type<T>> to !fir.class<!fir.type<T>>.

Other conversion involving fir.class are likely needed but will
be added when lowering needs them.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D135445
2022-10-10 08:59:09 +02:00
Slava Zakharin ac76fa480f [flang] Represent TARGET for globals with 'target' attribute.
TARGET dummy arguments have fir.target attribute attached to them,
but globals do not have any sign of TARGET. This patch adds
target attribute for globals, which can be queried via
::fir::GlobalOp::getTarget().

Differential Revision: https://reviews.llvm.org/D135313
2022-10-06 19:14:28 -07:00
Valentin Clement eaa583c330
[flang] Use assembly format for fir.dispatch
Remove custom parser/printer and make use of the assembly format
for the fir.dispatch operation.

Depends on D135358

Reviewed By: PeteSteinfeld, jeanPerier

Differential Revision: https://reviews.llvm.org/D135363
2022-10-06 21:41:13 +02:00
Valentin Clement 5a0722e046
[flang] Update fir.dispatch operation
Update the `fir.dispatch` operation to prepare
the lowering part. `nopass` and `pass_arg_pos` attributes
are added in the arguments list so accessors are generated
by MLIR tablegen. A verifier is added as well as some tests.

This patch is part of the implementation of the poltymorphic
entities.
https://github.com/llvm/llvm-project/blob/main/flang/docs/PolymorphicEntities.md

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D135358
2022-10-06 18:11:56 +02:00
Valentin Clement e50e19af00
[flang] Update to fir::isUnlimitedPolymorphicType and fir::isPolymorphicType functions
This patch update the fir::isUnlimitedPolymorphicType function
to reflect the chosen design. It adds also a fir::isPolymorphicType
function.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D135143
2022-10-05 10:05:11 +02:00
Valentin Clement 9d99b482cd
[flang] Lower polymorphic entities types in dummy argument and function result
This patch updates lowering to produce the correct fir.class types for
various polymorphic and unlimited polymoprhic entities cases. This is only the
lowering. Some TODOs have been added to the CodeGen part to avoid errors since
this part still need to be updated as well.
The fir.class<*> representation for unlimited polymorphic entities mentioned in
the document has been updated to fir.class<none> to avoid useless work in pretty
parse/printer.

This patch is part of the implementation of the poltymorphic
entities.
https://github.com/llvm/llvm-project/blob/main/flang/docs/PolymorphicEntities.md

Depends on D134957

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D134959
2022-10-04 09:43:59 +02:00
Rainer Orth 1774a8a763 [flang] Add Sparc support to Optimizer/CodeGen/Target.cpp
As described in Issue #57642, `flang` currently lacks SPARC support in
`Optimizer/CodeGen/Target.cpp`, which causes a considerable number of tests
to `FAIL` with

  error: flang/lib/Optimizer/CodeGen/Target.cpp:310: not yet implemented:
target not implemented

This patch fixes this by following GCC`s documentation of the ABI described
in the Issue.

Tested on `sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D133561
2022-10-03 14:03:35 +02:00
Valentin Clement a89b04805a
[flang][NFC] Use prefixed accessors for fircg dialect
The raw accessor is going away soon so switch to prefixed accessors in the
fircg dialect. The main dialect was switched some months ago.

https://github.com/llvm/llvm-project/issues/58090

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D135061
2022-10-03 11:02:43 +02:00
Valentin Clement 262c23d2ca
[flang] Introduce fir.class type
Introduce a new ClassType for polymorphic
entities. A fir.class type is similar to a fir.box type in
many ways and is also base on the BaseBoxType.

This patch is part of the implementation of the poltymorphic
entities.
https://github.com/llvm/llvm-project/blob/main/flang/docs/PolymorphicEntities.md

Depends on D134956

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D134957
2022-10-02 20:13:51 +02:00
Valentin Clement ceff415a1a
[flang] Introduce BaseBoxType
Introduce a BaseBoxType to be used by BoxType and
the a new ClassType that is introduced in a follow up patch.

This patch is part of the implementation of the poltymorphic
entities.
https://github.com/llvm/llvm-project/blob/main/flang/docs/PolymorphicEntities.md

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D134956
2022-10-02 20:08:54 +02:00
River Riddle c692a11e69 [mlir] Flip Async/GPU/MemRef/OpenACC/OpenMP/PDL dialects to prefixed
This flips all of the remaining dialects to prefixed except for linalg, which
will be done in a followup.

Differential Revision: https://reviews.llvm.org/D134995
2022-09-30 16:55:30 -07:00
Valentin Clement e8b701208c
[flang] Remove unused AffineMapAttr from fir.box type
AffineMapAttr on fir.box type is not used. This patch
remove it. It can be added back later when needed.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D134955
2022-09-30 20:35:55 +02:00
Jakub Kuderski 6c8d8d1045 [flang][mlir][arith] Fix flang build after dialect renaming
Tested with `ninja check-flang`
2022-09-29 11:55:49 -04:00
Tarun Prabhu ebfe8a7411 [flang] Lower F08 bitwise-reduction intrinsics (IALL, IANY, IPARITY)
This calls the corresponding runtime functions when appropriate. The implementation
follows the pattern of the SUM and PRODUCT intrinsics.

Differential Revision: https://reviews.llvm.org/D129616
2022-09-26 10:28:46 -06:00
Slava Zakharin 8bd76ac151 [flang] Support multidimensional reductions in SimplifyIntrinsicsPass.
Create simplified functions for each rank with "x<rank>" suffix
that implement multidimensional reductions. To enable this I had to fix
an issue with taking incorrect box shape in cases of sliced embox/rebox.

Differential Revision: https://reviews.llvm.org/D133820
2022-09-19 12:16:23 -07:00
Slava Zakharin 2b138567e0 [flang] Support more data types for reduction in SimplifyIntrinsicsPass.
All floating point (not complex) and integer types should be supported now.

Differential Revision: https://reviews.llvm.org/D133818
2022-09-19 12:16:22 -07:00
Jean Perier 9e1395ef14 [flang] Make a descriptor copy for fir.load fir.ref<fir.box>
`fir.box` and `fir.ref<fir.box>` are both lowered to LLVM as a
descriptor in memory. This is because fir.box of polymorphic and assumed
rank entities cannot be known at compile time, so fir.box cannot be
lowered to a struct value.

fir.load or fir.ref<fir.box> was previously lowered to a no-op,
propagating the operand descriptor storage as a result.
This is wrong because the operand descriptor storage may later be
modified, and these changes should not be visible in the loaded fir.box
that is an immutable SSA value.

Modify fir.load codegen for fir.box to make a copy into a new storage to
ensure the fir.box is immutable.

Differential Revision: https://reviews.llvm.org/D133779
2022-09-14 08:56:33 +02:00
Slava Zakharin 02f3fec391 [flang] Compute type allocation size based on the actual target representation.
This change makes sure that we compute the element size and the byte stride
based on the target representation of the element type.

For example, when REAL*10 is mapped to x86_fp80 each element occupies
16 bytes rather than 10 because of the padding.

Note that the size computation method used here actually returns
the distance between two adjacent element of the *same* type in memory
(which is equivalent to llvm::DataLayout::getTypeAllocSize()).
It does not return the number of bytes that may be overwritten
by storing a value of the specified type (e.g. what can be computed
via llvm::DataLayout::getTypeStoreSize(), but not available in
mlir::DataLayout).

Differential Revision: https://reviews.llvm.org/D133508
2022-09-09 08:39:15 -07:00
Peixin Qiao 109f9a2918 [flang] Support lowering of intrinsic module procedure C_F_POINTER
As Fortran 2018 18.2.3.3, the intrinsic module procedure
C_F_POINTER(CPTR, FPTR [, SHAPE]) associates a data pointer with the
target of a C pointer and specify its shape. CPTR shall be a scalar of
type C_PTR, and its value is the C address or the result of a reference
to C_LOC. FPTR is one pointer, either scalar or array. SHAPE is a
rank-one integer array, and it shall be present if and only if FPTR is
an array.

C_PTR is the derived type with only one component of integer 64, and the
integer 64 component value is the address. Build the right "source"
fir::ExtendedValue based on the address and shape, and use
associateMutableBox to associate the pointer with the target of the C
pointer.

Refactor the getting the address of C_PTR to reuse the code.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D132303
2022-09-06 08:15:01 +08:00
Mats Petersson aa94eb3877 [FLANG][NFC]Use RTNAME instead of hard-coding for simplify intrinsics
Use the RTNMAE macro (via stringify macros) to generate the name
strings for runtime functions, instead of using strings.
The sequence of macros generate exactly the same string as the
ones used previously, but this will support future changes in
runtime function names.

No functional change.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D132652
2022-09-05 13:06:44 +01:00
Mats Petersson 43159b5808 [FLANG][NFCI]De-duplicate code in SimplifyIntrinsics
This removes a bunch of duplicated code, by adding an intermediate
function simplifyReduction that takes a std::function argument
for the actual replacement of the code.

No functional change intended.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D132588
2022-09-02 10:49:25 +01:00
Slava Zakharin 69193c6cd7 [flang] Generate DOT_PRODUCT runtime call based on the result type.
We used to select the runtime function based on the first argument's
type, which was not correct behavior. The selection is done using
the result type now.

Differential Revision: https://reviews.llvm.org/D133032
2022-08-31 15:20:12 -07:00
Michele Scuttari 67d0d7ac0a
[MLIR] Update pass declarations to new autogenerated files
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure.

Reviewed By: mehdi_amini, rriddle

Differential Review: https://reviews.llvm.org/D132838
2022-08-31 12:28:45 +02:00
Slava Zakharin bac3aeda06 [flang] Lower integer exponentiation into math::IPowI.
Differential Revision: https://reviews.llvm.org/D132770
2022-08-30 14:09:05 -07:00
Michele Scuttari 039b969b32
Revert "[MLIR] Update pass declarations to new autogenerated files"
This reverts commit 2be8af8f0e.
2022-08-30 22:21:55 +02:00
Michele Scuttari 2be8af8f0e
[MLIR] Update pass declarations to new autogenerated files
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure.

Reviewed By: mehdi_amini, rriddle

Differential Review: https://reviews.llvm.org/D132838
2022-08-30 21:56:31 +02:00
Kazu Hirata 33b9304435 Use llvm::is_contained (NFC) 2022-08-27 21:21:00 -07:00
Daniil Dudkin a6f2f44f9c [flang] Introduce `AbstractResultOnGlobalOpt` pass
This pass allows to convert operations
which use functions with abstract results to ones that do not.

Depends on D130087

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D130088
2022-08-25 21:58:59 +03:00
Gabriel Ravier 9e37b1e5a0
[flang] Fixed a number of typos
I went over the output of the following mess of a command:

`(ulimit -m 2000000; ulimit -v 2000000; git ls-files -z | parallel --xargs -0 cat | aspell list --mode=none --ignore-case | grep -E '^[A-Za-z][a-z]*$' | sort | uniq -c | sort -n | grep -vE '.{25}' | aspell pipe -W3 | grep : | cut -d' ' -f2 | less)`

and proceeded to spend a few days looking at it to find probable typos
and fixed a few hundred of them in all of the llvm project (note, the
ones I found are not anywhere near all of them, but it seems like a
good start).

Reviewed By: awarzynski, clementval

Differential Revision: https://reviews.llvm.org/D130844
2022-08-25 18:11:38 +02:00
Mats Petersson 5653884e34 [FLANG]Remove experimental flag from SUM simplification
The SUM function does appear to be safe to use, so remove the
experimental flag for the SUM operation.

Reviewed By: vzakhari, awarzynski

Differential Revision: https://reviews.llvm.org/D132567
2022-08-25 14:11:41 +01:00
Alexander Batashev 79c2094881 [mlir][LLVMIR] Parse some type attributes for LLVM function parameters
With the transition to opaque pointers, type information has been
transferred to function parameter attributes. This patch adds correct
parsing for some of those arguments and fixes some tests, that
previously used UnitAttr for those.

Differential Revision: https://reviews.llvm.org/D132366
2022-08-25 11:06:51 +03:00
Tarun Prabhu 5259528fc8 [flang] Lower F08 parity intrinsic
Lower F08 parity intrinsic. This largely follows the implementation of the ANY
and ALL intrinsics which are related.

Differential Revision: https://reviews.llvm.org/D129788
2022-08-24 08:00:30 -06:00
Mats Petersson afa520ab34 [FLANG]Add maxval simplification support
Add simplifcation pass for MAXVAL intrinsic function

This refactors some of the code to allow variation on the
initialization value and operation performed within the loop,
reusing the majority of code for both SUM and MAXVAL.

Adding tests for the test-cases that produce different output
than the SUM function.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D132234
2022-08-24 14:08:19 +01:00
Kiran Chandramohan 367a1fa889 [NFC] Mark variable as maybe_unused to silence warning 2022-08-24 13:18:28 +01:00
Mats Petersson 72e599197c [Flang]Fix another way to crash SimplifyIntrinsics
Under some conditions, the defining op may be NULL, so
accept that rahter than try to use it and crash!

Adds test to prevent regression

Fixes github issue #57201

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D132238
2022-08-19 19:00:30 +01:00
Valentin Clement 5dbeb2ce2a
[flang] Shift argument attributes when result operand is inserted
The TargetRewrite pass convert the signature of the function.
In some cases it adds operands to the function to hanlde the result of it.
This patch makes sure the argument attributes present before the conversion
are replaced with the correct arguments after the conversion is performed.

Depends D132113

Reviewed By: vdonaldson

Differential Revision: https://reviews.llvm.org/D132114
2022-08-19 08:40:27 +02:00