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