MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
beta_red.cpp
Go to the documentation of this file.
1#include "mim/pass/beta_red.h"
2
3#include "mim/rewrite.h"
4
5namespace mim {
6
8 if (auto [app, lam] = isa_apped_mut_lam(def); isa_workable(lam) && !keep_.contains(lam)) {
9 if (auto [_, ins] = data().emplace(lam); ins) {
10 world().DLOG("beta-reduction {}", lam);
11 return lam->reduce(app->arg()).back();
12 } else {
13 return proxy(app->type(), {lam, app->arg()}, 0);
14 }
15 }
16
17 return def;
18}
19
21 auto lam = proxy->op(0)->as_mut<Lam>();
22 if (keep_.emplace(lam).second) {
23 world().DLOG("found proxy app of '{}' within '{}'", lam, curr_mut());
24 return undo_visit(lam);
25 }
26
27 return No_Undo;
28}
29
31 auto undo = No_Undo;
32 for (auto op : def->ops()) {
33 if (auto lam = isa_workable(op->isa_mut<Lam>()); lam && keep_.emplace(lam).second) {
34 auto [_, ins] = data().emplace(lam);
35 if (!ins) {
36 world().DLOG("non-callee-position of '{}'; undo inlining of {} within {}", lam, lam, curr_mut());
37 undo = std::min(undo, undo_visit(lam));
38 }
39 }
40 }
41
42 return undo;
43}
44
45} // namespace mim
undo_t analyze(const Proxy *) override
Definition beta_red.cpp:20
Ref rewrite(Ref) override
Definition beta_red.cpp:7
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
Definition def.h:455
const Def * op(size_t i) const
Definition def.h:269
T * isa_mut() const
If this is *mut*able, it will cast constness away and perform a dynamic_cast to T.
Definition def.h:447
auto ops() const
Definition def.h:268
undo_t undo_visit(Def *mut) const
Definition pass.h:273
A function.
Definition lam.h:103
World & world()
Definition pass.h:296
const Proxy * proxy(Ref type, Defs ops, u32 tag=0)
Definition pass.h:75
Def * curr_mut() const
Definition pass.h:232
Helper class to retrieve Infer::arg if present.
Definition def.h:86
Definition cfg.h:11
std::pair< const App *, Lam * > isa_apped_mut_lam(const Def *def)
Definition lam.h:256
Lam * isa_workable(Lam *lam)
These are Lams that are neither nullptr, nor Lam::is_external, nor Lam::is_unset.
Definition lam.h:251
size_t undo_t
Definition pass.h:14
static constexpr undo_t No_Undo
Definition pass.h:15