MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
optimize.cpp
Go to the documentation of this file.
1
#include "
mim/phase/optimize.h
"
2
3
#include "
mim/driver.h
"
4
#include "
mim/phase.h
"
5
6
namespace
mim
{
7
8
void
optimize
(
World
& world) {
9
world.
driver
().
move_to_library
(world);
10
11
// clang-format off
12
auto
compilation_functions = {
13
world.
sym
(
"_compile"
),
14
world.
sym
(
"_default_compile"
),
15
};
16
// clang-format on
17
18
const
Def
* compilation =
nullptr
;
19
for
(
auto
compilation_function : compilation_functions) {
20
if
(
auto
compilation_ = world.
externals
()[compilation_function]) {
21
if
(!compilation) compilation = compilation_;
22
compilation_->
internalize
();
23
}
24
}
25
26
// make all functions `[] -> compile.Phase` internal
27
for
(
auto
def : world.
externals
().
mutate
()) {
28
if
(
auto
lam = def->isa<
Lam
>(); lam && lam->
num_doms
() == 0) {
29
if
(lam->codom()->sym().view() ==
"compile.Phase"
) {
30
if
(!compilation) compilation = lam;
31
def->
internalize
();
32
}
33
}
34
}
35
36
if
(!compilation) {
37
world.
log
().i(
"no compilation function found; skipping optimization"
);
38
}
else
{
39
world.
log
().d(
"compile with {}: {}"
, compilation, compilation->
type
());
40
41
world.
log
().d(
"build pipeline"
);
42
if
(
auto
phase =
Phase::create
(world.
driver
().
phases
(), compilation->as<
Lam
>()->
body
())) phase->run();
43
}
44
}
45
46
}
// namespace mim
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Def::type
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition
def.h:1119
mim::Def::internalize
void internalize()
Definition
def.cpp:626
mim::Driver::move_to_library
void move_to_library(World &world)
Moves everything of world into library() and imports only its externals back.
Definition
driver.cpp:141
mim::Driver::phases
const auto & phases() const
Definition
driver.h:212
mim::Lam
A function.
Definition
lam.h:91
mim::Lam::body
const Def * body() const
Definition
lam.h:104
mim::Lam::num_doms
nat_t num_doms() const noexcept
Definition
lam.h:117
mim::Phase::create
static std::unique_ptr< Phase > create(const Flags2Phases &phases, const Def *def)
Definition
phase.cpp:25
mim::World::Externals::mutate
fe::Vector< Def * > mutate() const
Returns a copy of muts() in a fe::Vector; this allows you to modify the Externals while iterating.
Definition
world.h:194
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:43
mim::World::driver
Driver & driver()
Definition
world.h:107
mim::World::log
const fe::Log & log() const
Log via log().e("...", args) etc.; owned by the Driver.
Definition
world.cpp:224
mim::World::sym
Sym sym(std::string_view)
Definition
world.cpp:228
mim::World::externals
const Externals & externals() const
Definition
world.h:286
driver.h
mim
Definition
ast.h:16
mim::optimize
void optimize(World &)
Runs _compile or _default_compile, if available (in this order).
Definition
optimize.cpp:8
optimize.h
phase.h
src
mim
phase
optimize.cpp
Generated by
1.18.0