[flang-commits] [PATCH] D141136: [flang] Allow and use fir.rebox in fir.global

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jan 6 07:13:23 PST 2023


jeanPerier created this revision.
jeanPerier added reviewers: PeteSteinfeld, vdonaldson, vzakhari.
jeanPerier added a project: Flang.
Herald added subscribers: bzcheeseman, mehdi_amini, rriddle, jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
jeanPerier requested review of this revision.
Herald added a subscriber: stephenneuendorffer.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141136

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141136.486870.patch
Type: text/x-patch
Size: 57961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230106/265c7815/attachment-0001.bin>


More information about the flang-commits mailing list