MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
static_arg_opt.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <fe/bitset.h>
4
5
#include "
mim/phase.h
"
6
7
namespace
mim
{
8
9
/// Static Argument Transformation.
10
/// A recursive Lam whose self-calls merely forward some of its params is split into a wrapper `wrap`
11
/// (same signature) and a `loop` that drops those params;
12
/// self-calls forwarding all of them become jumps to `loop`, all others go through `wrap`.
13
/// Tail recursion elimination is the special case where the dropped param is the ret var.
14
/// @see [Compilation by Transformation in Non-Strict Functional Languages,
15
/// ยง7](https://theses.gla.ac.uk/74568/1/10992188.pdf)
16
class
StaticArgOpt
:
public
RWPhase
{
17
public
:
18
StaticArgOpt
(
World
&
world
,
flags_t
annex
)
19
:
RWPhase
(
world
,
annex
) {}
20
21
private
:
22
bool
analyze
() final;
23
void
analyze
(const
Def
*);
24
void
visit(const
App
*,
Lam
*);
25
26
const
Def
*
rewrite_imm_App
(const
App
*) final;
27
const
Def
*
rewrite_mut_Lam
(
Lam
*) final;
28
29
/// Which of @p lam's doms do the self-calls selected for the loop forward unchanged?
30
/// An empty Mask means: leave @p lam alone.
31
fe::Bitset statics(
Lam
* lam);
32
33
DefSet
analyzed_;
34
LamMap
<fe::Vector<fe::Bitset>> lam2sites_;
35
LamMap
<fe::Bitset> lam2statics_;
36
LamMap
<std::pair<
Lam
*,
Lam
*>> old2wrap_loop_;
37
};
38
39
}
// namespace mim
mim::App
Definition
lam.h:224
mim::Def
Base class for all Defs.
Definition
def.h:273
mim::Lam
A function.
Definition
lam.h:113
mim::Phase::annex
flags_t annex() const
Definition
phase.h:81
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:431
mim::RWPhase::world
World & world()=delete
Hides both and forbids direct access.
mim::StaticArgOpt::StaticArgOpt
StaticArgOpt(World &world, flags_t annex)
Definition
static_arg_opt.h:18
mim::StaticArgOpt::rewrite_mut_Lam
const Def * rewrite_mut_Lam(Lam *) final
Definition
static_arg_opt.cpp:66
mim::StaticArgOpt::analyze
bool analyze() final
Runs the optional pre-analysis on Phase::world, typically to a fixed point, before rewriting begins.
Definition
static_arg_opt.cpp:5
mim::StaticArgOpt::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
static_arg_opt.cpp:103
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:40
mim
Definition
ast.h:16
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::LamMap
GIDMap< Lam *, To > LamMap
Definition
lam.h:219
mim::DefSet
GIDSet< const Def * > DefSet
Definition
def.h:89
phase.h
include
mim
phase
static_arg_opt.h
Generated by
1.18.0