MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
heap2stack.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
mim/plug/mem/escape_analysis.h
"
4
5
namespace
mim::plug::mem::phase
{
6
7
/// Turns a `mem.alloc` that does not escape its function (see mem::EscapeAnalysis) into a `mem.slot`.
8
///
9
/// The slot's continuation receives the remainder of the alloc's home.
10
/// Only allocations of at most `-X mem:heap2stack=<n>` elements in address space 0 qualify; `0` disables this phase.
11
/// A slot lives until its function returns, so an alloc in a loop of its function stays on the heap.
12
/// A `mem.free` of a converted alloc is dropped.
13
class
Heap2Stack
:
public
RWPhase
{
14
public
:
15
Heap2Stack
(
World
&,
flags_t
annex
);
16
17
private
:
18
bool
analyze
()
final
;
19
const
Def
*
rewrite_imm_App
(
const
App
*)
final
;
20
21
/// The number of scalars in @p type; `std::nullopt` if not statically known or more than `max_`.
22
std::optional<nat_t> num_elems(
const
Def
* type)
const
;
23
24
EscapeAnalysis
escape_;
25
const
nat_t
max_;
26
/// Old tail ↦ the allocs on its chain to turn into slots, in program order.
27
DefMap<fe::Vector<const App*>
> slots_;
28
DefSet
converted_;
29
};
30
31
}
// namespace mim::plug::mem::phase
mim::App
Definition
lam.h:215
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Phase::annex
flags_t annex() const
Definition
phase.h:62
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:334
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:43
mim::plug::mem::EscapeAnalysis
Determines which allocations stay within the scope that allocates them.
Definition
escape_analysis.h:27
mim::plug::mem::phase::Heap2Stack::analyze
bool analyze() final
Runs the optional pre-analysis on old_world(), typically to a fixed point, before rewriting begins.
Definition
heap2stack.cpp:26
mim::plug::mem::phase::Heap2Stack::Heap2Stack
Heap2Stack(World &, flags_t annex)
Definition
heap2stack.cpp:21
mim::plug::mem::phase::Heap2Stack::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
heap2stack.cpp:80
escape_analysis.h
mim::plug::mem::phase
Definition
add_mem.h:5
mim::nat_t
u64 nat_t
Definition
types.h:37
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::DefMap
GIDMap< const Def *, To > DefMap
Definition
def.h:93
mim::DefSet
GIDSet< const Def * > DefSet
Definition
def.h:94
include
mim
plug
mem
phase
heap2stack.h
Generated by
1.18.0