FLANG
LowerRepackArrays.cpp File Reference
#include "flang/Optimizer/CodeGen/CodeGen.h"
#include "flang/Optimizer/Builder/Character.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Builder/MutableBox.h"
#include "flang/Optimizer/Builder/Runtime/Allocatable.h"
#include "flang/Optimizer/Builder/Runtime/Transformational.h"
#include "flang/Optimizer/Builder/Todo.h"
#include "flang/Optimizer/Dialect/FIRDialect.h"
#include "flang/Optimizer/Dialect/FIROps.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.h"
#include "flang/Optimizer/OpenMP/Support/RegisterOpenMPExtensions.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "flang/Optimizer/CodeGen/CGPasses.h.inc"

Namespaces

namespace  fir

Macros

#define GEN_PASS_DEF_LOWERREPACKARRAYSPASS
#define DEBUG_TYPE   "lower-repack-arrays"

Detailed Description

This pass expands fir.pack_array and fir.unpack_array operations into sequences of other FIR operations and Fortran runtime calls. This pass is using structured control flow FIR operations such as fir.if, so its placement in the pipeline should guarantee further lowering of these operations.

A fir.pack_array operation is converted into a sequence of checks identifying whether an array needs to be copied into a contiguous temporary. When the checks pass, a new memory allocation is done for the temporary array (in either stack or heap memory). If fir.pack_array does not have no_copy attribute, then the original array is shallow-copied into the temporary.

A fir.unpack_array operations is converted into a check of whether the original and the temporary arrays are different memory. When the check passes, the temporary array might be shallow-copied into the original array, and then the temporary array is deallocated (if it was allocated in stack memory, then there is no explicit deallocation).