Avoid memory allocation for empty arguments list

This commit is contained in:
Dmitry Stogov 2022-06-21 13:04:33 +03:00
parent 4060f9ca23
commit cb64f578eb
2 changed files with 10 additions and 2 deletions

View File

@ -3347,6 +3347,11 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
bool has_mem_const_args = 0;
ir_reg tmp_fp_reg = IR_REG_FP_LAST; /* Temporary register for FP loads and swap */
n = ir_input_edges_count(ctx, insn);
if (n < 3) {
return 0;
}
if (insn->op == IR_CALL && (ctx->flags & IR_PREALLOCATED_STACK)) {
// TODO: support for preallocated stack
used_stack = 0;
@ -3360,7 +3365,6 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
/* 1. move all arguments that should be passed through stack
* and collect arguments that should be passed through registers */
n = ir_input_edges_count(ctx, insn);
copies = ir_mem_malloc((n - 2) * sizeof(ir_copy));
for (j = 3; j <= n; j++) {
arg = insn->ops[j];

View File

@ -4975,6 +4975,11 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
bool has_mem_const_args = 0;
ir_reg tmp_fp_reg = IR_REG_FP_LAST; /* Temporary register for FP loads and swap */
n = ir_input_edges_count(ctx, insn);
if (n < 3) {
return 0;
}
if (insn->op == IR_CALL && (ctx->flags & IR_PREALLOCATED_STACK)) {
// TODO: support for preallocated stack
used_stack = 0;
@ -4988,7 +4993,6 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
/* 1. move all arguments that should be passed through stack
* and collect arguments that should be passed through registers */
n = ir_input_edges_count(ctx, insn);
copies = ir_mem_malloc((n - 2) * sizeof(ir_copy));
for (j = 3; j <= n; j++) {
arg = insn->ops[j];