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/Optimizer/Dialect/CUF/Attributes/CUFAttr.h"
18#include "flang/Runtime/allocator-registry-consts.h"
19#include "llvm/ADT/StringRef.h"
20
21namespace mlir {
22class Value;
23class ValueRange;
24class Type;
25class Location;
26} // namespace mlir
27
28namespace fir {
29class FirOpBuilder;
30class MutableBoxValue;
31class ExtendedValue;
32} // namespace fir
33
34namespace fir::factory {
35
45mlir::Value createUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc,
46 mlir::Type boxType,
47 mlir::ValueRange nonDeferredParams,
48 mlir::Value typeSourceBox = {},
49 unsigned allocator = kDefaultAllocator);
50
55fir::MutableBoxValue createTempMutableBox(fir::FirOpBuilder &builder,
56 mlir::Location loc, mlir::Type type,
57 llvm::StringRef name = {},
58 mlir::Value sourceBox = {},
59 bool isPolymorphic = false);
60
64void associateMutableBox(fir::FirOpBuilder &builder, mlir::Location loc,
65 const fir::MutableBoxValue &box,
66 const fir::ExtendedValue &source,
67 mlir::ValueRange lbounds);
68
73void associateMutableBoxWithRemap(fir::FirOpBuilder &builder,
74 mlir::Location loc,
75 const fir::MutableBoxValue &box,
76 const fir::ExtendedValue &source,
77 mlir::ValueRange lbounds,
78 mlir::ValueRange ubounds);
79
84void disassociateMutableBox(fir::FirOpBuilder &builder, mlir::Location loc,
85 const fir::MutableBoxValue &box,
86 bool polymorphicSetType = true,
87 unsigned allocator = kDefaultAllocator);
88
101 fir::ExtendedValue newValue;
102 mlir::Value oldAddress;
103 mlir::Value wasReallocated;
104 mlir::Value oldAddressWasAllocated;
105};
106
114
116genReallocIfNeeded(fir::FirOpBuilder &builder, mlir::Location loc,
117 const fir::MutableBoxValue &box, mlir::ValueRange shape,
118 mlir::ValueRange lenParams,
119 ReallocStorageHandlerFunc storageHandler = {},
120 cuf::DataAttributeAttr dataAttr = {});
121
122void finalizeRealloc(fir::FirOpBuilder &builder, mlir::Location loc,
123 const fir::MutableBoxValue &box, mlir::ValueRange lbounds,
124 bool takeLboundsIfRealloc,
125 const MutableBoxReallocation &realloc,
126 cuf::DataAttributeAttr dataAttr = {});
127
131void genFreememIfAllocated(fir::FirOpBuilder &builder, mlir::Location loc,
132 const fir::MutableBoxValue &box);
133
134void genInlinedAllocation(fir::FirOpBuilder &builder, mlir::Location loc,
135 const fir::MutableBoxValue &box,
136 mlir::ValueRange lbounds, mlir::ValueRange extents,
137 mlir::ValueRange lenParams, llvm::StringRef allocName,
138 bool mustBeHeap = false);
139
142mlir::Value genFreemem(fir::FirOpBuilder &builder, mlir::Location loc,
143 const fir::MutableBoxValue &box);
144
148void syncMutableBoxFromIRBox(fir::FirOpBuilder &builder, mlir::Location loc,
149 const fir::MutableBoxValue &box);
150
155fir::ExtendedValue genMutableBoxRead(fir::FirOpBuilder &builder,
156 mlir::Location loc,
157 const fir::MutableBoxValue &box,
158 bool mayBePolymorphic = true,
159 bool preserveLowerBounds = true);
160
165mlir::Value getMutableIRBox(fir::FirOpBuilder &builder, mlir::Location loc,
166 const fir::MutableBoxValue &box);
167
170mlir::Value genIsAllocatedOrAssociatedTest(fir::FirOpBuilder &builder,
171 mlir::Location loc,
172 const fir::MutableBoxValue &box);
173
176mlir::Value genIsNotAllocatedOrAssociatedTest(fir::FirOpBuilder &builder,
177 mlir::Location loc,
178 const fir::MutableBoxValue &box);
179
183mlir::Value genNullBoxStorage(fir::FirOpBuilder &builder, mlir::Location loc,
184 mlir::Type boxTy);
185
192mlir::Value getAndEstablishBoxStorage(fir::FirOpBuilder &builder,
193 mlir::Location loc,
194 fir::BaseBoxType boxTy, mlir::Value shape,
195 llvm::ArrayRef<mlir::Value> typeParams,
196 mlir::Value polymorphicMold);
197
198} // namespace fir::factory
199
200#endif // FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H
Definition BoxValue.h:469
Definition FIRBuilder.h:66
Definition BoxValue.h:361
Definition BoxValue.h:446
mlir::Value genIsNotAllocatedOrAssociatedTest(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:504
mlir::Value genIsAllocatedOrAssociatedTest(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:497
void associateMutableBox(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, const fir::ExtendedValue &source, mlir::ValueRange lbounds)
Definition MutableBox.cpp:539
mlir::Value genFreemem(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:839
fir::ExtendedValue genMutableBoxRead(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, bool mayBePolymorphic=true, bool preserveLowerBounds=true)
Definition MutableBox.cpp:459
void genFreememIfAllocated(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:522
fir::MutableBoxValue createTempMutableBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type, llvm::StringRef name={}, mlir::Value sourceBox={}, bool isPolymorphic=false)
Definition MutableBox.cpp:417
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:728
mlir::Value genNullBoxStorage(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxTy)
Definition MutableBox.cpp:1035
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:1045
mlir::Value createUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType, mlir::ValueRange nonDeferredParams, mlir::Value typeSourceBox={}, unsigned allocator=kDefaultAllocator)
Definition MutableBox.cpp:363
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:625
void syncMutableBoxFromIRBox(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:1029
mlir::Value getMutableIRBox(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box)
Definition MutableBox.cpp:1023
Definition AbstractConverter.h:37
Definition AbstractConverter.h:32
Definition MutableBox.h:100