MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
normalizers.cpp
Go to the documentation of this file.
3
4namespace mim::plug::compile {
5
6// `pass_phase (pass_list pass1 ... passn)` -> `passes_to_phase n (pass1, ..., passn)`
8 auto& world = type->world();
9
10 auto [ax, _] = collect_args(arg);
11 if (ax->flags() != flags_t(Annex::Base<pass_list>)) {
12 // return world.raw_app(type, callee, arg);
13 // TODO: remove when normalizers are fixed
14 if (ax->flags() == flags_t(Annex::Base<combine_pass_list>)) {
15 auto arg_cpl = arg->as<App>();
16 arg = normalize_combine_pass_list(arg_cpl->type(), arg_cpl->callee(), arg_cpl->arg());
17 } else {
18 world.ELOG("pass_phase expects a pass_list as argument but got {}", arg);
19 }
20 }
21
22 auto [f_ax, pass_list_defs] = collect_args(arg);
23 assert(f_ax->flags() == flags_t(Annex::Base<pass_list>));
24 auto n = pass_list_defs.size();
25
26 return world.call<passes_to_phase>(n, pass_list_defs);
27}
28
29/// `combined_phase (phase_list phase1 ... phasen)` -> `phases_to_phase n (phase1, ..., phasen)`
31 auto& world = type->world();
32
33 auto [ax, phase_list_defs] = collect_args(arg);
34 assert(ax->flags() == flags_t(Annex::Base<phase_list>));
35 auto n = phase_list_defs.size();
36
37 return world.call<phases_to_phase>(n, phase_list_defs);
38}
39
40/// `single_pass_phase pass` -> `passes_to_phase 1 pass`
41Ref normalize_single_pass_phase(Ref type, Ref, Ref arg) { return type->world().call<passes_to_phase>(1, arg); }
42
43/// `combine_pass_list K (pass_list pass11 ... pass1N) ... (pass_list passK1 ... passKM) = pass_list pass11 ... p1N ...
44/// passK1 ... passKM`
46 auto& world = type->world();
47 auto pass_lists = arg->projs();
48 DefVec passes;
49
50 for (auto pass_list_def : pass_lists) {
51 auto [ax, pass_list_defs] = collect_args(pass_list_def);
52 assert(ax->flags() == flags_t(Annex::Base<pass_list>));
53 passes.insert(passes.end(), pass_list_defs.begin(), pass_list_defs.end());
54 }
55 Ref app_list = world.annex<pass_list>();
56 for (auto pass : passes) app_list = world.app(app_list, pass);
57 return app_list;
58}
59
61
62} // namespace mim::plug::compile
World & world() const
Definition def.cpp:415
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == -1_n) or std::array (otherwise).
Definition def.h:367
Helper class to retrieve Infer::arg if present.
Definition def.h:86
const Def * call(Id id, Args &&... args)
Definition world.h:518
#define MIM_compile_NORMALIZER_IMPL
Definition autogen.h:270
The compile Plugin
Definition compile.h:8
Ref normalize_combined_phase(Ref type, Ref, Ref arg)
combined_phase (phase_list phase1 ... phasen) -> phases_to_phase n (phase1, ..., phasen)
Ref normalize_pass_phase(Ref type, Ref, Ref arg)
Ref normalize_single_pass_phase(Ref type, Ref, Ref arg)
single_pass_phase pass -> passes_to_phase 1 pass
Ref normalize_combine_pass_list(Ref type, Ref, Ref arg)
combine_pass_list K (pass_list pass11 ... pass1N) ... (pass_list passK1 ... passKM) = pass_list pass1...
u64 flags_t
Definition types.h:45
std::pair< const Def *, std::vector< const Def * > > collect_args(const Def *def)
Helper function to cope with the fact that normalizers take all arguments and not only its axiom argu...
Definition lam.cpp:86
static constexpr flags_t Base
Definition plugin.h:118