MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
beta_red.cpp
Go to the documentation of this file.
1
#include "
mim/phase/beta_red.h
"
2
3
namespace
mim
{
4
5
bool
BetaRed::analyze
() {
6
for
(
auto
def :
world
().roots())
7
visit(def,
false
);
8
return
false
;
// no fixed-point nccessary
9
}
10
11
void
BetaRed::analyze
(
const
Def
* def) {
12
if
(
auto
[_, ins] = analyzed_.emplace(def); !ins)
return
;
13
14
for
(
auto
d : def->
deps
())
15
visit(d,
true
);
16
}
17
18
void
BetaRed::visit(
const
Def* def,
bool
candidate) {
19
if
(
auto
lam = def->isa_mut<Lam>()) {
20
if
(
auto
[i, ins] = candidates_.emplace(lam, candidate); !ins) i->second =
false
;
21
}
22
analyze
(def);
23
}
24
25
const
Def
*
BetaRed::rewrite_imm_App
(
const
App
* app) {
26
if
(
auto
old_lam = app->
callee
()->
isa_mut
<
Lam
>(); old_lam && old_lam->
is_set
() && is_candidate(old_lam)) {
27
profile_count
(
"β-reduction"
);
28
if
(
auto
var = old_lam->has_var()) {
29
auto
new_arg = rewrite(app->
arg
());
30
map
(var, new_arg);
31
// if we want to reduce more than once, we need to push/pop
32
}
33
invalidate
();
34
return
rewrite(old_lam->body());
35
}
36
37
return
Rewriter::rewrite_imm_App(app);
38
}
39
40
}
// namespace mim
beta_red.h
mim::App
Definition
lam.h:224
mim::App::callee
const Def * callee() const
Definition
lam.h:275
mim::App::arg
const Def * arg() const
Definition
lam.h:284
mim::BetaRed::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
beta_red.cpp:25
mim::BetaRed::analyze
bool analyze() final
Runs the optional pre-analysis on Phase::world, typically to a fixed point, before rewriting begins.
Definition
beta_red.cpp:5
mim::Def
Base class for all Defs.
Definition
def.h:273
mim::Def::is_set
bool is_set() const
Definition
def.h:370
mim::Def::deps
Defs deps() const noexcept
Definition
def.cpp:468
mim::Def::isa_mut
T * isa_mut() const
If this is mutable, it will cast constness away and perform a dynamic_cast to T.
Definition
def.h:580
mim::InplaceRWPhase::world
World & world()
Definition
phase.h:77
mim::Lam
A function.
Definition
lam.h:113
mim::Phase::invalidate
void invalidate(bool todo=true)
Signals that another round of fixed-point iteration is required, either as part of.
Definition
phase.h:98
mim::Phase::profile_count
void profile_count(std::string_view key, uint64_t n=1)
Adds n to the custom fe::Profiler counter key of the current run; no-op unless profiling is enabled.
Definition
phase.cpp:41
mim::Rewriter::map
virtual const Def * map(const Def *old_def, const Def *new_def)
Definition
rewrite.h:47
mim
Definition
ast.h:16
src
mim
phase
beta_red.cpp
Generated by
1.18.0