MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
adce.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
mim/phase.h
"
4
5
namespace
mim
{
6
7
/// Aggressive Dead Code Elimination.
8
/// Removes Lam params nobody needs - including those that are merely forwarded to other dead params,
9
/// like a loop-carried value that never leaves its loop.
10
///
11
/// DCE is a backward problem, but an Analysis runs forward.
12
/// So we optimistically assume every param of a known Lam to be dead and propagate a Proxy for it.
13
/// Afterwards, Analysis::finalize walks the abstract World and pins each param whose Proxy survived in a live position.
14
/// Then, we redo.
15
///
16
/// Lattice per Lam::var:
17
/// ```
18
/// ⊤ ← Live
19
/// |
20
/// Dead ← Proxy
21
/// |
22
/// ⊥
23
/// ```
24
class
ADCE
:
public
RWPhase
{
25
private
:
26
using
Super =
RWPhase
;
27
28
class
Analysis :
public
mim::Analysis
{
29
public
:
30
using
Super =
mim::Analysis
;
31
32
Analysis
(
World
&
world
)
33
:
mim::Analysis
(
world
,
"ADCE::Analysis"
) {}
34
35
void
reset
()
final
;
36
bool
is_dead(
const
Def
* var)
const
;
37
38
private
:
39
const
Def
*
rewrite_imm_App
(
const
App
*)
final
;
40
41
void
finalize
()
final
;
42
void
analyze
(
const
Def
*);
43
44
DefSet
visited_;
45
};
46
47
public
:
48
ADCE
(
World
&
world
)
49
:
RWPhase
(
world
,
"ADCE"
, &analysis_)
50
, analysis_(
world
) {}
51
ADCE
(
World
&
world
,
flags_t
annex
)
52
:
RWPhase
(
world
,
annex
, &analysis_)
53
, analysis_(
world
) {}
54
55
private
:
56
const
Def
*
rewrite_imm_App
(
const
App
*)
final
;
57
const
Def
*
rewrite_mut_Lam
(
Lam
*)
final
;
58
59
/// Keeps @p lam's live tvars.
60
Sieve
sieve(
Lam
* lam);
61
Lam
* build_lam(
Lam
* old_lam);
62
63
Analysis
analysis_;
64
LamMap<Sieve>
lam2sieve_;
65
Lam2Lam
lam_old2new_;
66
Lam2Lam
lam_new2old_;
67
};
68
69
}
// namespace mim
mim::ADCE::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
adce.cpp:122
mim::ADCE::ADCE
ADCE(World &world, flags_t annex)
Definition
adce.h:51
mim::ADCE::rewrite_mut_Lam
const Def * rewrite_mut_Lam(Lam *) final
Definition
adce.cpp:137
mim::ADCE::ADCE
ADCE(World &world)
Definition
adce.h:48
mim::Analysis
Traverses the current World using Rewriter infrastructure while staying in the same world.
Definition
phase.h:130
mim::App
Definition
lam.h:215
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Lam
A function.
Definition
lam.h:91
mim::Phase::Analysis
friend class Analysis
Definition
phase.h:106
mim::Phase::annex
flags_t annex() const
Definition
phase.h:62
mim::RWPhase::analyze
virtual bool analyze()
Runs the optional pre-analysis on old_world(), typically to a fixed point, before rewriting begins.
Definition
phase.cpp:202
mim::RWPhase::finalize
virtual void finalize()
Run after all roots have been walked but still before the two worlds are swapped.
Definition
phase.h:406
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:334
mim::RWPhase::world
World & world()=delete
Hides both and forbids direct access.
mim::Rewriter::reset
void reset()
Definition
rewrite.cpp:23
mim::Sieve
Filters the components of an aggregate and keeps track of where the survivors end up.
Definition
tuple.h:116
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:43
mim
Definition
ast.h:16
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::Lam2Lam
LamMap< Lam * > Lam2Lam
Definition
lam.h:212
mim::LamMap
GIDMap< Lam *, To > LamMap
Definition
lam.h:210
mim::DefSet
GIDSet< const Def * > DefSet
Definition
def.h:94
phase.h
include
mim
phase
adce.h
Generated by
1.18.0