MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
spilling.cpp
Go to the documentation of this file.
1#include <limits>
2#include <ranges>
3
4#include <mim/driver.h>
5
9
10namespace mim::plug::mach {
11
12namespace {
13
14constexpr size_t Inf = std::numeric_limits<size_t>::max();
15/// Added to the next-use distance across an edge that leaves a loop.
16constexpr size_t Loop_Exit = 1 << 20;
17
18size_t add(size_t a, size_t b) { return a > Inf - b ? Inf : a + b; }
19
20const App* root(const Def* value) {
21 while (auto ex = value->isa<Extract>())
22 value = ex->tuple();
23 return value->isa<App>();
24}
25
26/// @p value with its instruction @p old_app replaced by @p new_app.
27const Def* reroot(const Def* value, const Def* old_app, const Def* new_app) {
28 if (value == old_app) return new_app;
29 auto ex = value->as<Extract>();
30 return value->world().extract(reroot(ex->tuple(), old_app, new_app), ex->index());
31}
32
33/// A closed instruction is recomputed instead of reloaded.
34bool is_remat(const Def* value) {
35 if (auto app = root(value); app && Axm::isa<sched>(app))
36 return Target::sched_insn(app)->is_closed() && app->arg()->is_closed();
37 return false;
38}
39
40class Spiller {
41public:
42 Spiller(const FunPhase& phase, Lam* fun, const LamMap<Conv>& convs, Liveness::Class cls, size_t k)
43 : target_(phase.target())
44 , world_(fun->world())
45 , fun_(fun)
46 , live_(phase, fun)
47 , convs_(convs)
48 , cls_(cls)
49 , k_(k)
50 , n_(live_.blocks().size()) {
51 ret_cont_.resize(n_, false);
52 for (size_t b = 0; b != n_; ++b)
53 node2block_[node(b)] = b;
54 for (size_t p = 0; p != n_; ++p)
55 if (auto k = call_cont(live_, fun_, block(p))) ret_cont_[index(k->lam)] = true;
56 }
57
58 void run() {
59 w_entry_.resize(n_);
60 w_exit_.resize(n_);
61 jumps_.resize(n_);
62 in_regs_.resize(n_);
63 for (size_t b = 0; b != n_; ++b)
64 reloads_.emplace_back(size(b) + 1);
65 next_uses();
66 for (size_t b = 0; b != n_; ++b)
67 walk(b);
68 couple();
69 build();
70 }
71
72private:
73 enum class Term { Call, Jump, Other };
74
75 const Liveness::Block& block(size_t b) const { return live_.blocks()[b]; }
76 const Nest::Node* node(size_t b) const { return block(b).node; }
77 size_t size(size_t b) const { return block(b).insns.size(); }
78 bool member(const Def* v) const { return is_value(v, cls_, target_); }
79 DefVec members(DefVec values) const {
80 std::erase_if(values, [&](const Def* v) { return !member(v); });
81 return values;
82 }
83 /// How many values of this class may stay in a register across the call at the end of @p b.
84 size_t survivors(size_t b) const {
85 auto conv = callee_conv(convs_, block(b));
86 auto lost = size_t(0);
87 for (size_t r = 0, e = target_.num_regs(cls_); r != e; ++r)
88 lost += !target_.reserved(cls_, r) && clobbered(target_, conv, cls_, r);
89 return k_ > lost ? k_ - lost : 0;
90 }
91 const App* term(size_t b) const { return block(b).lam->body()->as<App>(); }
92 size_t index(Lam* lam) const { return size_t(live_.block(lam) - live_.blocks().data()); }
93 Term kind(size_t b) const;
94 /// The argument that @p p passes for the @p i-th parameter of @p b, or `nullptr` for a return continuation.
95 const Def* arg(size_t p, size_t b, size_t i) const;
96 /// The join that @p b jumps to.
97 size_t target(size_t b) const { return index(Lam::isa_mut_basicblock(term(b)->callee())); }
98 /// Calls @p f with each parameter of the block that @p b jumps to and the argument that @p b passes it.
99 void for_each_param(size_t b, auto f) const {
100 auto lam = block(target(b)).lam;
101 auto n = lam->num_vars();
102 for (size_t i = 0; i != n; ++i)
103 f(lam->var(n, i), term(b)->arg(n, i));
104 }
105 /// The arguments of the jump @p t to the rebuilt @p s.
106 DefVec args(size_t b, const Def2Def& cur);
107
108 void next_uses();
109 bool summarize(const Nest::Node*);
110 bool next_uses(size_t b);
111 size_t next_use(size_t b, const Def* v, size_t pos) const;
112 void entry(size_t b);
113 void walk(size_t b);
114 void limit(size_t b, DefSet& w, size_t m, size_t pos) const;
115 void reload(size_t b, size_t pos, const Def* v);
116 void couple();
117 void build();
118 void build(size_t b);
119 Subst subst(const Def2Def& cur) const { return Subst(target_, world_, cur, m_, &new_lams_); }
120 const Def* sched(const Def* f, const Def* x);
121 const Def* spill(const Def* x);
122 const Def* slot(const Def* v) const {
123 if (auto slot = fe::lookup(stack_, v)) return slot;
124 v->blame("{} backend: `{}` has no spill slot", target_.name(), v).bail();
125 }
126
127 const Target& target_;
128 World& world_;
129 Lam* fun_;
130 Liveness live_;
131 const LamMap<Conv>& convs_;
132 Liveness::Class cls_;
133 size_t k_;
134 size_t n_;
135
137 fe::Vector<size_t> jumps_; ///< The jumps to a block that walk() has passed.
138 fe::Vector<DefMap<size_t>> in_regs_; ///< Of those, how many pass the argument for a parameter in a register.
139 fe::Vector<bool> ret_cont_;
140 fe::Vector<DefMap<fe::Vector<size_t>>> uses_;
141 fe::Vector<DefMap<size_t>> nu_out_;
142
143 fe::Vector<DefSet> w_entry_, w_exit_;
144 fe::Vector<fe::Vector<DefVec>> reloads_; ///< Per block and position; the terminator is at `size(b)`.
145 DefSet spill_; ///< Spilled right after their definition.
146 DefSet mphi_; ///< Parameters that become memory φs.
147
148 LamMap<Lam*> new_lams_;
149 DefMap<const Def*> stack_; ///< The spill slot of a value.
150 fe::Vector<Def2Def> exit_; ///< The current version of each value at the end of a rebuilt block.
151 const Def* m_ = nullptr;
152};
153
154Spiller::Term Spiller::kind(size_t b) const {
155 auto callee = term(b)->callee();
156 if (callee == fun_->ret_var() || callee->isa<Extract>()) return Term::Other;
157 if (auto lam = Lam::isa_mut_basicblock(callee); lam && live_.block(lam)) return Term::Jump;
158 return Term::Call;
159}
160
161const Def* Spiller::arg(size_t p, size_t b, size_t i) const {
162 if (ret_cont_[b]) return nullptr;
163 auto lam = block(b).lam;
164 return term(p)->arg(lam->num_vars(), i);
165}
166
167void Spiller::next_uses() {
168 uses_.resize(n_);
169 nu_out_.resize(n_);
170 for (size_t b = 0; b != n_; ++b) {
171 for (size_t i = 0; i != size(b); ++i)
172 for (auto v : members(live_.uses(block(b).insns[i])))
173 uses_[b][v].emplace_back(i);
174 // An argument of a jump is used where its parameter is.
175 if (kind(b) != Term::Jump)
176 for (auto v : members(live_.term_uses(block(b))))
177 uses_[b][v].emplace_back(size(b));
178 }
179 summarize(node(0));
180}
181
182/// A block comes after the blocks nested in it and the joins it jumps to forward, which come later in Nest::Node::topo.
183/// Only a jump back into a recursive SCC reads a distance that is not final yet, so such an SCC repeats until stable.
184bool Spiller::summarize(const Nest::Node* node) {
185 auto changed = false;
186 for (const auto& scc : node->topo() | std::views::reverse) {
187 auto nodes = sorted(*scc);
188 auto recursive = nodes.front()->is_recursive();
189 for (bool todo = true; todo;) {
190 todo = false;
191 for (auto n : nodes)
192 todo |= summarize(n);
193 changed |= todo;
194 todo &= recursive;
195 }
196 }
197 if (auto b = fe::lookup(node2block_, node)) changed |= next_uses(*b);
198 return changed;
199}
200
201/// Updates the next-use distances at the end of @p b from its targets; yields whether they changed.
202bool Spiller::next_uses(size_t b) {
203 auto d = DefMap<size_t>();
204 auto upd = [&](const Def* v, size_t s, size_t dist) {
205 auto x = add(dist, node(s)->loop_depth() < node(b)->loop_depth() ? Loop_Exit : 0);
206 auto [i, ins] = d.emplace(v, x);
207 if (!ins) i->second = std::min(i->second, x);
208 };
209 for (auto v : block(b).live_out)
210 if (member(v))
211 for (auto s : block(b).targets)
212 if (block(s).live_in.contains(v)) upd(v, s, next_use(s, v, 0));
213 if (kind(b) == Term::Jump)
214 for_each_param(b, [&, s = target(b)](const Def* x, const Def* a) {
215 if (member(a) && !Lit::isa(a)) upd(a, s, next_use(s, x, 0));
216 });
217 auto changed = false;
218 for (auto [v, x] : d) {
219 auto [i, ins] = nu_out_[b].emplace(v, x);
220 if (!ins && x < i->second) i->second = x, changed = true;
221 if (ins && x != Inf) changed = true;
222 }
223 return changed;
224}
225
226size_t Spiller::next_use(size_t b, const Def* v, size_t pos) const {
227 if (auto us = fe::lookup(uses_[b], v))
228 if (auto i = std::ranges::lower_bound(*us, pos); i != us->end()) return *i - pos;
229 if (auto d = fe::lookup(nu_out_[b], v)) return add(size(b) + 1 - pos, *d);
230 return Inf;
231}
232
233void Spiller::limit(size_t b, DefSet& w, size_t m, size_t pos) const {
234 while (w.size() > m) {
235 auto victim
236 = *std::ranges::max_element(w, {}, [&](const Def* v) { return std::pair(next_use(b, v, pos), v->gid()); });
237 w.erase(victim);
238 }
239}
240
241void Spiller::reload(size_t b, size_t pos, const Def* v) {
242 auto& rs = reloads_[b][pos];
243 if (std::ranges::contains(rs, v)) return;
244 rs.emplace_back(v);
245 if (!mphi_.contains(v) && !is_remat(v)) spill_.emplace(v);
246}
247
248void Spiller::entry(size_t b) {
249 auto lam = block(b).lam;
250 auto n = lam->num_vars();
251
252 auto params = DefVec();
253 for (size_t i = 0; i != n; ++i)
254 if (auto x = lam->var(n, i); member(x)) params.emplace_back(x);
255 auto next = [&](const Def* v) { return next_use(b, v, 0); };
256
257 auto take = DefVec();
258 auto by_use
259 = [&](DefVec& vs) { std::ranges::sort(vs, {}, [&](const Def* v) { return std::pair(next(v), v->gid()); }); };
260 auto fill = [&](DefVec vs, size_t cap) {
261 by_use(vs);
262 for (auto v : vs)
263 if (take.size() < cap && next(v) != Inf && !std::ranges::contains(take, v)) take.emplace_back(v);
264 };
265
266 auto vars = lam->vars();
267 auto cands = DefVec();
268 for (auto v : block(b).live_in)
269 if (member(v)) cands.emplace_back(v);
270
271 // These parameters cannot become memory φs; a dead one needs no register at all.
272 auto fixed = b == 0 || ret_cont_[b];
273 if (fixed) take = params;
274 if (take.size() > k_)
275 lam->blame("{} backend: `{}` takes more than {} register arguments", target_.name(), lam, k_).bail();
276 std::erase_if(params, [&](const Def* x) { return std::ranges::contains(take, x) || next(x) == Inf; });
277 std::ranges::copy(params, std::back_inserter(cands));
278
279 if (!block(b).live_in.empty()) {
280 // Only a block nested in the one block that jumps to it has live-in values.
281 auto p = block(b).parent;
282 assert(std::ranges::contains(block(p).targets, b));
283 auto avail = DefVec();
284 for (auto v : cands) {
285 auto i = size_t(std::ranges::find(vars, v) - vars.begin());
286 auto a = i < n ? arg(p, b, i) : v;
287 if (!a || Lit::isa(a) || w_exit_[p].contains(a)) avail.emplace_back(v);
288 }
289 fill(avail, k_);
290 } else if (!node(b)->is_recursive()) {
291 // All forward jumps to a join come before it, so they have counted what they pass in registers.
292 auto all = DefVec(), some = DefVec();
293 for (auto v : cands)
294 if (auto c = fe::lookup(in_regs_[b], v)) (*c == jumps_[b] ? all : some).emplace_back(v);
295 fill(all, k_);
296 fill(some, k_);
297 } else {
298 auto in_loop = DefVec(), through = DefVec();
299 for (auto v : cands)
300 (next(v) < Loop_Exit ? in_loop : through).emplace_back(v);
301 fill(in_loop, k_);
302 auto pressure = size_t(0);
303 for (size_t x = 0; x != n_; ++x)
304 if (node(x)->in_loop(node(b))) pressure = std::max(pressure, block(x).max_live[cls_]);
305 auto busy = pressure > through.size() ? pressure - through.size() : 0;
306 fill(through, std::min(k_, take.size() + (k_ > busy ? k_ - busy : 0)));
307 }
308
309 for (auto x : params)
310 if (!std::ranges::contains(take, x)) mphi_.emplace(x);
311 w_entry_[b] = DefSet(take.begin(), take.end());
312}
313
314void Spiller::walk(size_t b) {
315 entry(b);
316 auto w = w_entry_[b];
317 auto n = size(b);
318
319 auto use = [&](const DefVec& us, size_t pos, size_t more, const Def* at) {
320 if (us.size() + more > k_)
321 at->blame("{} backend: `{}` needs more than {} registers", target_.name(), at, k_).bail();
322 for (auto v : us)
323 if (w.emplace(v).second) reload(b, pos, v);
324 limit(b, w, k_ - more, pos);
325 };
326
327 for (size_t i = 0; i != n; ++i) {
328 auto insn = block(b).insns[i];
329 auto us = members(live_.uses(insn));
330 auto c = target_.constraint(insn);
331 // Fixed operands, results, and clobbers of an instruction are general-purpose registers.
332 if (cls_ != Liveness::Gpr) c.fixed.clear(), c.clobbers.clear();
333 if (c.tied && !member(c.ops[*c.tied])) c.tied.reset();
334 auto live = [&](const Def* v) { return next_use(b, v, i + 1) != Inf; };
335 auto cp = DefVec();
336 for (auto [j, _] : copies(c, live))
337 if (live(c.ops[j])) cp.emplace_back(c.ops[j]);
338 // If the copies of live operands do not fit, these operands leave their registers at the instruction instead.
339 auto evict = us.size() + c.clobbers.size() + cp.size() > k_;
340 use(us, i, c.clobbers.size() + (evict ? 0 : cp.size()), insn);
341 if (evict)
342 for (auto v : cp)
343 w.erase(v);
344 auto ds = members(live_.defs(insn));
345 if (target_.is_sched_cc(insn)) std::erase_if(ds, [&](const Def* d) { return !live(d); });
346 if (ds.size() > k_)
347 insn->blame("{} backend: `{}` defines more than {} registers", target_.name(), insn, k_).bail();
348 limit(b, w, k_ - ds.size(), i + 1);
349 w.insert(ds.begin(), ds.end());
350 }
351
352 auto t = kind(b);
353 if (t != Term::Jump) use(members(live_.term_uses(block(b))), n, 0, term(b));
354 if (t == Term::Call) limit(b, w, survivors(b), n + 1);
355 w_exit_[b] = std::move(w);
356 if (t == Term::Jump) {
357 auto s = target(b);
358 ++jumps_[s];
359 for_each_param(b, [&](const Def* x, const Def* a) {
360 if (member(x) && (Lit::isa(a) || w_exit_[b].contains(a))) ++in_regs_[s][x];
361 });
362 }
363}
364
365// A block with a single predecessor starts with a subset of what is in a register at its end, so only a jump couples.
366void Spiller::couple() {
367 for (size_t p = 0; p != n_; ++p) {
368 if (kind(p) != Term::Jump) continue;
369 for_each_param(p, [&, b = target(p)](const Def* x, const Def* a) {
370 if (!member(x) || Lit::isa(a)) return;
371 if (mphi_.contains(x)) {
372 if (!mphi_.contains(a)) spill_.emplace(a);
373 } else if (w_entry_[b].contains(x) && next_use(b, x, 0) != Inf && !w_exit_[p].contains(a)) {
374 reload(p, size(p), a);
375 }
376 });
377 }
378}
379
380const Def* Spiller::sched(const Def* f, const Def* x) {
381 auto res = world_.call<mach::sched>(f, m_, x);
382 m_ = res->proj(2, 0);
383 return res->proj(2, 1);
384}
385
386const Def* Spiller::spill(const Def* x) { return sched(Target::spill(x->type()), x); }
387
388void Spiller::build() {
389 exit_.resize(n_);
390 for (size_t b = 1; b != n_; ++b) {
391 auto lam = block(b).lam;
392 auto n = lam->num_vars();
393 auto mems = std::ranges::count_if(lam->vars(), [&](const Def* x) { return mphi_.contains(x); });
394 if (mems == 0) continue;
395 if (ret_cont_[b])
396 lam->blame("{} backend: return continuation `{}` would need new parameters", target_.name(), lam).bail();
397
398 auto dom = DefVec();
399 for (size_t i = 0; i != n; ++i) {
400 auto x = lam->var(n, i);
401 dom.emplace_back(mphi_.contains(x) ? Target::spill_type(x->type()) : x->type());
402 }
403 auto new_lam = world_.mut_con(dom);
404 new_lam->set(lam->dbg());
405 for (size_t i = 0; i != n; ++i)
406 new_lam->var(n, i)->set(lam->var(n, i)->sym());
407 new_lams_[lam] = new_lam;
408 }
409
410 for (size_t b = 0; b != n_; ++b)
411 build(b);
412}
413
414DefVec Spiller::args(size_t b, const Def2Def& cur) {
415 auto res = DefVec();
416 for_each_param(b, [&, s = target(b)](const Def* x, const Def* a) {
417 if (!mphi_.contains(x)) {
418 // A parameter neither in a register nor in memory is dead and may receive anything.
419 auto dead = member(a) && !Lit::isa(a) && (!cur.contains(a) || !w_entry_[s].contains(x));
420 res.emplace_back(dead ? world_.lit(x->type(), 0) : subst(cur).rewrite(a));
421 } else if (Lit::isa(a)) {
422 res.emplace_back(spill(a));
423 } else {
424 res.emplace_back(slot(a));
425 }
426 });
427 // m_ may have moved on through the spills of literals.
428 for (auto& a : res)
429 if (target_.is_mem(a)) a = m_;
430 return res;
431}
432
433void Spiller::build(size_t b) {
434 auto old = block(b).lam;
435 auto new_lam = fe::lookup(new_lams_, old);
436 if (!new_lam) new_lam = old;
437 auto n = old->num_vars();
438 auto m = new_lam->num_vars();
439 auto cur = Def2Def();
440 m_ = nullptr;
441
442 for (size_t i = 0; i != n; ++i) {
443 auto x = old->var(n, i);
444 auto y = new_lam->var(m, i);
445 if (target_.is_mem(x) && !m_) m_ = y;
446 if (mphi_.contains(x))
447 stack_[x] = y;
448 else
449 cur[x] = y;
450 }
451 // Only a block nested in the one block that jumps to it has live-in values, which come from the end of that block.
452 if (const auto& in = block(b).live_in; !in.empty()) {
453 const auto& from = exit_[block(b).parent];
454 for (auto v : in)
455 if (auto nv = fe::lookup(from, v)) cur[v] = nv;
456 }
457 for (auto x : old->vars())
458 if (spill_.contains(x)) stack_[x] = spill(cur[x]);
459
460 auto reloads = [&](size_t pos) {
461 for (auto v : reloads_[b][pos]) {
462 auto app = root(v);
463 cur[v] = is_remat(v) ? reroot(v, app->proj(2, 1), sched(Target::sched_insn(app), app->arg()))
464 : sched(Target::reload(v->type()), slot(v));
465 }
466 };
467
468 for (size_t i = 0, e = size(b); i != e; ++i) {
469 reloads(i);
470 auto insn = block(b).insns[i];
471 auto new_app = subst(cur).Rewriter::rewrite(insn);
472 m_ = target_.is_mem(new_app) ? new_app : new_app->proj(2, 0);
473 cur[insn] = new_app;
474 for (auto d : live_.defs(insn)) {
475 cur[d] = reroot(d, insn, new_app);
476 if (spill_.contains(d)) stack_[d] = spill(cur[d]);
477 }
478 }
479 reloads(size(b));
480
481 auto t = term(b);
482 auto kd = kind(b);
483 auto body = static_cast<const Def*>(nullptr);
484 if (kd == Term::Jump)
485 body = world_.app(subst(cur).rewrite(t->callee()), world_.tuple(args(b, cur)));
486 else
487 body = subst(cur).rewrite_jump(t);
488
489 auto filter = old->filter();
490 if (new_lam == old)
491 old->unset()->set(subst(cur).rewrite(filter), body);
492 else
493 new_lam->set(filter->is_closed() ? filter : world_.lit_ff(), body);
494 exit_[b] = std::move(cur);
495}
496
497} // namespace
498
499std::optional<size_t> arg_k(Driver& driver, const Target& target) {
500 auto k = driver.arg_nat(target.name(), "k");
501 if (!k) return {};
502 if (*k != 0) return size_t(*k);
503 driver.log().w("ignoring `-X {}:k=0`", target.name());
504 return {};
505}
506
507void spill_fun(const FunPhase& phase, Lam* fun, const LamMap<Conv>& convs, std::optional<size_t> k) {
508 const auto& t = phase.target();
509 for (auto cls : {Liveness::Gpr, Liveness::Fpr})
510 if (t.num_regs(cls) != 0) Spiller(phase, fun, convs, cls, k.value_or(t.num_allocatable(cls))).run();
511}
512
513void Spilling::visit(Lam* fun) { spill_fun(*this, fun, {}, k_); }
514
515} // namespace mim::plug::mach
static auto isa(const Def *def)
Definition axm.h:112
const Def * proj(nat_t a, nat_t i) const
Similar to World::extract while assuming an arity of a, but also works on Sigmas and Arrays.
Definition def.cpp:659
Def * set(size_t i, const Def *)
Successively set from left to right.
Definition def.cpp:188
const Def * var(nat_t a, nat_t i) noexcept
Definition def.h:488
Def * unset()
Unsets all Def::ops; works even, if not set at all or only partially set.
Definition def.cpp:205
Some "global" variables needed all over the place.
Definition driver.h:65
fe::Log & log()
Definition driver.h:80
std::optional< nat_t > arg_nat(std::string_view plugin, std::string_view key)
The number passed as -X <plugin>:<key>=<n>, if any; warns about and ignores a non-number.
Definition driver.cpp:224
A function.
Definition lam.h:91
Lam * set(Filter filter, const Def *body)
Definition lam.cpp:34
static Lam * isa_mut_basicblock(const Def *d)
Definition lam.h:130
const Def * ret_var()
Yields the Lam::var of the Lam::ret_pi.
Definition lam.h:136
std::string_view name() const
The plugin name, used as the prefix of diagnostics.
Definition target.h:18
const Lit * lit(const Def *type, u64 val)
Definition world.cpp:970
const Def * call(const Def *callee, auto &&arg, Args &&... args)
Definition world.h:693
const Def * app(const Def *callee, const Def *arg)
Definition world.cpp:416
const Def * tuple(Defs ops)
Definition world.cpp:546
const Lit * lit_ff()
Definition world.h:614
Lam * mut_con(const Def *dom)
Definition world.h:427
Visits the closed Cns with a body of a scheduled World for one Target, each before the ones that call...
Definition phase.h:55
const Target & target() const
Definition phase.h:61
const Block * block(Lam *lam) const
Definition liveness.h:64
const DefVec & uses(const App *insn) const
Definition liveness.h:74
Target::Class Class
Definition liveness.h:37
const DefVec & term_uses(const Block &block) const
The values the jump at the end reads.
Definition liveness.h:76
const DefVec & defs(const App *insn) const
Definition liveness.h:73
void visit(Lam *) final
Definition spilling.cpp:513
Subst(const Target &target, World &world, const Def2Def &map, const Def *m, const LamMap< Lam * > *lams=nullptr)
Definition subst.h:21
The machine facts of a native backend that the phases of mach need.
Definition target.h:45
static bool is_mem(const Def *def)
Definition target.h:205
virtual Constraint constraint(const App *insn) const
The register constraint of insn; by default, it has none.
Definition target.h:128
static const Def * sched_insn(const App *app)
Definition target.h:204
virtual bool is_sched_cc(const App *app) const =0
Is app the sched of the backend's cc?
The mach Plugin
Definition asm.h:15
bool clobbered(const Target &target, const Conv *conv, Target::Class cls, size_t r)
Does a call of a function with the convention conv, or of an ABI function if there is none,...
Definition liveness.h:173
std::optional< size_t > arg_k(Driver &, const Target &)
The k of spill_fun(): -X <backend>:k=<n>, if given.
Definition spilling.cpp:499
bool is_value(const Def *value, Liveness::Class cls, const Target &target)
Is value a value of class cls?
Definition liveness.h:98
const Liveness::Block * call_cont(const Liveness &live, Lam *fun, const Liveness::Block &block)
The block that a call at the end of block returns to, if any.
Definition liveness.h:178
fe::Vector< std::pair< size_t, std::optional< size_t > > > copies(const Constraint &c, auto live_after)
The fixed operands with their registers, and the tied one with no register if it is live_after.
Definition target.h:27
fe::Vector< const Nest::Node * > sorted(const Nest::Node::SCC &scc)
The Nodes of scc in a deterministic order.
Definition phase.h:24
void spill_fun(const FunPhase &, Lam *fun, const LamMap< Conv > &convs, std::optional< size_t > k)
Spills and reloads until at most k values of each register class are live at every point of a schedul...
Definition spilling.cpp:507
const Conv * callee_conv(const LamMap< Conv > &convs, const Liveness::Block &block)
The Conv of the callee that the call at the end of block returns from, if it has one.
Definition liveness.h:167
DefMap< const Def * > Def2Def
Definition def.h:93
ankerl::unordered_dense::map< K, V, GIDHash< K > > GIDMap
Definition gid.h:22
GIDMap< Lam *, To > LamMap
Definition lam.h:210
fe::Vector< const Def * > DefVec
Definition def.h:96
GIDSet< const Def * > DefSet
Definition def.h:92
@ Lam
Definition def.h:123
@ Extract
Definition def.h:123
@ App
Definition def.h:123