#include "beabi.h"
#include "bearch.h"
#include "benode_t.h"
+#include "belive_t.h"
#include "besched_t.h"
#define MAX(x, y) ((x) > (y) ? (x) : (y))
be_abi_call_t *be_abi_call_new(void)
{
be_abi_call_t *call = malloc(sizeof(call[0]));
- call->flags.val = 0;
- call->params = new_set(cmp_call_arg, 16);
- call->cb = NULL;
+ call->flags.val = 0;
+ call->params = new_set(cmp_call_arg, 16);
+ call->cb = NULL;
return call;
}
static void link_calls_in_block_walker(ir_node *irn, void *data)
{
if(is_Call(irn)) {
- ir_node *bl = get_nodes_block(irn);
- void *save = get_irn_link(bl);
+ be_abi_irg_t *env = data;
+ ir_node *bl = get_nodes_block(irn);
+ void *save = get_irn_link(bl);
+
+ env->call->flags.bits.irg_is_leaf = 0;
set_irn_link(irn, save);
set_irn_link(bl, irn);
{
ir_graph *irg = env->birg->irg;
- irg_walk_graph(irg, firm_clear_link, link_calls_in_block_walker, NULL);
+ env->call->flags.bits.irg_is_leaf = 1;
+ irg_walk_graph(irg, firm_clear_link, link_calls_in_block_walker, env);
irg_block_walk_graph(irg, NULL, process_calls_in_block, env);
}
ir_node *irn = ent->value;
if(reg == sp)
- irn = stack;
+ obstack_ptr_grow(&env->obst, stack);
else if(reg == bp)
- irn = frame;
-
- obstack_ptr_grow(obst, irn);
+ obstack_ptr_grow(&env->obst, frame);
+ else if(arch_register_type_is(reg, callee_save) || arch_register_type_is(reg, ignore))
+ obstack_ptr_grow(obst, irn);
}
}
obstack_free(&obst, NULL);
}
-static void create_barrier(be_abi_irg_t *env, ir_node *bl, ir_node **mem, pmap *regs,
- ir_node *(*barrier_node_constr)(ir_graph *irg, ir_node *bl, int n, ir_node *in[]))
+typedef struct {
+ const arch_register_t *reg;
+ ir_node *irn;
+} reg_node_map_t;
+
+static int cmp_regs(const void *a, const void *b)
{
- pmap_entry *ent;
- ir_node **in, *irn;
- int n = 0;
+ const reg_node_map_t *p = a;
+ const reg_node_map_t *q = b;
+
+ if(p->reg->reg_class == q->reg->reg_class)
+ return p->reg->index - q->reg->index;
+ else
+ return p->reg->reg_class - q->reg->reg_class;
+}
- for(ent = pmap_first(regs), n = 0; ent; ent = pmap_next(regs), ++n) {
- obstack_ptr_grow(&env->obst, ent->value);
+static reg_node_map_t *reg_map_to_arr(struct obstack *obst, pmap *reg_map)
+{
+ pmap_entry *ent;
+ int n = pmap_count(reg_map);
+ int i = 0;
+ reg_node_map_t *res = obstack_alloc(obst, n * sizeof(res[0]));
+
+ pmap_foreach(reg_map, ent) {
+ res[i].reg = ent->key;
+ res[i].irn = ent->value;
+ i++;
}
+ qsort(res, n, sizeof(res[0]), cmp_regs);
+ return res;
+}
+
+static void create_barrier(be_abi_irg_t *env, ir_node *bl, ir_node **mem, pmap *regs, int in_req)
+{
+ ir_graph *irg = env->birg->irg;
+ int i, n;
+ int n_regs = pmap_count(regs);
+ ir_node *irn;
+ ir_node **in;
+ reg_node_map_t *rm;
+
+ rm = reg_map_to_arr(&env->obst, regs);
+
+ for(i = 0, n = 0; i < n_regs; ++i, ++n)
+ obstack_ptr_grow(&env->obst, rm[i].irn);
+
if(mem) {
obstack_ptr_grow(&env->obst, *mem);
n++;
}
in = (ir_node **) obstack_finish(&env->obst);
- irn = barrier_node_constr(env->birg->irg, bl, n, in);
+ irn = be_new_Barrier(env->birg->irg, bl, n, in);
obstack_free(&env->obst, in);
- for(ent = pmap_first(regs), n = 0; ent; ent = pmap_next(regs), ++n) {
+ for(n = 0; n < n_regs; ++n) {
int pos = BE_OUT_POS(n);
- const arch_register_t *reg = ent->key;
+ ir_node *proj;
+ const arch_register_t *reg = rm[n].reg;
+ proj = new_r_Proj(env->birg->irg, bl, irn, get_irn_mode(rm[i].irn), n);
+ if(in_req)
+ be_set_constr_single_reg(irn, n, reg);
be_set_constr_single_reg(irn, pos, reg);
- ent->value = new_r_Proj(env->birg->irg, bl, irn, get_irn_mode(ent->value), n);
- if(arch_register_type_is(reg, ignore)) {
+ be_node_set_reg_class(irn, pos, reg->reg_class);
+ arch_set_irn_register(env->birg->main_env->arch_env, proj, reg);
+ if(arch_register_type_is(reg, ignore))
be_node_set_flags(irn, pos, arch_irn_flags_ignore);
- arch_set_irn_register(env->birg->main_env->arch_env, ent->value, reg);
- }
+
+ pmap_insert(regs, (void *) reg, proj);
}
+
+ if(mem) {
+ *mem = new_r_Proj(env->birg->irg, bl, irn, mode_M, n);
+ }
+
+ obstack_free(&env->obst, rm);
}
/**
ir_node *end = get_irg_end_block(irg);
ir_node *arg_tuple = get_irg_args(irg);
ir_node *no_mem = get_irg_no_mem(irg);
+ ir_node *mem = get_irg_initial_mem(irg);
type *method_type = get_entity_type(get_irg_entity(irg));
pset *dont_save = pset_new_ptr(8);
pmap *reg_proj_map = pmap_create();
int i, j, n;
+ reg_node_map_t *rm;
const arch_register_t *fp_reg;
ir_node *frame_pointer;
ir_node *reg_params_bl;
int nr = get_Proj_proj(irn);
max_arg = MAX(max_arg, nr);
}
- max_arg += 1;
+ max_arg = MAX(max_arg + 1, n_params);
args = obstack_alloc(&env->obst, max_arg * sizeof(args[0]));
memset(args, 0, max_arg * sizeof(args[0]));
used_proj_nr = bitset_alloca(1024);
/* Count the register params and add them to the number of Projs for the RegParams node */
for(i = 0; i < n_params; ++i) {
be_abi_call_arg_t *arg = get_call_arg(call, 0, i);
- if(arg->in_reg) {
+ if(arg->in_reg && args[i]) {
assert(arg->reg != sp && "cannot use stack pointer as parameter register");
assert(i == get_Proj_proj(args[i]));
* Note, that if a register corresponds to an argument, the regs map contains
* the old Proj from start for that argument.
*/
- pmap_foreach(env->regs, ent) {
- arch_register_t *reg = ent->key;
- ir_node *arg_proj = ent->value;
+
+ rm = reg_map_to_arr(&env->obst, env->regs);
+ for(i = 0, n = pmap_count(env->regs); i < n; ++i) {
+ arch_register_t *reg = (void *) rm[i].reg;
+ ir_node *arg_proj = rm[i].irn;
+ ir_node *proj;
ir_mode *mode = arg_proj ? get_irn_mode(arg_proj) : reg->reg_class->mode;
- long nr = arg_proj ? get_Proj_proj(arg_proj) : (long) bitset_next_clear(used_proj_nr, 0);
+ long nr = i;
int pos = BE_OUT_POS((int) nr);
assert(nr >= 0);
bitset_set(used_proj_nr, nr);
- ent->value = new_r_Proj(irg, reg_params_bl, env->reg_params, mode, nr);
+ proj = new_r_Proj(irg, reg_params_bl, env->reg_params, mode, nr);
+ pmap_insert(env->regs, (void *) reg, proj);
be_set_constr_single_reg(env->reg_params, pos, reg);
- arch_set_irn_register(env->birg->main_env->arch_env, ent->value, reg);
+ arch_set_irn_register(env->birg->main_env->arch_env, proj, reg);
/*
* If the register is an ignore register,
DBG((dbg, LEVEL_2, "\tregister save proj #%d -> reg %s\n", nr, reg->name));
}
+ obstack_free(&env->obst, rm);
/* Generate the Prologue */
- fp_reg = call->cb->prologue(env->cb, env->regs);
- create_barrier(env, bl, NULL, env->regs, be_new_Epilogue);
- frame_pointer = pmap_get(env->regs, (void *) fp_reg);
- env->init_sp = pmap_get(env->regs, (void *) sp);
+ fp_reg = call->cb->prologue(env->cb, &mem, env->regs);
+ create_barrier(env, bl, &mem, env->regs, 0);
+
+ env->init_sp = be_abi_reg_map_get(env->regs, sp);
+ env->init_sp = be_new_IncSP(sp, irg, bl, env->init_sp, no_mem, BE_STACK_FRAME_SIZE, be_stack_dir_along);
+ arch_set_irn_register(env->birg->main_env->arch_env, env->init_sp, sp);
+ be_abi_reg_map_set(env->regs, sp, env->init_sp);
+ frame_pointer = be_abi_reg_map_get(env->regs, sp);
set_irg_frame(irg, frame_pointer);
/* Now, introduce stack param nodes for all parameters passed on the stack */
}
assert(repl != NULL);
- exchange(args[i], repl);
+ edges_reroute(args[i], repl, irg);
}
}
ir_node *irn = get_irn_n(end, i);
if(get_irn_opcode(irn) == iro_Return) {
- ir_node *bl = get_nodes_block(irn);
- int n_res = get_Return_n_ress(irn);
- pmap *reg_map = pmap_create();
- ir_node *mem = get_Return_mem(irn);
+ ir_node *bl = get_nodes_block(irn);
+ int n_res = get_Return_n_ress(irn);
+ pmap *reg_map = pmap_create();
+ ir_node *mem = get_Return_mem(irn);
ir_node *ret;
int i, n;
ir_node **in;
- /* Add the stack pointer as an argument to the epilogue. */
pmap_insert(reg_map, (void *) sp, pmap_get(env->regs, (void *) sp));
/* Insert results for Return into the register map. */
}
/* Make the Epilogue node and call the arch's epilogue maker. */
- create_barrier(env, bl, &mem, reg_map, be_new_Epilogue);
+ create_barrier(env, bl, &mem, reg_map, 1);
call->cb->epilogue(env->cb, bl, &mem, reg_map);
obstack_ptr_grow(&env->obst, mem);
arch_env_push_irn_handler(env->birg->main_env->arch_env, &env->irn_handler);
env->call->cb->done(env->cb);
-
+ be_liveness(irg);
return env;
}
be_ssa_constr_set_phis(df, stack_nodes, env->stack_phis);
del_pset(stack_nodes);
+ /* Liveness could have changed due to Phi nodes. */
+ be_liveness(env->birg->irg);
+
/* free these dominance frontiers */
be_free_dominance_frontiers(df);
}
static const void *abi_get_irn_ops(const arch_irn_handler_t *handler, const ir_node *irn)
{
const be_abi_irg_t *abi = get_abi_from_handler(handler);
- return is_Phi(irn) && pset_find_ptr(abi->stack_phis, (void *) irn) != NULL ? &abi->irn_ops : NULL;
+ const void *res = NULL;
+
+ if(is_Phi(irn) && pset_find_ptr(abi->stack_phis, (void *) irn))
+ res = &abi->irn_ops;
+
+ return res;
}
static void be_abi_limited(void *data, bitset_t *bs)
be_abi_irg_t *abi = get_abi_from_ops(self);
const arch_register_t *reg = abi->isa->sp;
- req->cls = reg->reg_class;
- req->type = arch_register_req_type_limited;
- req->limited = be_abi_limited;
- req->limited_env = abi;
+ memset(req, 0, sizeof(req[0]));
+
+ if(pos == BE_OUT_POS(0)) {
+ req->cls = reg->reg_class;
+ req->type = arch_register_req_type_limited;
+ req->limited = be_abi_limited;
+ req->limited_env = abi;
+ }
+
+ else if(pos >= 0 && pos < get_irn_arity(irn)) {
+ req->cls = reg->reg_class;
+ req->type = arch_register_req_type_normal;
+ }
+
return req;
}