This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Lower pointer and allocatable sub-part references
ClosedPublic

Authored by jeanPerier on Jan 19 2023, 8:09 AM.

Details

Summary

The previous patches dealt with allocatable and pointer symbol
and component whole references.
This one deals with the remaining sub-part case where a dereference
must be created before applying the sub-part reference on the target.

With this patch the support to designate allocatable and pointer in
HLFIR is complete, but some use points will need to be updated to
use HLFIR designator lowering (at least allocate/deallocate statement
and whole allocatable assignment).

The partInfo.base had to be turned into an std::optional<hlfir::Entity>
because loads of allocatable/pointers do create a
fir::FortranVariableOpInterface (there is no need to). The optional part
comes from the fact that the partInfo.base is not set when creating the
partInfo, but later when visiting the designator parts.

They are three cases when dereferences must be inserted:

  • The pointer/allocatable is a symbol followed by a sub-part that is not

a component ref. This is done in visit(Symbol).

  • The pointer/allocatable is a component followed by a sub-part that is

not another component ref. This is done in visit(Component).

  • The pointer/allocatable is followed by a component ref. This case is

special since it does not call the above "visit" but instead calls "gen"
to break the visit and generate an hlfir.designate for the component
base (since one hlfir.designate can only represent one Fortran part-ref,
and must be chained to implement a Fortran designator with several part
refs). This is done in visitComponentImpl().

Diff Detail

Event Timeline

jeanPerier created this revision.Jan 19 2023, 8:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 8:09 AM
jeanPerier requested review of this revision.Jan 19 2023, 8:09 AM

All builds and tests correctly, and aside from the one nit, looks good.

I don't understand these changes very well, so someone who does should approve.

flang/lib/Lower/ConvertExprToHLFIR.cpp
258

I got baffled by this statement. What's that lone "_" mean?

311

Should read "components need"

jeanPerier added inline comments.Jan 19 2023, 11:58 PM
flang/lib/Lower/ConvertExprToHLFIR.cpp
258

Fascinating, I was sure that is was a handy way to indicate that one ignore a results in structured-binding (like it is the case in python). But reading at the C++ standard to answer you, it turns out "_" is a legal variable name in C++, so this has no special meaning an you could just use "_" in " _ + _".
Well, thanks for asking, I will just use "componentType = xxx.second" then.

Remove "_" bogus usage.

This revision is now accepted and ready to land.Jan 20 2023, 1:40 AM