Commit 26582949 authored by Michael Beck's avatar Michael Beck
Browse files

made copy_attrs an ir_op operation

the additional registered data is copied as well

[r4628]
parent 988067f5
......@@ -245,7 +245,7 @@ copy_node (ir_node *n, void *env) {
/* Copy the attributes. These might point to additional data. If this
was allocated on the old obstack the pointers now are dangling. This
frees e.g. the memory of the graph_arr allocated in new_immBlock. */
copy_attrs(n, nn);
copy_node_attr(n, nn);
new_backedge_info(nn);
set_new_node(n, nn);
......@@ -357,7 +357,7 @@ copy_graph (int copy_node_nr) {
-1,
NULL);
/* Copy the attributes. Well, there might be some in the future... */
copy_attrs(oe, ne);
copy_node_attr(oe, ne);
set_new_node(oe, ne);
/* copy the Bad node */
......
......@@ -97,23 +97,22 @@ static int forbid_new_data = 0;
* The amount of additional space for custom data to be allocated upon
* creating a new node.
*/
static size_t additional_node_data_size = 0;
unsigned firm_add_node_size = 0;
size_t register_additional_node_data(size_t size)
{
assert(!forbid_new_data && "Too late to register additional node data");
/* register new space for every node */
unsigned register_additional_node_data(unsigned size) {
assert(!forbid_new_data && "Too late to register additional node data");
if(forbid_new_data)
return 0;
if (forbid_new_data)
return 0;
return additional_node_data_size += size;
return firm_add_node_size += size;
}
void
init_irnode (void)
{
init_irnode(void) {
/* Forbid the addition of new data to an ir node. */
forbid_new_data = 1;
}
......@@ -129,13 +128,13 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo
int arity, ir_node **in)
{
ir_node *res;
size_t node_size = offsetof(ir_node, attr) + op->attr_size + additional_node_data_size;
size_t node_size = offsetof(ir_node, attr) + op->attr_size + firm_add_node_size;
char *p;
assert(irg && op && mode);
p = obstack_alloc (irg->obst, node_size);
memset(p, 0, node_size);
res = (ir_node *) (p + additional_node_data_size);
res = (ir_node *) (p + firm_add_node_size);
res->kind = k_ir_node;
res->op = op;
......@@ -161,15 +160,6 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo
return res;
}
/* Copies all attributes stored in the old node to the new node.
Assumes both have the same opcode and sufficient size. */
void
copy_attrs (const ir_node *old_node, ir_node *new_node) {
assert(get_irn_op(old_node) == get_irn_op(new_node));
memcpy(&new_node->attr, &old_node->attr, get_op_attr_size(get_irn_op(old_node)));
if (get_irn_op(new_node) == op_Call) remove_Call_callee_arr(new_node);
}
/*-- getting some parameters from ir_nodes --*/
int
......
......@@ -922,7 +922,7 @@ int is_forking_op(const ir_node *node);
* must be passed to the access macro get_irn_data(), 0 if the
* registration failed.
*/
size_t register_additional_node_data(size_t size);
unsigned register_additional_node_data(unsigned size);
/*-----------------------------------------------------------------*/
......
......@@ -10,7 +10,6 @@
* Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
/**
* @file irnode_t.h
*
......@@ -19,7 +18,6 @@
* @author Martin Trapp, Christian Schaefer
*/
# ifndef _IRNODE_T_H_
# define _IRNODE_T_H_
......@@ -239,12 +237,6 @@ struct ir_node {
};
/** Copies all attributes stored in the old node to the new node.
Assumes both have the same opcode and sufficient size. */
void
copy_attrs(const ir_node *old_node, ir_node *new_node);
/** Returns the array with the ins. The content of the array may not be
changed. */
ir_node **get_irn_in (const ir_node *node);
......@@ -266,6 +258,11 @@ store_attr get_irn_store_attr (ir_node *node);
except_attr get_irn_except_attr (ir_node *node);
/** @} */
/*
* The amount of additional space for custom data to be allocated upon creating a new node.
*/
extern unsigned firm_add_node_size;
/*-------------------------------------------------------------------*/
/* These function are most used in libfirm. Give them as static */
/* functions so they can be inlined. */
......@@ -290,6 +287,16 @@ __get_irn_op (const ir_node *node) {
return node->op;
}
/** Copies all attributes stored in the old node to the new node.
Assumes both have the same opcode and sufficient size. */
static INLINE void
copy_node_attr(const ir_node *old_node, ir_node *new_node) {
ir_op *op = __get_irn_op(old_node);
/* must always exist */
op->copy_attr(old_node, new_node);
}
/**
* Gets the opcode of a node.
* Intern version for libFirm.
......
......@@ -22,7 +22,7 @@
# include "irnode_t.h"
# include "firmstat.h"
# include "iropt.h" /* for firm_set_default_operations */
# include "iropt_t.h" /* for firm_set_default_operations */
# include "xmalloc.h"
......@@ -90,6 +90,45 @@ ir_op *op_EndExcept; ir_op *get_op_EndExcept (void) { return op_EndExcept; }
ir_op *op_NoMem; ir_op *get_op_NoMem (void) { return op_NoMem; }
/*
* Copies all attributes stored in the old node to the new node.
* Assumes both have the same opcode and sufficient size.
*/
void default_copy_attr(const ir_node *old_node, ir_node *new_node) {
unsigned size = firm_add_node_size;
assert(get_irn_op(old_node) == get_irn_op(new_node));
memcpy(&new_node->attr, &old_node->attr, get_op_attr_size(get_irn_op(old_node)));
if (size > 0) {
/* copy additional node data */
memcpy(get_irn_data(new_node, void, size), get_irn_data(old_node, void, size), size);
}
}
/**
* Copies all attributes stored in the old node to the new node.
* Assumes both have the same opcode and sufficient size.
*/
static void
call_copy_attr(const ir_node *old_node, ir_node *new_node) {
default_copy_attr(old_node, new_node);
remove_Call_callee_arr(new_node);
}
/**
* Sets the copy_attr operation for an ir_op
*/
static ir_op *firm_set_default_copy_attr(ir_op *op) {
if (op->code == iro_Call)
op->copy_attr = call_copy_attr;
else
op->copy_attr = default_copy_attr;
return op;
}
ir_op *
new_ir_op(opcode code, const char *name, op_pin_state p, unsigned flags, op_arity opar, int op_index, size_t attr_size)
{
......@@ -107,6 +146,8 @@ new_ir_op(opcode code, const char *name, op_pin_state p, unsigned flags, op_arit
res->op_index = op_index;
firm_set_default_operations(res);
firm_set_default_copy_attr(res);
stat_new_ir_op(res);
return res;
}
......
......@@ -86,6 +86,12 @@ typedef int (*node_cmp_attr_func)(ir_node *a, ir_node *b);
*/
typedef int (*reassociate_func)(ir_node *n);
/**
* The copy attribute operation.
* Copy the node attributes from a 'old' node to a 'new' one.
*/
typedef void (*copy_attr_func)(const ir_node *old_node, ir_node *new_node);
/** The type of an ir_op. */
struct ir_op {
opcode code; /**< the unique opcode of the op */
......@@ -102,6 +108,7 @@ struct ir_op {
transform_node_func transform_node; /**< optimizes the node by transforming it. */
node_cmp_attr_func node_cmp_attr; /**< compares two node attributes. */
reassociate_func reassociate; /**< reassociate a tree */
copy_attr_func copy_attr; /**< copy node attributes */
};
/**
......@@ -132,6 +139,12 @@ void init_op(void);
/** Free memory used by irop module. */
void finish_op(void);
/**
* Copies simply all attributes stored in the old node to the new node.
* Assumes both have the same opcode and sufficient size.
*/
void default_copy_attr(const ir_node *old_node, ir_node *new_node);
/** Returns the attribute size of nodes of this opcode.
@note Use not encouraged, internal feature. */
static INLINE int get_op_attr_size (const ir_op *op) {
......
......@@ -41,9 +41,4 @@ tarval *computed_value (ir_node *n);
*/
ir_node *optimize_in_place (ir_node *n);
/**
* set the default ir op operations
*/
ir_op *firm_set_default_operations(ir_op *op);
# endif /* _IROPT_H_ */
......@@ -52,5 +52,9 @@ value_of(ir_node *n) {
return tarval_bad;
}
/**
* set the default ir op operations
*/
ir_op *firm_set_default_operations(ir_op *op);
# endif /* _IROPT_T_H_ */
Supports Markdown
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