5#include <fe/worklist.h>
19 auto lam =
map->isa_mut<
Lam>();
20 return lam && lam->
is_set() && lam->body() == lam->var();
34 return ret && ret == post->
as_mut<
Lam>()->var(2, 0)->
proj(2, 0);
54 auto [nis_nps, meta, shapes, in_tys, comb_init, map_out, maps_all, is_all] = mr->uncurry_args<8>();
56 auto [nis, nps] = nis_nps->projs<2>();
58 if (
Lit::isa(nis) != 1 ||
Lit::isa(nps) != 0 || meta->proj(5, 2) != meta->proj(5, 3))
return {};
59 auto [So, Sr, sched] = shapes->projs<3>();
60 if (Sr != So)
return {};
62 auto [comb, init, post] = comb_init->projs<3>();
65 auto sole = [](
const Def* d,
u64 n,
u64 i) {
return d->proj(n, i)->proj(1, 0); };
66 return PureRead{sole(is_all, 2, 0), sole(maps_all, 2, 0), sole(in_tys, 6, 0), sole(in_tys, 6, 1),
72 auto res = fe::Vector<u64>(n);
73 for (
u64 i = 0; i != n; ++i)
82inline std::optional<fe::Vector<u64>>
lit_perm(
const Def* perm) {
95 auto perm = app->decurry()->decurry()->arg();
97 auto [p0, p1] = perm->projs<2>();
111 auto charge = [&](
this auto&& charge,
const Def* d) ->
void {
114 else if (d->isa<
Tuple>() || d->isa<
Pack>())
115 for (
auto op : d->ops())
119 auto wl = fe::BFSWorklist<DefSet>();
122 while (!wl.empty()) {
124 auto transparent = def->isa<
Tuple>() || def->isa<
Pack>();
125 for (
auto op : def->ops())
127 if (!transparent) charge(op);
130 if (def->type()) wl.push(def->type());
const App * decurry() const
Returns App::callee again as App.
static auto isa(const Def *def)
const Def * proj(nat_t a, nat_t i) const
Similar to World::extract while assuming an arity of a, but also works on Sigmas and Arrays.
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
static const Def * isa_ret_arg(const Def *d)
Yields the y of λ (x, ret) = ret y - the argument d's body hands to its Lam::ret_var.
static std::optional< T > isa(const Def *def)
A (possibly paramterized) Tuple.
Data constructor for a Sigma.
The World represents the whole program and manages creation of MimIR nodes (Defs).
const Externals & externals() const
std::optional< fe::Vector< u64 > > lit_projs(const Def *def, u64 n)
The literal values of def's n projections, or nothing if one of them is not a literal.
bool is_identity_post(const Def *post)
Is post the (rebuilt) CPS identity tensor.id, i.e.
DefMap< u64 > count_consumers(const World &world, std::predicate< const Def * > auto pred)
Counts the consumers of every def of world matched by pred.
std::optional< PureRead > is_pure_read(const Def *value)
If value is a pure re-indexed read — a copy-combiner map_reduce without reduction loops that writes i...
const Def * isa_transpose_2d(const Def *def)
The input of a 2-D transpose transpose (1, 0), or nullptr.
std::optional< fe::Vector< u64 > > transpose_perm(const App *app)
The permutation of a transpose app, if it is literal.
std::optional< fe::Vector< u64 > > lit_perm(const Def *perm)
perm as literals, if it is literal.
bool is_copy_comb(const Def *comb)
Recognizes the (rebuilt) tensor_copy combiner (acc, ys) ↦ ys#0: the result is exactly the single inpu...
bool is_identity_map(const Def *map)
Is map the identity access map λ x. x?
A pure re-indexed read: the source tensor, the access map into it (over the read's output coordinates...
GIDMap< const Def *, To > DefMap