FLANG
AllocationPlacementPolicy.h
1//===-- Optimizer/Transforms/AllocationPlacementPolicy.h --------*- 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// This header defines the policy used by the allocation-placement pass to
10// decide whether an array allocation should live on the stack (fir.alloca) or
11// on the heap (fir.allocmem). The policy is expressed with tunable thresholds
12// and a per-function stack budget, and can be customized through a hook (e.g.
13// with different thresholds inside device routines or parallel regions).
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_ALLOCATIONPLACEMENTPOLICY_H
18#define FORTRAN_OPTIMIZER_TRANSFORMS_ALLOCATIONPLACEMENTPOLICY_H
19
20#include <cstddef>
21#include <cstdint>
22#include <functional>
23#include <optional>
24
25namespace mlir {
26class Operation;
27} // namespace mlir
28
29namespace fir {
30
40
45 bool stackArrays = false;
47 std::size_t smallArrayThresholdBytes = 64;
49 std::size_t totalStackLimitBytes = 4ull * 1024 * 1024;
50};
51
55 mlir::Operation *op = nullptr;
57 bool isCurrentlyOnStack = false;
60 bool isTemporary = false;
65 bool isDynamic = false;
67 std::optional<std::int64_t> byteSize;
68};
69
76 const AllocationPlacementThresholds &thresholds,
77 std::size_t stackBytesUsed);
78
84 const AllocationInfo & /*info*/,
85 const AllocationPlacementThresholds & /*thresholds*/,
86 std::size_t /*stackBytesUsed*/)>;
87
88} // namespace fir
89
90#endif // FORTRAN_OPTIMIZER_TRANSFORMS_ALLOCATIONPLACEMENTPOLICY_H
Definition AbstractConverter.h:37
std::function< AllocationPlacement( const AllocationInfo &, const AllocationPlacementThresholds &, std::size_t)> AllocationPlacementHook
Definition AllocationPlacementPolicy.h:83
AllocationPlacement decideAllocationPlacement(const AllocationInfo &info, const AllocationPlacementThresholds &thresholds, std::size_t stackBytesUsed)
Definition AllocationPlacement.cpp:54
AllocationPlacement
Desired placement for an array allocation.
Definition AllocationPlacementPolicy.h:32
@ Stack
The allocation should live on the stack (fir.alloca).
Definition AllocationPlacementPolicy.h:34
@ Heap
The allocation should live on the heap (fir.allocmem).
Definition AllocationPlacementPolicy.h:36
@ Leave
The allocation should be left where it currently is.
Definition AllocationPlacementPolicy.h:38
Definition AbstractConverter.h:32
Facts about a single array allocation used to decide its placement.
Definition AllocationPlacementPolicy.h:53
std::optional< std::int64_t > byteSize
The constant size of the allocation in bytes, if it can be determined.
Definition AllocationPlacementPolicy.h:67
bool isTemporary
Definition AllocationPlacementPolicy.h:60
bool isDynamic
Definition AllocationPlacementPolicy.h:65
mlir::Operation * op
The allocation operation (fir.alloca or fir.allocmem).
Definition AllocationPlacementPolicy.h:55
bool isCurrentlyOnStack
True if the allocation currently lives on the stack (fir.alloca).
Definition AllocationPlacementPolicy.h:57
Tunable thresholds controlling where array allocations are placed.
Definition AllocationPlacementPolicy.h:42
std::size_t totalStackLimitBytes
Per-function budget (in bytes) for small arrays placed on the stack.
Definition AllocationPlacementPolicy.h:49
std::size_t smallArrayThresholdBytes
Constant-size arrays up to this many bytes are considered "small".
Definition AllocationPlacementPolicy.h:47
bool stackArrays
Definition AllocationPlacementPolicy.h:45