+be_stack_dir_t be_get_IncSP_direction(const ir_node *irn)
+{
+ be_stack_attr_t *a = get_irn_attr(irn);
+ assert(be_is_IncSP(irn));
+ return a->dir;
+}
+
+ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn)
+{
+ ir_node *bl = get_nodes_block(irn);
+ ir_graph *irg = get_irn_irg(bl);
+ ir_node *frame = get_irg_frame(irg);
+ ir_node *spill;
+
+ const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
+ const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
+
+ spill = be_new_Spill(cls, cls_frame, irg, bl, frame, irn);
+ return spill;
+}
+
+ir_node *be_reload(const arch_env_t *arch_env, const arch_register_class_t *cls, ir_node *insert, ir_mode *mode, ir_node *spill)
+{
+ ir_node *reload;
+
+ ir_node *bl = is_Block(insert) ? insert : get_nodes_block(insert);
+ ir_graph *irg = get_irn_irg(bl);
+ ir_node *frame = get_irg_frame(irg);
+ const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
+
+ assert(be_is_Spill(spill) || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
+
+ reload = be_new_Reload(cls, cls_frame, irg, bl, frame, spill, mode);
+
+ if(is_Block(insert)) {
+ insert = sched_skip(insert, 0, sched_skip_cf_predicator, (void *) arch_env);
+ sched_add_after(insert, reload);
+ }
+
+ else
+ sched_add_before(insert, reload);
+
+ return reload;
+}
+
+/*
+ ____ ____
+ | _ \ ___ __ _ | _ \ ___ __ _ ___
+ | |_) / _ \/ _` | | |_) / _ \/ _` / __|
+ | _ < __/ (_| | | _ < __/ (_| \__ \
+ |_| \_\___|\__, | |_| \_\___|\__, |___/
+ |___/ |_|
+
+*/
+
+
+static void *put_out_reg_req(arch_register_req_t *req, const ir_node *irn, int out_pos)
+{
+ const be_node_attr_t *a = get_irn_attr(irn);
+
+ if(out_pos < a->max_reg_data) {
+ memcpy(req, &a->reg_data[out_pos].req, sizeof(req[0]));
+
+ if(be_is_Copy(irn)) {
+ req->type |= arch_register_req_type_should_be_same;
+ req->other_same = be_get_Copy_op(irn);
+ }
+ }
+ else {
+ req->type = arch_register_req_type_none;
+ req->cls = NULL;
+ }
+
+ return req;
+}
+
+static void *put_in_reg_req(arch_register_req_t *req, const ir_node *irn, int pos)
+{
+ const be_node_attr_t *a = get_irn_attr(irn);
+
+ if(pos < get_irn_arity(irn) && pos < a->max_reg_data)
+ memcpy(req, &a->reg_data[pos].in_req, sizeof(req[0]));
+ else {
+ req->type = arch_register_req_type_none;
+ req->cls = NULL;
+ }
+
+ return req;
+}
+
+static const arch_register_req_t *
+be_node_get_irn_reg_req(const void *self, arch_register_req_t *req, const ir_node *irn, int pos)
+{
+ int out_pos = pos;
+
+ if(pos < 0) {
+ if(get_irn_mode(irn) == mode_T)
+ return NULL;
+
+ out_pos = redir_proj((const ir_node **) &irn, pos);
+ assert(is_be_node(irn));
+ return put_out_reg_req(req, irn, out_pos);
+ }
+
+ else {
+ return is_be_node(irn) ? put_in_reg_req(req, irn, pos) : NULL;
+ }
+
+ return req;
+}
+
+const arch_register_t *
+be_node_get_irn_reg(const void *_self, const ir_node *irn)
+{
+ be_reg_data_t *r = retrieve_reg_data(irn);
+ return r ? r->reg : NULL;
+}
+
+static arch_irn_class_t be_node_classify(const void *_self, const ir_node *irn)
+{
+ redir_proj((const ir_node **) &irn, -1);
+
+ switch(be_get_irn_opcode(irn)) {
+#define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b
+ XXX(Spill, spill);
+ XXX(Reload, reload);
+ XXX(Perm, perm);
+ XXX(Copy, copy);
+ XXX(Return, branch);
+ XXX(StackParam, stackparam);
+#undef XXX
+ default:
+ return arch_irn_class_normal;
+ }
+
+ return 0;
+}
+
+static arch_irn_flags_t be_node_get_flags(const void *_self, const ir_node *irn)
+{
+ be_reg_data_t *r = retrieve_reg_data(irn);
+ return r ? r->req.flags : 0;
+}
+
+static entity *be_node_get_frame_entity(const void *self, const ir_node *irn)
+{
+ return be_get_frame_entity(irn);
+}
+
+static void be_node_set_frame_entity(const void *self, ir_node *irn, entity *ent)
+{
+ be_frame_attr_t *a;
+
+ assert(be_has_frame_entity(irn));
+
+ a = get_irn_attr(irn);
+ a->ent = ent;
+}
+
+static void be_node_set_frame_offset(const void *self, ir_node *irn, int offset)
+{
+ if(be_has_frame_entity(irn)) {
+ be_frame_attr_t *a = get_irn_attr(irn);
+ a->offset = offset;
+ }
+}
+
+/*
+ ___ ____ _ _ _ _ _ _
+ |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
+ | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
+ | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
+ |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
+
+*/
+
+static const arch_irn_ops_if_t be_node_irn_ops_if = {
+ be_node_get_irn_reg_req,
+ be_node_set_irn_reg,
+ be_node_get_irn_reg,
+ be_node_classify,
+ be_node_get_flags,
+ be_node_get_frame_entity,
+ be_node_set_frame_entity,
+ be_node_set_frame_offset,
+ NULL, /* get_inverse */
+ NULL, /* get_op_estimated_cost */
+ NULL, /* possible_memory_operand */
+ NULL, /* perform_memory_operand */
+};
+
+static const arch_irn_ops_t be_node_irn_ops = {
+ &be_node_irn_ops_if
+};
+
+const void *be_node_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
+{
+ redir_proj((const ir_node **) &irn, -1);
+ return is_be_node(irn) ? &be_node_irn_ops : NULL;
+}
+
+const arch_irn_handler_t be_node_irn_handler = {
+ be_node_get_irn_ops
+};
+
+/*
+ ____ _ _ ___ ____ _ _ _ _ _ _
+ | _ \| |__ (_) |_ _| _ \| \ | | | | | | __ _ _ __ __| | | ___ _ __
+ | |_) | '_ \| | | || |_) | \| | | |_| |/ _` | '_ \ / _` | |/ _ \ '__|
+ | __/| | | | | | || _ <| |\ | | _ | (_| | | | | (_| | | __/ |
+ |_| |_| |_|_| |___|_| \_\_| \_| |_| |_|\__,_|_| |_|\__,_|_|\___|_|
+
+*/
+
+typedef struct {
+ arch_irn_handler_t irn_handler;
+ arch_irn_ops_t irn_ops;
+ const arch_env_t *arch_env;
+ pmap *regs;
+} phi_handler_t;
+
+#define get_phi_handler_from_handler(h) container_of(h, phi_handler_t, irn_handler)
+#define get_phi_handler_from_ops(h) container_of(h, phi_handler_t, irn_ops)
+
+static const void *phi_get_irn_ops(const arch_irn_handler_t *handler, const ir_node *irn)
+{
+ const phi_handler_t *h = get_phi_handler_from_handler(handler);
+ return is_Phi(irn) && mode_is_datab(get_irn_mode(irn)) ? &h->irn_ops : NULL;
+}
+
+/**
+ * Get register class of a Phi.
+ *
+ */
+static const arch_register_req_t *get_Phi_reg_req_recursive(const phi_handler_t *h, arch_register_req_t *req, const ir_node *phi, pset **visited)
+{
+ int n = get_irn_arity(phi);
+ ir_node *op;
+ int i;
+
+ if(*visited && pset_find_ptr(*visited, phi))
+ return NULL;
+
+ for(i = 0; i < n; ++i) {
+ op = get_irn_n(phi, i);
+ if(!is_Phi(op))
+ return arch_get_register_req(h->arch_env, req, op, BE_OUT_POS(0));
+ }