MimIR
MimIR is my Intermediate Representation
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
7
8namespace 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.
15class Schedule : public NestPhase<Nest::Place::Late, Lam>, private Rewriter {
16public:
18 : NestPhase(world, annex, true)
20 , target_(target) {}
21
22 using NestPhase::world;
23
24private:
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
Base class for all Defs.
Definition def.h:285
A function.
Definition lam.h:91
NestPhase(World &world, std::string name, bool elide_empty, bool schedule=false)
Definition phase.h:594
Builds a nesting tree for all mutables/binders.
Definition nest.h:26
flags_t annex() const
Definition phase.h:64
World & world()
Definition phase.h:60
World & world()
Definition rewrite.h:33
Rewriter(World &world)
Definition rewrite.cpp:16
static bool is_remat(const Def *def)
Definition schedule.h:72
The machine a native backend compiles for, as far as libmim needs to know it.
Definition target.h:11
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:43
void visit(const Nest &) final
Definition schedule.cpp:25
const Def * rewrite(const Def *) final
Definition schedule.cpp:36
const Def * rewrite_imm_App(const App *) final
Definition schedule.cpp:45
Schedule(World &world, flags_t annex, const Target &target)
Definition schedule.h:17
The machine facts of a native backend that the phases of mach need.
Definition target.h:45
virtual bool is_flags(const Def *def) const =0
bool is_insn(const App *app) const
Is app an instruction that belongs on a mem.M 0 chain?
Definition target.h:119
The mach Plugin
Definition asm.h:15
GIDSet< Lam * > LamSet
Definition lam.h:211
u64 flags_t
Definition types.h:39
GIDMap< Lam *, To > LamMap
Definition lam.h:210
GIDSet< const Def * > DefSet
Definition def.h:92