MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
color.cpp
Go to the documentation of this file.
1#include <print>
2#include <ranges>
3
4#include <pbqp/dot.h>
5#include <pbqp/solver.h>
6
7#include <mim/rewrite.h>
8
11
12namespace mim::plug::mach {
13
14namespace {
15
16constexpr pbqp::Cost Move = 4;
17// A callee-saved register costs a save and a restore once per function, not per value.
18constexpr pbqp::Cost Callee_Saved = 1;
19
20class Prune : public Rewriter {
21public:
22 Prune(const Target& target, World& world, const DefSet& dead)
23 : Rewriter(world)
24 , target_(target)
25 , dead_(dead) {}
26
27 const Def* rewrite(const Def* def) final {
28 if (def->isa_mut() || def->is_closed()) return def;
29 if (auto ex = def->isa<Extract>(); ex && target_.is_mem(def))
30 if (auto app = ex->tuple()->isa<App>(); app && dead_.contains(app)) return rewrite(target_.prev_mem(app));
31 return Rewriter::rewrite(def);
32 }
33
34private:
35 const Target& target_;
36 const DefSet& dead_;
37};
38
39/// Removes dead instructions; returns whether there were any, which makes @p live stale.
40bool prune(const Target& target, Lam* fun, const Liveness& live) {
41 // Rewriting a jump in place must not inline its target, e.g., once pruning made both targets of a branch equal.
42 for (const auto& block : live.blocks()) {
43 if (auto lam = block.lam; lam->filter() != fun->world().lit_ff()) {
44 auto body = lam->body();
45 lam->unset()->set(false, body);
46 }
47 }
48
49 auto count = DefMap<size_t>();
50 for_each_use(live, [&](const Def* u) { ++count[u]; });
51
52 auto unused = [&](const Def* d) {
53 auto n = fe::lookup(count, d);
54 return !n || *n == 0;
55 };
56 auto dead = DefSet();
57 for (bool todo = true; todo;) {
58 todo = false;
59 for (const auto& block : live.blocks()) {
60 auto ex = block.lam->body()->as<App>()->callee()->isa<Extract>();
61 auto cond = ex ? target.isa_sched_cc(ex->index()) : nullptr;
62 for (auto insn : block.insns | std::views::reverse) {
63 if (dead.contains(insn) || insn == cond || !target.is_removable(insn)) continue;
64 auto ds = live.defs(insn);
65 if (ds.empty() || !std::ranges::all_of(ds, unused)) continue;
66 dead.emplace(insn);
67 todo = true;
68 for (auto u : live.uses(insn))
69 --count[u];
70 }
71 }
72 }
73 if (dead.empty()) return false;
74
75 auto p = Prune(target, fun->world(), dead);
77 return true;
78}
79
80class Colorer {
81public:
82 Colorer(const Target& target,
83 Lam* fun,
84 const Liveness& live,
85 const LamMap<Conv>& convs,
86 bool known,
88 std::ostream* dot = nullptr)
89 : target_(target)
90 , fun_(fun)
91 , live_(live)
92 , convs_(convs)
93 , known_(known)
94 , cls_(cls)
95 , dot_(dot)
96 , n_(target.num_regs(cls))
97 , interfere_(n_, n_, [](size_t i, size_t j) { return i == j ? pbqp::Cost::inf() : 0; })
98 , tie_(n_, n_, [](size_t i, size_t j) { return i == j ? 0 : pbqp::Cost::inf(); })
99 , move_(n_, n_, [](size_t i, size_t j) { return i == j ? 0 : Move; })
100 , base_(n_, [&](size_t r) {
101 if (target.reserved(cls, r)) return pbqp::Cost::inf();
102 return target.caller_saved(cls, r) ? pbqp::Cost(0) : Callee_Saved;
103 }) {}
104
105 void run() {
106 nodes();
107 for (const auto& block : live_.blocks())
109 live_, block, [&](const Def* v) { return ids_.contains(v); },
110 [&](const Def* a, const Def* b) { link(a, b, interfere_); });
111 constraints();
112 copies();
113 solve();
114 }
115
116 const DefMap<size_t>& regs() const { return regs_; }
117
118private:
119 void nodes();
120 void constraints();
121 void copies();
122 void solve();
123
124 bool is_value(const Def* v) const { return mach::is_value(v, cls_, target_); }
125 void add(const Def* v);
126 pbqp::Costs* costs(const Def* v) {
127 auto id = fe::lookup(ids_, target_.strip(v));
128 return id ? &costs_[*id] : nullptr;
129 }
130 void fix(const Def* v, size_t r) {
131 if (auto cs = costs(v))
132 for (size_t o = 0; o != n_; ++o)
133 if (o != r) (*cs)[o] = pbqp::Cost::inf();
134 }
135 void forbid(const Def* v, size_t r) {
136 if (auto cs = costs(v)) (*cs)[r] = pbqp::Cost::inf();
137 }
138 void prefer(const Def* v, size_t r) {
139 if (auto cs = costs(v))
140 for (size_t o = 0; o != n_; ++o)
141 if (o != r) (*cs)[o] += Move;
142 }
143 void link(const Def* a, const Def* b, pbqp::MatrixView m) {
144 a = target_.strip(a), b = target_.strip(b);
145 if (a == b) return;
146 if (auto i = fe::lookup(ids_, a))
147 if (auto j = fe::lookup(ids_, b)) graph_.add_edge_costs(*i, *j, m);
148 }
149 void jump(Lam* target, const Def* arg) {
150 auto n = target->num_vars();
151 for (size_t i = 0; i != n; ++i)
152 link(arg->proj(n, i), target->var(n, i), move_);
153 }
154
155 const Target& target_;
156 Lam* fun_;
157 const Liveness& live_;
158 const LamMap<Conv>& convs_;
159 bool known_;
160 Liveness::Class cls_;
161 std::ostream* dot_;
162 size_t n_;
163 pbqp::Graph graph_;
165 DefVec values_;
166 fe::Vector<pbqp::Costs> costs_;
167 fe::Vector<size_t> points_; ///< Where each value is defined; a block's parameters share one.
168 size_t num_points_ = 0;
169 const pbqp::Matrix interfere_, tie_, move_;
170 const pbqp::Costs base_;
171 DefMap<size_t> regs_;
172};
173
174void Colorer::add(const Def* v) {
175 ids_[v] = graph_.add(base_);
176 values_.emplace_back(v);
177 costs_.emplace_back(base_);
178 points_.emplace_back(num_points_);
179}
180
181/// Values are added in an order that respects dominance, which is the reverse of a PEO.
182void Colorer::nodes() {
183 auto used = DefSet();
184 for_each_use(live_, [&](const Def* u) { used.emplace(u); });
185
186 for (const auto& block : live_.blocks()) {
187 ++num_points_;
188 for (auto x : live_.params(block))
189 if (is_value(x) && used.contains(x)) add(x);
190 for (auto insn : block.insns) {
191 ++num_points_;
192 auto implied = DefSet();
193 for (auto [j, _] : target_.constraint(insn).results)
194 implied.emplace(Target::result(insn, j));
195 for (auto d : live_.defs(insn))
196 if (is_value(d) && (used.contains(d) || implied.contains(d))) add(d);
197 }
198 }
199}
200
201void Colorer::constraints() {
202 for (const auto& block : live_.blocks()) {
203 for (auto insn : block.insns) {
204 auto c = target_.constraint(insn);
205 // Fixed operands, results, and clobbers of an instruction are general-purpose registers.
206 if (cls_ == Liveness::Gpr) {
207 for (auto [j, r] : c.fixed)
208 fix(c.ops[j], r);
209 for (auto [j, r] : c.results)
210 fix(Target::result(insn, j), r);
211 for (auto r : c.clobbers)
212 for (auto u : live_.uses(insn))
213 forbid(u, r);
214 }
215 if (c.tied && is_value(c.ops[*c.tied])) link(c.ops[*c.tied], Target::result(insn, 0), tie_);
216 }
217 }
218}
219
220void Colorer::copies() {
221 auto args = [&](const Def* arg, size_t n, size_t num, const Conv* conv) {
222 auto locs = arg_locs(target_, arg, n, num, conv ? &conv->params : nullptr);
223 for (size_t i = 0; i != num; ++i)
224 if (auto x = arg->proj(n, i); is_value(x) && locs[i].reg) prefer(x, *locs[i].reg);
225 };
226 if (!known_) args(fun_->var(), fun_->num_vars(), num_params(fun_), nullptr);
227
228 for (const auto& block : live_.blocks()) {
229 auto term = block.lam->body()->as<App>();
230 auto callee = term->callee();
231 if (callee == fun_->ret_var()) {
232 for (auto a : term->args())
233 if (is_value(a)) prefer(a, target_.ret_reg(cls_));
234 } else if (auto bb = Lam::isa_mut_basicblock(callee); bb && live_.block(bb)) {
235 jump(bb, term->arg());
236 } else if (auto bb = Lam::isa_mut_basicblock(callee)) {
237 args(term->arg(), term->num_args(), term->num_args(), fe::lookup(convs_, bb));
238 } else if (auto f = Lam::isa_mut_returning(callee)) {
239 auto conv = fe::lookup(convs_, f);
240 args(term->arg(), term->num_args(), term->num_args() - 1, conv);
241 if (auto k = call_cont(live_, fun_, block)) {
242 for (auto v : k->live_in)
243 if (auto cs = costs(v))
244 for (size_t r = 0; r != n_; ++r)
245 if (clobbered(target_, conv, cls_, r)) (*cs)[r] = pbqp::Cost::inf();
246 for (auto x : live_.params(*k))
247 if (is_value(x)) prefer(x, target_.ret_reg(cls_));
248 }
249 }
250 }
251}
252
253void Colorer::solve() {
254 for (size_t i = 0; i != values_.size(); ++i)
255 graph_.set_node_costs(i, costs_[i]);
256
257 // RN decides an earlier definition first, as the PEO demands, and the most constrained of a point first.
258 auto order = fe::Vector<size_t>(values_.size(), [](size_t i) { return i; });
259 auto fixed = fe::Vector<std::ptrdiff_t>(values_.size(),
260 [&](size_t i) { return std::ranges::count(costs_[i], pbqp::Cost::inf()); });
261 std::ranges::sort(order, {}, [&](size_t i) { return std::tuple(points_[i], -fixed[i], i); });
262 auto priority = fe::Vector<size_t>(values_.size());
263 for (size_t r = 0; r != order.size(); ++r)
264 priority[order[r]] = order.size() - 1 - r;
265 auto sol = pbqp::solve(graph_, priority);
266 if (dot_) {
267 std::println(*dot_, "// fun {}", fun_);
268 for (size_t i = 0; i != values_.size(); ++i)
269 std::println(*dot_, "// n{} = {}", i, values_[i]);
270 pbqp::write_dot(*dot_, graph_, sol.choices);
271 }
272 if (!sol.feasible()) {
273 auto conflicts = DefVec();
274 for (size_t i = 0; i != values_.size(); ++i)
275 if (sol.conflicts[i]) conflicts.emplace_back(values_[i]);
276 fun_->blame("{} backend: cannot assign registers in `{}`; conflicting values: {}", target_.name(), fun_,
277 fe::Join(conflicts, ", "))
278 .bail();
279 }
280 for (size_t i = 0; i != values_.size(); ++i)
281 regs_[values_[i]] = sol.choices[i];
282}
283
284/// Checks the invariants of an assignment over a Liveness of @p fun after Assign.
285class Checker {
286public:
287 Checker(const Target& target, Lam* fun, const Liveness& live, const LamMap<Conv>& convs, Liveness::Class cls)
288 : target_(target)
289 , fun_(fun)
290 , live_(live)
291 , convs_(convs)
292 , cls_(cls) {}
293
294 void run();
295
296private:
297 bool is_value(const Def* v) const { return mach::is_value(v, cls_, target_); }
298 void walk(const Def* def, const Def* at);
299 std::optional<size_t> reg(const Def* v) const {
300 if (auto r = fe::lookup(regs_, target_.strip(v))) return *r;
301 return std::nullopt;
302 }
303 [[noreturn]] void fail(const Def* at, std::string msg) {
304 at->blame("{} backend: register assignment of `{}`: {}", target_.name(), fun_, msg).bail();
305 }
306
307 const Target& target_;
308 Lam* fun_;
309 const Liveness& live_;
310 const LamMap<Conv>& convs_;
311 Liveness::Class cls_;
312 DefMap<size_t> regs_;
313};
314
315void Checker::walk(const Def* def, const Def* at) {
316 if (def->isa_mut() || def->is_closed() || target_.is_mem(def)) return;
317 if (target_.is_in(def)) {
318 auto v = target_.strip(def);
319 if (target_.cls(v) != cls_) return;
320 auto r = Target::in_reg(def);
321 auto [i, ins] = regs_.emplace(v, r);
322 if (!live_.local(v) || !is_value(v)) fail(at, std::format("`{}` is no value", v));
323 if (target_.reserved(cls_, r)) fail(at, std::format("`{}` is in a reserved register", v));
324 if (!ins && i->second != r) fail(at, std::format("`{}` is in two registers", v));
325 return;
326 }
327 if (live_.local(def)) {
328 for (auto d : def->projs())
329 if (is_value(d)) fail(at, std::format("`{}` is used without a register", d));
330 return;
331 }
332 if (auto app = def->isa<App>(); app && target_.prev_mem(app)) fail(at, std::format("`{}` is off the chain", app));
333 for (auto op : def->ops())
334 walk(op, at);
335}
336
337void Checker::run() {
338 for (const auto& block : live_.blocks()) {
339 for (auto insn : block.insns) {
340 walk(insn->callee(), insn);
341 walk(insn->arg(), insn);
342 }
343 auto term = block.lam->body()->as<App>();
344 if (auto ex = term->callee()->isa<Extract>(); ex && target_.isa_sched_cc(ex->index())) {
345 walk(ex->tuple(), term);
346 walk(term->arg(), term);
347 } else {
348 walk(term, term);
349 }
350 }
351
352 for (const auto& block : live_.blocks()) {
353 for (auto insn : block.insns) {
354 auto c = target_.constraint(insn);
355 if (cls_ == Liveness::Gpr) {
356 for (auto [j, r] : c.results) {
357 auto d = Target::result(insn, j);
358 if (regs_.emplace(d, r).first->second != r)
359 fail(insn, std::format("`{}` is not in its fixed register", d));
360 }
361 for (auto [j, r] : c.fixed)
362 if (!target_.is_in(c.ops[j]) || Target::in_reg(c.ops[j]) != r)
363 fail(insn, std::format("operand `{}` is not in its fixed register", c.ops[j]));
364 for (auto r : c.clobbers)
365 for (auto u : live_.uses(insn))
366 if (reg(u) == r) fail(insn, std::format("operand `{}` is in a clobbered register", u));
367 }
368 if (c.tied && is_value(c.ops[*c.tied]) && reg(c.ops[*c.tied]) != reg(Target::result(insn, 0)))
369 fail(insn, std::format("`{}` is not in the register of operand `{}`", Target::result(insn, 0),
370 c.ops[*c.tied]));
371 }
372 }
373
374 for (const auto& block : live_.blocks()) {
376 live_, block, [&](const Def* v) { return regs_.contains(v); },
377 [&](const Def* a, const Def* b) {
378 if (regs_[a] == regs_[b])
379 fail(block.lam, std::format("`{}` and `{}` interfere but share a register", a, b));
380 });
381 if (auto k = call_cont(live_, fun_, block))
382 for (auto v : k->live_in)
383 if (auto r = reg(v); r && clobbered(target_, callee_conv(convs_, block), cls_, *r))
384 fail(block.lam, std::format("`{}` lives across a call in a clobbered register", v));
385 }
386}
387
388Conv convention(const Target& target,
389 Lam* fun,
390 const Liveness& live,
391 const LamMap<Conv>& convs,
392 const DefMap<size_t>& regs) {
393 auto res = Conv{.params = param_regs(target, fun, regs)};
394 auto& cl = res.clobbers;
395 auto classes = {Liveness::Gpr, Liveness::Fpr};
396 for (auto cls : classes) {
397 cl[cls].resize(target.num_regs(cls));
398 if (!cl[cls].empty()) cl[cls][target.ret_reg(cls)] = true;
399 }
400 for (auto [v, r] : regs)
401 if (auto cls = target.cls(v); target.caller_saved(cls, r)) cl[cls][r] = true;
402 for (size_t i = 0, n = fun->num_vars(); i != res.params.size(); ++i)
403 if (auto r = res.params[i]) cl[target.cls(fun->var(n, i))][*r] = true;
404
405 for (const auto& block : live.blocks()) {
406 for (auto insn : block.insns) {
407 auto c = target.constraint(insn);
408 for (auto [_, r] : c.results)
409 cl[Liveness::Gpr][r] = true;
410 for (auto r : c.clobbers)
411 cl[Liveness::Gpr][r] = true;
412 }
413 if (Lam::isa_mut_returning(block.lam->body()->as<App>()->callee())) {
414 auto conv = callee_conv(convs, block);
415 for (auto cls : classes)
416 for (size_t r = 0; r != cl[cls].size(); ++r)
417 if (clobbered(target, conv, cls, r)) cl[cls][r] = true;
418 }
419 }
420 return res;
421}
422
423} // namespace
424
425void color_fun(const FunPhase& phase, Lam* fun, Liveness live, LamMap<Conv>& convs, std::ostream* dot) {
426 const auto& t = phase.target();
427 auto known = phase.known().contains(fun);
428 if (prune(t, fun, live)) live = Liveness(phase, fun);
429 auto regs = DefMap<size_t>();
430 for (auto cls : {Liveness::Gpr, Liveness::Fpr}) {
431 if (t.num_regs(cls) == 0) continue;
432 auto colorer = Colorer(t, fun, live, convs, known, cls, dot);
433 colorer.run();
434 regs.insert(colorer.regs().begin(), colorer.regs().end());
435 }
436 auto assign = Assign(fun->world(), live, regs);
437 rewrite_blocks(live, assign);
438
439 live = Liveness(phase, fun);
440 for (auto cls : {Liveness::Gpr, Liveness::Fpr})
441 if (t.num_regs(cls) != 0) Checker(t, fun, live, convs, cls).run();
442 if (known) convs[fun] = convention(t, fun, live, convs, regs);
443}
444
446 spill_fun(*this, fun, convs_, k_);
447 auto live = Liveness(*this, fun);
448 if (constrain_fun(live)) live = Liveness(*this, fun);
449 color_fun(*this, fun, std::move(live), convs_, dot());
450}
451
452std::ostream* RegAlloc::dot() {
453 if (auto d = arg_value(target_args(), "color-dot")) {
454 if (dot_.name().empty()) dot_.name() = std::string(*d);
455 return dot_.os();
456 }
457 return nullptr;
458}
459
460} // namespace mim::plug::mach
World & world() const noexcept
Definition def.h:1102
const Def * var(nat_t a, nat_t i) noexcept
Definition def.h:488
nat_t num_vars() noexcept
Definition def.h:488
fe::Error & blame(fe::cite_string< Args... > s, Args &&... args) const
Reports an error that blames this; chain Error::n for Notes and Error::bail to throw.
Definition def.h:329
A function.
Definition lam.h:91
static Lam * isa_mut_returning(const Def *d)
Definition lam.h:129
const Def * ret_var()
Yields the Lam::var of the Lam::ret_pi.
Definition lam.h:136
virtual const Def * rewrite(const Def *)
Definition rewrite.cpp:62
std::string_view name() const
The plugin name, used as the prefix of diagnostics.
Definition target.h:18
Assign(World &world, const Liveness &live, const DefMap< size_t > &regs)
Definition liveness.h:129
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 LamSet & known() const
The functions with a convention of their own, see mach::known.
Definition phase.h:65
const Target & target() const
Definition phase.h:61
Liveness of the values of one scheduled function, as a side table.
Definition liveness.h:35
const auto & blocks() const
In pre-order of the Nest with siblings in topological order, so a block comes after the block it is n...
Definition liveness.h:63
const Block * block(Lam *lam) const
Definition liveness.h:64
const DefVec & uses(const App *insn) const
Definition liveness.h:74
const DefVec & params(const Block &block) const
Definition liveness.h:72
Target::Class Class
Definition liveness.h:37
bool local(const Def *def) const
Is def a parameter of a block or a result of an instruction on a chain, or a projection thereof?
Definition liveness.cpp:91
Liveness(const FunPhase &phase, Lam *fun, bool solve=false)
Bails unless the blocks of the function fun are closed; with solve, it iterates to the fixed point in...
Definition liveness.cpp:11
const DefVec & defs(const App *insn) const
Definition liveness.h:73
void visit(Lam *) final
Definition color.cpp:445
The machine facts of a native backend that the phases of mach need.
Definition target.h:45
static const Def * strip(const Def *def)
The v of in r v, zext d v, or zext d (in r v), otherwise def.
Definition target.h:195
static bool is_mem(const Def *def)
Definition target.h:205
const Def * prev_mem(const App *app) const
The memory app continues, if app is an instruction on a mem.M 0 chain.
Definition target.h:210
virtual Constraint constraint(const App *insn) const
The register constraint of insn; by default, it has none.
Definition target.h:128
virtual bool reserved(Class cls, size_t r) const =0
Is r never available to register allocation?
static bool is_in(const Def *def)
Definition target.h:180
Class cls(const Def *def) const
Definition target.h:105
virtual size_t ret_reg(Class cls) const =0
const App * isa_sched_cc(const Def *cond) const
The sched of a cc that yields cond, if any.
Definition target.h:225
static constexpr Cost inf()
Definition graph.h:39
void set_node_costs(NodeId n, fe::View< Cost > costs)
Replace a cost vector; the option count must not change.
Definition graph.cpp:43
NodeId add(fe::View< Cost > costs)
Add a node with the given cost vector.
Definition graph.cpp:12
The mach Plugin
Definition asm.h:15
void for_each_use(const Liveness &live, auto f)
Calls f for each use of a value in live.
Definition liveness.h:113
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
fe::Vector< std::pair< size_t, size_t > > results
Results, see Target::result, that land in a given register.
Definition target.h:20
bool is_value(const Def *value, Liveness::Class cls, const Target &target)
Is value a value of class cls?
Definition liveness.h:98
size_t num_params(Lam *lam)
The parameters of lam without its return continuation.
Definition liveness.h:145
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
void interferences(const Liveness &live, const Liveness::Block &block, Keep keep, F f)
Calls f (d, v) for each value v that is live at the definition of d or defined along with it.
Definition liveness.h:188
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
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
void rewrite_blocks(const Liveness &live, Rewriter &rw)
Rewrites the filter and body of each block of live in place.
Definition liveness.cpp:263
bool constrain_fun(const Liveness &live)
Copies fixed and live tied operands by a jump right before their instruction, keeping the graph chord...
Definition constrain.cpp:51
LamSet known(World &world)
The closed Cns with a body that get a convention of their own instead of the ABI.
Definition phase.h:33
void color_fun(const FunPhase &, Lam *fun, Liveness live, LamMap< Conv > &convs, std::ostream *dot)
Assigns a register to every value by one PBQP per function and register class (Buchwald,...
Definition color.cpp:425
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
fe::Vector< ArgLoc > arg_locs(const Target &target, const Def *arg, size_t n, size_t num, const ParamRegs *conv)
The ArgLocs of the first num of the n arguments in arg under conv, or the ABI if it is nullptr.
Definition liveness.cpp:217
ParamRegs param_regs(const Target &target, Lam *fun, const DefMap< size_t > &regs)
Where the known() function fun receives its parameters, given the registers regs that Color assigned ...
Definition liveness.cpp:234
GIDMap< const Def *, To > DefMap
Definition def.h:91
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
std::optional< std::string_view > arg_value(fe::View< std::string > args, Keys... keys)
Definition plugin.h:65
@ Lam
Definition def.h:123
@ Extract
Definition def.h:123
@ App
Definition def.h:123
BasicMatrix< const Cost > MatrixView
Definition graph.h:186
Solution solve(const Graph &graph, fe::View< size_t > rn_priority={})
Heuristic PBQP solver.
Definition solver.cpp:629
void write_dot(std::ostream &out, const Graph &graph, fe::View< OptionId > choices={})
Write graph in Graphviz DOT format with cost vectors and matrices as HTML-like labels.
Definition dot.cpp:23
fe::Bitset conflicts(const Graph &graph, fe::View< OptionId > choices)
Nodes whose choice is Cost::inf in their cost vector or, given the neighbour's choice,...
Definition solver.cpp:607
fe::Vector< Cost, 4 > Costs
Definition graph.h:66