MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
lower.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
mim/phase.h
>
4
5
namespace
mim::plug::tensor::phase
{
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`.
14
class
Lower
:
public
RWPhase
{
15
public
:
16
using
RWPhase::RWPhase
;
17
18
private
:
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
mim::App
Definition
lam.h:215
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Extract
Extracts from a Sigma or Array-typed Extract::tuple the element at position Extract::index.
Definition
tuple.h:360
mim::Phase::annex
flags_t annex() const
Definition
phase.h:62
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:334
mim::RWPhase::old_world
World & old_world()
Get old Defs from here.
Definition
phase.h:378
mim::Rewriter::rewrite
virtual const Def * rewrite(const Def *)
Definition
rewrite.cpp:62
mim::plug::tensor::phase::Lower
Lowers the high-level tensor axioms into the low-level tensor axioms (map_reduce, …).
Definition
lower.h:14
mim::plug::tensor::phase::Lower::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
lower.cpp:89
mim::plug::tensor::phase::Lower::rewrite_imm_Extract
const Def * rewrite_imm_Extract(const Extract *) final
Definition
lower.cpp:57
mim::plug::tensor::phase::Lower::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:334
mim::plug::tensor::phase
Definition
constraints.h:5
mim::Defs
fe::View< const Def * > Defs
Definition
def.h:96
phase.h
include
mim
plug
tensor
phase
lower.h
Generated by
1.18.0