19#ifndef FORTRAN_OPTIMIZER_BUILDER_TEMPORARYSTORAGE_H
20#define FORTRAN_OPTIMIZER_BUILDER_TEMPORARYSTORAGE_H
22#include "flang/Optimizer/HLFIR/HLFIROps.h"
47 mlir::Value initialValue,
bool canCountThroughLoops =
true);
53 const bool canCountThroughLoops;
57 mlir::Value initialValue;
68class HomogeneousScalarStack {
71 fir::SequenceType declaredType, mlir::Value extent,
73 bool allocateOnHeap,
bool stackThroughLoops,
74 llvm::StringRef name);
94 const bool allocateOnHeap;
109 assert(
false &&
"must not be called: value already set");
113 return copy.getBase();
116 bool canBeFetchedAfterPush()
const {
return true; }
140 bool canBeFetchedAfterPush()
const {
return true; }
155 mlir::Type valueStaticType);
162 bool canBeFetchedAfterPush()
const {
return true; }
167 mlir::Type valueStaticType;
170 mlir::Value opaquePtr;
174 mlir::Value retValueBox;
184class AnyVariableStack {
187 mlir::Type valueStaticType);
194 bool canBeFetchedAfterPush()
const {
return true; }
198 mlir::Type variableStaticType;
201 mlir::Value opaquePtr;
205 mlir::Value retValueBox;
212class AnyAddressStack :
public AnyValueStack {
215 mlir::Type addressType);
222 mlir::Type addressType;
232class AnyVectorSubscriptStack :
public AnyVariableStack {
235 mlir::Type valueStaticType,
236 bool shapeCanBeSavedAsRegister,
int rank);
242 bool canBeFetchedAfterPush()
const {
return true; }
245 std::unique_ptr<TemporaryStorage> shapeTemp;
248 std::optional<mlir::Type> boxType;
252class TemporaryStorage {
254 template <
typename T>
255 TemporaryStorage(T &&impl) : impl{std::forward<T>(impl)} {}
259 std::visit([&](
auto &temp) { temp.pushValue(loc, builder, value); }, impl);
262 std::visit([&](
auto &temp) { temp.resetFetchPosition(loc, builder); },
266 return std::visit([&](
auto &temp) {
return temp.fetch(loc, builder); },
270 std::visit([&](
auto &temp) { temp.destroy(loc, builder); }, impl);
275 return std::visit([&](
auto &temp) {
return temp.canBeFetchedAfterPush(); },
279 template <
typename T>
281 return std::get<T>(impl);
285 std::variant<HomogeneousScalarStack, SimpleCopy, SSARegister, AnyValueStack,
286 AnyVariableStack, AnyVectorSubscriptStack, AnyAddressStack>
Definition FIRBuilder.h:55
hlfir::Entity moveStackAsArrayExpr(mlir::Location loc, fir::FirOpBuilder &builder)
Definition TemporaryStorage.cpp:130
bool canBeFetchedAfterPush() const
Definition TemporaryStorage.h:90
mlir::Value ssaRegister
Temporary storage for the copy.
Definition TemporaryStorage.h:144
hlfir::AssociateOp copy
Temporary storage for the copy.
Definition TemporaryStorage.h:120
Generic wrapper over the different sorts of temporary storages.
Definition TemporaryStorage.h:252
bool canBeFetchedAfterPush() const
Definition TemporaryStorage.h:274
Definition HLFIRTools.h:52
Definition BoxValue.h:445
Definition AbstractConverter.h:34
Definition TemporaryStorage.h:44
void reset(mlir::Location loc, fir::FirOpBuilder &builder)
Set the counter to the initial value.
Definition TemporaryStorage.cpp:52
mlir::Value getAndIncrementIndex(mlir::Location loc, fir::FirOpBuilder &builder)
Return "counter++".
Definition TemporaryStorage.cpp:38
Counter(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value initialValue, bool canCountThroughLoops=true)
Create a counter set to the initial value.
Definition TemporaryStorage.cpp:23