We can't preallocate stack for fastcall function calls

This commit is contained in:
Dmitry Stogov 2023-01-31 16:13:15 +03:00
parent 58ba18bb7d
commit 038b1e43cd
2 changed files with 19 additions and 6 deletions

View File

@ -4748,9 +4748,11 @@ static void ir_preallocate_call_stack(ir_ctx *ctx, ir_backend_data *data)
i += n;
insn += n;
}
if (peak_call_stack_size) {
data->call_stack_size = peak_call_stack_size;
ctx->flags |= IR_PREALLOCATED_STACK;
}
}
static void ir_calc_stack_frame_size(ir_ctx *ctx, ir_backend_data *data)
{

View File

@ -5780,7 +5780,12 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
}
#endif
if (insn->op == IR_CALL && (ctx->flags & IR_PREALLOCATED_STACK)) {
if (insn->op == IR_CALL
&& (ctx->flags & IR_PREALLOCATED_STACK)
#ifdef IR_HAVE_FASTCALL
&& !ir_is_fastcall(ctx, insn) /* fast call functions restore stack pointer */
#endif
) {
// TODO: support for preallocated stack
used_stack = 0;
} else {
@ -7332,7 +7337,11 @@ static void ir_preallocate_call_stack(ir_ctx *ctx, ir_backend_data *data)
for (i = 1, insn = ctx->ir_base + 1; i < ctx->insns_count;) {
if (insn->op == IR_CALL) {
call_stack_size = ir_call_used_stack(ctx, insn);
if (call_stack_size > peak_call_stack_size) {
if (call_stack_size > peak_call_stack_size
#ifdef IR_HAVE_FASTCALL
&& (!ir_is_fastcall(ctx, insn) || !call_stack_size) /* fast call functions restore stack pointer */
#endif
) {
peak_call_stack_size = call_stack_size;
}
}
@ -7341,9 +7350,11 @@ static void ir_preallocate_call_stack(ir_ctx *ctx, ir_backend_data *data)
i += n;
insn += n;
}
if (peak_call_stack_size) {
data->call_stack_size = peak_call_stack_size;
ctx->flags |= IR_PREALLOCATED_STACK;
}
}
static void ir_calc_stack_frame_size(ir_ctx *ctx, ir_backend_data *data)
{