MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
sccp.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/phase.h"
4
5namespace mim {
6
7/// SCCP - Sparse Conditional Constant Propagation - but propagates **arbitrary expressions**.
8/// @see [Constant propagation with conditional branches](https://dl.acm.org/doi/pdf/10.1145/103135.103136)
9///
10/// Lattice per Lam::var:
11/// ```
12/// ⊤ ← Keep as is
13/// |
14/// Expr ← Whole expression is propagated (vertically) through var
15/// |
16/// ⊥
17/// ```
18/// @pre EtaConv ran beforehand, so no rewritable Lam escapes as a value.
19/// Otherwise, the vars of such unknown functions would have to be pinned to ⊤.
20class SCCP : public RWPhase {
21private:
22 class Analysis : public mim::Analysis {
23 public:
25 : mim::Analysis(world, "SCCP::Analyzer") {}
26
27 private:
28 const Def* propagate(Lam* lam, const Def* var, const Def* def);
29 const Def* rewrite_imm_App(const App* app) final;
30 };
31
32public:
34 : RWPhase(world, annex, &analysis_)
35 , analysis_(world) {}
36
37private:
38 const Def* rewrite_imm_App(const App* old_app) final;
39
40 Analysis analysis_;
41 Lam2Lam lam2lam_;
42};
43
44} // namespace mim
Traverses the current World using Rewriter infrastructure while staying in the same world.
Definition phase.h:130
Base class for all Defs.
Definition def.h:289
A function.
Definition lam.h:91
friend class Analysis
Definition phase.h:106
flags_t annex() const
Definition phase.h:62
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
World & world()=delete
Hides both and forbids direct access.
SCCP(World &world, flags_t annex)
Definition sccp.h:33
const Def * rewrite_imm_App(const App *old_app) final
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:43
Definition ast.h:16
u64 flags_t
Definition types.h:39
LamMap< Lam * > Lam2Lam
Definition lam.h:212