-/**
- * @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>
*
* @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))
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.
*
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)
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;
op_be_Keep = new_ir_op(beo_base + beo_Keep, "be_Keep", op_pin_state_pinned, K, oparity_dynamic, 0, sizeof(be_node_attr_t), &be_node_op_ops);
op_be_CopyKeep = new_ir_op(beo_base + beo_CopyKeep, "be_CopyKeep", op_pin_state_pinned, K, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
op_be_Call = new_ir_op(beo_base + beo_Call, "be_Call", op_pin_state_pinned, F, oparity_variable, 0, sizeof(be_call_attr_t), &be_node_op_ops);
- op_be_Return = new_ir_op(beo_base + beo_Return, "be_Return", op_pin_state_pinned, X, oparity_variable, 0, sizeof(be_return_attr_t), &be_node_op_ops);
+ op_be_Return = new_ir_op(beo_base + beo_Return, "be_Return", op_pin_state_pinned, X, oparity_dynamic, 0, sizeof(be_return_attr_t), &be_node_op_ops);
op_be_AddSP = new_ir_op(beo_base + beo_AddSP, "be_AddSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
op_be_SubSP = new_ir_op(beo_base + beo_SubSP, "be_SubSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
op_be_SetSP = new_ir_op(beo_base + beo_SetSP, "be_SetSP", op_pin_state_pinned, N, oparity_binary, 0, sizeof(be_stack_attr_t), &be_node_op_ops);
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;
}
/**
}
/* Construct a new be_Return. */
-ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *bl, int n_res, int n, ir_node *in[])
+ir_node *be_new_Return(dbg_info *dbg, ir_graph *irg, ir_node *block, int n_res,
+ int n, ir_node *in[])
{
be_return_attr_t *a;
- ir_node *irn = new_ir_node(dbg, irg, bl, op_be_Return, mode_X, n, in);
- init_node_attr(irn, n);
- a = get_irn_attr(irn);
+ ir_node *res;
+ int i;
+
+ res = new_ir_node(dbg, irg, block, op_be_Return, mode_X, -1, NULL);
+ init_node_attr(res, -1);
+ for(i = 0; i < n; ++i) {
+ add_irn_n(res, in[i]);
+ add_register_req(res);
+ }
+
+ a = get_irn_attr(res);
a->num_ret_vals = n_res;
- return irn;
+ return res;
}
/* Returns the number of real returns values */
return a->num_ret_vals;
}
+int be_Return_append_node(ir_node *ret, ir_node *node)
+{
+ int pos;
+
+ pos = add_irn_n(ret, node);
+ add_register_req(ret);
+
+ return pos;
+}
+
ir_node *be_new_IncSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, int offset)
{
be_stack_attr_t *a;
be_node_set_reg_class(irn, 0, cls_frame);
be_node_set_reg_class(irn, OUT_POS(0), cls);
+ be_node_set_flags(irn, OUT_POS(0), arch_irn_flags_rematerializable);
+
return irn;
}
assert(be_is_RegParams(regparams));
proj = new_r_Proj(irg, block, regparams, mode, n);
add_register_req(regparams);
- be_set_constr_single_reg(regparams, n, reg);
+ be_set_constr_single_reg(regparams, BE_OUT_POS(n), reg);
arch_set_irn_register(arch_env, proj, reg);
/* TODO decide, whether we need to set ignore/modify sp flags here? */
ir_node *block = get_nodes_block(barrier);
ir_mode *mode = get_irn_mode(node);
int n = add_irn_n(barrier, node);
+
ir_node *proj = new_r_Proj(irg, block, barrier, mode, n);
add_register_req(barrier);
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;
}
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 {
#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) {
return &attr->req;
}
-static void phi_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
+void be_set_phi_reg_req(const arch_env_t *arch_env, ir_node *node,
+ const arch_register_req_t *req)
+{
+ 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);
+ memcpy(&attr->req, req, sizeof(req[0]));
+}
+
+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,
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]));
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);