This is an archive of the discontinued LLVM Phabricator instance.

[flang] Lower tbp dispatch calls for polymorphic array element
ClosedPublic

Authored by clementval on Oct 13 2022, 1:02 AM.

Details

Summary

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

Diff Detail

Event Timeline

clementval created this revision.Oct 13 2022, 1:02 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 13 2022, 1:02 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Oct 13 2022, 1:02 AM
clementval added inline comments.Oct 13 2022, 1:03 AM
flang/lib/Optimizer/Builder/FIRBuilder.cpp
485–495

Not sure this is the best way to retrieve the array descriptor to get the tdesc. This will probably need to be rework in the future to handle other cases.

jeanPerier accepted this revision.Oct 13 2022, 2:40 AM
jeanPerier added inline comments.
flang/lib/Optimizer/Builder/FIRBuilder.cpp
485–495

Agreed. I think the issue here is that fir::ExtendedValue is currently not meant to deal with polymorphic scalars that are not fir.class.

We could either:

  • embox such scalars right after emitting the fir.coordinate_of with te right type desc,
  • extend fir.coordinate_of/array_coor to generate fir.class when the array argument is a fir.class. That may be the most robust way to deal with the situation, but it is not clear to me if we want to force the addressing to generate descriptors that may not always be needed (although LLVM should be good at getting rid of the store addr in descriptor and load it in those cases).
  • or we could extent fir::ExtendedValue to carry a type descriptor for scalars otherwise tracked with only a raw address.
This revision is now accepted and ready to land.Oct 13 2022, 2:40 AM
clementval added inline comments.Oct 13 2022, 5:18 AM
flang/lib/Optimizer/Builder/FIRBuilder.cpp
485–495

Thanks for the suggestions. I'll start to work on a follow up patch to achieve a better solution here.