MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
heap2stack.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace 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.
13class Heap2Stack : public RWPhase {
14public:
16
17private:
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.
28 DefSet converted_;
29};
30
31} // namespace mim::plug::mem::phase
Base class for all Defs.
Definition def.h:289
flags_t annex() const
Definition phase.h:62
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:43
Determines which allocations stay within the scope that allocates them.
bool analyze() final
Runs the optional pre-analysis on old_world(), typically to a fixed point, before rewriting begins.
Heap2Stack(World &, flags_t annex)
const Def * rewrite_imm_App(const App *) final
u64 nat_t
Definition types.h:37
u64 flags_t
Definition types.h:39
GIDMap< const Def *, To > DefMap
Definition def.h:93
GIDSet< const Def * > DefSet
Definition def.h:94