[all-commits] [llvm/llvm-project] 131c91: [flang][hlfir] Add hlfir.parent_comp for leaf pare...

jeanPerier via All-commits all-commits at lists.llvm.org
Tue Feb 28 05:09:11 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 131c9174d9f176a0f6eeaea996ac20314e0c6b05
      https://github.com/llvm/llvm-project/commit/131c9174d9f176a0f6eeaea996ac20314e0c6b05
  Author: Jean Perier <jperier at nvidia.com>
  Date:   2023-02-28 (Tue, 28 Feb 2023)

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

  Log Message:
  -----------
  [flang][hlfir] Add hlfir.parent_comp for leaf parent component references

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.

Differential Revision: https://reviews.llvm.org/D144946




More information about the All-commits mailing list