Skip to content

Commit

Permalink
Unify naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
vacantron committed Nov 20, 2023
1 parent 90d4a8e commit 4c9c88e
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/reg-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void refresh(basic_block_t *bb, Inst_t *inst)
}
}

ph2_ir_t *add_bb_ph2_ir(basic_block_t *bb, opcode_t op)
ph2_ir_t *bb_add_ph2_ir(basic_block_t *bb, opcode_t op)
{
ph2_ir_t *n = calloc(1, sizeof(ph2_ir_t));
n->op = op;
Expand Down Expand Up @@ -61,8 +61,8 @@ void spill_var(basic_block_t *bb, var_t *var, int idx)
var->offset = bb->belong_to->func->stack_size;
bb->belong_to->func->stack_size += 4;
}
ph2_ir_t *ir = var->is_global ? add_bb_ph2_ir(bb, OP_global_store)
: add_bb_ph2_ir(bb, OP_store);
ph2_ir_t *ir = var->is_global ? bb_add_ph2_ir(bb, OP_global_store)
: bb_add_ph2_ir(bb, OP_store);
ir->src0 = idx;
ir->src1 = var->offset;
REGS[idx].var = NULL;
Expand All @@ -71,8 +71,8 @@ void spill_var(basic_block_t *bb, var_t *var, int idx)

void load_var(basic_block_t *bb, var_t *var, int idx)
{
ph2_ir_t *ir = var->is_global ? add_bb_ph2_ir(bb, OP_global_load)
: add_bb_ph2_ir(bb, OP_load);
ph2_ir_t *ir = var->is_global ? bb_add_ph2_ir(bb, OP_global_load)
: bb_add_ph2_ir(bb, OP_load);
ir->src0 = var->offset;
ir->dest = idx;
REGS[idx].var = var;
Expand Down Expand Up @@ -232,7 +232,7 @@ void reg_alloc()
GLOBAL_FUNC.stack_size += PTR_SIZE;
dest =
prepare_dest(GLOBAL_FUNC.fn->bbs, global_inst->rd, -1, -1);
ir = add_bb_ph2_ir(GLOBAL_FUNC.fn->bbs, OP_global_address_of);
ir = bb_add_ph2_ir(GLOBAL_FUNC.fn->bbs, OP_global_address_of);
ir->src0 = global_inst->rd->offset;
ir->dest = dest;
spill_var(GLOBAL_FUNC.fn->bbs, global_inst->rd, dest);
Expand All @@ -243,14 +243,14 @@ void reg_alloc()
break;
case OP_load_constant:
dest = prepare_dest(GLOBAL_FUNC.fn->bbs, global_inst->rd, -1, -1);
ir = add_bb_ph2_ir(GLOBAL_FUNC.fn->bbs, OP_load_constant);
ir = bb_add_ph2_ir(GLOBAL_FUNC.fn->bbs, OP_load_constant);
ir->src0 = global_inst->rd->init_val;
ir->dest = dest;
break;
case OP_assign:
src0 = prepare_operand(GLOBAL_FUNC.fn->bbs, global_inst->rs1, -1);
dest = prepare_dest(GLOBAL_FUNC.fn->bbs, global_inst->rd, src0, -1);
ir = add_bb_ph2_ir(GLOBAL_FUNC.fn->bbs, OP_assign);
ir = bb_add_ph2_ir(GLOBAL_FUNC.fn->bbs, OP_assign);
ir->src0 = src0;
ir->dest = dest;
spill_var(GLOBAL_FUNC.fn->bbs, global_inst->rd, dest);
Expand Down Expand Up @@ -279,7 +279,7 @@ void reg_alloc()
/* variadic function implementation */
if (fn->func->va_args) {
for (i = 0; i < MAX_PARAMS; i++) {
ph2_ir_t *ir = add_bb_ph2_ir(fn->bbs, OP_store);
ph2_ir_t *ir = bb_add_ph2_ir(fn->bbs, OP_store);

if (i < fn->func->num_params)
fn->func->param_defs[i].subscripts[0]->offset =
Expand Down Expand Up @@ -312,7 +312,7 @@ void reg_alloc()
bb->belong_to->func->stack_size += 4;
}

ir = add_bb_ph2_ir(bb, OP_store);
ir = bb_add_ph2_ir(bb, OP_store);
ir->src0 = src0;
ir->src1 = inst->rd->offset;
break;
Expand All @@ -339,14 +339,14 @@ void reg_alloc()
fn->func->stack_size += PTR_SIZE;

dest = prepare_dest(bb, inst->rd, -1, -1);
ir = add_bb_ph2_ir(bb, OP_address_of);
ir = bb_add_ph2_ir(bb, OP_address_of);
ir->src0 = src0;
ir->dest = dest;
break;
case OP_load_constant:
case OP_load_data_address:
dest = prepare_dest(bb, inst->rd, -1, -1);
ir = add_bb_ph2_ir(bb, inst->opcode);
ir = bb_add_ph2_ir(bb, inst->opcode);
ir->src0 = inst->rd->init_val;
ir->dest = dest;
break;
Expand All @@ -359,27 +359,27 @@ void reg_alloc()
int i;
for (i = 0; i < REG_CNT; i++)
if (REGS[i].var == inst->rs1) {
ir = add_bb_ph2_ir(bb, OP_store);
ir = bb_add_ph2_ir(bb, OP_store);
ir->src0 = i;
ir->src1 = inst->rs1->offset;
}
}

dest = prepare_dest(bb, inst->rd, -1, -1);
ir = add_bb_ph2_ir(bb, OP_address_of);
ir = bb_add_ph2_ir(bb, OP_address_of);
ir->src0 = inst->rs1->offset;
ir->dest = dest;
break;
case OP_assign:
src0 = prepare_operand(bb, inst->rs1, -1);
dest = prepare_dest(bb, inst->rd, ir->src0, -1);
ir = add_bb_ph2_ir(bb, inst->opcode);
ir = bb_add_ph2_ir(bb, inst->opcode);
ir->src0 = src0;
ir->dest = dest;

/* store global variable after assignment immediately */
if (inst->rd->is_global) {
ir = add_bb_ph2_ir(bb, OP_global_store);
ir = bb_add_ph2_ir(bb, OP_global_store);
ir->src0 = dest;
ir->src1 = inst->rd->offset;
REGS[dest].polluted = 0;
Expand All @@ -389,23 +389,23 @@ void reg_alloc()
/* FIXME: indirect assignment of pointer */
src0 = prepare_operand(bb, inst->rs1, -1);
dest = prepare_dest(bb, inst->rd, src0, -1);
ir = add_bb_ph2_ir(bb, OP_read);
ir = bb_add_ph2_ir(bb, OP_read);
ir->src0 = src0;
ir->src1 = inst->sz;
ir->dest = dest;
break;
case OP_write:
if (inst->rs2->is_func) {
src0 = prepare_operand(bb, inst->rs1, -1);
ir = add_bb_ph2_ir(bb, OP_address_of_func);
ir = bb_add_ph2_ir(bb, OP_address_of_func);
ir->src0 = src0;
strcpy(ir->func_name, inst->rs2->var_name);
} else {
/* FIXME: indirect assignment of pointer */
spill_alive(bb, inst);
src0 = prepare_operand(bb, inst->rs1, -1);
src1 = prepare_operand(bb, inst->rs2, src0);
ir = add_bb_ph2_ir(bb, OP_write);
ir = bb_add_ph2_ir(bb, OP_write);
ir->src0 = src0;
ir->src1 = src1;
ir->dest = inst->sz;
Expand All @@ -420,7 +420,7 @@ void reg_alloc()
*/
spill_live_out(bb);

ir = add_bb_ph2_ir(bb, OP_branch);
ir = bb_add_ph2_ir(bb, OP_branch);
ir->src0 = src0;
ir->then_bb = bb->then_;
ir->else_bb = bb->else_;
Expand All @@ -434,15 +434,15 @@ void reg_alloc()
}

src0 = prepare_operand(bb, inst->rs1, -1);
ir = add_bb_ph2_ir(bb, OP_assign);
ir = bb_add_ph2_ir(bb, OP_assign);
ir->src0 = src0;
ir->dest = args++;
break;
case OP_call:
if (!find_func(inst->str)->num_params)
spill_alive(bb, inst);

ir = add_bb_ph2_ir(bb, OP_call);
ir = bb_add_ph2_ir(bb, OP_call);
strcpy(ir->func_name, inst->str);

is_pushing_args = 0;
Expand All @@ -457,17 +457,17 @@ void reg_alloc()
spill_alive(bb, inst);

src0 = prepare_operand(bb, inst->rs1, -1);
ir = add_bb_ph2_ir(bb, OP_load_func);
ir = bb_add_ph2_ir(bb, OP_load_func);
ir->src0 = src0;

add_bb_ph2_ir(bb, OP_indirect);
bb_add_ph2_ir(bb, OP_indirect);

is_pushing_args = 0;
args = 0;
break;
case OP_func_ret:
dest = prepare_dest(bb, inst->rd, -1, -1);
ir = add_bb_ph2_ir(bb, OP_assign);
ir = bb_add_ph2_ir(bb, OP_assign);
ir->src0 = 0;
ir->dest = dest;
break;
Expand All @@ -477,7 +477,7 @@ void reg_alloc()
else
src0 = -1;

ir = add_bb_ph2_ir(bb, OP_return);
ir = bb_add_ph2_ir(bb, OP_return);
ir->src0 = src0;
break;
case OP_add:
Expand All @@ -501,7 +501,7 @@ void reg_alloc()
src0 = prepare_operand(bb, inst->rs1, -1);
src1 = prepare_operand(bb, inst->rs2, ir->src0);
dest = prepare_dest(bb, inst->rd, ir->src0, ir->src1);
ir = add_bb_ph2_ir(bb, inst->opcode);
ir = bb_add_ph2_ir(bb, inst->opcode);
ir->src0 = src0;
ir->src1 = src1;
ir->dest = dest;
Expand All @@ -511,7 +511,7 @@ void reg_alloc()
case OP_log_not:
src0 = prepare_operand(bb, inst->rs1, -1);
dest = prepare_dest(bb, inst->rd, ir->src0, -1);
ir = add_bb_ph2_ir(bb, inst->opcode);
ir = bb_add_ph2_ir(bb, inst->opcode);
ir->src0 = src0;
ir->dest = dest;
break;
Expand All @@ -537,7 +537,7 @@ void reg_alloc()
/* jump to the beginning of loop or over the else block */
if (bb->next->visited == fn->visited ||
bb->next->visited != bb->rpo + 1) {
ph2_ir_t *ir = add_bb_ph2_ir(bb, OP_jump);
ph2_ir_t *ir = bb_add_ph2_ir(bb, OP_jump);
ir->next_bb = bb->next;
}
}
Expand All @@ -555,7 +555,7 @@ void reg_alloc()
if (bb->inst_list.tail && bb->inst_list.tail->opcode == OP_return)
continue;

ph2_ir_t *ir = add_bb_ph2_ir(bb, OP_return);
ph2_ir_t *ir = bb_add_ph2_ir(bb, OP_return);
ir->src0 = -1;
}
}
Expand Down

0 comments on commit 4c9c88e

Please sign in to comment.