forked from AnyDSL/MimIR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphase.cpp
51 lines (38 loc) · 1.08 KB
/
phase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "thorin/phase/phase.h"
namespace thorin {
void Phase::run() {
world().ILOG("=== {}: start ===", name());
start();
world().ILOG("=== {}: done ===", name());
}
void RWPhase::start() {
for (const auto& [_, ax] : old_world().axioms()) rewrite(ax);
for (const auto& [_, nom] : old_world().externals()) rewrite(nom)->as_nom()->make_external();
swap(world_, new_world_);
}
void FPPhase::start() {
for (bool todo = true; todo;) {
todo = false;
todo |= analyze();
}
RWPhase::start();
}
void Pipeline::start() {
for (auto& phase : phases()) phase->run();
}
void ScopePhase::start() {
unique_queue<NomSet> noms;
for (const auto& [name, nom] : world().externals()) {
assert(nom->is_set() && "external must not be empty");
noms.push(nom);
}
while (!noms.empty()) {
auto nom = noms.pop();
if (elide_empty_ && nom->is_unset()) continue;
Scope scope(nom);
scope_ = &scope;
visit(scope);
for (auto nom : scope.free_noms()) noms.push(nom);
}
}
} // namespace thorin