[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
Loading
Please sign in to comment