MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
lower.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/phase.h>
4
6
7/// Lowers the high-level tensor axioms into the low-level tensor axioms (`map_reduce`, …).
8/// Each high-level axiom comes with a matching `*_impl` annex (a
9/// `lam` with the same signature as the axiom); the lowering simply re-applies the args
10/// to the `_impl` annex. Each `_impl` body references the `_impl` variants of its
11/// dependencies, so the chain of beta-reductions bottoms out at the low-level axioms in
12/// one step. The resulting low-level axioms are then lowered to primitives by
13/// `LowerMapReduce`.
14class Lower : public RWPhase {
15public:
16 using RWPhase::RWPhase;
17
18private:
19 const Def* rewrite_imm_App(const App*) final;
20 const Def* rewrite_imm_Extract(const Extract*) final;
21
22 /// Reads straight through a `broadcast` / `repeat` at @p index instead of materializing it.
23 /// Per axis the shape op either passes the index through, reads a size-1 input axis at 0, or (for `repeat`)
24 /// wraps it; an axis that is none of these decidably keeps the shape op.
25 const Def* read_through(const Def* base, Defs index);
26
27 /// The `_impl` @p Id: as code, it is rewritten - and thus lowered - once per phase.
28 template<annex_without_subs Id>
29 const Def* impl() {
30 return rewrite(old_world().annex<Id>());
31 }
32
33 const Def* lower_via_impl(const App*, const Def* impl);
34 /// `tensor.fastest_axis` applied to the dot family's right operand (of the given rank):
35 /// the reflection the dot `_impl`s take as their leading argument, pre-applied here because the
36 /// operand is only concrete at this staging point. The schedule decision built on the answer
37 /// stays in the `_impl`'s IR (see tensor.dot_product_impl).
38 const Def* fastest_axis_2(const App*, const Def* rank);
39};
40
41} // namespace mim::plug::tensor::phase
Base class for all Defs.
Definition def.h:289
Extracts from a Sigma or Array-typed Extract::tuple the element at position Extract::index.
Definition tuple.h:360
flags_t annex() const
Definition phase.h:62
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
World & old_world()
Get old Defs from here.
Definition phase.h:378
virtual const Def * rewrite(const Def *)
Definition rewrite.cpp:62
Lowers the high-level tensor axioms into the low-level tensor axioms (map_reduce, …).
Definition lower.h:14
const Def * rewrite_imm_App(const App *) final
Definition lower.cpp:89
const Def * rewrite_imm_Extract(const Extract *) final
Definition lower.cpp:57
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
fe::View< const Def * > Defs
Definition def.h:96