12const Def* LowerGetSet::lower_get(
const App* app) {
17 auto [arr,
index] = arg->projs<2>();
18 auto callee =
c->as<
App>();
19 auto [T,
r,
s] = callee->args<3>();
22 DLOG(
" arr = {} : {}", arr, arr->type());
23 if (
auto arr_seq = arr->type()->isa<Seq>())
DLOG(
" arr shape = {}", arr_seq->arity());
24 DLOG(
" index = {} : {}", index,
index->type());
25 DLOG(
" T = {} : {}", T, T->type());
26 DLOG(
" r = {} : {}", r,
r->type());
27 DLOG(
" s = {} : {}", s,
s->type());
31 WLOG(
"{} doesn't have a lowering-time known rank: {}", app, r);
35 DLOG(
"index of size 1, extract");
36 return w.extract(arr, index);
39 for (
auto ri = 0_u64; ri < *r_nat; ++ri) {
41 DLOG(
" idx = {} : {}", idx,
idx->type());
42 curr_arr =
w.extract(curr_arr, idx);
47const Def* LowerGetSet::lower_set(
const App* app) {
52 auto [arr,
index, x] = arg->projs<3>();
55 DLOG(
" arr = {} : {}", arr, arr->type());
56 DLOG(
" index = {} : {}", index,
index->type());
57 DLOG(
" x = {} : {}", x, x->type());
59 auto callee =
c->as<
App>();
60 auto [T,
r,
s] = callee->args<3>();
61 DLOG(
" T = {} : {}", T, T->type());
62 DLOG(
" r = {} : {}", r,
r->type());
63 DLOG(
" s = {} : {}", s,
s->type());
67 WLOG(
"{} doesn't have a lowering-time known rank: {}", app, r);
71 DLOG(
"index of size 1, insert");
72 return w.insert(arr, index, x);
76 DefVec arrs_to_insert_into(*r_nat);
77 arrs_to_insert_into[0] = arr;
78 for (
auto ri = 0_u64; ri < *r_nat - 1; ++ri) {
80 DLOG(
" extract idx = {} : {}", idx,
idx->type());
81 arrs_to_insert_into[ri + 1] =
w.extract(arrs_to_insert_into[ri], idx);
85 for (
auto ri =
static_cast<s64>(*r_nat - 1); ri >= 0; --ri) {
87 DLOG(
" idx = {} : {}", idx,
idx->type());
88 DLOG(
" arr_to_insert_into = {} : {}", arrs_to_insert_into[ri], arrs_to_insert_into[ri]->
type());
90 new_arr =
w.insert(arrs_to_insert_into[ri], idx, new_arr);
97 if (
auto res = lower_get(
get))
return res;
99 if (
auto res = lower_set(
set))
return res;
101 return RWPhase::rewrite_imm_App(app);
static auto isa(const Def *def)
static std::optional< T > isa(const Def *def)
World & new_world()
Create new Defs into this.
virtual const Def * rewrite(const Def *)
const Def * rewrite_imm_App(const App *) final
#define DLOG(...)
Vaporizes to nothingness in Debug build.
Vector< const Def * > DefVec