Commit 83a74d1a authored by Christoph Mallon's avatar Christoph Mallon
Browse files

template: Enable Return to return any number of results.

parent d267e80a
...@@ -208,7 +208,12 @@ static void emit_Return(const ir_node *node) ...@@ -208,7 +208,12 @@ static void emit_Return(const ir_node *node)
} }
/* return */ /* return */
TEMPLATE_emitf(node, "ret %S0"); unsigned const n_res = get_irn_arity(node) - n_TEMPLATE_Return_first_result;
char const *const fmt =
n_res == 0 ? "ret" :
n_res == 1 ? "ret %S2" :
"ret %S2, ...";
TEMPLATE_emitf(node, fmt);
} }
/** /**
......
...@@ -213,10 +213,10 @@ Start => { ...@@ -213,10 +213,10 @@ Start => {
Return => { Return => {
state => "pinned", state => "pinned",
op_flags => [ "cfopcode" ], op_flags => [ "cfopcode" ],
# This is fixed to 1 result in a gp register arity => "variable",
ins => [ "result", "stack", "mem" ], reg_req => { out => [ "none" ] },
ins => [ "mem", "stack", "first_result" ],
outs => [ "X" ], outs => [ "X" ],
reg_req => { in => [ "gp", "sp", "none", ], out => [ "none" ] },
mode => "mode_X", mode => "mode_X",
}, },
......
...@@ -232,22 +232,32 @@ static ir_node *gen_Start(ir_node *node) ...@@ -232,22 +232,32 @@ static ir_node *gen_Start(ir_node *node)
static ir_node *gen_Return(ir_node *node) static ir_node *gen_Return(ir_node *node)
{ {
dbg_info *dbgi = get_irn_dbg_info(node); int p = n_TEMPLATE_Return_first_result;
ir_node *block = get_nodes_block(node); unsigned const n_res = get_Return_n_ress(node);
ir_node *new_block = be_transform_node(block); unsigned const n_ins = p + n_res;
ir_node *mem = get_Return_mem(node); ir_node **const in = ALLOCAN(ir_node*, n_ins);
ir_node *new_mem = be_transform_node(mem); ir_graph *const irg = get_irn_irg(node);
ir_graph *irg = get_irn_irg(node); struct obstack *const obst = be_get_be_obst(irg);
ir_node *sp = get_irg_frame(irg); arch_register_req_t const **const reqs = OALLOCN(obst, arch_register_req_t const*, n_ins);
in[n_TEMPLATE_Return_mem] = be_transform_node(get_Return_mem(node));
reqs[n_TEMPLATE_Return_mem] = arch_no_register_req;
in[n_TEMPLATE_Return_stack] = get_irg_frame(irg);
reqs[n_TEMPLATE_Return_stack] = TEMPLATE_registers[REG_SP].single_req;
for (unsigned i = 0; i != n_res; ++p, ++i) {
ir_node *const res = get_Return_res(node, i);
in[p] = be_transform_node(res);
reqs[p] = arch_get_irn_register_req(in[p])->cls->class_req;
}
if (get_Return_n_ress(node) != 1) dbg_info *const dbgi = get_irn_dbg_info(node);
panic("TEMPLATE: only return with 1 result supported"); ir_node *const block = be_transform_node(get_nodes_block(node));
ir_node *result = get_Return_res(node, 0); ir_node *const ret = new_bd_TEMPLATE_Return(dbgi, block, n_ins, in);
if (!mode_needs_gp_reg(get_irn_mode(result))) arch_set_irn_register_reqs_in(ret, reqs);
panic("TEMPLATE: return result must have gp mode");
ir_node *new_result = be_transform_node(result);
return new_bd_TEMPLATE_Return(dbgi, new_block, new_result, sp, new_mem); return ret;
} }
static ir_node *gen_Phi(ir_node *node) static ir_node *gen_Phi(ir_node *node)
......
Supports Markdown
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