be_abi_put_ignore_regs returns now number of ignore registers as unsigned
[libfirm] / ir / be / benode.c
index 706ef5d..1a19f1d 100644 (file)
@@ -1,17 +1,34 @@
-/**
- * @file   benode.c
- * @date   17.05.2005
- * @author Sebastian Hack
+/*
+ * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
  *
- * Backend node support.
+ * This file is part of libFirm.
  *
- * This file provides Perm, Copy, Spill and Reload nodes.
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
  *
- * Copyright (C) 2005-2006 Universitaet Karlsruhe
- * Released under the GPL
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+/**
+ * @file
+ * @brief       Backend node support for generic backend nodes.
+ * @author      Sebastian Hack
+ * @date        17.05.2005
+ * @version     $Id$
+ *
+ * Backend node support for generic backend nodes.
+ * This file provides Perm, Copy, Spill and Reload nodes.
  */
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <stdlib.h>
@@ -138,7 +155,7 @@ static const ir_op_ops be_node_op_ops;
  *
  * @return zero if both attributes are identically
  */
-static int cmp_node_attr(be_node_attr_t *a, be_node_attr_t *b) {
+static int _node_cmp_attr(be_node_attr_t *a, be_node_attr_t *b) {
        int i, len;
 
        if(ARR_LEN(a->reg_data) != ARR_LEN(b->reg_data))
@@ -155,6 +172,13 @@ static int cmp_node_attr(be_node_attr_t *a, be_node_attr_t *b) {
        return 0;
 }
 
+static int node_cmp_attr(ir_node *a, ir_node *b) {
+       be_node_attr_t *a_attr = get_irn_attr(a);
+       be_node_attr_t *b_attr = get_irn_attr(b);
+
+       return _node_cmp_attr(a_attr, b_attr);
+}
+
 /**
  * Compare the attributes of two FrameAddr nodes.
  *
@@ -164,9 +188,41 @@ static int FrameAddr_cmp_attr(ir_node *a, ir_node *b) {
        be_frame_attr_t *a_attr = get_irn_attr(a);
        be_frame_attr_t *b_attr = get_irn_attr(b);
 
-       if (a_attr->ent == b_attr->ent && a_attr->offset == b_attr->offset)
-               return cmp_node_attr(&a_attr->node_attr, &b_attr->node_attr);
-       return 1;
+       if (a_attr->ent != b_attr->ent || a_attr->offset != b_attr->offset)
+               return 1;
+
+       return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
+}
+
+static int Return_cmp_attr(ir_node *a, ir_node *b) {
+       be_return_attr_t *a_attr = get_irn_attr(a);
+       be_return_attr_t *b_attr = get_irn_attr(b);
+
+       if (a_attr->num_ret_vals != b_attr->num_ret_vals)
+               return 1;
+
+       return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
+}
+
+static int Stack_cmp_attr(ir_node *a, ir_node *b) {
+       be_stack_attr_t *a_attr = get_irn_attr(a);
+       be_stack_attr_t *b_attr = get_irn_attr(b);
+
+       if (a_attr->offset != b_attr->offset)
+               return 1;
+
+       return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
+}
+
+static int Call_cmp_attr(ir_node *a, ir_node *b) {
+       be_call_attr_t *a_attr = get_irn_attr(a);
+       be_call_attr_t *b_attr = get_irn_attr(b);
+
+       if (a_attr->ent != b_attr->ent ||
+                       a_attr->call_tp != b_attr->call_tp)
+               return 1;
+
+       return _node_cmp_attr((be_node_attr_t*) a_attr, (be_node_attr_t*) b_attr);
 }
 
 static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
@@ -190,7 +246,7 @@ static INLINE be_req_t *get_be_req(const ir_node *node, int pos)
        return pos < 0 ? &rd->req : &rd->in_req;
 }
 
-static inline arch_register_req_t *get_req(const ir_node *node, int pos)
+static INLINE arch_register_req_t *get_req(const ir_node *node, int pos)
 {
        be_req_t *bereq = get_be_req(node, pos);
        return &bereq->req;
@@ -228,26 +284,43 @@ void be_node_init(void) {
        op_be_Barrier    = new_ir_op(beo_base + beo_Barrier,    "be_Barrier",    op_pin_state_pinned,     N, oparity_dynamic,  0, sizeof(be_node_attr_t),    &be_node_op_ops);
 
        set_op_tag(op_be_Spill,      &be_node_tag);
+       op_be_Spill->ops.node_cmp_attr = FrameAddr_cmp_attr;
        set_op_tag(op_be_Reload,     &be_node_tag);
+       op_be_Reload->ops.node_cmp_attr = FrameAddr_cmp_attr;
        set_op_tag(op_be_Perm,       &be_node_tag);
+       op_be_Perm->ops.node_cmp_attr = node_cmp_attr;
        set_op_tag(op_be_MemPerm,    &be_node_tag);
+       op_be_MemPerm->ops.node_cmp_attr = node_cmp_attr;
        set_op_tag(op_be_Copy,       &be_node_tag);
+       op_be_Copy->ops.node_cmp_attr = node_cmp_attr;
        set_op_tag(op_be_Keep,       &be_node_tag);
+       op_be_Keep->ops.node_cmp_attr = node_cmp_attr;
        set_op_tag(op_be_CopyKeep,   &be_node_tag);
+       op_be_CopyKeep->ops.node_cmp_attr = node_cmp_attr;
        set_op_tag(op_be_Call,       &be_node_tag);
+       op_be_Call->ops.node_cmp_attr = Call_cmp_attr;
        set_op_tag(op_be_Return,     &be_node_tag);
+       op_be_Return->ops.node_cmp_attr = Return_cmp_attr;
        set_op_tag(op_be_AddSP,      &be_node_tag);
+       op_be_AddSP->ops.node_cmp_attr = node_cmp_attr;
        set_op_tag(op_be_SubSP,      &be_node_tag);
+       op_be_SubSP->ops.node_cmp_attr = node_cmp_attr;
        set_op_tag(op_be_SetSP,      &be_node_tag);
+       op_be_SetSP->ops.node_cmp_attr = Stack_cmp_attr;
        set_op_tag(op_be_IncSP,      &be_node_tag);
+       op_be_IncSP->ops.node_cmp_attr = Stack_cmp_attr;
        set_op_tag(op_be_RegParams,  &be_node_tag);
+       op_be_RegParams->ops.node_cmp_attr = node_cmp_attr;
        set_op_tag(op_be_StackParam, &be_node_tag);
+       op_be_StackParam->ops.node_cmp_attr = FrameAddr_cmp_attr;
        set_op_tag(op_be_FrameLoad,  &be_node_tag);
+       op_be_FrameLoad->ops.node_cmp_attr = FrameAddr_cmp_attr;
        set_op_tag(op_be_FrameStore, &be_node_tag);
+       op_be_FrameStore->ops.node_cmp_attr = FrameAddr_cmp_attr;
        set_op_tag(op_be_FrameAddr,  &be_node_tag);
-       set_op_tag(op_be_Barrier,    &be_node_tag);
-
        op_be_FrameAddr->ops.node_cmp_attr = FrameAddr_cmp_attr;
+       set_op_tag(op_be_Barrier,    &be_node_tag);
+       op_be_Barrier->ops.node_cmp_attr = node_cmp_attr;
 }
 
 /**
@@ -1128,7 +1201,11 @@ be_node_get_irn_reg_req(const void *self, const ir_node *irn, int pos)
 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);
+       be_reg_data_t *r;
+
+       if (get_irn_mode(irn) == mode_T)
+               return NULL;
+       r = retrieve_reg_data(irn);
        return r->reg;
 }
 
@@ -1245,7 +1322,8 @@ const arch_irn_handler_t be_node_irn_handler = {
 
 typedef struct {
        const arch_register_t *reg;
-       arch_register_req_t req;
+       arch_register_req_t    req;
+       arch_irn_flags_t       flags;
 } phi_attr_t;
 
 typedef struct {
@@ -1258,14 +1336,20 @@ typedef struct {
 #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)
+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;
+       const phi_handler_t *h;
+       if(!is_Phi(irn) || !mode_is_datab(get_irn_mode(irn)))
+               return NULL;
+
+       h = get_phi_handler_from_handler(handler);
+       return &h->irn_ops;
 }
 
-static INLINE phi_attr_t *get_Phi_attr(const phi_handler_t *handler,
-                                       const ir_node *phi)
+static INLINE
+phi_attr_t *get_Phi_attr(const phi_handler_t *handler, const ir_node *phi)
 {
        phi_attr_t *attr = pmap_get(handler->phi_attrs, (void*) phi);
        if(attr == NULL) {
@@ -1363,49 +1447,75 @@ void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
        memcpy(&attr->req, req, sizeof(req[0]));
 }
 
-static void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
+void be_set_phi_flags(const arch_env_t *arch_env, ir_node *node,
+                      arch_irn_flags_t flags)
+{
+       const arch_irn_ops_t *ops = arch_get_irn_ops(arch_env, node);
+       const phi_handler_t *handler = get_phi_handler_from_ops(ops);
+       phi_attr_t *attr;
+
+       assert(mode_is_datab(get_irn_mode(node)));
+
+       attr = get_Phi_attr(handler, node);
+       attr->flags = flags;
+}
+
+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);
        phi_attr_t *attr = get_Phi_attr(h, irn);
        attr->reg = reg;
 }
 
-static const arch_register_t *phi_get_irn_reg(const void *self, const ir_node *irn)
+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);
        phi_attr_t *attr = get_Phi_attr(h, irn);
        return attr->reg;
 }
 
-static arch_irn_class_t phi_classify(const void *_self, const ir_node *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)
+static
+arch_irn_flags_t phi_get_flags(const void *self, const ir_node *irn)
 {
-       return arch_irn_flags_none;
+       phi_handler_t *h = get_phi_handler_from_ops(self);
+       phi_attr_t *attr = get_Phi_attr(h, irn);
+       return attr->flags;
 }
 
-static ir_entity *phi_get_frame_entity(const void *_self, const ir_node *irn)
+static
+ir_entity *phi_get_frame_entity(const void *_self, const ir_node *irn)
 {
        return NULL;
 }
 
-static void phi_set_frame_entity(const void *_self, ir_node *irn, ir_entity *ent)
+static
+void phi_set_frame_entity(const void *_self, ir_node *irn, ir_entity *ent)
 {
+       assert(0);
 }
 
-static void phi_set_frame_offset(const void *_self, ir_node *irn, int bias)
+static
+void phi_set_frame_offset(const void *_self, ir_node *irn, int bias)
 {
+       assert(0);
 }
 
-static int phi_get_sp_bias(const void* self, const ir_node *irn)
+static
+int phi_get_sp_bias(const void* self, const ir_node *irn)
 {
        return 0;
 }
 
-static const arch_irn_ops_if_t phi_irn_ops = {
+static
+const arch_irn_ops_if_t phi_irn_ops = {
        phi_get_irn_reg_req,
        phi_set_irn_reg,
        phi_get_irn_reg,
@@ -1421,10 +1531,6 @@ static const arch_irn_ops_if_t phi_irn_ops = {
        NULL,    /* perform_memory_operand  */
 };
 
-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]));
@@ -1442,12 +1548,6 @@ void be_phi_handler_free(arch_irn_handler_t *handler)
        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);