MLIR
23.0.0git
include
mlir
Dialect
Bufferization
Transforms
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
22
namespace
mlir
{
23
namespace
bufferization
{
24
25
/// Descriptor for a single allocation to be placed by the memory planner.
26
struct
MemoryPlannerAlloc
{
27
int64_t
sizeInBytes
= 0;
28
int64_t
alignment
= 1;
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.
36
llvm::SmallVector<int64_t>
37
trivialMemoryPlanner
(
int64_t
arenaAlignment,
38
llvm::ArrayRef<MemoryPlannerAlloc>
allocs);
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.
43
llvm::SmallVector<int64_t>
44
bestFitMemoryPlanner
(
int64_t
arenaAlignment,
45
llvm::ArrayRef<MemoryPlannerAlloc>
allocs);
46
47
}
// namespace bufferization
48
}
// namespace mlir
49
50
#endif
// MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_STATICMEMORYPLANNING_H
int64_t
llvm::ArrayRef
Definition
LLVM.h:40
llvm::SmallVector
Definition
LLVM.h:64
mlir::bufferization
Definition
AllExtensions.h:20
mlir::bufferization::trivialMemoryPlanner
llvm::SmallVector< int64_t > trivialMemoryPlanner(int64_t arenaAlignment, llvm::ArrayRef< MemoryPlannerAlloc > allocs)
Sequential packing without lifetime overlap.
Definition
StaticMemoryPlanning.cpp:24
mlir::bufferization::bestFitMemoryPlanner
llvm::SmallVector< int64_t > bestFitMemoryPlanner(int64_t arenaAlignment, llvm::ArrayRef< MemoryPlannerAlloc > allocs)
Best-fit packing with lifetime-aware gap reuse.
Definition
StaticMemoryPlanning.cpp:46
mlir
Include the generated interface declarations.
Definition
ABIRewriteContext.h:29
mlir::bufferization::MemoryPlannerAlloc
Descriptor for a single allocation to be placed by the memory planner.
Definition
StaticMemoryPlanning.h:26
mlir::bufferization::MemoryPlannerAlloc::timeStart
int64_t timeStart
Definition
StaticMemoryPlanning.h:29
mlir::bufferization::MemoryPlannerAlloc::alignment
int64_t alignment
Definition
StaticMemoryPlanning.h:28
mlir::bufferization::MemoryPlannerAlloc::timeEnd
int64_t timeEnd
Definition
StaticMemoryPlanning.h:30
mlir::bufferization::MemoryPlannerAlloc::sizeInBytes
int64_t sizeInBytes
Definition
StaticMemoryPlanning.h:27
Generated on
for MLIR by
1.14.0