MimIR
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:
32 : mim::Analysis(world, "SEO::Analyzer") {}
33
34 private:
35 const Def* propagate(const Def*, const Def*);
36 const Def* rewrite_imm_App(const App*) final;
37 };
38
39public:
41 : RWPhase(world, annex, &analysis_)
42 , analysis_(world) {}
43
44private:
45 const Def* rewrite_imm_App(const App*) final;
46
47 Analysis analysis_;
48 Lam2Lam lam2lam_;
49};
50
51} // namespace mim
Traverses the current World using Rewriter infrastructure while staying in the same world.
Definition phase.h:82
Base class for all Defs.
Definition def.h:246
friend class Analysis
Definition phase.h:67
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:194
World & world()=delete
Hides both and forbids direct access.
flags_t annex() const
Definition pass.h:81
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:36
Definition ast.h:14
u64 flags_t
Definition types.h:39
LamMap< Lam * > Lam2Lam
Definition lam.h:221