MLIR 23.0.0git
StaticMemoryPlanning.h
Go to the documentation of this file.
1//===- StaticMemoryPlanning.h - Memory planning algorithms ------*- 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// Pure memory planning algorithms for static arena allocation. These operate
10// on abstract allocation descriptors (size, alignment, lifetime) and produce
11// byte offsets. They are independent of MLIR IR.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_STATICMEMORYPLANNING_H
16#define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_STATICMEMORYPLANNING_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/SmallVector.h"
20#include <cstdint>
21
22namespace mlir {
23namespace bufferization {
24
25/// Descriptor for a single allocation to be placed by the memory planner.
29 int64_t timeStart = 0; // Operation index when allocation becomes live
30 int64_t timeEnd = 0; // Operation index when allocation is freed
31};
32
33/// Sequential packing without lifetime overlap. Each allocation is placed
34/// immediately after the previous one (with alignment padding). Ignores
35/// lifetimes entirely.
37trivialMemoryPlanner(int64_t arenaAlignment,
39
40/// Best-fit packing with lifetime-aware gap reuse. Processes allocations in
41/// time order and places each one in the smallest gap left by expired
42/// allocations. Falls back to extending the arena if no gap fits.
44bestFitMemoryPlanner(int64_t arenaAlignment,
46
47} // namespace bufferization
48} // namespace mlir
49
50#endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_STATICMEMORYPLANNING_H
llvm::SmallVector< int64_t > trivialMemoryPlanner(int64_t arenaAlignment, llvm::ArrayRef< MemoryPlannerAlloc > allocs)
Sequential packing without lifetime overlap.
llvm::SmallVector< int64_t > bestFitMemoryPlanner(int64_t arenaAlignment, llvm::ArrayRef< MemoryPlannerAlloc > allocs)
Best-fit packing with lifetime-aware gap reuse.
Include the generated interface declarations.
Descriptor for a single allocation to be placed by the memory planner.