MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
sccp_transform.cpp
Go to the documentation of this file.
1
#include "
mim/phase/sccp.h
"
2
3
namespace
mim
{
4
5
const
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())) {
8
invalidate
();
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
mim::App
Definition
lam.h:215
mim::App::targs
auto targs(Projector auto f) const noexcept
Definition
lam.h:252
mim::App::callee
const Def * callee() const
Definition
lam.h:237
mim::Def
Base class for all Defs.
Definition
def.h:289
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:588
mim::Lam
A function.
Definition
lam.h:91
mim::Lam::set
Lam * set(Filter filter, const Def *body)
Definition
lam.cpp:34
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:79
mim::RWPhase::new_world
World & new_world()
Create new Defs into this.
Definition
phase.h:379
mim::RWPhase::abstracted
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
mim::RWPhase::is_top
bool is_top(const Def *old_def) const
Definition
phase.h:355
mim::RWPhase::rewrite_imm_App
const Def * rewrite_imm_App(const App *) override
Definition
phase.cpp:223
mim::Rewriter::map
const Def * map(const Def *old_def, const Def *new_def)
Definition
rewrite.cpp:29
mim::Rewriter::rewrite
virtual const Def * rewrite(const Def *)
Definition
rewrite.cpp:62
mim::SCCP::rewrite_imm_App
const Def * rewrite_imm_App(const App *old_app) final
Definition
sccp_transform.cpp:5
mim::Sieve::Sieve
Sieve(size_t num)
Definition
tuple.h:123
mim::World::app
const Def * app(const Def *callee, const Def *arg)
Definition
world.cpp:416
mim::World::mut_lam
Lam * mut_lam(const Pi *pi)
Definition
world.h:415
mim
Definition
ast.h:16
mim::DefVec
fe::Vector< const Def * > DefVec
Definition
def.h:98
sccp.h
src
mim
phase
sccp_transform.cpp
Generated by
1.18.0