X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=ir%2Fir%2Firop.c;h=23ed46ea9e92f7ded879fe07c74073f5743fa037;hb=183c08a8d00578cfc700cdd0d8387b920a5996da;hp=4392a4b76e85318cc77e9a57dc0db947616dda6d;hpb=abbf9492df1993d211412ba520feb81de0688c2a;p=libfirm diff --git a/ir/ir/irop.c b/ir/ir/irop.c index 4392a4b76..23ed46ea9 100644 --- a/ir/ir/irop.c +++ b/ir/ir/irop.c @@ -21,7 +21,6 @@ * @file * @brief Representation of opcode of intermediate operation. * @author Christian Schaefer, Goetz Lindenmaier, Michael Beck - * @version $Id$ */ #include "config.h" @@ -33,23 +32,21 @@ #include "irbackedge_t.h" #include "iropt_t.h" -#include "irvrfy_t.h" +#include "irverify_t.h" #include "reassoc_t.h" #include "xmalloc.h" +#include "benode.h" -void be_init_op(void); - +static ir_op **opcodes; /** the available next opcode */ static unsigned next_iro = iro_MaxOpcode; -/* - * 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) +void default_copy_attr(ir_graph *irg, const ir_node *old_node, + ir_node *new_node) { unsigned size = firm_add_node_size; + (void) irg; 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))); @@ -58,65 +55,69 @@ void default_copy_attr(const ir_node *old_node, ir_node *new_node) /* copy additional node data */ memcpy(get_irn_data(new_node, void, size), get_irn_data(old_node, void, size), size); } -} /* default_copy_attr */ +} /** * Copies all Call attributes stored in the old node to the new node. */ -static void call_copy_attr(const ir_node *old_node, ir_node *new_node) +static void call_copy_attr(ir_graph *irg, const ir_node *old_node, + ir_node *new_node) { - default_copy_attr(old_node, new_node); + default_copy_attr(irg, old_node, new_node); remove_Call_callee_arr(new_node); -} /* call_copy_attr */ +} /** * Copies all Block attributes stored in the old node to the new node. */ -static void block_copy_attr(const ir_node *old_node, ir_node *new_node) +static void block_copy_attr(ir_graph *irg, const ir_node *old_node, + ir_node *new_node) { - ir_graph *irg = current_ir_graph; - - default_copy_attr(old_node, new_node); - new_node->attr.block.phis = NULL; - new_node->attr.block.cg_backedge = NULL; - new_node->attr.block.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node)); + default_copy_attr(irg, old_node, new_node); + new_node->attr.block.irg.irg = irg; + new_node->attr.block.phis = NULL; + new_node->attr.block.cg_backedge = NULL; + new_node->attr.block.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node)); + new_node->attr.block.block_visited = 0; + memset(&new_node->attr.block.dom, 0, sizeof(new_node->attr.block.dom)); + memset(&new_node->attr.block.pdom, 0, sizeof(new_node->attr.block.pdom)); + /* It should be safe to copy the entity here, as it has no back-link to the old block. + * It serves just as a label number, so copying a labeled block results in an exact copy. + * This is at least what we need for DCE to work. */ + new_node->attr.block.entity = old_node->attr.block.entity; + new_node->attr.block.phis = NULL; INIT_LIST_HEAD(&new_node->attr.block.succ_head); -} /* block_copy_attr */ +} /** * Copies all phi attributes stored in old node to the new node */ -static void phi_copy_attr(const ir_node *old_node, ir_node *new_node) +static void phi_copy_attr(ir_graph *irg, const ir_node *old_node, + ir_node *new_node) { - ir_graph *irg = current_ir_graph; - - default_copy_attr(old_node, new_node); + default_copy_attr(irg, old_node, new_node); new_node->attr.phi.next = NULL; new_node->attr.phi.u.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node)); } /** - * Copies all filter attributes stored in old node to the new node + * Copies all ASM attributes stored in old node to the new node */ -static void filter_copy_attr(const ir_node *old_node, ir_node *new_node) +static void ASM_copy_attr(ir_graph *irg, const ir_node *old_node, + ir_node *new_node) { - ir_graph *irg = current_ir_graph; - - default_copy_attr(old_node, new_node); - new_node->attr.filter.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node)); + default_copy_attr(irg, old_node, new_node); + new_node->attr.assem.input_constraints = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.input_constraints); + new_node->attr.assem.output_constraints = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.output_constraints); + new_node->attr.assem.clobbers = DUP_ARR_D(ident*, irg->obst, old_node->attr.assem.clobbers); } -/** - * Copies all ASM attributes stored in old node to the new node - */ -static void ASM_copy_attr(const ir_node *old_node, ir_node *new_node) +static void switch_copy_attr(ir_graph *irg, const ir_node *old_node, + ir_node *new_node) { - ir_graph *irg = current_ir_graph; - - default_copy_attr(old_node, new_node); - new_node->attr.assem.inputs = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.inputs); - new_node->attr.assem.outputs = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.outputs); - new_node->attr.assem.clobber = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.clobber); + const ir_switch_table *table = get_Switch_table(old_node); + new_node->attr.switcha.table = ir_switch_table_duplicate(irg, table); + new_node->attr.switcha.n_outs = old_node->attr.switcha.n_outs; } /** @@ -128,33 +129,37 @@ static void ASM_copy_attr(const ir_node *old_node, ir_node *new_node) * @return * The operations. */ -static ir_op_ops *firm_set_default_copy_attr(ir_opcode code, ir_op_ops *ops) +static void firm_set_default_copy_attr(unsigned code, ir_op_ops *ops) { switch (code) { - case iro_Call: - ops->copy_attr = call_copy_attr; - break; - case iro_Block: - ops->copy_attr = block_copy_attr; - break; - case iro_Phi: - ops->copy_attr = phi_copy_attr; - break; - case iro_Filter: - ops->copy_attr = filter_copy_attr; - break; - case iro_ASM: - ops->copy_attr = ASM_copy_attr; - break; + case iro_Call: ops->copy_attr = call_copy_attr; break; + case iro_Block: ops->copy_attr = block_copy_attr; break; + case iro_Phi: ops->copy_attr = phi_copy_attr; break; + case iro_ASM: ops->copy_attr = ASM_copy_attr; break; + case iro_Switch: ops->copy_attr = switch_copy_attr; break; default: - /* not allowed to be NULL */ - if (! ops->copy_attr) + if (ops->copy_attr == NULL) ops->copy_attr = default_copy_attr; } - return ops; -} /* firm_set_default_copy_attr */ +} + +/* + * Sets the default operation for an ir_ops. + */ +static void set_default_operations(unsigned code, ir_op_ops *ops) +{ + firm_set_default_hash(code, ops); + firm_set_default_computed_value(code, ops); + firm_set_default_equivalent_node(code, ops); + firm_set_default_transform_node(code, ops); + firm_set_default_node_cmp_attr(code, ops); + firm_set_default_get_type_attr(code, ops); + firm_set_default_get_entity_attr(code, ops); + firm_set_default_copy_attr(code, ops); + firm_set_default_verifier(code, ops); + firm_set_default_reassoc(code, ops); +} -/* Creates a new ir operation. */ ir_op *new_ir_op(unsigned code, const char *name, op_pin_state p, unsigned flags, op_arity opar, int op_index, size_t attr_size, const ir_op_ops *ops) @@ -171,44 +176,87 @@ ir_op *new_ir_op(unsigned code, const char *name, op_pin_state p, res->tag = 0; if (ops) - memcpy(&res->ops, ops, sizeof(res->ops)); + res->ops = *ops; else /* no given ops, set all operations to NULL */ memset(&res->ops, 0, sizeof(res->ops)); - firm_set_default_operations(code, &res->ops); - firm_set_default_copy_attr(code, &res->ops); - firm_set_default_verifyer(code, &res->ops); - firm_set_default_reassoc(code, &res->ops); - - add_irp_opcode(res); + set_default_operations(code, &res->ops); + + { + size_t len = ARR_LEN(opcodes); + if ((size_t)code >= len) { + ARR_RESIZE(ir_op*, opcodes, (size_t)code+1); + memset(&opcodes[len], 0, (code-len+1) * sizeof(opcodes[0])); + } + if (opcodes[code] != NULL) + panic("opcode registered twice"); + opcodes[code] = res; + } hook_new_ir_op(res); return res; -} /* new_ir_op */ +} void free_ir_op(ir_op *code) { hook_free_ir_op(code); - remove_irp_opcode(code); + assert(opcodes[code->code] == code); + opcodes[code->code] = NULL; + free(code); -} /* free_ir_op */ +} + +unsigned ir_get_n_opcodes(void) +{ + return ARR_LEN(opcodes); +} + +ir_op *ir_get_opcode(unsigned code) +{ + assert((size_t)code < ARR_LEN(opcodes)); + return opcodes[code]; +} + +void ir_clear_opcodes_generic_func(void) +{ + size_t n = ir_get_n_opcodes(); + size_t i; + + for (i = 0; i < n; ++i) { + ir_op *op = ir_get_opcode(i); + if (op != NULL) + op->ops.generic = (op_func)NULL; + } +} + +void ir_op_set_memory_index(ir_op *op, int memory_index) +{ + assert(op->flags & irop_flag_uses_memory); + op->memory_index = memory_index; +} + +void ir_op_set_fragile_indices(ir_op *op, int pn_x_regular, int pn_x_except) +{ + assert(op->flags & irop_flag_fragile); + op->pn_x_regular = pn_x_regular; + op->pn_x_except = pn_x_except; +} -/* Returns the string for the opcode. */ const char *get_op_name (const ir_op *op) { return get_id_str(op->name); -} /* get_op_name */ +} unsigned (get_op_code)(const ir_op *op) { - return _get_op_code(op); -} /* get_op_code */ + return get_op_code_(op); +} ident *(get_op_ident)(const ir_op *op) { - return _get_op_ident(op); -} /* get_op_ident */ + return get_op_ident_(op); +} const char *get_op_pin_state_name(op_pin_state s) { @@ -221,56 +269,67 @@ const char *get_op_pin_state_name(op_pin_state s) #undef XXX } return ""; -} /* get_op_pin_state_name */ +} op_pin_state (get_op_pinned)(const ir_op *op) { - return _get_op_pinned(op); -} /* get_op_pinned */ + return get_op_pinned_(op); +} -/* Sets op_pin_state_pinned in the opcode. Setting it to floating has no effect - for Phi, Block and control flow nodes. */ void set_op_pinned(ir_op *op, op_pin_state pinned) { if (op == op_Block || op == op_Phi || is_op_cfopcode(op)) return; op->pin_state = pinned; -} /* set_op_pinned */ +} -/* retrieve the next free opcode */ unsigned get_next_ir_opcode(void) { return next_iro++; -} /* get_next_ir_opcode */ +} -/* Returns the next free n IR opcode number, allows to register a bunch of user ops */ unsigned get_next_ir_opcodes(unsigned num) { unsigned base = next_iro; next_iro += num; return base; -} /* get_next_ir_opcodes */ +} -/* Returns the generic function pointer from an ir operation. */ op_func (get_generic_function_ptr)(const ir_op *op) { - return _get_generic_function_ptr(op); -} /* get_generic_function_ptr */ + return get_generic_function_ptr_(op); +} -/* Store a generic function pointer into an ir operation. */ void (set_generic_function_ptr)(ir_op *op, op_func func) { - _set_generic_function_ptr(op, func); -} /* set_generic_function_ptr */ + set_generic_function_ptr_(op, func); +} -/* Returns the ir_op_ops of an ir_op. */ const ir_op_ops *(get_op_ops)(const ir_op *op) { - return _get_op_ops(op); -} /* get_op_ops */ + return get_op_ops_(op); +} irop_flags get_op_flags(const ir_op *op) { - return op->flags; + return (irop_flags)op->flags; +} + +static void generated_init_op(void); +static void generated_finish_op(void); + +void firm_init_op(void) +{ + opcodes = NEW_ARR_F(ir_op*, 0); + generated_init_op(); + be_init_op(); +} + +void firm_finish_op(void) +{ + be_finish_op(); + generated_finish_op(); + DEL_ARR_F(opcodes); + opcodes = NULL; } #include "gen_irop.c.inl"