Fix CALL/1 copying. Fallback to CALL+RETURN when we can't generate code for TAILCALL.

This commit is contained in:
Dmitry Stogov 2022-06-22 17:57:31 +03:00
parent a165c43196
commit ef3ffff81b
3 changed files with 17 additions and 3 deletions

View File

@ -3589,7 +3589,14 @@ static void ir_emit_tailcall(ir_ctx *ctx, ir_ref def, ir_insn *insn)
dasm_State **Dst = &data->dasm_state;
int32_t used_stack = ir_emit_arguments(ctx, def, insn, ctx->regs[def][1]);
IR_ASSERT(used_stack == 0);
if (used_stack != 0) {
ir_emit_call(ctx, def, insn);
if (ctx->flags & IR_FUNCTION) {
ir_emit_epilogue(ctx);
}
ir_emit_return_void(ctx);
return;
}
ir_emit_epilogue(ctx);

View File

@ -269,7 +269,7 @@ static int ir_copy(ir_ctx *new_ctx, ir_ctx *ctx, ir_ref *_next, bool preserve_co
insn = &ctx->ir_base[i];
flags = ir_op_flags[insn->op];
n = ir_operands_count(ctx, insn);
if ((insn->op == IR_MERGE || insn->op == IR_LOOP_BEGIN) && n != 2) {
if ((insn->op == IR_MERGE || insn->op == IR_LOOP_BEGIN || insn->op == IR_CALL || insn->op == IR_TAILCALL) && n != 2) {
new_ref = ir_emit_N(new_ctx, insn->opt, n);
} else if (n <= 3) {
new_ref = ir_emit0(new_ctx, insn->opt);

View File

@ -5406,7 +5406,14 @@ static void ir_emit_tailcall(ir_ctx *ctx, ir_ref def, ir_insn *insn)
int32_t used_stack = ir_emit_arguments(ctx, def, insn, ctx->regs[def][1]);
(void) used_stack;
IR_ASSERT(used_stack == 0);
if (used_stack != 0) {
ir_emit_call(ctx, def, insn);
if (ctx->flags & IR_FUNCTION) {
ir_emit_epilogue(ctx);
}
ir_emit_return_void(ctx);
return;
}
if (ctx->flags & IR_FUNCTION) {
ir_emit_epilogue(ctx);