This is an archive of the discontinued LLVM Phabricator instance.

[flang] Lower elemental intrinsics to hlfir.elemental
ClosedPublic

Authored by jeanPerier on Jan 12 2023, 7:43 AM.

Details

Summary
  • Move the core code generating hlfir.elemental for user calls from genUserElementalCall into a new ElementalCallBuilder class and use C++ CRTP (curiously recursive template pattern) to implement the parts specific to user and intrinsic call into ElementalUserCallBuilder and ElementalIntrinsicCallBuilder. This allows sharing the core logic to lower elemental procedures for both user defined and intrinsics procedures.
  • To allow using ElementalCallBuilder, split the intrinsic lowering code into two parts: first lower the arguments to hlfir::Entity regardless of the interface of the intrinsics, and then, in a different function (genIntrinsicProcRefCore), prepare the hlfir::Entity according to the interface. This allows using the same core logic to prepare "normal" arguments for non-elemental intrinsics, and to prepare the elements of array arguments inside elemental call (ElementalIntrinsicCallBuilder calls genIntrinsicProcRefCore once it has computed the scalar actual arguments). To allow this split, genExprBox/genExprAddr/genExprValue logic had to be split in ConvertExprToHlfir.[cpp/h].
  • Add missing statement context pushScope/finalizeAndPop around the code generation inside the hlfir.elemental so that any temps created while lowering the call at the element level is correctly cleaned-up.
  • One piece of code in hlfir::Entity::hasNonDefaultLowerBounds() was wrong for assumed shape arrays (returned true when an assumed shaped array had no explicit lower bounds). This caused the added test to hit a bogus TODO, so fix it.

Elemental intrinsics returning are still TODO (e.g., adjustl). I will implement this in a next patch, this one is big enough.

Diff Detail

Event Timeline

jeanPerier created this revision.Jan 12 2023, 7:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 7:43 AM
jeanPerier requested review of this revision.Jan 12 2023, 7:43 AM
PeteSteinfeld edited the summary of this revision. (Show Details)Jan 12 2023, 8:19 AM
PeteSteinfeld edited the summary of this revision. (Show Details)

Other than the nits in comments, all builds and tests correctly. I don't understand this code very well, though, so @clementval should take a look and approve.

flang/lib/Lower/ConvertCall.cpp
765

Should read "are cleaned up".

832

Should read "will be passed"

865

Should read "never need the actual addresses"

flang/lib/Lower/ConvertExprToHLFIR.cpp
1258

Should read "not needed"

jeanPerier marked 2 inline comments as done.

Fix comment typos caught by Pete, thanks!

clementval accepted this revision.Jan 12 2023, 11:33 AM

LGTM. The pre-commit failure seems related to a patch that has been reverted now.

This revision is now accepted and ready to land.Jan 12 2023, 11:33 AM
This revision was automatically updated to reflect the committed changes.