Commit 60c29ab0 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

be: Use one common function to copy the node attributes in the backend.

All backends had identical implementations.
Now rematerialization works out of the box for new backends.
parent baeded4f
......@@ -82,24 +82,5 @@ static int TEMPLATE_attrs_equal(const ir_node *a, const ir_node *b)
&& attr_a->entity == attr_b->entity;
}
static void TEMPLATE_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
struct obstack *obst = get_irg_obstack(irg);
const void *attr_old = get_irn_generic_attr_const(old_node);
void *attr_new = get_irn_generic_attr(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
/* copy the attributes */
memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
/* copy out flags */
new_info->flags = old_info->flags;
new_info->out_infos =
DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
new_info->in_reqs = old_info->in_reqs;
}
/* Include the generated constructor functions */
#include "gen_TEMPLATE_new_nodes.c.inl"
......@@ -71,7 +71,6 @@ $mode_fp = "mode_F"; # mode used by floatingpoint registers
);
$default_attr_type = "TEMPLATE_attr_t";
$default_copy_attr = "TEMPLATE_copy_attr";
my $binop = {
irn_flags => [ "rematerializable" ],
......
......@@ -244,24 +244,5 @@ static int amd64_switch_jmp_attrs_equal(const ir_node *const a,
return amd64_attrs_equal(a, b) && attr_a->table == attr_b->table;
}
static void amd64_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
struct obstack *obst = get_irg_obstack(irg);
const amd64_attr_t *attr_old = get_amd64_attr_const(old_node);
amd64_attr_t *attr_new = get_amd64_attr(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
/* copy the attributes */
memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
/* copy out flags */
new_info->flags = old_info->flags;
new_info->out_infos =
DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
new_info->in_reqs = old_info->in_reqs;
}
/* Include the generated constructor functions */
#include "gen_amd64_new_nodes.c.inl"
......@@ -53,8 +53,6 @@ $mode_xmm = "amd64_mode_xmm";
commutative => "(arch_irn_flags_t)amd64_arch_irn_flag_commutative_binop",
);
$default_copy_attr = "amd64_copy_attr";
%init_attr = (
amd64_attr_t =>
"init_amd64_attributes(res, irn_flags, in_reqs, n_res, op_mode);",
......
......@@ -441,24 +441,5 @@ static int arm_farith_attrs_equal(const ir_node *a, const ir_node *b)
return arm_attrs_equal(a, b) && attr_a->mode == attr_b->mode;
}
/** copies the ARM attributes of a node. */
static void arm_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
struct obstack *obst = get_irg_obstack(irg);
const arm_attr_t *attr_old = get_arm_attr_const(old_node);
arm_attr_t *attr_new = get_arm_attr(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
/* copy the attributes */
memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
/* copy out flags */
new_info->flags = old_info->flags;
new_info->out_infos = DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
new_info->in_reqs = old_info->in_reqs;
}
/* Include the generated constructor functions */
#include "gen_arm_new_nodes.c.inl"
......@@ -45,7 +45,6 @@ $mode_fp = "mode_F";
);
$default_attr_type = "arm_attr_t";
$default_copy_attr = "arm_copy_attr";
%init_attr = (
arm_attr_t =>
......
......@@ -607,15 +607,8 @@ static void dump_node(FILE *f, const ir_node *irn, dump_reason_t reason)
}
}
/**
* ir_op-Operation:
* Copies the backend specific attributes from old node to new node.
*/
static void copy_attr(ir_graph *const irg, ir_node const *const old_node, ir_node *const new_node)
void be_copy_attr(ir_graph *const irg, ir_node const *const old_node, ir_node *const new_node)
{
assert(is_be_node(old_node));
assert(is_be_node(new_node));
void const *const old_attr = get_irn_generic_attr_const(old_node);
void *const new_attr = get_irn_generic_attr(new_node);
memcpy(new_attr, old_attr, get_op_attr_size(get_irn_op(old_node)));
......@@ -640,7 +633,7 @@ static ir_op *new_be_op(unsigned code, const char *name, op_pin_state p,
{
ir_op *res = new_ir_op(code, name, p, flags, opar, 0, attr_size);
set_op_dump(res, dump_node);
set_op_copy_attr(res, copy_attr);
set_op_copy_attr(res, be_copy_attr);
set_op_tag(res, be_op_tag);
return res;
}
......
......@@ -238,4 +238,9 @@ static inline be_asm_attr_t const *get_be_asm_attr_const(ir_node const *const as
return (be_asm_attr_t const*)get_irn_generic_attr_const(asmn);
}
/**
* Copies the backend specific attributes from old node to new node.
*/
void be_copy_attr(ir_graph *irg, ir_node const *old_node, ir_node *new_node);
#endif
......@@ -858,26 +858,6 @@ static int ia32_return_attrs_equal(const ir_node *a, const ir_node *b)
&& attr_a->pop == attr_b->pop;
}
/* copies the ia32 attributes */
static void ia32_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
struct obstack *obst = get_irg_obstack(irg);
const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
ia32_attr_t *attr_new = get_ia32_attr(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
/* copy the attributes */
memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
/* copy out flags */
new_info->out_infos =
DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
new_info->in_reqs = old_info->in_reqs;
new_info->flags = old_info->flags;
}
static void ia32_init_op(ir_op *op, unsigned latency)
{
ia32_op_attr_t *attr = OALLOCZ(&opcodes_obst, ia32_op_attr_t);
......
......@@ -67,7 +67,6 @@ $mode_fpcw = "ia32_mode_fpcw";
);
$default_attr_type = "ia32_attr_t";
$default_copy_attr = "ia32_copy_attr";
sub ia32_custom_init_attr {
my ($constr, $node, $name) = @_;
......
......@@ -18,10 +18,8 @@ my $target_dir = $ARGV[1];
our $arch;
our %nodes;
our $default_attr_type;
our $default_copy_attr;
our %init_attr;
our $custom_init_attr_func;
our %copy_attr;
our %reg_classes;
our %custom_irn_flags;
......@@ -503,15 +501,9 @@ EOF
$obst_new_irop .= "\tset_op_attrs_equal(op, $attrs_equal_func);\n";
}
my $copy_attr_func = $copy_attr{$attr_type};
if (!defined($copy_attr_func)) {
# don't set a copy_attr function if the node has no additional attributes.
if ($attr_type ne "") {
$copy_attr_func = $default_copy_attr;
}
}
if (defined($copy_attr_func)) {
$obst_new_irop .= "\tset_op_copy_attr(op, $copy_attr_func);\n";
# don't set a copy_attr function if the node has no additional attributes.
if ($attr_type ne "") {
$obst_new_irop .= "\tset_op_copy_attr(op, be_copy_attr);\n";
}
# determine hash function
......@@ -548,6 +540,7 @@ $d //= '\0';
open(my $out_c, ">", $target_c) // die("Fatal error: Could not open $target_c, reason: $!\n");
print $out_c <<EOF;
#include "benode.h"
#include "gen_${arch}_regalloc_if.h"
#include "fourcc.h"
#include "irgopt.h"
......
......@@ -262,27 +262,6 @@ static void init_sparc_call_attributes(ir_node *node, ir_type *call_type)
attr->call_type = call_type;
}
/**
* copies sparc attributes of node
*/
static void sparc_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
struct obstack *obst = get_irg_obstack(irg);
const sparc_attr_t *attr_old = get_sparc_attr_const(old_node);
sparc_attr_t *attr_new = get_sparc_attr(new_node);
backend_info_t *old_info = be_get_info(old_node);
backend_info_t *new_info = be_get_info(new_node);
/* copy the attributes */
memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
/* copy out flags */
new_info->flags = old_info->flags;
new_info->out_infos =
DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
new_info->in_reqs = old_info->in_reqs;
}
static int sparc_attrs_equal(const ir_node *a, const ir_node *b)
{
const sparc_attr_t *attr_a = get_sparc_attr_const(a);
......
......@@ -99,7 +99,6 @@ $mode_fp4 = "sparc_mode_Q";
);
$default_attr_type = "sparc_attr_t";
$default_copy_attr = "sparc_copy_attr";
%init_attr = (
sparc_attr_t => "be_info_init_irn(res, irn_flags, in_reqs, n_res);",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment