MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
subst.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
mim/rewrite.h
>
4
#include <
mim/world.h
>
5
6
#include "
mim/plug/mach/target.h
"
7
8
namespace
mim::plug::mach
{
9
10
/// Rewrites a value of a block under reconstruction: memory becomes @p m; @p map and @p lams replace values and blocks.
11
/// `mach.spilling` and `mach.constrain` rebuild a block in place, which neither Rewriter nor VarRewriter can do:
12
/// - The keys are no Var%s: @p map holds the current version of each value, instructions and projections alike.
13
/// After reloads, splits, and SSA reconstruction, a value has several definitions.
14
/// - Every `mem.M` becomes @p m, the block's current chain end.
15
/// - It never builds an instruction itself, since the chain places them one by one; reaching an unmapped one bails.
16
/// Closed Def%s and mutables pass through as they are.
17
/// - The substitution changes after every instruction, as @p map and @p m move on.
18
/// A memo shared across instructions would be wrong, so each instruction gets a Subst of its own.
19
class
Subst
:
public
Rewriter
{
20
public
:
21
Subst
(
const
Target
& target,
World
&
world
,
const
Def2Def
&
map
,
const
Def
* m,
const
LamMap<Lam*>
* lams =
nullptr
)
22
:
Rewriter
(
world
)
23
, target_(target)
24
, map_(
map
)
25
, lams_(lams)
26
, m_(m) {}
27
28
const
Def
*
rewrite
(
const
Def
* def)
final
;
29
30
/// Rewrites @p term per argument, so an instruction passed as the whole argument gets the new memory.
31
const
Def
*
rewrite_jump
(
const
App
* term) {
32
auto
n = term->
num_args
();
33
auto
args =
DefVec
(n, [&](
size_t
i) {
return
rewrite
(term->
arg
(n, i)); });
34
return
world
().
app
(
rewrite
(term->
callee
()),
world
().
tuple
(args));
35
}
36
37
private
:
38
const
Target
& target_;
39
const
Def2Def
& map_;
40
const
LamMap<Lam*>
* lams_;
41
const
Def
* m_;
42
};
43
44
}
// namespace mim::plug::mach
mim::App
Definition
lam.h:215
mim::App::num_args
nat_t num_args() const noexcept
Definition
lam.h:252
mim::App::callee
const Def * callee() const
Definition
lam.h:237
mim::App::arg
const Def * arg() const
Definition
lam.h:251
mim::Def
Base class for all Defs.
Definition
def.h:285
mim::Rewriter::world
World & world()
Definition
rewrite.h:33
mim::Rewriter::map
const Def * map(const Def *old_def, const Def *new_def)
Definition
rewrite.cpp:29
mim::Rewriter::Rewriter
Rewriter(World &world)
Definition
rewrite.cpp:16
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:43
mim::World::app
const Def * app(const Def *callee, const Def *arg)
Definition
world.cpp:416
mim::plug::mach::Subst::rewrite
const Def * rewrite(const Def *def) final
Definition
subst.cpp:5
mim::plug::mach::Subst::rewrite_jump
const Def * rewrite_jump(const App *term)
Rewrites term per argument, so an instruction passed as the whole argument gets the new memory.
Definition
subst.h:31
mim::plug::mach::Subst::Subst
Subst(const Target &target, World &world, const Def2Def &map, const Def *m, const LamMap< Lam * > *lams=nullptr)
Definition
subst.h:21
mim::plug::mach::Target
The machine facts of a native backend that the phases of mach need.
Definition
target.h:45
mim::plug::mach
The mach Plugin
Definition
asm.h:15
mim::plug::tuple
The tuple Plugin
Definition
normalizers.cpp:6
mim::Def2Def
DefMap< const Def * > Def2Def
Definition
def.h:93
mim::LamMap
GIDMap< Lam *, To > LamMap
Definition
lam.h:210
mim::DefVec
fe::Vector< const Def * > DefVec
Definition
def.h:96
target.h
rewrite.h
world.h
include
mim
plug
mach
subst.h
Generated by
1.18.0