[flang-commits] [PATCH] D144946: [flang][hlfir] Add hlfir.parent_comp for leaf parent component references

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Feb 28 01:55:08 PST 2023


jeanPerier created this revision.
jeanPerier added reviewers: clementval, PeteSteinfeld.
jeanPerier added a project: Flang.
Herald added subscribers: sunshaoce, mehdi_amini, jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144946

Files:
  flang/include/flang/Optimizer/HLFIR/HLFIROps.td
  flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
  flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
  flang/test/HLFIR/invalid.fir
  flang/test/HLFIR/parent_comp-codegen.fir
  flang/test/HLFIR/parent_comp.fir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144946.501052.patch
Type: text/x-patch
Size: 17427 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230228/2fcf9b42/attachment-0001.bin>


More information about the flang-commits mailing list