FLANG
MutableBox.h
1//===-- MutableBox.h -- MutableBox utilities -----------------------------===//
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// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H
14#define FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H
15
16#include "flang/Optimizer/Builder/BoxValue.h"
17#include "flang/Runtime/allocator-registry-consts.h"
18#include "llvm/ADT/StringRef.h"
19
20namespace mlir {
21class Value;
22class ValueRange;
23class Type;
24class Location;
25} // namespace mlir
26
27namespace fir {
28class FirOpBuilder;
29class MutableBoxValue;
30class ExtendedValue;
31} // namespace fir
32
33namespace fir::factory {
34
44mlir::Value createUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc,
45 mlir::Type boxType,
46 mlir::ValueRange nonDeferredParams,
47 mlir::Value typeSourceBox = {},
48 unsigned allocator = kDefaultAllocator);
49
54fir::MutableBoxValue createTempMutableBox(fir::FirOpBuilder &builder,
55 mlir::Location loc, mlir::Type type,
56 llvm::StringRef name = {},
57 mlir::Value sourceBox = {},
58 bool isPolymorphic = false);
59
63void associateMutableBox(fir::FirOpBuilder &builder, mlir::Location loc,
64 const fir::MutableBoxValue &box,
65 const fir::ExtendedValue &source,
66 mlir::ValueRange lbounds);
67
72void associateMutableBoxWithRemap(fir::FirOpBuilder &builder,
73 mlir::Location loc,
74 const fir::MutableBoxValue &box,
75 const fir::ExtendedValue &source,
76 mlir::ValueRange lbounds,
77 mlir::ValueRange ubounds);
78
83void disassociateMutableBox(fir::FirOpBuilder &builder, mlir::Location loc,
84 const fir::MutableBoxValue &box,
85 bool polymorphicSetType = true,
86 unsigned allocator = kDefaultAllocator);
87
100 fir::ExtendedValue newValue;
101 mlir::Value oldAddress;
102 mlir::Value wasReallocated;
103 mlir::Value oldAddressWasAllocated;
104};
105
114
116genReallocIfNeeded(fir::FirOpBuilder &builder, mlir::Location loc,
117 const fir::MutableBoxValue &box, mlir::ValueRange shape,
118 mlir::ValueRange lenParams,
119 ReallocStorageHandlerFunc storageHandler = {});
120
121void finalizeRealloc(fir::FirOpBuilder &builder, mlir::Location loc,
122 const fir::MutableBoxValue &box, mlir::ValueRange lbounds,
123 bool takeLboundsIfRealloc,
124 const MutableBoxReallocation &realloc);
125
129void genFreememIfAllocated(fir::FirOpBuilder &builder, mlir::Location loc,
130 const fir::MutableBoxValue &box);
131
132void genInlinedAllocation(fir::FirOpBuilder &builder, mlir::Location loc,
133 const fir::MutableBoxValue &box,
134 mlir::ValueRange lbounds, mlir::ValueRange extents,
135 mlir::ValueRange lenParams, llvm::StringRef allocName,
136 bool mustBeHeap = false);
137
140mlir::Value genFreemem(fir::FirOpBuilder &builder, mlir::Location loc,
141 const fir::MutableBoxValue &box);
142
146void syncMutableBoxFromIRBox(fir::FirOpBuilder &builder, mlir::Location loc,
147 const fir::MutableBoxValue &box);
148
154 mlir::Location loc,
155 const fir::MutableBoxValue &box,
156 bool mayBePolymorphic = true,
157 bool preserveLowerBounds = true);
158
163mlir::Value getMutableIRBox(fir::FirOpBuilder &builder, mlir::Location loc,
164 const fir::MutableBoxValue &box);
165
169 mlir::Location loc,
170 const fir::MutableBoxValue &box);
171
175 mlir::Location loc,
176 const fir::MutableBoxValue &box);
177
181mlir::Value genNullBoxStorage(fir::FirOpBuilder &builder, mlir::Location loc,
182 mlir::Type boxTy);
183
191 mlir::Location loc,
192 fir::BaseBoxType boxTy, mlir::Value shape,
194 mlir::Value polymorphicMold);
195
196} // namespace fir::factory
197
198#endif // FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H
This class provides a shared interface for box and class types.
Definition FIRType.h:40
Definition BoxValue.h:478
Definition FIRBuilder.h:55
Definition BoxValue.h:360
Definition FIRType.h:89
Definition BoxValue.h:445
mlir::Value genIsNotAllocatedOrAssociatedTest(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:479
mlir::Value genIsAllocatedOrAssociatedTest(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:472
void associateMutableBox(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, const fir::ExtendedValue &source, mlir::ValueRange lbounds)
Definition MutableBox.cpp:514
mlir::Value genFreemem(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:794
fir::ExtendedValue genMutableBoxRead(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, bool mayBePolymorphic=true, bool preserveLowerBounds=true)
Definition MutableBox.cpp:434
void genFreememIfAllocated(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:497
fir::MutableBoxValue createTempMutableBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type, llvm::StringRef name={}, mlir::Value sourceBox={}, bool isPolymorphic=false)
Definition MutableBox.cpp:392
std::function< void(fir::ExtendedValue)> ReallocStorageHandlerFunc
Definition MutableBox.h:113
void disassociateMutableBox(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, bool polymorphicSetType=true, unsigned allocator=kDefaultAllocator)
Definition MutableBox.cpp:703
mlir::Value genNullBoxStorage(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxTy)
Definition MutableBox.cpp:977
mlir::Value getAndEstablishBoxStorage(fir::FirOpBuilder &builder, mlir::Location loc, fir::BaseBoxType boxTy, mlir::Value shape, llvm::ArrayRef< mlir::Value > typeParams, mlir::Value polymorphicMold)
Definition MutableBox.cpp:987
mlir::Value createUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType, mlir::ValueRange nonDeferredParams, mlir::Value typeSourceBox={}, unsigned allocator=kDefaultAllocator)
Definition MutableBox.cpp:338
void associateMutableBoxWithRemap(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, const fir::ExtendedValue &source, mlir::ValueRange lbounds, mlir::ValueRange ubounds)
Definition MutableBox.cpp:600
void syncMutableBoxFromIRBox(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:971
mlir::Value getMutableIRBox(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:965
Definition AbstractConverter.h:34
Definition AbstractConverter.h:29
Definition MutableBox.h:99