This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Add hlfir.parent_comp for leaf parent component references
ClosedPublic

Authored by jeanPerier on Feb 28 2023, 1:55 AM.

Details

Summary

In Fortran, it is possible to refer to the "parent part" of a derived
type as if it were a component:

Fortran
type t1
 integer :: i
end type
type t2
 integer :: j
end type
type(t2) :: a
  print *, a%t1%i ! "inner" parent component reference
  print *, a%t1   ! "leaf" parent component reference
end

Inner parent component references can be dropped on the floor in
lowering: "a%t1%i" is equivalent to "a%i".
Leaf parent component references, however, must be taken care of. For
scalars, "a%t1" is a simple addressc ast to "t1", for arrays, however,
this creates an array section that must be represented with a descriptor
(fir.box).

hlfir.designate could have been extended to deal with this, but I think
it would make hlfir.designate too complex and hard to manipulate.

This patch adds an hlfir.parent_comp op that represents and implements
leaf parent component references.

Diff Detail

Event Timeline

jeanPerier created this revision.Feb 28 2023, 1:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2023, 1:55 AM
jeanPerier requested review of this revision.Feb 28 2023, 1:55 AM
clementval accepted this revision.Feb 28 2023, 2:45 AM

LGTM

flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
399
This revision is now accepted and ready to land.Feb 28 2023, 2:45 AM

Correct typo in verifier error message.