MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
phase.cpp
Go to the documentation of this file.
1#include "mim/phase/phase.h"
2
3namespace mim {
4
5void Phase::run() {
6 world().verify().ILOG("=== {}: Phase start ===", name());
7 start();
8 world().verify().ILOG("=== {}: Phase done ===", name());
9}
10
12 for (const auto& [f, def] : old_world().flags2annex())
13 rewrite_annex(f, def);
14
15 bootstrapping_ = false;
16
17 for (auto mut : old_world().copy_externals())
19
20 swap(old_world(), new_world());
21}
22
24
25void RWPhase::rewrite_external(Def* mut) { mut->transfer_external(rewrite(mut)->as_mut()); }
26
28 for (bool todo = true; todo;) {
29 todo = false;
30 todo |= analyze();
31 }
32
34}
35
37 : Phase(world, std::format("pipeline (fixed_point_: `{}`)", fixed_point))
38 , fixed_point_(fixed_point) {}
39
41 do {
42 for (auto& phase : phases()) {
43 phase->run();
44 todo_ |= phase->todo();
45 }
46
47 todo_ &= fixed_point();
48
49 if (todo_) {
50 for (auto& phase : phases())
51 phase->reset();
52 reset();
53 }
54 } while (todo_);
55}
56
57} // namespace mim
Base class for all Defs.
Definition def.h:251
void transfer_external(Def *to)
Definition def.cpp:566
void start() override
Actual entry.
Definition phase.cpp:27
virtual bool analyze()=0
bool fixed_point() const
Definition phase.h:164
const auto & phases() const
Definition phase.h:169
void start() override
Actual entry.
Definition phase.cpp:40
PhaseMan(World &, bool fixed_point=false)
Definition phase.cpp:36
bool todo_
Set to true to indicate that you want to rerun all Phasees in current your fixed-point PhaseMan.
Definition phase.h:55
virtual void reset()
Definition phase.h:29
Phase(World &world, std::string name)
Definition phase.h:24
virtual void run()
Entry point and generates some debug output; invokes Phase::start.
Definition phase.cpp:5
bool todo() const
Definition phase.h:36
std::string_view name() const
Definition phase.h:35
virtual void start()=0
Actual entry.
World & world()
Definition phase.h:34
World & new_world()
Create new Defs into this.
Definition phase.h:99
virtual void rewrite_annex(flags_t, const Def *)
Definition phase.cpp:23
void start() override
Actual entry.
Definition phase.cpp:11
bool bootstrapping_
Definition phase.h:105
World & old_world()
Get old Defs from here.
Definition phase.h:98
virtual void rewrite_external(Def *)
Definition phase.cpp:25
virtual const Def * rewrite(const Def *)
Definition rewrite.cpp:14
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:36
World & verify()
Verifies that all externals() and annexes() are Def::is_closed(), if MIM_ENABLE_CHECKS.
Definition world.cpp:687
const Def * register_annex(flags_t f, const Def *)
Definition world.cpp:78
Definition ast.h:14
u64 flags_t
Definition types.h:45
Definition span.h:122