MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
sccp_transform.cpp
Go to the documentation of this file.
1#include "mim/phase/sccp.h"
2
3namespace mim {
4
5const Def* SCCP::rewrite_imm_App(const App* old_app) {
6 if (auto old_lam = old_app->callee()->isa_mut<Lam>()) {
7 if (abstracted(old_lam->var())) {
9
10 auto old_vars = old_lam->tvars();
11 auto keep = Sieve(old_vars, [this](const Def* var) { return is_top(var); });
12
13 auto new_lam = fe::lookup(lam2lam_, old_lam);
14 if (!new_lam) {
15 auto new_doms = rewrite(keep.gather(old_lam->tdoms()));
16 new_lam = new_world().mut_lam(new_doms, rewrite(old_lam->codom()))->set(old_lam->dbg());
17 lam2lam_[old_lam] = new_lam;
18
19 auto new_vars = DefVec(keep.num_old(), [&](size_t i) {
20 auto j = keep[i];
21 return j == Sieve::Gone ? rewrite(lattice(old_vars[i])) // SCCP propagate
22 : new_lam->var(keep.num_new(), j);
23 });
24
25 map(old_lam->var(), new_vars);
26 new_lam->set(rewrite(old_lam->filter()), rewrite(old_lam->body()));
27 }
28
29 return new_world().app(new_lam, rewrite(keep.gather(old_app->targs())));
30 }
31 }
32
33 return RWPhase::rewrite_imm_App(old_app);
34}
35
36} // namespace mim
auto targs(Projector auto f) const noexcept
Definition lam.h:252
const Def * callee() const
Definition lam.h:237
Base class for all Defs.
Definition def.h:289
T * isa_mut() const
If this is mutable, it will cast constness away and perform a dynamic_cast to T.
Definition def.h:588
A function.
Definition lam.h:91
Lam * set(Filter filter, const Def *body)
Definition lam.cpp:34
void invalidate(bool todo=true)
Signals that another round of fixed-point iteration is required, either as part of.
Definition phase.h:79
World & new_world()
Create new Defs into this.
Definition phase.h:379
const Def * abstracted(const Def *old_def) const
Returns lattice(old_def) if it differs from old_def (i.e. we learned something), otherwise nullptr.
Definition phase.h:350
bool is_top(const Def *old_def) const
Definition phase.h:355
const Def * rewrite_imm_App(const App *) override
Definition phase.cpp:223
const Def * map(const Def *old_def, const Def *new_def)
Definition rewrite.cpp:29
virtual const Def * rewrite(const Def *)
Definition rewrite.cpp:62
const Def * rewrite_imm_App(const App *old_app) final
Sieve(size_t num)
Definition tuple.h:123
const Def * app(const Def *callee, const Def *arg)
Definition world.cpp:416
Lam * mut_lam(const Pi *pi)
Definition world.h:415
Definition ast.h:16
fe::Vector< const Def * > DefVec
Definition def.h:98