Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander.nutz committed Jun 4, 2024
1 parent 70b2573 commit 29a5c36
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ir/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ size_t vx_IrBlock_inline_cost(vx_IrBlock *block) {

static bool is_tail__rec(vx_IrBlock *block, vx_IrOp *op) {
if (!op)
return false;
return true;
if (op->next == NULL) {
if (block->parent)
return is_tail__rec(block->parent, block->parent_op);
Expand Down
24 changes: 16 additions & 8 deletions ir/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,22 +310,28 @@ void vx_IrOp_steal_outs(vx_IrOp *dest, const vx_IrOp *src)
void vx_IrOp_remove_out_at(vx_IrOp *op,
const size_t id)
{
memmove(op->outs + id, op->outs + id + 1, sizeof(vx_IrTypedVar) * (op->outs_len - id - 1));
op->outs_len --;
if (op && op->outs) {
memmove(op->outs + id, op->outs + id + 1, sizeof(vx_IrTypedVar) * (op->outs_len - id - 1));
op->outs_len --;
}
}

void vx_IrBlock_remove_out_at(vx_IrBlock *block,
size_t id)
{
memmove(block->outs + id, block->outs + id + 1, sizeof(vx_IrVar) * (block->outs_len - id - 1));
block->outs_len --;
if (block && block->outs) {
memmove(block->outs + id, block->outs + id + 1, sizeof(vx_IrVar) * (block->outs_len - id - 1));
block->outs_len --;
}
}

void vx_IrOp_remove_param_at(vx_IrOp *op,
const size_t id)
{
memmove(op->params + id, op->params + id + 1, sizeof(vx_IrNamedValue) * (op->params_len - id - 1));
op->params_len --;
if (op && op->params) {
memmove(op->params + id, op->params + id + 1, sizeof(vx_IrNamedValue) * (op->params_len - id - 1));
op->params_len --;
}
}

void vx_IrOp_remove_param(vx_IrOp *op, vx_IrName param) {
Expand All @@ -341,8 +347,10 @@ void vx_IrOp_remove_param(vx_IrOp *op, vx_IrName param) {
void vx_IrOp_remove_state_at(vx_IrOp *op,
const size_t id)
{
memmove(op->args + id, op->args + id + 1, sizeof(vx_IrNamedValue) * (op->args_len - id - 1));
op->args_len --;
if (op && op->args) {
memmove(op->args + id, op->args + id + 1, sizeof(vx_IrNamedValue) * (op->args_len - id - 1));
op->args_len --;
}
}

void vx_IrOp_steal_states(vx_IrOp *dest,
Expand Down
18 changes: 16 additions & 2 deletions ir/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,34 @@ void vx_IrBlock_llir_fix_decl(vx_IrBlock *root) {

// TODO: WHY THE FUCK IS THIS EVEN REQUIRED????

memset(root->as_root.labels, 0, sizeof(*root->as_root.labels) * root->as_root.labels_len);
memset(root->as_root.vars, 0, sizeof(*root->as_root.vars) * root->as_root.vars_len);

size_t total = 0;
size_t tot_var = 0;
size_t tot_label = 0;

for (vx_IrOp *op = root->first; op; op = op->next) {
for (size_t j = 0; j < op->outs_len; j ++) {
vx_IrTypedVar out = op->outs[j];
vx_IrOp **decl = &root->as_root.vars[out.var].decl;
if (*decl == NULL) {
*decl = op;
root->as_root.vars[out.var].ll_type = out.type;
total ++;
tot_var ++;
}
}

if (op->id == VX_LIR_OP_LABEL) {
size_t id = vx_IrOp_param(op, VX_IR_NAME_ID)->id;
vx_IrOp **decl = &root->as_root.labels[id].decl;
if (*decl == NULL) {
*decl = op;
tot_label ++;
}
}
}

printf("recoverd %zu variables and %zu labels\n", tot_var, tot_label);
}

void vx_IrOp_warn(vx_IrOp *op, const char *optMsg0, const char *optMsg1) {
Expand Down
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ static int cir_test(void) {
printf("After CG prepare:\n");
vx_IrBlock_dump(block, stdout, 0);

vx_IrBlock_llir_fix_decl(block);
opt_ll(block);

printf("After LL IR opt:\n");
Expand Down

0 comments on commit 29a5c36

Please sign in to comment.