51using Alts = fe::Vector<Alt>;
62 return std::unique_ptr<Phase>(
87 std::span<const rules::Rewrite> rewrites(
flags_t flags)
const;
88 std::optional<flags_t> root_of(
const Def* def)
const;
90 bool atomic(
const rules::Rewrite& r)
const;
92 Ty leaf_ty(
const Def* def)
const;
93 pbqp::Cost leaf(
const Def* def, Want want)
const {
return conv(leaf_ty(def), want); }
94 bool literal(
const Def* def, Want want)
const {
97 Want resolve(
const Def* def, Want want)
const;
102 size_t uses(
const Def* def)
const {
103 auto n = fe::lookup(uses_, def);
108 bool overwritten(
const Def* def)
const;
110 const App* sole_value(
const Def* def)
const;
112 const Def* hole(
const Def* def,
Want want = Want::Reg);
114 const Def* build(
const Alt& alt);
119 void count(const Def*);
121 void match(const Def* def,
Alts& alts);
123 void append(const rules::Rewrite& rule, const Def* root,
Alts& alts);
127 append(const rules::Rewrite& rule, const Def* root,
u32 swap, std::optional<
u32> rival,
Alts& alts);
129 const App* sole(const Def* parent, const Def* def) const;
131 bool holds(const Alt& alt);
133 const Def* key(const Def* def) const;
135 const Alt* choice(const Def* def) const;
137 const Def* select(const Def* def);
139 const Def* selected(const Def* def);
141 const Def* convert(const Def* x,
Ty from,
Want want);
146 const Target& target_;
147 const rules::Table& table_;
static std::optional< T > isa(const Def *def)
A Phase performs one self-contained task over the whole World.
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
World & world()=delete
Hides both and forbids direct access.
friend void swap(Rewriter &rw1, Rewriter &rw2) noexcept
The World represents the whole program and manages creation of MimIR nodes (Defs).
const Def * rewrite_imm_App(const App *) final
ISel(World &world, flags_t annex, const Target &target, const rules::Table &table)
bool analyze() final
Runs the optional pre-analysis on old_world(), typically to a fixed point, before rewriting begins.
const Def * rewrite_imm_Extract(const Extract *) final
The machine facts of a native backend that the phases of mach need.
virtual bool fits_imm(const Def *) const
Does the literal lit fit a hole of type Want::Imm?
A saturating cost; Cost::inf forbids an option or option pair.
Want
What a rule wants of the term a meta variable matches; a Param is bound but no operand.
std::span< const Want > wants
Ty
The non-terminal a rule yields by the type of its rhs: a register of either class,...
A closed rule lhs ↦ rhs, whose metas want num_metas consecutive entries of wants.
The generated tables of one backend, as its isel_rules.h defines them.
void hook_isel(Flags2Phases &phases, const rules::Table &table)
Registers ISel with the rules table as the Phase of the backend's annex A.
fe::Vector< Cover > covers
u32 copies
The operands its two-address instructions overwrite although something else uses them.
const rules::Rewrite * rule
nullptr for an inner alternative, whose id is its index plus one.
fe::Vector< Demand > demands
fe::Vector< Demand > demands
Phase * mim_mach_isel(World &, flags_t annex, const rules::Table &table)
A new ISel for the annex annex of a backend, with the rules table; compiled once into libmim_mach.
DefVec metas
What the meta variables of its rule match.
bool through
The match only looks through it, since something else uses it.
An alternative of a PBQP node: a match rooted there, or the class of all matches covering it as the s...
An inner node a match covers, with what it needs of its own operands.
DefMap< const Def * > Def2Def
GIDMap< const Def *, To > DefMap
fe::Vector< const Def * > DefVec
GIDSet< const Def * > DefSet
ankerl::unordered_dense::map< flags_t, std::function< std::unique_ptr< Phase >(World &)> > Flags2Phases
Maps an axiom of a Phase to a function that creates one.
static consteval flags_t base()
What a match needs of the operand def: a hole of type want or, if inner is set, that inner pattern no...
bool operator==(const Demand &) const =default