+
+static const arch_register_req_t *phi_get_irn_reg_req(const void *self, arch_register_req_t *req, const ir_node *irn, int pos)
+{
+ phi_handler_t *phi_handler = get_phi_handler_from_ops(self);
+ pset *visited = NULL;
+
+ get_Phi_reg_req_recursive(phi_handler, req, irn, &visited);
+ /* Set the requirements type to normal, since an operand of the Phi could have had constraints. */
+ req->type = arch_register_req_type_normal;
+ if(visited)
+ del_pset(visited);
+
+ return req;
+}
+
+static void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
+{
+ phi_handler_t *h = get_phi_handler_from_ops(self);
+ pmap_insert(h->regs, irn, (void *) reg);
+}
+
+static const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
+{
+ phi_handler_t *h = get_phi_handler_from_ops(self);
+ return pmap_get(h->regs, (void *) irn);
+}
+
+static arch_irn_class_t phi_classify(const void *_self, const ir_node *irn)
+{
+ return arch_irn_class_normal;
+}
+
+static arch_irn_flags_t phi_get_flags(const void *_self, const ir_node *irn)
+{
+ return arch_irn_flags_none;
+}
+
+static entity *phi_get_frame_entity(const void *_self, const ir_node *irn)
+{
+ return NULL;
+}
+
+static void phi_set_frame_offset(const void *_self, ir_node *irn, int bias)
+{
+}
+
+static const arch_irn_ops_if_t phi_irn_ops = {
+ phi_get_irn_reg_req,
+ phi_set_irn_reg,
+ phi_get_irn_reg,
+ phi_classify,
+ phi_get_flags,
+ phi_get_frame_entity,
+ phi_set_frame_offset
+};
+
+static const arch_irn_handler_t phi_irn_handler = {
+ phi_get_irn_ops
+};
+
+arch_irn_handler_t *be_phi_handler_new(const arch_env_t *arch_env)
+{
+ phi_handler_t *h = xmalloc(sizeof(h[0]));
+ h->irn_handler.get_irn_ops = phi_get_irn_ops;
+ h->irn_ops.impl = &phi_irn_ops;
+ h->arch_env = arch_env;
+ h->regs = pmap_create();
+ return (arch_irn_handler_t *) h;
+}
+
+void be_phi_handler_free(arch_irn_handler_t *handler)
+{
+ phi_handler_t *h = (void *) handler;
+ pmap_destroy(h->regs);
+ free(handler);
+}
+
+const void *be_phi_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn)
+{
+ phi_handler_t *phi_handler = get_phi_handler_from_handler(self);
+ return is_Phi(irn) ? &phi_handler->irn_ops : NULL;
+}
+
+void be_phi_handler_reset(arch_irn_handler_t *handler)
+{
+ phi_handler_t *h = get_phi_handler_from_handler(handler);
+ if(h->regs)
+ pmap_destroy(h->regs);
+ h->regs = pmap_create();
+}
+
+
+/*
+ _ _ _ ____ _
+ | \ | | ___ __| | ___ | _ \ _ _ _ __ ___ _ __ (_)_ __ __ _
+ | \| |/ _ \ / _` |/ _ \ | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
+ | |\ | (_) | (_| | __/ | |_| | |_| | | | | | | |_) | | | | | (_| |
+ |_| \_|\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
+ |_| |___/
+*/
+
+/**
+ * Dumps a register requirement to a file.
+ */
+static void dump_node_req(FILE *f, int idx, be_req_t *req)
+{
+ unsigned i;
+ int did_something = 0;
+ char buf[16];
+ const char *prefix = buf;
+
+ snprintf(buf, sizeof(buf), "#%d ", idx);
+
+ if(req->flags != arch_irn_flags_none) {
+ fprintf(f, "%sflags: ", prefix);
+ prefix = "";
+ for(i = arch_irn_flags_none; i <= log2_ceil(arch_irn_flags_last); ++i) {
+ if(req->flags & (1 << i)) {
+ fprintf(f, "%s%s", prefix, arch_irn_flag_str(1 << i));
+ prefix = "|";
+ }
+ }
+ prefix = ", ";
+ did_something = 1;
+ }
+
+ if(req->req.cls != 0) {
+ char tmp[256];
+ fprintf(f, prefix);
+ arch_register_req_format(tmp, sizeof(tmp), &req->req);
+ fprintf(f, "%s", tmp);
+ did_something = 1;
+ }
+
+ if(did_something)
+ fprintf(f, "\n");
+}
+
+/**
+ * Dumps node register requirements to a file.
+ */
+static void dump_node_reqs(FILE *f, ir_node *irn)
+{
+ int i;
+ be_node_attr_t *a = get_irn_attr(irn);
+
+ fprintf(f, "registers: \n");
+ for(i = 0; i < a->max_reg_data; ++i) {
+ be_reg_data_t *rd = &a->reg_data[i];
+ if(rd->reg)
+ fprintf(f, "#%d: %s\n", i, rd->reg->name);
+ }
+
+ fprintf(f, "in requirements\n");
+ for(i = 0; i < a->max_reg_data; ++i) {
+ dump_node_req(f, i, &a->reg_data[i].in_req);
+ }
+
+ fprintf(f, "\nout requirements\n");
+ for(i = 0; i < a->max_reg_data; ++i) {
+ dump_node_req(f, i, &a->reg_data[i].req);
+ }
+}
+
+/**
+ * ir_op-Operation: dump a be node to file
+ */
+static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
+{
+ be_node_attr_t *at = get_irn_attr(irn);
+
+ assert(is_be_node(irn));
+
+ switch(reason) {
+ case dump_node_opcode_txt:
+ fprintf(f, get_op_name(get_irn_op(irn)));
+ break;
+ case dump_node_mode_txt:
+ fprintf(f, get_mode_name(get_irn_mode(irn)));
+ break;
+ case dump_node_nodeattr_txt:
+ break;
+ case dump_node_info_txt:
+ dump_node_reqs(f, irn);
+
+ if(be_has_frame_entity(irn)) {
+ be_frame_attr_t *a = (be_frame_attr_t *) at;
+ if (a->ent)
+ ir_fprintf(f, "frame entity: %+F offset %x (%d)\n", a->ent, a->offset, a->offset);
+
+ }
+
+ switch(be_get_irn_opcode(irn)) {
+ case beo_Spill:
+ {
+ be_spill_attr_t *a = (be_spill_attr_t *) at;
+ ir_fprintf(f, "spill context: %+F\n", a->spill_ctx);
+ }
+ break;
+
+ case beo_IncSP:
+ {
+ be_stack_attr_t *a = (be_stack_attr_t *) at;
+ fprintf(f, "offset: %u\n", a->offset);
+ fprintf(f, "direction: %s\n", a->dir == be_stack_dir_expand ? "expand" : "shrink");
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * ir_op-Operation:
+ * Copies the backend specific attributes from old node to new node.
+ */
+static void copy_attr(const ir_node *old_node, ir_node *new_node)
+{
+ be_node_attr_t *old_attr = get_irn_attr(old_node);
+ be_node_attr_t *new_attr = get_irn_attr(new_node);
+ int i;
+
+ assert(is_be_node(old_node));
+ assert(is_be_node(new_node));
+
+ memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
+ new_attr->reg_data = NULL;
+
+ if(new_attr->max_reg_data > 0) {
+ new_attr->reg_data = NEW_ARR_D(be_reg_data_t, get_irg_obstack(get_irn_irg(new_node)), new_attr->max_reg_data);
+ memcpy(new_attr->reg_data, old_attr->reg_data, new_attr->max_reg_data * sizeof(be_reg_data_t));
+
+ for(i = 0; i < old_attr->max_reg_data; ++i) {
+ be_req_t *r;
+
+ r = &new_attr->reg_data[i].req;
+ r->req.limited_env = r;
+
+ r = &new_attr->reg_data[i].in_req;
+ r->req.limited_env = r;
+ }
+ }
+}
+
+static const ir_op_ops be_node_op_ops = {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ copy_attr,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ dump_node,
+ NULL
+};