MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
affine.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
mim/lam.h
>
4
#include <
mim/world.h
>
5
6
#include <
mim/plug/core/core.h
>
7
8
#include "
mim/plug/affine/autogen.h
"
9
10
namespace
mim::plug::affine
{
11
12
/// `affine.For (0, bound, 1, acc)` over a fresh `body: Cn [I64, acc_t, Cn acc_t]` named @p name.
13
/// @returns `{body, for_call}`.
14
inline
std::pair<Lam*, const Def*>
counting_for
(
const
Def
* bound,
const
Def
* acc,
const
Def
* exit, Sym name) {
15
auto
& w = bound->
world
();
16
auto
acc_ty = acc->
type
();
17
auto
body = w.mut_con({
/* iter */
w.type_i64(),
/* acc */
acc_ty,
/* return */
w.cn(acc_ty)})->set(name);
18
auto
for_loop = w.call<
For
>(body, exit,
Defs
{w.lit_i64(0), bound, w.lit_i64(1), acc});
19
return
{body, for_loop};
20
}
21
22
/// Nests one counting loop per bound of @p dims inside @p cur, threading @p cur, @p exit and @p acc down to
23
/// the innermost body; @returns the raw i64 loop counters.
24
inline
DefVec
counting_nest
(
Lam
*& cur,
const
Def
*& exit,
const
Def
*& acc,
Defs
dims, std::string_view name) {
25
auto
& w = cur->
world
();
26
auto
iters =
DefVec
();
27
iters.reserve(dims.size());
28
for
(
size_t
i = 0, e = dims.size(); i != e; ++i) {
29
auto
bound = w.call<
core::bitcast
>(w.type_i64(), dims[i]);
30
auto
[body, for_call] =
counting_for
(bound, acc, exit, w.sym(std::format(
"{}_{}"
, name, i)));
31
auto
[iter, new_acc, yield] = body->vars<3>();
32
exit = yield;
33
acc = new_acc;
34
iters.emplace_back(iter);
35
cur->
set
(
true
, for_call);
36
cur = body;
37
}
38
return
iters;
39
}
40
41
}
// namespace mim::plug::affine
autogen.h
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Def::world
World & world() const noexcept
Definition
def.h:1105
mim::Def::type
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition
def.h:1119
mim::Lam
A function.
Definition
lam.h:91
mim::Lam::set
Lam * set(Filter filter, const Def *body)
Definition
lam.cpp:34
core.h
lam.h
mim::plug::affine
The affine Plugin
Definition
affine.h:10
mim::plug::affine::counting_for
std::pair< Lam *, const Def * > counting_for(const Def *bound, const Def *acc, const Def *exit, Sym name)
affine.For (0, bound, 1, acc) over a fresh body: Cn [I64, acc_t, Cn acc_t] named name.
Definition
affine.h:14
mim::plug::affine::For
For
Definition
autogen.h:14
mim::plug::affine::counting_nest
DefVec counting_nest(Lam *&cur, const Def *&exit, const Def *&acc, Defs dims, std::string_view name)
Nests one counting loop per bound of dims inside cur, threading cur, exit and acc down to the innermo...
Definition
affine.h:24
mim::plug::core::bitcast
bitcast
Definition
autogen.h:278
mim::Defs
fe::View< const Def * > Defs
Definition
def.h:96
mim::DefVec
fe::Vector< const Def * > DefVec
Definition
def.h:98
world.h
include
mim
plug
affine
affine.h
Generated by
1.18.0