19 fe::Vector<std::pair<size_t, size_t>>
fixed;
20 fe::Vector<std::pair<size_t, size_t>>
results;
21 std::optional<size_t>
tied;
27inline fe::Vector<std::pair<size_t, std::optional<size_t>>>
copies(
const Constraint& c,
auto live_after) {
28 auto res = fe::Vector<std::pair<size_t, std::optional<size_t>>>();
29 for (
auto [j, r] : c.fixed)
30 res.emplace_back(j, r);
31 auto copied = [&](
size_t j) {
return std::ranges::any_of(res, [j](
auto p) {
return p.first == j; }); };
32 if (c.tied && !copied(*c.tied) && live_after(c.ops[*c.tied])) res.emplace_back(*c.tied, std::nullopt);
33 if (!c.clobbers.empty())
34 for (
size_t j = 0; j != c.ops.size(); ++j)
35 if (!
Lit::isa(c.ops[j]) && !copied(j)) res.emplace_back(j, std::nullopt);
106 auto type = def->
type();
114 auto axm = app->
axm();
115 return axm && (axm->plugin() == plugin_ || axm->plugin() == Plugin_Id) && !app->
type()->isa<
Pi>()
131 for (
auto& op : res.ops)
144 return p == core::Plugin_Id || p == mem::Plugin_Id || p == math::Plugin_Id
150 return DefVec(ops.begin(), ops.end());
154 auto res = insn->
proj(2, 1);
155 return res->
proj(res->num_projs(), j);
159 auto& w = insn->
world();
163 return w.app(insn->
callee(), w.tuple(args))->as<
App>();
183 auto& w = v->
world();
197 return is_in(def) ? def->as<
App>()->arg() : def;
206 auto type = def->
type();
226 if (
auto ex = cond->isa<
Extract>())
227 if (
auto app = ex->tuple()->isa<
App>(); app &&
is_sched_cc(app))
return app;
auto args(Projector auto f) const noexcept
nat_t num_args() const noexcept
const Def * callee() const
static auto isa(const Def *def)
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.
World & world() const noexcept
constexpr flags_t flags() const noexcept
auto projs(Projector auto f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Some "global" variables needed all over the place.
const Target & target(Loc loc={})
The Target of the one loaded native backend; errors at loc if there is none or more than one.
static std::optional< T > isa(const Def *def)
A dependent function type.
The machine a native backend compiles for, as far as libmim needs to know it.
std::string_view name() const
The plugin name, used as the prefix of diagnostics.
static bool is_view(const Def *def)
Is def a zext d v, which reads v's register?
virtual size_t num_regs(Class cls) const =0
static DefVec operands(const App *insn)
The operands of insn: the argument of a sched's instruction, otherwise the arguments including the me...
static const Def * strip(const Def *def)
The v of in r v, zext d v, or zext d (in r v), otherwise def.
virtual size_t negate_cc(size_t cc) const =0
The subtag of the backend's cc that holds iff the one with subtag cc does not.
static bool is_mem(const Def *def)
const Def * prev_mem(const App *app) const
The memory app continues, if app is an instruction on a mem.M 0 chain.
virtual Constraint constraint(const App *insn) const
The register constraint of insn; by default, it has none.
static size_t in_reg(const Def *in)
The register r of in r v.
Class
The register classes; Stack values live in a spill slot and are unbounded.
virtual bool reserved(Class cls, size_t r) const =0
Is r never available to register allocation?
static const Def * spill(const Def *type)
static bool is_in(const Def *def)
Class cls(const Def *def) const
static const Def * unview(const Def *def)
The v of zext d v, otherwise def.
static const App * rebuild(const App *insn, const Def *m, const DefVec &ops)
insn continuing m with ops instead of its operands.
virtual size_t num_arg_regs(Class cls) const =0
static const Def * sched_insn(const App *app)
size_t num_caller_saved(Class cls) const
The number of those that a call may clobber.
virtual size_t ret_reg(Class cls) const =0
virtual bool is_removable(const App *insn) const
May insn go if nothing uses its results, e.g.
static const Target & of(Driver &driver)
The Target of the one loaded backend; every backend's Target is a mach::Target.
virtual bool fits_imm(const Def *) const
Does the literal lit fit a hole of type Want::Imm?
static constexpr std::string_view global_prefix()
The prefix that the object format adds to a C symbol.
virtual bool is_flags(const Def *def) const =0
virtual const App * untie(const App *, const DefSet &, const Def *) const
An equivalent of insn that needs no copy of its tied operand if the values after the instruction hold...
virtual bool caller_saved(Class cls, size_t r) const =0
static const Def * spill_type(const Def *type)
The type of the spill slot of a value of type.
virtual bool is_machine_insn(const App *app) const
Is app an instruction of this backend, other than mach.sched, that belongs on a mem....
static bool is_lowered(const Axm *axm)
Is axm an operation that instruction selection must have replaced?
Target(std::string_view name, plugin_t plugin)
plugin is the backend's plugin id.
virtual bool is_sched_cc(const App *app) const =0
Is app the sched of the backend's cc?
bool is_insn(const App *app) const
Is app an instruction that belongs on a mem.M 0 chain?
nat_t ptr_size() const override
The size and alignment of a pointer in bytes; see core.trait.
static const Def * reload(const Def *type)
The instruction that reloads a value of type from its spill slot.
static constexpr std::string_view local_prefix()
The prefix of an assembler-local label.
virtual bool is_mem_insn(const App *app) const
Is app an instruction that takes the mem.M 0 it continues as its first argument?
const App * isa_sched_cc(const Def *cond) const
The sched of a cc that yields cond, if any.
static constexpr bool is_elf()
const Def * in(Class cls, size_t r, const Def *v) const
The value v of class cls in register r.
size_t num_allocatable(Class cls) const
The number of registers of cls that register allocation may assign.
static const Def * result(const App *insn, size_t j)
The j-th projection of the non-memory result of insn.
virtual size_t arg_reg(Class cls, size_t i) const =0
The register of the i-th argument of class cls.
fe::Vector< size_t > clobbers
Registers written while the operands still occupy theirs.
fe::Vector< std::pair< size_t, size_t > > results
Results, see Target::result, that land in a given register.
fe::Vector< std::optional< size_t > > ParamRegs
The register per parameter of a function with a convention of its own, or none if it is unused.
DefVec ops
See Target::operands.
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.
fe::Vector< std::pair< size_t, size_t > > fixed
Non-literal operands that have to be in a given register.
std::optional< size_t > tied
The operand whose register the (only) result takes.
What an instruction on the chain prescribes about the registers of its operands; registers are hardwa...
std::optional< nat_t > isa_f(const Def *def)
fe::Vector< const Def * > DefVec
GIDSet< const Def * > DefSet
static constexpr flags_t Base