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 // TODO: remove when normalizers are fixed
13 if (ax->flags() == flags_t(Annex::Base<combine_pass_list>)) {
14 auto arg_cpl = arg->as<App>();
15 arg = normalize_combine_pass_list(arg_cpl->type(), arg_cpl->callee(), arg_cpl->arg());
16 } else {
17 world.ELOG("pass_phase expects a pass_list as argument but got {}", arg);
18 }
19 }
20
21 auto [f_ax, pass_list_defs] = collect_args(arg);
22 assert(f_ax->flags() == flags_t(Annex::Base<pass_list>));
23 auto n = pass_list_defs.size();
24
25 return world.call<passes_to_phase>(n, pass_list_defs);
26}
27
28/// `combined_phase (phase_list phase1 ... phasen)` -> `phases_to_phase n (phase1, ..., phasen)`
30 auto& world = type->world();
31
32 auto [ax, phase_list_defs] = collect_args(arg);
33 assert(ax->flags() == flags_t(Annex::Base<phase_list>));
34 auto n = phase_list_defs.size();
35
36 return world.call<phases_to_phase>(n, phase_list_defs);
37}
38
39/// `single_pass_phase pass` -> `passes_to_phase 1 pass`
40Ref normalize_single_pass_phase(Ref type, Ref, Ref arg) { return type->world().call<passes_to_phase>(1, arg); }
41
42/// `combine_pass_list K (pass_list pass11 ... pass1N) ... (pass_list passK1 ... passKM) = pass_list pass11 ... p1N ...
43/// passK1 ... passKM`
45 auto& world = type->world();
46 auto pass_lists = arg->projs();
47 DefVec passes;
48
49 for (auto pass_list_def : pass_lists) {
50 auto [ax, pass_list_defs] = collect_args(pass_list_def);
51 assert(ax->flags() == flags_t(Annex::Base<pass_list>));
52 passes.insert(passes.end(), pass_list_defs.begin(), pass_list_defs.end());
53 }
54 Ref app_list = world.annex<pass_list>();
55 for (auto pass : passes) app_list = world.app(app_list, pass);
56 return app_list;
57}
58
60
61} // namespace mim::plug::compile
World & world() const
Definition def.cpp:411
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
Definition def.h:361
Helper class to retrieve Infer::arg if present.
Definition def.h:86
const Def * call(Id id, Args &&... args)
Complete curried call of annexes obeying implicits.
Definition world.h:507
#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< Ref, DefVec > collect_args(Ref 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