This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Add move semantics to hlfir.as_expr.
ClosedPublic

Authored by jeanPerier on Jan 16 2023, 2:21 AM.

Details

Summary

hlfir.as_expr allows turning an array, character, or derived type
variable into a value when it the usage require an hlfir.expr (e.g,
when returning the element value inside and hlfir.elemental).

The default implementation of this operation in bufferization is to
make a copy of the variable into a temporary buffer.
This adds a time and memory overhead in cases where such copy is not
needed because the variable is already a temporary that was created
in lowering to compute the expression value, and the "as_expr" is
the sole usage of the variable.

This is for instance the case for many transformational intrinsics
that do not have hlfir.expr operation (at least for now, but some may
never benefit from having one) and must be implemented "on memory"
in lowering.

This patch adds a way to "move" the variable storage along its value.
It allows the bufferization to re-use the variable storage for the
hlfir.expr created by hlfir.as_expr, and in exchange, the
responsibility of deallocating the buffer (if the variable was heap
allocated) if passed along to the hlfir.expr, and will need to be
done after the last hlfir.expr usage.

Diff Detail

Event Timeline

jeanPerier created this revision.Jan 16 2023, 2:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 16 2023, 2:21 AM
jeanPerier requested review of this revision.Jan 16 2023, 2:21 AM
This revision is now accepted and ready to land.Jan 16 2023, 4:36 AM

Rebase to incorporate windows build fix.

This revision was automatically updated to reflect the committed changes.