1 //===-- Allocatable.h - generate Allocatable runtime API calls---*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ALLOCATABLE_H 10 #define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ALLOCATABLE_H 11 12 #include "mlir/IR/Value.h" 13 14 namespace mlir { 15 class Location; 16 } // namespace mlir 17 18 namespace fir { 19 class FirOpBuilder; 20 } 21 22 namespace fir::runtime { 23 24 /// Generate runtime call to assign \p sourceBox to \p destBox. 25 /// \p destBox must be a fir.ref<fir.box<T>> and \p sourceBox a fir.box<T>. 26 /// \p destBox Fortran descriptor may be modified if destBox is an allocatable 27 /// according to Fortran allocatable assignment rules, otherwise it is not 28 /// modified. 29 mlir::Value genMoveAlloc(fir::FirOpBuilder &builder, mlir::Location loc, 30 mlir::Value to, mlir::Value from, mlir::Value hasStat, 31 mlir::Value errMsg); 32 33 /// Generate runtime call to apply bounds, cobounds, length type 34 /// parameters and derived type information from \p mold descriptor 35 /// to \p desc descriptor. The resulting rank of \p desc descriptor 36 /// is set to \p rank. The resulting descriptor must be initialized 37 /// and deallocated before the call. 38 void genAllocatableApplyMold(fir::FirOpBuilder &builder, mlir::Location loc, 39 mlir::Value desc, mlir::Value mold, int rank); 40 41 /// Generate runtime call to set the bounds (\p lowerBound and \p upperBound) 42 /// for the specified dimension \p dimIndex (zero-based) in the given 43 /// \p desc descriptor. 44 void genAllocatableSetBounds(fir::FirOpBuilder &builder, mlir::Location loc, 45 mlir::Value desc, mlir::Value dimIndex, 46 mlir::Value lowerBound, mlir::Value upperBound); 47 48 /// Generate runtime call to allocate an allocatable entity 49 /// as described by the given \p desc descriptor. 50 void genAllocatableAllocate(fir::FirOpBuilder &builder, mlir::Location loc, 51 mlir::Value desc, mlir::Value hasStat = {}, 52 mlir::Value errMsg = {}); 53 54 } // namespace fir::runtime 55 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ALLOCATABLE_H 56