MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
copy_prop.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/pass/pass.h"
4
5namespace mim {
6
7class BetaRed;
8class EtaExp;
9
10namespace plug::mem {
11
12/// This FPPass is similar to sparse conditional constant propagation (SCCP).
13/// However, this optmization also works on all Lam%s alike and does not only consider basic blocks as opposed to
14/// traditional SCCP. What is more, this optimization will also propagate arbitrary Def%s and not only constants.
15/// Finally, it will also remove dead Var%s.
16class CopyProp : public FPPass<CopyProp, Lam> {
17public:
18 CopyProp(PassMan& man, BetaRed* beta_red, EtaExp* eta_exp, bool bb_only = false)
19 : FPPass(man, "copy_prop")
20 , beta_red_(beta_red)
21 , eta_exp_(eta_exp)
22 , bb_only_(bb_only) {}
23
25
26private:
27 /// Lattice used for this Pass:
28 /// ```
29 /// Keep <-- We cannot do anything here.
30 /// |
31 /// Prop <-- Var is live but the same Def everywhere.
32 /// |
33 /// Dead <-- Var is dead.
34 /// ```
35 enum Lattice : u8 { Dead, Prop, Keep };
36 enum : u32 { Varxy, Appxy };
37 using Lattices = Vector<Lattice>;
38
39 /// @name PassMan hooks
40 ///@{
41 const Def* rewrite(const Def*) override;
42 undo_t analyze(const Proxy*) override;
43 ///@}
44
45 BetaRed* beta_red_;
46 EtaExp* eta_exp_;
48 const bool bb_only_;
49};
50
51} // namespace plug::mem
52} // namespace mim
Optimistically performs β-reduction (aka inlining).
Definition beta_red.h:9
Base class for all Defs.
Definition def.h:198
Performs η-expansion: f -> λx.f x, if f is a Lam with more than one user and does not appear in calle...
Definition eta_exp.h:13
FPPass(PassMan &man, std::string_view name)
Definition pass.h:247
PassMan & man()
Definition pass.h:30
friend class PassMan
Definition pass.h:101
This is a thin wrapper for absl::InlinedVector<T, N, A> which is a drop-in replacement for std::vecto...
Definition vector.h:17
CopyProp(PassMan &man, BetaRed *beta_red, EtaExp *eta_exp, bool bb_only=false)
Definition copy_prop.h:18
const Def * rewrite(const Def *) override
Definition copy_prop.cpp:10
undo_t analyze(const Proxy *) override
Definition copy_prop.cpp:93
LamMap< DefVec > Data
Definition copy_prop.h:24
The mem Plugin
Definition mem.h:11
Definition ast.h:14
GIDMap< Lam *, To > LamMap
Definition lam.h:197
size_t undo_t
Definition pass.h:14
uint32_t u32
Definition types.h:34
uint8_t u8
Definition types.h:34