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 Ref rewrite(Ref) 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
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
Inherit from this class using CRTP, if you do need a Pass with a state and a fixed-point.
Definition pass.h:242
An optimizer that combines several optimizations in an optimal way.
Definition pass.h:107
PassMan & man()
Definition pass.h:30
Helper class to retrieve Infer::arg if present.
Definition def.h:85
This is a thin wrapper for absl::InlinedVector<T, N, / A> which in turn is a drop-in replacement for ...
Definition vector.h:16
This FPPass is similar to sparse conditional constant propagation (SCCP).
Definition copy_prop.h:16
Ref rewrite(Ref) override
Definition copy_prop.cpp:10
CopyProp(PassMan &man, BetaRed *beta_red, EtaExp *eta_exp, bool bb_only=false)
Definition copy_prop.h:18
undo_t analyze(const Proxy *) override
Definition copy_prop.cpp:93
LamMap< DefVec > Data
Definition copy_prop.h:24
Definition cfg.h:11
GIDMap< Lam *, To > LamMap
Definition lam.h:188
size_t undo_t
Definition pass.h:14
uint32_t u32
Definition types.h:34
uint8_t u8
Definition types.h:34