18#define MIM_MACH_RULE_WANTS(X) \
19 X(Param) X(Lit) X(Reg) X(FReg) X(Imm) X(Sh) X(RegImm) X(RegSh) X(Base) X(Index) X(Addr) X(Scaled) X(Zx)
34#define MIM_MACH_RULE_TYS(X) X(Reg) X(FReg) X(Base) X(Index) X(Scaled) X(Zx) X(Lit)
126constexpr bool is_param(
Want w) {
return w == Want::Param || w == Want::Lit; }
129constexpr bool is_literal(
Want want) {
return want == Want::Imm || want == Want::Sh; }
133 return want == Want::RegImm ? Want::Imm : want == Want::RegSh ? Want::Sh : want;
141 case Want::RegSh:
return ty == Ty::Reg;
142 case Want::FReg:
return ty == Ty::FReg;
143 case Want::Base:
return ty == Ty::Base;
144 case Want::Index:
return ty == Ty::Index;
145 case Want::Addr:
return ty == Ty::Base || ty == Ty::Index;
146 case Want::Scaled:
return ty == Ty::Scaled;
147 case Want::Zx:
return ty == Ty::Zx;
148 default:
return false;
153constexpr Want reg_want(
Ty ty) {
return ty == Ty::FReg ? Want::FReg : Want::Reg; }
158 if (want == Want::FReg)
return ty == Ty::FReg;
159 return ty != Ty::FReg;
167 std::array<bool, Num_Tys>
used{};
170 constexpr Chains(
const auto& conversions) {
171 for (
size_t i = 0; i !=
Num_Tys; ++i)
172 for (
size_t j = 0; j !=
Num_Tys; ++j)
174 used[size_t(Ty::Reg)] =
used[size_t(Ty::Lit)] =
true;
176 for (
const auto& c : conversions) {
177 used[size_t(c.from)] =
used[size_t(c.to)] =
true;
178 if (
auto& d =
cost[
size_t(c.from)][
size_t(c.to)];
u32(c.cost) < d)
179 d =
u32(c.cost),
first[size_t(c.from)][size_t(c.to)] = n;
182 for (
size_t k = 0; k !=
Num_Tys; ++k)
183 for (
size_t i = 0; i !=
Num_Tys; ++i)
184 for (
size_t j = 0; j !=
Num_Tys; ++j)
190 auto res = std::pair(from,
Inf);
191 for (
size_t t = 0; t !=
Num_Tys; ++t)
192 if (
auto c =
cost[
size_t(from)][t];
fills(
Ty(t), want) && c < res.second) res = {
Ty(t), c};
199 return target(from, want).second;
205 for (
size_t t = 0; t !=
Num_Tys; ++t)
212 for (
size_t t = 0; t !=
Num_Tys; ++t)
The World represents the whole program and manages creation of MimIR nodes (Defs).
The closed rewrite rules of a backend's isel plugin as C++; its gen writes them to the backend's isel...
constexpr u32 Copy
A register-to-register copy, which move elimination makes free of latency.
std::span< const Use > uses
std::span< const Conversion > conversions
std::span< const Root > roots
u32 cost
The summed instruction costs of its rhs.
const Def *(*)(World &, const Def *const *holes) BuildFn
Builds the rhs from holes, one per meta variable, already in the new world.
constexpr bool is_literal(Want want)
Does a hole of type want take a literal rather than a replacement?
constexpr bool fills(Ty ty, Want want)
Does a value of non-terminal ty fill a hole of type want as it is?
constexpr bool is_param(Want w)
Is a meta variable that w wants bound to its rewrite rather than an operand?
Ref
How the lhs refers to one of its inner nodes.
@ Value
As an operand of its owner, which nothing outside the match uses.
@ Mem
By its memory, which only the match uses.
u32 swaps
The swaps of match that may yield another match.
std::span< const RefInfo > refs
Want
What a rule wants of the term a meta variable matches; a Param is bound but no operand.
Ty type
The non-terminal its rhs yields.
std::span< const Rewrite > rewrites
constexpr Want literal_of(Want want)
The literal form of a hole of type want, or want itself.
u32 copy_swaps
Those of swaps whose operands differ only as a RegImm or RegSh, which a literal never fills.
std::span< const Want > wants
bool(*)(const Def *def, u32 swap, const Def **metas, const Def **refs) MatchFn
Matches the root def with the commuting nodes in swap swapped and binds metas and refs.
u32 tied
The meta variables that a two-address instruction of the rhs overwrites.
constexpr u32 add(u32 a, u32 b)
constexpr Want reg_want(Ty ty)
The register hole that a value of non-terminal ty fills.
constexpr bool same_class(Ty ty, Want want)
Is a value of non-terminal ty in the same register class as a hole of type want?
u8 maps
k + 1 if the rhs replaces cover k as a whole, or 0.
Ty
The non-terminal a rule yields by the type of its rhs: a register of either class,...
std::span< const Matcher > matchers
flags_t root
The axiom at the head of its lhs, or 0 for an Extract.
A conversion rule x ↦ rhs, whose lhs is all of its meta variables: a value of non-terminal from as on...
A matcher and the shape of its lhs; a cover's operands follow it in preorder.
A ref of a matcher: its cover and how the lhs refers to it.
A closed rule lhs ↦ rhs, whose metas want num_metas consecutive entries of wants.
The rewrites rewrites[first, first + num) with the root axiom flags; roots is sorted by it.
The generated tables of one backend, as its isel_rules.h defines them.
An operand position of a matcher in preorder: meta variable or Value ref index of the node owner.
#define MIM_MACH_RULE_WANTS(X)
#define MIM_MACH_RULE_TYS(X)
The cheapest chains of conversions between two non-terminals: their costs and each one's first conver...
constexpr u32 conv(Ty from, Want want) const
Cost of converting a replacement or operand of non-terminal from into a hole of type want.
std::array< bool, Num_Tys > used
The non-terminals of the backend: Reg, Lit, and those its conversions mention.
constexpr bool reachable(Want w) const
Does some non-terminal of the register class of a rule convert into a hole of type w?
constexpr std::pair< Ty, u32 > target(Ty from, Want want) const
The non-terminal that from converts to most cheaply for a hole of type want, and the cost.
std::array< std::array< u32, Num_Tys >, Num_Tys > first
constexpr bool total(Want w) const
Does every non-terminal of w's register class convert into a hole of type w, as an atomic rule's hole...
std::array< std::array< u32, Num_Tys >, Num_Tys > cost
constexpr Chains(const auto &conversions)
The closure of conversions, a range of Conversion-like rules with from, to, and cost.