Commit 25013743 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

mips: Calculate the correct stack size for calls.

parent 4801addd
......@@ -26,11 +26,11 @@ void mips_determine_calling_convention(mips_calling_convention_t *const cconv, i
{
/* Handle parameters. */
mips_reg_or_slot_t *params;
size_t gp_param = 0;
size_t const n_params = get_method_n_params(fun_type);
if (n_params != 0) {
params = XMALLOCNZ(mips_reg_or_slot_t, n_params);
size_t gp_param = 0;
for (size_t i = 0; i != n_params; ++i) {
ir_type *const param_type = get_method_param_type(fun_type, i);
ir_mode *const param_mode = get_type_mode(param_type);
......@@ -48,7 +48,9 @@ void mips_determine_calling_convention(mips_calling_convention_t *const cconv, i
} else {
params = 0;
}
cconv->parameters = params;
cconv->param_stack_size = MAX(4, gp_param) * (MIPS_MACHINE_SIZE / 8);
cconv->n_mem_param = gp_param > 4 ? gp_param - 4 : 0;
cconv->parameters = params;
/* Handle results. */
mips_reg_or_slot_t *results;
......
......@@ -15,6 +15,8 @@ typedef struct mips_reg_or_slot_t {
} mips_reg_or_slot_t;
typedef struct mips_calling_convention_t {
unsigned param_stack_size;
unsigned n_mem_param;
mips_reg_or_slot_t *parameters;
mips_reg_or_slot_t *results;
} mips_calling_convention_t;
......
......@@ -390,14 +390,17 @@ static ir_node *gen_Call(ir_node *const node)
++p;
}
unsigned const n_mem_param = n_params > 4 ? n_params - 4 : 0;
ir_node *mems[1 + n_mem_param];
unsigned m = 0;
mips_calling_convention_t cconv;
ir_type *const fun_type = get_Call_type(node);
mips_determine_calling_convention(&cconv, fun_type);
ir_node *mems[1 + cconv.n_mem_param];
unsigned m = 0;
ir_node *const mem = get_Call_mem(node);
mems[m++] = be_transform_node(mem);
int const frame_size = (MIPS_MACHINE_SIZE / 8) * (4 + n_mem_param);
int const frame_size = cconv.param_stack_size;
ir_node *const block = be_transform_nodes_block(node);
ir_node *const sp = get_Start_sp(irg);
ir_node *const call_frame = be_new_IncSP(&mips_registers[REG_SP], block, sp, frame_size, 0);
......@@ -405,10 +408,6 @@ static ir_node *gen_Call(ir_node *const node)
ins[n_mips_jal_stack] = call_frame;
reqs[n_mips_jal_stack] = &mips_single_reg_req_gp_sp;
mips_calling_convention_t cconv;
ir_type *const fun_type = get_Call_type(node);
mips_determine_calling_convention(&cconv, fun_type);
dbg_info *const dbgi = get_irn_dbg_info(node);
for (size_t i = 0; i != n_params; ++i) {
mips_reg_or_slot_t const *const param = &cconv.parameters[i];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment