24const Def* op_lea_tuple(
const Def* arr,
const Def* tuple) {
25 auto& world = arr->world();
26 world.DLOG(
"op_lea_tuple arr {} : {}", arr, arr->type());
27 auto n = tuple->num_projs();
29 for (
size_t i = 0; i < n; ++i) element =
mem::op_lea(element, tuple->proj(n, i));
33const Def* op_pack_tuple(
u64 n,
const Def* tuple,
const Def* val) {
34 auto& world = val->
world();
37 for (
int i = n - 1; i >= 0; i--) {
38 auto dim = tuple->proj(n, i);
39 element = world.pack(dim, element);
41 world.DLOG(
"op_pack_tuple: {} -> {}", val, element);
42 world.DLOG(
" for tuple: {} : {}", tuple, tuple->type());
46const Def* arr_ty_of_matrix_ty(
const Def* S,
const Def* T) {
47 auto& world =
S->world();
48 auto n =
S->num_projs();
50 for (
int i = n - 1; i >= 0; i--) {
51 auto dim =
S->proj(n, i);
52 arr_ty = world.arr(dim, arr_ty);
61 assert(!
match<matrix::shape>(def) &&
"high level operations should have been lowered to for loops by now");
62 assert(!
match<matrix::prod>(def) &&
"high level operations should have been lowered to for loops by now");
64 assert(!
match<matrix::sum>(def) &&
"high level operations should have been lowered to for loops by now");
68 auto [_, S, T] = mat_ax->args<3>();
71 auto arr_ty = arr_ty_of_matrix_ty(S, T);
78 world().DLOG(
"init {} : {}", def, def->
type());
79 auto [_, S, T,
mem] = init_ax->args<4>();
80 world().DLOG(
" S T mem {} {} {}", S, T,
mem);
84 world().DLOG(
" S T mem {} {} {}", S, T,
mem);
85 auto arr_ty = arr_ty_of_matrix_ty(S, T);
88 world().DLOG(
" res {} : {}", res, res->type());
91 auto [
mem, mat, idx] = read_ax->args<3>();
92 world().DLOG(
"read_ax: {}", read_ax);
94 world().DLOG(
" mat: {} : {}", mat, mat->type());
95 world().DLOG(
" idx: {} : {}", idx, idx->type());
99 world().DLOG(
"rewritten read");
101 world().DLOG(
" mat: {} : {}", mat, mat->type());
102 world().DLOG(
" idx: {} : {}", idx, idx->type());
105 auto element_ptr = op_lea_tuple(ptr_mat, idx);
109 auto [
mem, mat, idx, val] = insert_ax->args<4>();
110 world().DLOG(
"insert_ax: {}", insert_ax);
112 world().DLOG(
" mat: {} : {}", mat, mat->type());
113 world().DLOG(
" idx: {} : {}", idx, idx->type());
114 world().DLOG(
" val: {} : {}", val, val->type());
119 world().DLOG(
"rewritten insert");
121 world().DLOG(
" mat: {} : {}", mat, mat->type());
122 world().DLOG(
" idx: {} : {}", idx, idx->type());
123 world().DLOG(
" val: {} : {}", val, val->type());
125 auto element_ptr = op_lea_tuple(ptr_mat, idx);
129 auto [
mem, val] = const_ax->args<2>();
132 auto [n_def, S, T] = const_ax->callee()->as<
App>()->args<3>();
135 auto arr_ty = arr_ty_of_matrix_ty(S, T);
140 auto initial = op_pack_tuple(n, S, val);
148 if (def->isa<
Axiom>())
return def;
World & world() const noexcept
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
virtual const Def * rewrite_imm(const Def *)
virtual const Def * rewrite(const Def *)
const Def * tuple(Defs ops)
const Def * call(Id id, Args &&... args)
Complete curried call of annexes obeying implicits.
const Def * rewrite_imm(const Def *) override
const Def * op_lea(const Def *ptr, const Def *index)
const Def * op_alloc(const Def *type, const Def *mem)
constexpr decltype(auto) get(Span< T, N > span) noexcept
auto match(const Def *def)