Skip to content

Commit

Permalink
classic blunder
Browse files Browse the repository at this point in the history
  • Loading branch information
RealNeGate committed Nov 14, 2023
1 parent 3c5290c commit 8ee3b0b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 36 deletions.
1 change: 1 addition & 0 deletions libCuik/lib/back/ir_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ static IRVal irgen_subexpr(TranslationUnit* tu, TB_Function* func, Cuik_Expr* _,
tb_inst_goto(func, exit);
}
tb_inst_set_control(func, exit);
emit_location(tu, func, e->loc.start);

return (IRVal){
.value_type = RVALUE,
Expand Down
41 changes: 11 additions & 30 deletions tb/src/generic_cg.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,13 @@ static void isel_region(Ctx* restrict ctx, TB_Node* bb_start, TB_Node* end, size
ctx->head = &dummy;

if (n->type == TB_SAFEPOINT_NOP) {
if (prev_loc != NULL) {
SUBMIT(inst_line(prev_loc));
}
prev_loc = n;
continue;
TB_OPTDEBUG(CODEGEN)(
printf(" LINE %u: ", n->gvn),
print_node_sexpr(n, 0),
printf("\n")
);

SUBMIT(inst_line(n));
} else if (n->type != TB_MULPAIR && (n->dt.type == TB_TUPLE || n->dt.type == TB_CONTROL || n->dt.type == TB_MEMORY)) {
TB_OPTDEBUG(CODEGEN)(
printf(" EFFECT %u: ", n->gvn),
Expand Down Expand Up @@ -831,31 +833,6 @@ static void isel_region(Ctx* restrict ctx, TB_Node* bb_start, TB_Node* end, size
}
}

// write location for the top effect
if (prev_loc != NULL) {
// attach to dummy list
Inst dummy;
dummy.next = NULL;
ctx->head = &dummy;

SUBMIT(inst_line(prev_loc));

Inst* seq_start = dummy.next;
Inst* seq_end = ctx->head;
assert(seq_end->next == NULL);

if (seq_start != NULL) {
if (last == NULL) {
last = seq_end;
head->next = dummy.next;
} else {
Inst* old_next = head->next;
head->next = seq_start;
seq_end->next = old_next;
}
}
}

// restore the PHI value to normal
FOREACH_N(i, our_phis, dyn_array_length(phi_vals)) {
PhiVal* v = &phi_vals[i];
Expand All @@ -874,6 +851,10 @@ static void isel_region(Ctx* restrict ctx, TB_Node* bb_start, TB_Node* end, size
printf("\n")
);

if (end->type == TB_SAFEPOINT_NOP) {
SUBMIT(inst_line(end));
}

// implicit goto
TB_Node* succ_n = cfg_next_control(end);

Expand Down
2 changes: 1 addition & 1 deletion tb/src/opt/passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static bool cfg_is_terminator(TB_Node* n) {
}

static bool ctrl_out_as_cproj_but_not_branch(TB_Node* n) {
return n->type == TB_CALL || n->type == TB_SYSCALL || n->type == TB_READ || n->type == TB_WRITE;
return n->type == TB_CALL || n->type == TB_TAILCALL || n->type == TB_SYSCALL || n->type == TB_READ || n->type == TB_WRITE;
}

// includes tuples which have control flow
Expand Down
15 changes: 10 additions & 5 deletions tb/src/x64/x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,8 @@ static void isel(Ctx* restrict ctx, TB_Node* n, const int dst) {
if (n->dt.type != TB_FLOAT) {
int src = input_reg(ctx, n->inputs[1]);

SUBMIT(inst_op_rr(type == TB_NOT ? NOT : NEG, n->dt, dst, src));
SUBMIT(inst_move(n->dt, dst, src));
SUBMIT(inst_op_rr(type == TB_NOT ? NOT : NEG, n->dt, dst, dst));
} else {
if (type == TB_NEG) {
TB_Global* g = NULL;
Expand Down Expand Up @@ -1849,7 +1850,7 @@ static void emit_code(Ctx* restrict ctx, TB_FunctionOutput* restrict func_out, i
// emit prologue
func_out->prologue_length = emit_prologue(ctx);

TB_NodeSafepoint* prev_line = NULL;
Inst* prev_line = NULL;
for (Inst* restrict inst = ctx->first; inst; inst = inst->next) {
size_t in_base = inst->out_count;
size_t inst_table_size = sizeof(inst_table) / sizeof(*inst_table);
Expand Down Expand Up @@ -1891,15 +1892,15 @@ static void emit_code(Ctx* restrict ctx, TB_FunctionOutput* restrict func_out, i
uint32_t pos = GET_CODE_POS(&ctx->emit);

size_t top = dyn_array_length(ctx->locations);
if (prev_line == NULL || !is_same_location(prev_line, loc)) {
if (prev_line == NULL || (prev_line->next != inst && !is_same_location(TB_NODE_GET_EXTRA(prev_line->n), loc))) {
TB_Location l = {
.file = loc->file,
.line = loc->line,
.column = loc->column,
.pos = pos
};
dyn_array_put(ctx->locations, l);
prev_line = loc;
prev_line = inst;
}
continue;
} else if (cat == INST_BYTE || cat == INST_BYTE_EXT) {
Expand Down Expand Up @@ -1980,6 +1981,10 @@ static void emit_code(Ctx* restrict ctx, TB_FunctionOutput* restrict func_out, i
} else if (inst->type == IDIV || inst->type == DIV) {
inst1(e, inst->type, &lhs, dt);
continue;
} else if (cat == INST_UNARY || cat == INST_UNARY_EXT) {
if (!is_value_match(&out, &lhs)) {
inst2_print(e, MOV, &out, &lhs, dt);
}
} else {
if (ternary || inst->type == MOV || inst->type == FP_MOV) {
if (!is_value_match(&out, &lhs)) {
Expand Down Expand Up @@ -2201,7 +2206,7 @@ static void disassemble(TB_CGEmitter* e, Disasm* restrict d, int bb, size_t pos,
}

while (pos < end) {
if (d->loc != d->end && d->loc->pos == pos) {
while (d->loc != d->end && d->loc->pos == pos) {
E(" // %s : line %d\n", d->loc->file->path, d->loc->line);
d->loc++;
}
Expand Down

0 comments on commit 8ee3b0b

Please sign in to comment.