summaryrefslogtreecommitdiff
path: root/ir.c
diff options
context:
space:
mode:
Diffstat (limited to 'ir.c')
-rw-r--r--ir.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/ir.c b/ir.c
index dd7a8ac..f895323 100644
--- a/ir.c
+++ b/ir.c
@@ -172,6 +172,15 @@ void node_add_in(Proc *p, Node *a, Node *b) {
if (b) b->refs++;
}
+void node_set_in(Proc *p, Node *n, int idx, Node *to) {
+ Node *in = n->in.data[idx];
+ if (in) in->refs--;
+ node_del_out(in, n);
+ node_add_out(p, to, n);
+ n->in.data[0] = to;
+ if (in->out.len < 1) node_kill(in, p);
+}
+
void node_add(Proc *p, Node *src, Node *dest) {
node_add_in(p, dest, src);
if (!src) return;
@@ -712,11 +721,11 @@ zero_no_effect: if (node_eql_i64(CAR(n), 0)) return CDR(n);
case N_PROJ:
if (T(CTRL(n), N_IF_ELSE) && CTRL(n)->type.t == T_TUPLE) {
- if (CTRL(n)->val.tuple.data[n->val.i].type.lvl == T_XCTRL) {
+ /*if (CTRL(n)->val.tuple.data[n->val.i].type.lvl == T_XCTRL) {
return node_new_lit(p, (Value) {
.type = { .lvl = T_XCTRL, .t = T_NONE }
});
- }
+ }*/
if (CTRL(n)->val.tuple.data[(n->val.i + 1) % CTRL(n)->val.tuple.len].type.lvl == T_XCTRL) {
return CTRL(CTRL(n));
}
@@ -734,26 +743,24 @@ zero_no_effect: if (node_eql_i64(CAR(n), 0)) return CDR(n);
}
break;
- case N_REGION:
- {
- int live_in = 0;
+ case N_REGION: if (0) {
+ int live_in = 0;
+ for (int i = 0; i < n->in.len; i++) {
+ if (IN(n, i)->type.lvl != T_XCTRL) live_in++;
+ }
+ if (live_in == 1) {
for (int i = 0; i < n->in.len; i++) {
- if (IN(n, i)->type.lvl != T_XCTRL) live_in++;
- }
- if (live_in == 1) {
- for (int i = 0; i < n->in.len; i++) {
- if (IN(n, i)->type.lvl != T_XCTRL) {
- return IN(n, i);
- }
+ if (IN(n, i)->type.lvl != T_XCTRL) {
+ return IN(n, i);
}
}
- if (live_in == 0) {
- return node_new_lit(p, (Value) {
- .type = { .lvl = T_XCTRL, .t = T_NONE }
- });
- }
}
- break;
+ if (live_in == 0) {
+ return node_new_lit(p, (Value) {
+ .type = { .lvl = T_XCTRL, .t = T_NONE }
+ });
+ }
+ } break;
default:
break;
@@ -817,7 +824,7 @@ void proc_init(Proc *proc, Str name) {
.t = T_TUPLE,
.next = NULL
};
- proc->stop = node_new(proc, N_STOP, NULL);
+ proc->stop = node_new_empty(proc, N_STOP);
proc->ctrl = proc->start;
proc->keepalive = node_new(proc, N_KEEPALIVE, NULL);
proc->name = name;