[flang] Use Assign() runtime for copy-in/copy-out.
authorSlava Zakharin <szakharin@nvidia.com>
Wed, 21 Dec 2022 01:13:25 +0000 (17:13 -0800)
committerSlava Zakharin <szakharin@nvidia.com>
Wed, 21 Dec 2022 17:55:33 +0000 (09:55 -0800)
commit2b60ed405b8110b20ab2e383839759ea34003127
treea52f1b3fa086d37c488de147d09ede9a9dc139ad
parent829733af4ac2895543797443c82f1f1709472c4f
[flang] Use Assign() runtime for copy-in/copy-out.

The loops generated under IsContiguous check for copy-in/copy-out
result in LLVM backend spending too much time optimizing them.
At the same time, the copy loops do not provide any optimization
opportunities with the surrounding code (since they are executed
under runtime IsContiguous check), so the copy code may be optimized
on its own and this can be done in runtime.

I thought I could implement and use new APIs for packing/unpacking
non-contiguous data (interfaces added in D136378), but then I found
that Assign() is already doing what is needed. If performance
becomes an issue for these loops, we can optimize code in Assign()
rather than creating new APIs.

Thus, this change makes use of Assign() for copy-in/copy-out
of boxed objects, and this is done only if the objects
are non-contiguous during execution. Copies for non-boxed
objects (e.g. for passing as VALUE dummy argument) are still
done inline, because they can potentially be optimized with
surrounding loops.

I added internal -inline-copyinout-for-boxes option to revert to the old
behavior just to make it easier to triage performance regressions,
if any appear after the change.

CPU2017/521.wrf compiles for 2179 seconds without the change and
the module_dm.f90 compiled with -O0 (without -O0 this single
module compiles for 5775 seconds). With the change total compilation
time of the benchmark reduces to 722 seconds.

Differential Revision: https://reviews.llvm.org/D140446
flang/lib/Lower/ConvertExpr.cpp
flang/test/Lower/call-by-value-attr.f90
flang/test/Lower/call-copy-in-out.f90
flang/test/Lower/dummy-argument-assumed-shape-optional.f90
flang/test/Lower/dummy-argument-optional-2.f90
flang/test/Lower/optional-value-caller.f90
flang/test/Lower/parent-component.f90