MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
target.h
Go to the documentation of this file.
1#pragma once
2
4
5#include "mim/plug/x86/imm.h"
6#include "mim/plug/x86/x86.h"
7
8namespace mim::plug::x86 {
9
10/// The machine facts of the x86-64 backend; the ABI is System V AMD64.
11class Target : public mach::Target {
12public:
14 : mach::Target("x86", Plugin_Id) {}
15
16 bool is_flags(const Def* def) const final { return Axm::isa<mach::Flags>(def->type()) || Axm::isa<cc>(def); }
17 bool is_sched_cc(const App* app) const final {
19 }
20 /// The hardware encoding pairs each condition code with its negation in bit 0.
21 size_t negate_cc(size_t c) const final { return c ^ 1; }
22 static_assert((Annex::flags2sub(flags_t(cc::l)) ^ 1) == Annex::flags2sub(flags_t(cc::ge)));
23
24 /// An address is no instruction.
25 bool is_machine_insn(const App* app) const final {
26 return mach::Target::is_machine_insn(app) && !Axm::isa<Addr>(app->type());
27 }
28 bool is_mem_insn(const App* app) const final;
29
30 size_t num_regs(Class cls) const final { return cls == Gpr ? Num_Regs : Num_Xmm; }
31 bool reserved(Class cls, size_t r) const final { return cls == Gpr && x86::reserved(r); }
32 /// The XMM registers are all caller-saved.
33 bool caller_saved(Class cls, size_t r) const final { return cls != Gpr || Caller_Saved[r]; }
34 /// The XMM registers are their own argument registers.
35 size_t num_arg_regs(Class cls) const final { return cls == Gpr ? Arg_Regs.size() : 8; }
36 size_t arg_reg(Class cls, size_t i) const final { return cls == Gpr ? Arg_Regs[i] : i; }
37 size_t ret_reg(Class cls) const final { return cls == Gpr ? encoding(reg::rax) : 0; }
38
39 mach::Constraint constraint(const App* insn) const final;
40 /// Swaps a commutative operation whose other operand dies and turns such a `sub` into an `rsub`.
41 /// Otherwise, it turns an `imul` by a literal into an `imul3` and an `add` into an `add3`.
42 const App* untie(const App* insn, const DefSet& after, const Def* phi) const final;
43 /// A literal that fits a sign-extended 32-bit immediate.
44 bool fits_imm(const Def* lit) const final { return x86::fits_imm(lit); }
45 bool is_removable(const App* insn) const final;
46};
47
48} // namespace mim::plug::x86
static auto isa(const Def *def)
Definition axm.h:112
Base class for all Defs.
Definition def.h:285
The machine facts of a native backend that the phases of mach need.
Definition target.h:45
Class
The register classes; Stack values live in a spill slot and are unbounded.
Definition target.h:48
Class cls(const Def *def) const
Definition target.h:105
static const Def * sched_insn(const App *app)
Definition target.h:204
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....
Definition target.h:113
bool caller_saved(Class cls, size_t r) const final
The XMM registers are all caller-saved.
Definition target.h:33
bool is_mem_insn(const App *app) const final
Is app an instruction that takes the mem.M 0 it continues as its first argument?
Definition target.cpp:7
bool is_machine_insn(const App *app) const final
An address is no instruction.
Definition target.h:25
bool fits_imm(const Def *lit) const final
A literal that fits a sign-extended 32-bit immediate.
Definition target.h:44
bool is_flags(const Def *def) const final
Definition target.h:16
size_t ret_reg(Class cls) const final
Definition target.h:37
size_t num_regs(Class cls) const final
Definition target.h:30
bool is_sched_cc(const App *app) const final
Is app the sched of the backend's cc?
Definition target.h:17
size_t arg_reg(Class cls, size_t i) const final
The register of the i-th argument of class cls.
Definition target.h:36
const App * untie(const App *insn, const DefSet &after, const Def *phi) const final
Swaps a commutative operation whose other operand dies and turns such a sub into an rsub.
Definition target.cpp:37
bool is_removable(const App *insn) const final
May insn go if nothing uses its results, e.g.
Definition target.cpp:60
size_t negate_cc(size_t c) const final
The hardware encoding pairs each condition code with its negation in bit 0.
Definition target.h:21
mach::Constraint constraint(const App *insn) const final
The register constraint of insn; by default, it has none.
Definition target.cpp:12
size_t num_arg_regs(Class cls) const final
The XMM registers are their own argument registers.
Definition target.h:35
bool reserved(Class cls, size_t r) const final
Is r never available to register allocation?
Definition target.h:31
The mach Plugin
Definition asm.h:15
What an instruction on the chain prescribes about the registers of its operands; registers are hardwa...
Definition target.h:17
Machine facts about the instructions of the x86 plugin, shared by x86_isel.gen and the backend.
Definition insn.h:15
The x86 Plugin
Definition emit.h:9
constexpr std::array< bool, Num_Regs > Caller_Saved
Definition x86.h:25
constexpr size_t encoding(Reg r)
The hardware encoding of the register r of a backend's module reg, whose subtags are in encoding orde...
Definition mach.h:15
constexpr bool reserved(size_t r)
Definition x86.h:26
constexpr std::array< size_t, 6 > Arg_Regs
System V AMD64 ABI.
Definition x86.h:20
bool fits_imm(std::optional< nat_t > size, nat_t val)
Does the literal val fit a sign-extended 32-bit immediate, if it is an Idx size?
Definition imm.h:19
constexpr size_t Num_Regs
Definition x86.h:15
constexpr size_t Num_Xmm
Definition x86.h:16
u64 flags_t
Definition types.h:39
GIDSet< const Def * > DefSet
Definition def.h:92
static constexpr sub_t flags2sub(flags_t f)
Yields the sub part of the name as integer.
Definition plugin.h:262