9 Commits

Author SHA1 Message Date
Slava Zakharin
b9e435cbe4 [flang][hlfir] Removed incorrect clean-up in the implied-do lowering.
The lowering of calls/expressions unconditionally inserts DestroyOp
clean-up for hlfir.expr values, which is wrong in the case where
the value is used as a result of the elemental operation created
during the implied-do lowering. A cleaner fix could be to avoid
DestroyOp insertion at all, but I have not figure out an easy
way to do it. The DestroyOp look-up I used seems to be quite
reliable, so it should just work.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D155665
2023-07-19 14:38:31 -07:00
Slava Zakharin
7b4aa95d7c [flang][hlfir] Set/propagate 'unordered' attribute for elementals.
This patch adds 'unordered' attribute handling the HLFIR elementals'
builders and fixes the attribute handling in lowering and transformations.

Depends on D154031, D154032

Reviewed By: jeanPerier, tblah

Differential Revision: https://reviews.llvm.org/D154035
2023-06-29 11:16:38 -07:00
Jean Perier
9ac452b286 [flang][NFC] Move Array constructor inlined temp management into a utility
This patch moves the counter and storage management part of the array
constructor inlined temporary strategy into its own utility so that it
can be reused for the simple cases of temporary creations inside WHERE
and FORALL.

It actually fixes a bug where the counter first value  used for addressing
was "2" leading to read/write after the allocated storage... It seems
I ran the tests end-to-end without the HLFIR flag when previously testing
this. So this may clear some segfaults.

Differential Revision: https://reviews.llvm.org/D151106
2023-05-23 17:00:31 +02:00
Slava Zakharin
ebae4cc7cb [flang][hlfir] Fixed array constructor lowering.
First issue is that the clean-ups were generated after the yield_element
operation that must be the terminator. Second issue is that codegen for
elemenal operation was not working properly with nested elemental ops.

Differential Revision: https://reviews.llvm.org/D149921
2023-05-05 10:09:22 -07:00
Jean Perier
bc991d940f [flang][hlfir] Array constructor lowering [part 4/4]
Enable character and derived type array constructor lowering.
Nothing special needs to be done other than lowering the types
before the array constructor lowering.
Derived type are forced to use the runtime for now to avoid
undesired usage of user defined assignment that hlfir.assign
may trigger when using the runtime.

Differential Revision: https://reviews.llvm.org/D144548
2023-02-24 09:18:27 +01:00
Jean Perier
9683a9c998 [flang][hlfir] Array constructor lowering [part 3/4]
Lower the cases that require runtime support to deal
with the allocation, reallocation, or copy of ac-values to
the array constructor storage.

Differential Revision: https://reviews.llvm.org/D144513
2023-02-24 09:11:28 +01:00
Jean Perier
5226f8a943 [flang][runtime] Add API to help with the difficult array constructor cases
This runtime API can be used to lower any flavor of array constructors,
but is mainly intended to be used with:

- array constructors for which the extent or length parameters cannot
 be computed without lowering some ac-value or ac-implied-do-control
 that cannot be pre-evaluated.

- array constructors of a derived type with allocatable component where
 copy is not trivial or PDTS.

Example of use cases:
 - `[((i+j,i=1, ifoo()), j=1,n)]` where ifoo() is not pure.
 - `[return_allocatable_array(), return_allocatable_array()]`

Differential Revision: https://reviews.llvm.org/D144411
2023-02-22 09:16:09 +01:00
Jean Perier
a9e4bb387b [flang][hlfir] Array constructor lowering [part 2/4]
This patch adds the lowering strategy that lowers an array constructor
to an hlfir.elemental (without creating any temporary yet in lowering).
This will allow more high level array expression optimization to elide
the array constructor temporary when possible, but this is only doable
for a restricted although common form of array constructors:
"[(pure_scalar_expr(i),i=lower,upper,stride)]".

Differential Revision: https://reviews.llvm.org/D144111
2023-02-16 15:20:46 +01:00
Jean Perier
ffde9f1730 [flang][hlfir] Array constructor lowering [part 1/4]
This is the first and biggest chunk that introduces support for
array constructor to HLFIR.

This patch:
- adds a new ConvertArrayConstructor.cpp that centralizes the
  code dealing with array constructor lowering.
- introduces a framework to lower array constructor according to
  different strategies: A common analysis of the array constructor is
  done, and based on that, a lowering startegy is selected and driven
  through the ac-values of the array constructor. See
  ConvertArrayConstructor.cpp comments for more details.
- implements the first strategy that creates a temporary inlined and
  updates it with inlined code. This strategy can only be used if the
  temporary can be pre-allocated (i.e: the extents and length parameters
  can be pre-computed without evaluating any ac-values), and if all the
  ac-value expressions are scalars.

For the sake of simplicity, characters and derived type will be enabled
once all the strategies are added.

Reviewed By: clementval, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D144102
2023-02-16 15:18:55 +01:00