sparc: Clean up introduce_epilog().
[libfirm] / ir / be / benode.c
index 90149ab..cd6a794 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <stdlib.h>
 
+#include "beirg.h"
 #include "obst.h"
 #include "set.h"
 #include "pmap.h"
@@ -185,9 +186,8 @@ static int Call_cmp_attr(const ir_node *a, const ir_node *b)
        return be_nodes_equal(a, b);
 }
 
-static arch_register_req_t *allocate_reg_req(const ir_node *node)
+static arch_register_req_t *allocate_reg_req(ir_graph *const irg)
 {
-       ir_graph       *irg  = get_irn_irg(node);
        struct obstack *obst = be_get_be_obst(irg);
 
        arch_register_req_t *req = OALLOCZ(obst, arch_register_req_t);
@@ -212,6 +212,8 @@ void be_set_constr_out(ir_node *node, int pos, const arch_register_req_t *req)
  */
 static void init_node_attr(ir_node *node, int n_inputs, int n_outputs)
 {
+       assert(n_outputs >= 0);
+
        ir_graph       *irg  = get_irn_irg(node);
        struct obstack *obst = be_get_be_obst(irg);
        backend_info_t *info = be_get_info(node);
@@ -229,15 +231,10 @@ static void init_node_attr(ir_node *node, int n_inputs, int n_outputs)
        }
        info->in_reqs = in_reqs;
 
-       if (n_outputs >= 0) {
-               int i;
-               info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_outputs);
-               memset(info->out_infos, 0, n_outputs * sizeof(info->out_infos[0]));
-               for (i = 0; i < n_outputs; ++i) {
-                       info->out_infos[i].req = arch_no_register_req;
-               }
-       } else {
-               info->out_infos = NEW_ARR_F(reg_out_info_t, 0);
+       info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_outputs);
+       memset(info->out_infos, 0, n_outputs * sizeof(info->out_infos[0]));
+       for (int i = 0; i < n_outputs; ++i) {
+               info->out_infos[i].req = arch_no_register_req;
        }
 }
 
@@ -341,7 +338,7 @@ ir_node *be_new_Perm(const arch_register_class_t *cls, ir_node *block,
                        be_set_constr_in(irn, i, cls->class_req);
                        be_set_constr_out(irn, i, cls->class_req);
                } else {
-                       arch_register_req_t *new_req = allocate_reg_req(irn);
+                       arch_register_req_t *const new_req = allocate_reg_req(irg);
                        new_req->cls   = cls;
                        new_req->type  = (req->type & arch_register_req_type_aligned);
                        new_req->width = req->width;
@@ -413,7 +410,6 @@ ir_node *be_new_Copy(ir_node *bl, ir_node *op)
 {
        ir_node *in[1];
        ir_node *res;
-       arch_register_req_t *req;
        be_node_attr_t *attr;
        ir_graph *irg = get_Block_irg(bl);
        const arch_register_req_t   *in_req = arch_get_irn_register_req(op);
@@ -427,7 +423,7 @@ ir_node *be_new_Copy(ir_node *bl, ir_node *op)
        be_node_set_reg_class_in(res, 0, cls);
        be_node_set_reg_class_out(res, 0, cls);
 
-       req = allocate_reg_req(res);
+       arch_register_req_t *const req = allocate_reg_req(irg);
        req->cls        = cls;
        req->type       = arch_register_req_type_should_be_same
                | (in_req->type & arch_register_req_type_aligned);
@@ -969,7 +965,6 @@ static const arch_irn_ops_t be_node_irn_ops = {
        be_node_get_frame_entity,
        be_node_set_frame_offset,
        be_node_get_sp_bias,
-       NULL,    /* get_inverse             */
        NULL,    /* get_op_estimated_cost   */
        NULL,    /* possible_memory_operand */
        NULL,    /* perform_memory_operand  */
@@ -978,14 +973,11 @@ static const arch_irn_ops_t be_node_irn_ops = {
 static int get_start_reg_index(ir_graph *irg, const arch_register_t *reg)
 {
        ir_node *start  = get_irg_start(irg);
-       unsigned n_outs = arch_get_irn_n_outs(start);
-       int      i;
 
        /* do a naive linear search... */
-       for (i = 0; i < (int)n_outs; ++i) {
-               const arch_register_req_t *out_req
-                       = arch_get_irn_register_req_out(start, i);
-               if (! (out_req->type & arch_register_req_type_limited))
+       be_foreach_out(start, i) {
+               arch_register_req_t const *const out_req = arch_get_irn_register_req_out(start, i);
+               if (!arch_register_req_is(out_req, limited))
                        continue;
                if (out_req->cls != reg->reg_class)
                        continue;
@@ -1013,24 +1005,6 @@ ir_node *be_get_initial_reg_value(ir_graph *irg, const arch_register_t *reg)
        return new_r_Proj(start, mode, i);
 }
 
-int be_find_return_reg_input(ir_node *ret, const arch_register_t *reg)
-{
-       int arity = get_irn_arity(ret);
-       int i;
-       /* do a naive linear search... */
-       for (i = 0; i < arity; ++i) {
-               const arch_register_req_t *req = arch_get_irn_register_req_in(ret, i);
-               if (! (req->type & arch_register_req_type_limited))
-                       continue;
-               if (req->cls != reg->reg_class)
-                       continue;
-               if (!rbitset_is_set(req->limited, reg->index))
-                       continue;
-               return i;
-       }
-       panic("Tried querying undefined register '%s' at Return", reg->name);
-}
-
 static ir_entity* dummy_get_frame_entity(const ir_node *node)
 {
        (void) node;
@@ -1055,7 +1029,6 @@ static const arch_irn_ops_t dummy_be_irn_ops = {
        dummy_get_frame_entity,
        dummy_set_frame_offset,
        dummy_get_sp_bias,
-       NULL,      /* get_inverse           */
        NULL,      /* get_op_estimated_cost */
        NULL,      /* possible_memory_operand */
        NULL,      /* perform_memory_operand */
@@ -1130,7 +1103,6 @@ static const arch_irn_ops_t phi_irn_ops = {
        dummy_get_frame_entity,
        dummy_set_frame_offset,
        dummy_get_sp_bias,
-       NULL,    /* get_inverse             */
        NULL,    /* get_op_estimated_cost   */
        NULL,    /* possible_memory_operand */
        NULL,    /* perform_memory_operand  */
@@ -1231,20 +1203,8 @@ static void copy_attr(ir_graph *irg, const ir_node *old_node, ir_node *new_node)
 
        memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
 
-       new_info->flags = old_info->flags;
-       if (old_info->out_infos != NULL) {
-               size_t n_outs = ARR_LEN(old_info->out_infos);
-               /* need dyanmic out infos? */
-               if (be_is_Perm(new_node)) {
-                       new_info->out_infos = NEW_ARR_F(reg_out_info_t, n_outs);
-               } else {
-                       new_info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_outs);
-               }
-               memcpy(new_info->out_infos, old_info->out_infos,
-                          n_outs * sizeof(new_info->out_infos[0]));
-       } else {
-               new_info->out_infos = NULL;
-       }
+       new_info->flags     = old_info->flags;
+       new_info->out_infos = old_info->out_infos ? DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos) : NULL;
 
        /* input infos */
        if (old_info->in_reqs != NULL) {