[all-commits] [llvm/llvm-project] de2811: [flang] Allow and use fir.rebox in fir.global

jeanPerier via All-commits all-commits at lists.llvm.org
Tue Jan 10 00:27:33 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: de2811ee45d340920cdd325bc791dafeef827808
      https://github.com/llvm/llvm-project/commit/de2811ee45d340920cdd325bc791dafeef827808
  Author: Jean Perier <jperier at nvidia.com>
  Date:   2023-01-10 (Tue, 10 Jan 2023)

  Changed paths:
    M flang/lib/Lower/ConvertVariable.cpp
    M flang/lib/Optimizer/CodeGen/CodeGen.cpp
    M flang/lib/Optimizer/CodeGen/TypeConverter.h
    M flang/test/Fir/array-coor.fir
    M flang/test/Fir/arrexp.fir
    M flang/test/Fir/convert-to-llvm.fir
    M flang/test/Fir/coordinateof.fir
    A flang/test/Fir/rebox-global.fir
    M flang/test/Fir/rebox-susbtring.fir
    M flang/test/Fir/rebox.fir
    M flang/test/Lower/default-initialization-globals.f90
    M flang/test/Lower/derived-pointer-components.f90
    M flang/test/Lower/pointer-initial-target-2.f90
    M flang/test/Lower/pointer-initial-target.f90

  Log Message:
  -----------
  [flang] Allow and use fir.rebox in fir.global

The current lowering of initial target in fir.global is relying
on how fir.box are created: instead of using a fir.rebox to add
the POINTER attribute to the created descriptor, it is looking
for a fir.embox defining operation and creating a copy of
it with a different result types.

The rational for doing so was that fir.rebox codegen was not possible
inside fir.global because it expects to manipulate the input fir.box
in memory, while objects cannot be manipulated in memory inside
a fir.global region that must be constant foldable.

But this approach has two problems:
- it won't work with hlfir where fir.box may be created by more
  operations than fir.embox (e.g. hlfir.delcare or hlfir.designate).
  In general, looking for a precise defining op for a value is
  fragile.
- manually copying and modifying an operation is risky: it is easy
  to forget copying some default operands (that could be added later).

This patch modifies the helpers to get descriptor fields so that they
can both operate on fir.box lowered in memory or in an llvm.struct
value. This enables the usage of fir.rebox in fir.global op.

The fallout in FIR tests is caused by the usage of constant index
when creating GEP (because extractOp requires constant indices).
MLIR builder uses i32 bit constant indices when non mlir::Value
indices are passed to the MLIR GEP op builder. Previously,
an 64 nist mlir constant value was created and passed to the GEP
builder. In this case, the builder respect the value type when
later generating the GEP.
Given this changes impact the "dimension" index that can, per
Fortran requirement, not be greated than 15, using a 32 bit index
is just fine and actually simplify the MLIR LLVM IR generation.

The fallout in lowering tests is caused by the introduction
of the fir.rebox everytime an initial target is created.

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




More information about the All-commits mailing list