MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
schedule.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
mim/phase.h
>
4
#include <
mim/schedule.h
>
5
6
#include "
mim/plug/mach/target.h
"
7
8
namespace
mim::plug::mach
{
9
10
/// Makes each continuation's `mem.M 0` chain total over the instructions of the Target, in a topological order.
11
/// Memory instructions are rethreaded onto the chain; all others are wrapped in `mach.sched`.
12
/// Scheduler::smart picks the continuation of an instruction; a closed one is rematerialized right before each use.
13
/// Every use of a memory token outside an instruction receives the end of the chain.
14
/// No type changes, so each Nest is rewritten in place.
15
class
Schedule
:
public
NestPhase
<Nest::Place::Late, Lam>,
private
Rewriter
{
16
public
:
17
Schedule
(
World
&
world
,
flags_t
annex
,
const
Target
& target)
18
:
NestPhase
(
world
,
annex
, true)
19
,
Rewriter
(
world
)
20
, target_(target) {}
21
22
using
NestPhase::world
;
23
24
private
:
25
void
visit
(
const
Nest
&)
final
;
26
const
Def
*
rewrite
(
const
Def
*)
final
;
27
const
Def
*
rewrite_imm_App
(
const
App
*)
final
;
28
void
thread(
Lam
*);
29
/// Maps the instructions of @p lam onto the chain that starts at its `i`th Var.
30
void
chain(
Lam
* lam,
size_t
i);
31
32
/// Places the instructions and memory tokens @p def depends on, stopping at mutables.
33
/// @p curr is the continuation of the user of @p def.
34
void
place(
Lam
* curr,
const
Def
* def);
35
36
bool
is_insn(
const
Def
* def)
const
{
return
def->isa<
App
>() && target_.
is_insn
(def->as<
App
>()); }
37
/// An instruction without a place of its own: a fresh copy goes right before each use.
38
bool
is_remat(
const
Def
* def)
const
{
return
is_insn(def) && (
Scheduler::is_remat
(def) || target_.
is_flags
(def)); }
39
40
const
Target
& target_;
41
Scheduler
* scheduler_ =
nullptr
;
42
DefSet
placed_;
43
LamSet
threaded_;
44
LamMap<DefSet>
visited_;
45
LamMap<DefVec>
insns_;
///< Per continuation in a topological order; a closed instruction once per use.
46
LamMap<DefVec>
mems_;
47
};
48
49
}
// namespace mim::plug::mach
mim::App
Definition
lam.h:215
mim::Def
Base class for all Defs.
Definition
def.h:285
mim::Lam
A function.
Definition
lam.h:91
mim::NestPhase< Nest::Place::Late, Lam >::NestPhase
NestPhase(World &world, std::string name, bool elide_empty, bool schedule=false)
Definition
phase.h:594
mim::Nest
Builds a nesting tree for all mutables/binders.
Definition
nest.h:26
mim::Phase::annex
flags_t annex() const
Definition
phase.h:64
mim::Phase::world
World & world()
Definition
phase.h:60
mim::Rewriter::world
World & world()
Definition
rewrite.h:33
mim::Rewriter::Rewriter
Rewriter(World &world)
Definition
rewrite.cpp:16
mim::Scheduler
Definition
schedule.h:43
mim::Scheduler::is_remat
static bool is_remat(const Def *def)
Definition
schedule.h:72
mim::Target
The machine a native backend compiles for, as far as libmim needs to know it.
Definition
target.h:11
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:43
mim::plug::mach::Schedule::visit
void visit(const Nest &) final
Definition
schedule.cpp:25
mim::plug::mach::Schedule::rewrite
const Def * rewrite(const Def *) final
Definition
schedule.cpp:36
mim::plug::mach::Schedule::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
schedule.cpp:45
mim::plug::mach::Schedule::Schedule
Schedule(World &world, flags_t annex, const Target &target)
Definition
schedule.h:17
mim::plug::mach::Target
The machine facts of a native backend that the phases of mach need.
Definition
target.h:45
mim::plug::mach::Target::is_flags
virtual bool is_flags(const Def *def) const =0
mim::plug::mach::Target::is_insn
bool is_insn(const App *app) const
Is app an instruction that belongs on a mem.M 0 chain?
Definition
target.h:119
mim::plug::mach
The mach Plugin
Definition
asm.h:15
mim::LamSet
GIDSet< Lam * > LamSet
Definition
lam.h:211
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::LamMap
GIDMap< Lam *, To > LamMap
Definition
lam.h:210
mim::DefSet
GIDSet< const Def * > DefSet
Definition
def.h:92
phase.h
target.h
schedule.h
include
mim
plug
mach
schedule.h
Generated by
1.18.0