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("=== {}: start ===", name());
7 start();
8 world().verify().ILOG("=== {}: done ===", name());
9}
10
12 for (const auto& [_, def] : world().annexes()) rewrite(def);
13 auto externals = world().externals();
14 for (const auto& [_, mut] : externals) mut->transfer_external(rewrite(mut)->as_mut());
15}
16
18 for (bool todo = true; todo;) {
19 todo = false;
20 todo |= analyze();
21 }
22
24}
25
27 auto new_world = world().inherit();
28 Rewriter rewriter(new_world);
29
30 for (const auto& [f, def] : world().annexes()) new_world.register_annex(f, rewriter.rewrite(def));
31 for (const auto& [_, mut] : world().externals()) {
32 auto new_mut = rewriter.rewrite(mut)->as_mut();
33 new_mut->make_external();
34 }
35
36 swap(world(), new_world);
37}
38
40 for (auto& phase : phases()) phase->run();
41}
42
45 for (const auto& [name, mut] : world().externals()) muts.push(mut);
46
47 while (!muts.empty()) {
48 auto mut = muts.pop();
49 if (elide_empty_ && !mut->is_set()) continue;
50
51 Scope scope(mut);
52 scope_ = &scope;
53 visit(scope);
54
55 for (auto mut : scope.free_muts()) muts.push(mut);
56 }
57}
58
59} // namespace mim
void start() override
Actual entry.
Definition phase.cpp:26
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
Definition def.h:452
void start() override
Actual entry.
Definition phase.cpp:17
virtual bool analyze()=0
virtual void run()
Entry point and generates some debug output; invokes Phase::start.
Definition phase.cpp:5
std::string_view name() const
Definition phase.h:26
virtual void start()=0
Actual entry.
World & world()
Definition phase.h:25
void start() override
Actual entry.
Definition phase.cpp:39
const auto & phases() const
Definition phase.h:122
World & world()
Definition phase.h:58
void start() override
Actual entry.
Definition phase.cpp:11
Recurseivly rewrites part of a program into the provided World.
Definition rewrite.h:9
virtual Ref rewrite(Ref)
Definition rewrite.cpp:9
virtual void visit(const Scope &)=0
const Scope & scope() const
Definition phase.h:159
void start() override
Actual entry.
Definition phase.cpp:43
A Scope represents a region of Defs that are live from the view of an entry's Var.
Definition scope.h:21
const MutSet & free_muts() const
All muts that occurr free in this Scope.
Definition scope.h:44
World inherit()
Definition world.h:73
World & verify()
Verifies that all externals() and annexes() are Def::is_closed(), if MIM_ENABLE_CHECKS.
Definition world.cpp:568
const auto & externals() const
Definition world.h:168
bool empty() const
Definition util.h:150
bool push(T val)
Definition util.h:142
Definition cfg.h:11