MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
sym_expr_opt.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/phase.h"
4
5namespace mim {
6
7/// Symbolic Expression Optimization. Combines:
8/// * *[Constant propagation with conditional branches](https://dl.acm.org/doi/pdf/10.1145/103135.103136)* but
9/// propagates arbitrary expressions
10/// * *[Detecting equality of variables in programs](https://dl.acm.org/doi/10.1145/73560.73561)*
11/// * Much in the spirit of *[Combining analyses, combining
12/// optimizations](https://dl.acm.org/doi/pdf/10.1145/201059.201061)*.
13///
14/// Due to MimIR's sea of node structure a number of other optimizations kick in such as arithmetic simplifications and
15/// code motion.
16///
17/// Lattice per Lam::var:
18/// ```
19/// ⊤ ← Keep as is
20/// |
21/// Bundle ← Vars that (horizontally) behave the same build a single congruence class
22/// |
23/// Expr ← Whole expression is propagated (vertically) through var
24/// |
25/// ⊥
26/// ```
27class SymExprOpt : public RWPhase {
28private:
29 class Analysis : public mim::Analysis {
30 public:
31 Analysis(World& world)
32 : mim::Analysis(world, "SEO::Analyzer") {}
33
34 auto& lattice() { return lattice_; }
35
36 private:
37 const Def* propagate(const Def*, const Def*);
38 Def* rewrite_mut(Def*) final;
39 const Def* rewrite_imm_App(const App*) final;
40
41 Def2Def lattice_;
42 };
43
44public:
46 : RWPhase(world, annex, &analysis_)
47 , analysis_(world) {}
48
49private:
50 const Def* lattice(const Def* def) { return analysis_.lattice()[def]; }
51 const Def* rewrite_imm_App(const App*) final;
52
53 Analysis analysis_;
54 Lam2Lam lam2lam_;
55};
56
57} // namespace mim
This Phase will recursively Rewriter::rewrite.
Definition phase.h:64
Base class for all Defs.
Definition def.h:251
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:112
World & world()=delete
Hides both and forbids direct access.
virtual const Def * rewrite_mut(Def *)
Definition rewrite.cpp:48
flags_t annex() const
Definition pass.h:68
SymExprOpt(World &world, flags_t annex)
const Def * rewrite_imm_App(const App *) final
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:31
Definition ast.h:14
DefMap< const Def * > Def2Def
Definition def.h:75
u64 flags_t
Definition types.h:46
LamMap< Lam * > Lam2Lam
Definition lam.h:221
@ App
Definition def.h:114