fixed indents
[libfirm] / ir / be / benode.c
index 7721a0c..b8e3090 100644 (file)
@@ -46,6 +46,7 @@ typedef enum _node_kind_t {
        node_kind_reload,
        node_kind_perm,
        node_kind_copy,
+       node_kind_kill,
        node_kind_last
 } node_kind_t;
 
@@ -76,6 +77,22 @@ typedef struct {
                                                   in the spill area. */
 } be_spill_attr_t;
 
+
+ir_node *new_Keep(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
+{
+       static ir_op *keep_op = NULL;
+       ir_node *irn;
+
+       if(!keep_op)
+               keep_op = new_ir_op(get_next_ir_opcode(), "Keep", op_pin_state_pinned,
+                       irop_flag_keep, oparity_variable, 0, 0, NULL);
+
+       irn = new_ir_node(NULL, irg, bl, keep_op, mode_ANY, n, in);
+       keep_alive(irn);
+
+       return irn;
+}
+
 static int templ_pos_Spill[] = {
        0
 };
@@ -88,6 +105,10 @@ static int templ_pos_Copy[] = {
        0, -1
 };
 
+static int templ_pos_Kill[] = {
+       0
+};
+
 static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason);
 
 static const ir_op_ops be_node_ops = {
@@ -140,9 +161,10 @@ static be_node_attr_t *init_node_attr(ir_node *irn,
        for(i = 0; i < n_regs; ++i) {
                be_reg_data_t *rd = attr->reg_data + i;
 
-               rd->reg      = NULL;
-               rd->req.cls  = cls;
-               rd->req.type = arch_register_req_type_normal;
+               memset(&rd->req, 0, sizeof(rd->req));
+               rd->reg         = NULL;
+               rd->req.cls     = cls;
+               rd->req.type    = arch_register_req_type_normal;
        }
 
        return attr;
@@ -170,6 +192,8 @@ static be_op_t *get_op(const be_node_factory_t *fact,
                HASH_PTR(cls) + 7 * kind);
 }
 
+
+
 ir_node *new_Spill(const be_node_factory_t *factory,
                const arch_register_class_t *cls,
                ir_graph *irg, ir_node *bl, ir_node *node_to_spill, ir_node *ctx)
@@ -341,7 +365,7 @@ ir_node *be_reload(const be_node_factory_t *factory,
        ir_node *bl   = get_nodes_block(irn);
        ir_graph *irg = get_irn_irg(bl);
 
-       assert(is_Spill(spill)
+       assert(be_is_Spill(spill)
                        || (is_Phi(spill) && get_irn_mode(spill) == mode_M));
 
        reload = new_Reload(factory, cls, irg, bl, mode, spill);
@@ -351,17 +375,6 @@ ir_node *be_reload(const be_node_factory_t *factory,
        return reload;
 }
 
-static INLINE arch_register_req_t *get_Perm_reqs(ir_node *perm)
-{
-       be_node_attr_t *attr = (be_node_attr_t *) &perm->attr;
-       char *ptr            = (char *) &perm->attr;
-
-       ptr += sizeof(be_node_attr_t);
-       ptr += sizeof(arch_register_t *) * attr->n_regs;
-
-       return (arch_register_req_t *) ptr;
-}
-
 /**
  * If the node is a proj, reset the node to the proj's target and return
  * the proj number.
@@ -387,10 +400,6 @@ static const arch_register_req_t *
 be_node_get_irn_reg_req(const arch_irn_ops_t *_self,
                arch_register_req_t *req, const ir_node *irn, int pos)
 {
-       be_op_t *bo;
-       const be_node_factory_t *factory =
-               container_of(_self, const be_node_factory_t, irn_ops);
-
        /* We cannot get output requirements for tuple nodes. */
        if(get_irn_mode(irn) == mode_T && pos < 0)
                return NULL;
@@ -401,10 +410,9 @@ be_node_get_irn_reg_req(const arch_irn_ops_t *_self,
        if(pos < 0)
                pos = redir_proj((const ir_node **) &irn, pos);
 
-       /* look if the node is one of ours. */
-       bo = pmap_get(factory->irn_op_map, get_irn_op(irn));
-
-       if(bo) {
+       if(is_be_node(irn)) {
+               const be_node_attr_t *a = (const be_node_attr_t *) &irn->attr;
+               const be_op_t *bo       = a->op;
                int i;
 
                for(i = 0; i < bo->n_pos; ++i) {
@@ -413,6 +421,7 @@ be_node_get_irn_reg_req(const arch_irn_ops_t *_self,
                                /* be nodes have no input constraints.
                                   so return normal register requirements. */
                                if(pos >= 0) {
+                                       memset(req, 0, sizeof(req[0]));
                                        req->cls = bo->cls;
                                        req->type = arch_register_req_type_normal;
                                }
@@ -421,10 +430,8 @@ be_node_get_irn_reg_req(const arch_irn_ops_t *_self,
                                 * if an output requirement is requested,
                                 * return the one stored in the node.
                                 */
-                               else {
-                                       be_node_attr_t *attr = (be_node_attr_t *) &irn->attr;
-                                       *req = attr->reg_data[pos].req;
-                               }
+                               else
+                                       *req = a->reg_data[-pos - 1].req;
 
                                return req;
                        }
@@ -437,10 +444,7 @@ be_node_get_irn_reg_req(const arch_irn_ops_t *_self,
 void be_set_Perm_out_req(ir_node *irn, int pos, const arch_register_req_t *req)
 {
        be_node_attr_t *a = get_attr_and_check(irn, node_kind_perm);
-
        assert(pos >= 0 && pos < get_irn_arity(irn) && "position out of range");
-       assert(a->op->kind == node_kind_perm && "node must be a perm node");
-
        a->reg_data[pos].req = *req;
 }
 
@@ -541,16 +545,27 @@ const arch_irn_handler_t *be_node_get_irn_handler(const be_node_factory_t *f)
        return &f->handler;
 }
 
-int is_Spill(const ir_node *irn)
+int be_is_Spill(const ir_node *irn)
 {
        return is_be_kind(irn, node_kind_spill);
 }
 
-int is_Perm(const ir_node *irn)
+int be_is_Reload(const ir_node *irn)
+{
+       return is_be_kind(irn, node_kind_reload);
+}
+
+int be_is_Copy(const ir_node *irn)
+{
+       return is_be_kind(irn, node_kind_copy);
+}
+
+int be_is_Perm(const ir_node *irn)
 {
        return is_be_kind(irn, node_kind_perm);
 }
 
+
 be_node_factory_t *be_node_factory_init(be_node_factory_t *factory, const arch_isa_t *isa)
 {
        int i, j, n;
@@ -639,6 +654,7 @@ static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason)
                        if(bo->kind == node_kind_spill) {
                                be_spill_attr_t *a = (be_spill_attr_t *) at;
                                ir_fprintf(f, "spill context: %+F\n", a->spill_ctx);
+                               ir_fprintf(f, "spill offset: %u\n", a->offset);
                        }
                        break;
        }
@@ -655,13 +671,12 @@ ir_node *insert_Perm_after(const be_main_env_t *env,
        ir_node *bl                 = is_Block(pos) ? pos : get_nodes_block(pos);
        ir_graph *irg               = get_irn_irg(bl);
        pset *live                  = pset_new_ptr_default();
-       firm_dbg_module_t *dbg      = firm_dbg_register("firm.be.node");
+       firm_dbg_module_t *dbg      = firm_dbg_register("be.node");
 
        irn_live_t *li;
        ir_node *curr, *irn, *perm, **nodes;
        int i, n;
 
-       firm_dbg_set_mask(dbg, DBG_LEVEL);
        DBG((dbg, LEVEL_1, "Insert Perm after: %+F\n", pos));