This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Enable lowering and passing of allocatables and pointers.
ClosedPublic

Authored by jeanPerier on Jan 18 2023, 10:32 AM.

Details

Summary

Adds support for:

  • referencing a whole allocatable/pointer symbol
  • passing allocatable/pointer in a call

This required update in HLFIRTools.cpp helpers so that the
raw address, extents, lower bounds, and type parameters of a
fir.box/fir.class can be extracted.
This is required because in hlfir lowering, dereferencing a
pointer/alloc is only doing the fir.load fir.box part, and the
helpers have to be able to reason about that fir.box without the
help of a "fir::FortranVariableOpInterface".

Missing:

  • referencing part of allocatable/pointer (will need to update Designator lowering to dereference the pointer/alloc). Same for whole allocatable and pointer components.
  • allocate/deallocate/pointer assignment statements.
  • Whole allocatable assignment.
  • Lower inquires.

Diff Detail

Event Timeline

jeanPerier created this revision.Jan 18 2023, 10:32 AM
jeanPerier requested review of this revision.Jan 18 2023, 10:32 AM
jeanPerier retitled this revision from [flang] Enable lowering and passing of allocatables and pointers. to [flang][hlfir] Enable lowering and passing of allocatables and pointers..Jan 18 2023, 10:34 AM
PeteSteinfeld accepted this revision.Jan 18 2023, 12:15 PM

Aside from some nits and questions, all builds and tests correctly and looks good.

flang/include/flang/Optimizer/Builder/HLFIRTools.h
137

"know" should be "known"

flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td
125

"has" should be "have"

flang/lib/Optimizer/Builder/HLFIRTools.cpp
74–78

This interface seems a little off to me. In the name "Extents" is plural, while "Lbound" is singular. Also, in every call, the "lbounds" argument is non-null, but the code allows for it to be null. Would it be better to assert that it's non-null?

418

Is "boxes" supposed to be "boxed"?

697

"avoid" should be "avoids".

This revision is now accepted and ready to land.Jan 18 2023, 12:15 PM
jeanPerier marked 4 inline comments as done.Jan 19 2023, 1:12 AM
jeanPerier added inline comments.
flang/lib/Optimizer/Builder/HLFIRTools.cpp
74–78

Good points, I renamed it to genLboundsAndExtentsFromBox (so that the name reflects the argument order), and I made the first argument a reference.

418

Yes, thanks

jeanPerier marked an inline comment as done.

Thanks for the review Pete, I addressed your comments.