X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firnode.c;h=30aee7e0f3e80f41f74e9b88a90eb2a8b71b1b69;hb=01c4c27c4b7824dd0020f6fd2218edbe9ab40548;hp=0d2aebfa147b46e0dc351a66f986ba6848559af5;hpb=32ea6ea0320f551448bb66e534e3351977464d42;p=libfirm diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index 0d2aebfa1..30aee7e0f 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -21,7 +21,6 @@ * @file * @brief Representation of an intermediate operation. * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck - * @version $Id$ */ #include "config.h" @@ -39,115 +38,74 @@ #include "iredgekinds.h" #include "iredges_t.h" #include "ircons.h" +#include "error.h" #include "irhooks.h" #include "irtools.h" +#include "util.h" #include "beinfo.h" /* some constants fixing the positions of nodes predecessors in the in array */ -#define CALL_PARAM_OFFSET 2 -#define BUILDIN_PARAM_OFFSET 1 -#define SEL_INDEX_OFFSET 2 -#define RETURN_RESULT_OFFSET 1 /* mem is not a result */ +#define CALL_PARAM_OFFSET (n_Call_max+1) +#define BUILTIN_PARAM_OFFSET (n_Builtin_max+1) +#define ASM_PARAM_OFFSET (n_ASM_max+1) +#define SEL_INDEX_OFFSET (n_Sel_max+1) +#define RETURN_RESULT_OFFSET (n_Return_max+1) #define END_KEEPALIVE_OFFSET 0 -static const char *pnc_name_arr [] = { - "pn_Cmp_False", "pn_Cmp_Eq", "pn_Cmp_Lt", "pn_Cmp_Le", - "pn_Cmp_Gt", "pn_Cmp_Ge", "pn_Cmp_Lg", "pn_Cmp_Leg", - "pn_Cmp_Uo", "pn_Cmp_Ue", "pn_Cmp_Ul", "pn_Cmp_Ule", - "pn_Cmp_Ug", "pn_Cmp_Uge", "pn_Cmp_Ne", "pn_Cmp_True" +static const char *relation_names [] = { + "false", + "equal", + "less", + "less_equal", + "greater", + "greater_equal", + "less_greater", + "less_equal_greater", + "unordered", + "unordered_equal", + "unordered_less", + "unordered_less_equal", + "unordered_greater", + "unordered_greater_equal", + "not_equal", + "true" }; -/** - * returns the pnc name from an pnc constant - */ -const char *get_pnc_string(int pnc) -{ - assert(pnc >= 0 && pnc < - (int) (sizeof(pnc_name_arr)/sizeof(pnc_name_arr[0]))); - return pnc_name_arr[pnc]; -} - -/* - * Calculates the negated (Complement(R)) pnc condition. - */ -pn_Cmp get_negated_pnc(long pnc, ir_mode *mode) -{ - pnc ^= pn_Cmp_True; - - /* do NOT add the Uo bit for non-floating point values */ - if (! mode_is_float(mode)) - pnc &= ~pn_Cmp_Uo; - - return (pn_Cmp) pnc; -} - -/* Calculates the inversed (R^-1) pnc condition, i.e., "<" --> ">" */ -pn_Cmp get_inversed_pnc(long pnc) +const char *get_relation_string(ir_relation relation) { - long code = pnc & ~(pn_Cmp_Lt|pn_Cmp_Gt); - long lesser = pnc & pn_Cmp_Lt; - long greater = pnc & pn_Cmp_Gt; - - code |= (lesser ? pn_Cmp_Gt : 0) | (greater ? pn_Cmp_Lt : 0); - - return (pn_Cmp) code; + assert(relation < (ir_relation)ARRAY_SIZE(relation_names)); + return relation_names[relation]; } -/** - * Indicates, whether additional data can be registered to ir nodes. - * If set to 1, this is not possible anymore. - */ -static int forbid_new_data = 0; - -/** - * The amount of additional space for custom data to be allocated upon - * creating a new node. - */ -unsigned firm_add_node_size = 0; - - -/* register new space for every node */ -unsigned firm_register_additional_node_data(unsigned size) +ir_relation get_negated_relation(ir_relation relation) { - assert(!forbid_new_data && "Too late to register additional node data"); - - if (forbid_new_data) - return 0; - - return firm_add_node_size += size; + return relation ^ ir_relation_true; } - -void init_irnode(void) +ir_relation get_inversed_relation(ir_relation relation) { - /* Forbid the addition of new data to an ir node. */ - forbid_new_data = 1; + ir_relation code = relation & ~(ir_relation_less|ir_relation_greater); + bool less = relation & ir_relation_less; + bool greater = relation & ir_relation_greater; + code |= (less ? ir_relation_greater : ir_relation_false) + | (greater ? ir_relation_less : ir_relation_false); + return code; } -/* - * irnode constructor. - * Create a new irnode in irg, with an op, mode, arity and - * some incoming irnodes. - * If arity is negative, a node with a dynamic array is created. - */ -ir_node * -new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mode, - int arity, ir_node **in) +ir_node *new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, + ir_mode *mode, int arity, ir_node *const *in) { - ir_node *res; - size_t node_size = offsetof(ir_node, attr) + op->attr_size + firm_add_node_size; - char *p; int i; assert(irg); assert(op); assert(mode); - p = obstack_alloc(irg->obst, node_size); - memset(p, 0, node_size); - res = (ir_node *)(p + firm_add_node_size); + + size_t const node_size = offsetof(ir_node, attr) + op->attr_size; + ir_node *const res = (ir_node*)OALLOCNZ(irg->obst, char, node_size); res->kind = k_ir_node; res->op = op; @@ -170,7 +128,6 @@ new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mod res->in[0] = block; set_irn_dbg_info(res, db); - res->out = NULL; res->node_nr = get_irp_new_node_nr(); for (i = 0; i < EDGE_KIND_LAST; ++i) { @@ -186,76 +143,25 @@ new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mod edges_notify_edge(res, i - 1, res->in[i], NULL, irg); hook_new_node(irg, res); - if (get_irg_phase_state(irg) == phase_backend) { - be_info_new_node(res); - } - // Init the VRP structures - res->vrp.range_type = VRP_UNDEFINED; - res->vrp.valid = 0; - if(mode_is_int(mode)) { - // We are assuming that 0 is always represented as 0x0000 - res->vrp.bits_set = new_tarval_from_long(0, mode); - res->vrp.bits_not_set = new_tarval_from_long(0, mode); - res->vrp.range_bottom = get_tarval_top(); - res->vrp.range_top = get_tarval_top(); - } else { - res->vrp.bits_set = get_tarval_bad(); - res->vrp.bits_not_set = get_tarval_bad(); - res->vrp.range_bottom = get_tarval_bad(); - res->vrp.range_top = get_tarval_bad(); + if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) { + be_info_new_node(irg, res); } - res->vrp.bits_node = NULL; - res->vrp.range_node = NULL; - res->vrp.range_op = VRP_NONE; - return res; } -/*-- getting some parameters from ir_nodes --*/ - int (is_ir_node)(const void *thing) { - return _is_ir_node(thing); -} - -int (get_irn_intra_arity)(const ir_node *node) -{ - return _get_irn_intra_arity(node); -} - -int (get_irn_inter_arity)(const ir_node *node) -{ - return _get_irn_inter_arity(node); + return is_ir_node_(thing); } -int (*_get_irn_arity)(const ir_node *node) = _get_irn_intra_arity; - int (get_irn_arity)(const ir_node *node) { - return _get_irn_arity(node); + return get_irn_arity_(node); } -/* Returns the array with ins. This array is shifted with respect to the - array accessed by get_irn_n: The block operand is at position 0 not -1. - (@@@ This should be changed.) - The order of the predecessors in this array is not guaranteed, except that - lists of operands as predecessors of Block or arguments of a Call are - consecutive. */ ir_node **get_irn_in(const ir_node *node) { - assert(node); -#ifdef INTERPROCEDURAL_VIEW - if (get_interprocedural_view()) { /* handle Filter and Block specially */ - if (get_irn_opcode(node) == iro_Filter) { - assert(node->attr.filter.in_cg); - return node->attr.filter.in_cg; - } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) { - return node->attr.block.in_cg; - } - /* else fall through */ - } -#endif /* INTERPROCEDURAL_VIEW */ return node->in; } @@ -265,34 +171,27 @@ void set_irn_in(ir_node *node, int arity, ir_node **in) ir_node *** pOld_in; ir_graph *irg = get_irn_irg(node); - assert(node); -#ifdef INTERPROCEDURAL_VIEW - if (get_interprocedural_view()) { /* handle Filter and Block specially */ - ir_opcode code = get_irn_opcode(node); - if (code == iro_Filter) { - assert(node->attr.filter.in_cg); - pOld_in = &node->attr.filter.in_cg; - } else if (code == iro_Block && node->attr.block.in_cg) { - pOld_in = &node->attr.block.in_cg; - } else { - pOld_in = &node->in; - } - } else -#endif /* INTERPROCEDURAL_VIEW */ - pOld_in = &node->in; + pOld_in = &node->in; +#ifndef NDEBUG + assert(node != NULL && node->kind == k_ir_node); + assert(arity >= 0); + for (i = 0; i < arity; ++i) { + assert(in[i] != NULL && in[0]->kind == k_ir_node); + } +#endif for (i = 0; i < arity; i++) { - if (i < ARR_LEN(*pOld_in)-1) + if (i < (int)ARR_LEN(*pOld_in)-1) edges_notify_edge(node, i, in[i], (*pOld_in)[i+1], irg); else edges_notify_edge(node, i, in[i], NULL, irg); } - for (;i < ARR_LEN(*pOld_in)-1; i++) { + for (;i < (int)ARR_LEN(*pOld_in)-1; i++) { edges_notify_edge(node, i, NULL, (*pOld_in)[i+1], irg); } - if (arity != ARR_LEN(*pOld_in) - 1) { + if (arity != (int)ARR_LEN(*pOld_in) - 1) { ir_node * block = (*pOld_in)[0]; *pOld_in = NEW_ARR_D(ir_node *, irg->obst, arity + 1); (*pOld_in)[0] = block; @@ -300,60 +199,34 @@ void set_irn_in(ir_node *node, int arity, ir_node **in) fix_backedges(irg->obst, node); memcpy((*pOld_in) + 1, in, sizeof(ir_node *) * arity); -} - -ir_node *(get_irn_intra_n)(const ir_node *node, int n) -{ - return _get_irn_intra_n(node, n); -} -ir_node *(get_irn_inter_n)(const ir_node *node, int n) -{ - return _get_irn_inter_n(node, n); + /* update irg flags */ + clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS | IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO); } -ir_node *(*_get_irn_n)(const ir_node *node, int n) = _get_irn_intra_n; - ir_node *(get_irn_n)(const ir_node *node, int n) { - return _get_irn_n(node, n); + return get_irn_n_(node, n); } void set_irn_n(ir_node *node, int n, ir_node *in) { + ir_graph *irg = get_irn_irg(node); assert(node && node->kind == k_ir_node); assert(-1 <= n); assert(n < get_irn_arity(node)); assert(in && in->kind == k_ir_node); -#ifdef INTERPROCEDURAL_VIEW - if ((n == -1) && (get_irn_opcode(node) == iro_Filter)) { - /* Change block pred in both views! */ - node->in[n + 1] = in; - assert(node->attr.filter.in_cg); - node->attr.filter.in_cg[n + 1] = in; - return; - } - if (get_interprocedural_view()) { /* handle Filter and Block specially */ - if (get_irn_opcode(node) == iro_Filter) { - assert(node->attr.filter.in_cg); - node->attr.filter.in_cg[n + 1] = in; - return; - } else if (get_irn_opcode(node) == iro_Block && node->attr.block.in_cg) { - node->attr.block.in_cg[n + 1] = in; - return; - } - /* else fall through */ - } -#endif /* INTERPROCEDURAL_VIEW */ - /* Call the hook */ hook_set_irn_n(node, n, in, node->in[n + 1]); /* Here, we rely on src and tgt being in the current ir graph */ - edges_notify_edge(node, n, in, node->in[n + 1], current_ir_graph); + edges_notify_edge(node, n, in, node->in[n + 1], irg); node->in[n + 1] = in; + + /* update irg flags */ + clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS | IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO); } int add_irn_n(ir_node *node, ir_node *in) @@ -383,52 +256,58 @@ void del_Sync_n(ir_node *n, int i) int (get_irn_deps)(const ir_node *node) { - return _get_irn_deps(node); + return get_irn_deps_(node); } ir_node *(get_irn_dep)(const ir_node *node, int pos) { - return _get_irn_dep(node, pos); + return get_irn_dep_(node, pos); } -void (set_irn_dep)(ir_node *node, int pos, ir_node *dep) +void set_irn_dep(ir_node *node, int pos, ir_node *dep) { - _set_irn_dep(node, pos, dep); + ir_node *old; + ir_graph *irg; + + assert(node->deps && "dependency array node yet allocated. use add_irn_dep()"); + assert(pos >= 0 && pos < (int)ARR_LEN(node->deps) && "dependency index out of range"); + assert(dep != NULL); + old = node->deps[pos]; + node->deps[pos] = dep; + irg = get_irn_irg(node); + if (edges_activated_kind(irg, EDGE_KIND_DEP)) + edges_notify_edge_kind(node, pos, dep, old, EDGE_KIND_DEP, irg); } -int add_irn_dep(ir_node *node, ir_node *dep) +void add_irn_dep(ir_node *node, ir_node *dep) { - int res = 0; - - /* DEP edges are only allowed in backend phase */ - assert(get_irg_phase_state(get_irn_irg(node)) == phase_backend); + ir_graph *irg; + assert(dep != NULL); if (node->deps == NULL) { - node->deps = NEW_ARR_F(ir_node *, 1); - node->deps[0] = dep; - } else { - int i, n; - int first_zero = -1; - - for(i = 0, n = ARR_LEN(node->deps); i < n; ++i) { - if(node->deps[i] == NULL) - first_zero = i; + node->deps = NEW_ARR_F(ir_node *, 0); + } + ARR_APP1(ir_node*, node->deps, dep); + irg = get_irn_irg(node); + if (edges_activated_kind(irg, EDGE_KIND_DEP)) + edges_notify_edge_kind(node, ARR_LEN(node->deps)-1, dep, NULL, EDGE_KIND_DEP, irg); +} - if(node->deps[i] == dep) - return i; - } +void delete_irn_dep(ir_node *node, ir_node *dep) +{ + size_t i; + size_t n_deps; + if (node->deps == NULL) + return; - if (first_zero >= 0) { - node->deps[first_zero] = dep; - res = first_zero; - } else { - ARR_APP1(ir_node *, node->deps, dep); - res = n; + n_deps = ARR_LEN(node->deps); + for (i = 0; i < n_deps; ++i) { + if (node->deps[i] == dep) { + set_irn_dep(node, i, node->deps[n_deps-1]); + edges_notify_edge(node, i, NULL, dep, get_irn_irg(node)); + ARR_SHRINKLEN(node->deps, n_deps-1); + break; } } - - edges_notify_edge_kind(node, res, dep, NULL, EDGE_KIND_DEP, get_irn_irg(node)); - - return res; } void add_irn_deps(ir_node *tgt, ir_node *src) @@ -442,47 +321,31 @@ void add_irn_deps(ir_node *tgt, ir_node *src) ir_mode *(get_irn_mode)(const ir_node *node) { - return _get_irn_mode(node); + return get_irn_mode_(node); } void (set_irn_mode)(ir_node *node, ir_mode *mode) { - _set_irn_mode(node, mode); -} - -/** Gets the string representation of the mode .*/ -const char *get_irn_modename(const ir_node *node) -{ - assert(node); - return get_mode_name(node->mode); -} - -ident *get_irn_modeident(const ir_node *node) -{ - assert(node); - return get_mode_ident(node->mode); + set_irn_mode_(node, mode); } ir_op *(get_irn_op)(const ir_node *node) { - return _get_irn_op(node); + return get_irn_op_(node); } -/* should be private to the library: */ void (set_irn_op)(ir_node *node, ir_op *op) { - _set_irn_op(node, op); + set_irn_op_(node, op); } unsigned (get_irn_opcode)(const ir_node *node) { - return _get_irn_opcode(node); + return get_irn_opcode_(node); } const char *get_irn_opname(const ir_node *node) { - assert(node); - if (is_Phi0(node)) return "Phi0"; return get_id_str(node->op->name); } @@ -494,47 +357,47 @@ ident *get_irn_opident(const ir_node *node) ir_visited_t (get_irn_visited)(const ir_node *node) { - return _get_irn_visited(node); + return get_irn_visited_(node); } void (set_irn_visited)(ir_node *node, ir_visited_t visited) { - _set_irn_visited(node, visited); + set_irn_visited_(node, visited); } void (mark_irn_visited)(ir_node *node) { - _mark_irn_visited(node); + mark_irn_visited_(node); } int (irn_visited)(const ir_node *node) { - return _irn_visited(node); + return irn_visited_(node); } int (irn_visited_else_mark)(ir_node *node) { - return _irn_visited_else_mark(node); + return irn_visited_else_mark_(node); } void (set_irn_link)(ir_node *node, void *link) { - _set_irn_link(node, link); + set_irn_link_(node, link); } void *(get_irn_link)(const ir_node *node) { - return _get_irn_link(node); + return get_irn_link_(node); } op_pin_state (get_irn_pinned)(const ir_node *node) { - return _get_irn_pinned(node); + return get_irn_pinned_(node); } op_pin_state (is_irn_pinned_in_irg) (const ir_node *node) { - return _is_irn_pinned_in_irg(node); + return is_irn_pinned_in_irg_(node); } void set_irn_pinned(ir_node *node, op_pin_state state) @@ -549,151 +412,41 @@ void set_irn_pinned(ir_node *node, op_pin_state state) node->attr.except.pin_state = state; } -/* Outputs a unique number for this node */ long get_irn_node_nr(const ir_node *node) { assert(node); return node->node_nr; } -const_attr *get_irn_const_attr(ir_node *node) -{ - assert(is_Const(node)); - return &node->attr.con; -} - -long get_irn_proj_attr(ir_node *node) -{ - /* BEWARE: check for true Proj node here, no Filter */ - assert(node->op == op_Proj); - return node->attr.proj; -} - -alloc_attr *get_irn_alloc_attr(ir_node *node) -{ - assert(is_Alloc(node)); - return &node->attr.alloc; -} - -free_attr *get_irn_free_attr(ir_node *node) -{ - assert(is_Free(node)); - return &node->attr.free; -} - -symconst_attr *get_irn_symconst_attr(ir_node *node) -{ - assert(is_SymConst(node)); - return &node->attr.symc; -} - -call_attr *get_irn_call_attr(ir_node *node) -{ - assert(is_Call(node)); - return &node->attr.call; -} - -sel_attr *get_irn_sel_attr(ir_node *node) -{ - assert(is_Sel(node)); - return &node->attr.sel; -} - -phi_attr *get_irn_phi_attr(ir_node *node) -{ - return &node->attr.phi; -} - -block_attr *get_irn_block_attr(ir_node *node) -{ - assert(is_Block(node)); - return &node->attr.block; -} - -load_attr *get_irn_load_attr(ir_node *node) -{ - assert(is_Load(node)); - return &node->attr.load; -} - -store_attr *get_irn_store_attr(ir_node *node) -{ - assert(is_Store(node)); - return &node->attr.store; -} - -except_attr *get_irn_except_attr(ir_node *node) -{ - assert(node->op == op_Div || node->op == op_Quot || - node->op == op_DivMod || node->op == op_Mod || node->op == op_Call || node->op == op_Alloc || node->op == op_Bound); - return &node->attr.except; -} - -divmod_attr *get_irn_divmod_attr(ir_node *node) -{ - assert(node->op == op_Div || node->op == op_Quot || - node->op == op_DivMod || node->op == op_Mod); - return &node->attr.divmod; -} - -builtin_attr *get_irn_builtin_attr(ir_node *node) -{ - assert(is_Builtin(node)); - return &node->attr.builtin; -} - void *(get_irn_generic_attr)(ir_node *node) { assert(is_ir_node(node)); - return _get_irn_generic_attr(node); + return get_irn_generic_attr_(node); } const void *(get_irn_generic_attr_const)(const ir_node *node) { assert(is_ir_node(node)); - return _get_irn_generic_attr_const(node); + return get_irn_generic_attr_const_(node); } unsigned (get_irn_idx)(const ir_node *node) { assert(is_ir_node(node)); - return _get_irn_idx(node); -} - -int get_irn_pred_pos(ir_node *node, ir_node *arg) -{ - int i; - for (i = get_irn_arity(node) - 1; i >= 0; i--) { - if (get_irn_n(node, i) == arg) - return i; - } - return -1; + return get_irn_idx_(node); } -/** manipulate fields of individual nodes **/ - -/* this works for all except Block */ -ir_node *get_nodes_block(const ir_node *node) +ir_node *(get_nodes_block)(const ir_node *node) { - assert(node->op != op_Block); - return get_irn_n(node, -1); + return get_nodes_block_(node); } void set_nodes_block(ir_node *node, ir_node *block) { - assert(node->op != op_Block); + assert(!is_Block(node)); set_irn_n(node, -1, block); } -/* this works for all except Block */ -ir_node *get_nodes_MacroBlock(const ir_node *node) -{ - assert(node->op != op_Block); - return get_Block_MacroBlock(get_irn_n(node, -1)); -} - -/* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base) - * from Start. If so returns frame type, else Null. */ ir_type *is_frame_pointer(const ir_node *n) { if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_frame_base)) { @@ -705,19 +458,6 @@ ir_type *is_frame_pointer(const ir_node *n) return NULL; } -/* Test whether arbitrary node is tls pointer, i.e. Proj(pn_Start_P_tls) - * from Start. If so returns tls type, else Null. */ -ir_type *is_tls_pointer(const ir_node *n) -{ - if (is_Proj(n) && (get_Proj_proj(n) == pn_Start_P_tls)) { - ir_node *start = get_Proj_pred(n); - if (is_Start(start)) { - return get_tls_type(); - } - } - return NULL; -} - ir_node **get_Block_cfgpred_arr(ir_node *node) { assert(is_Block(node)); @@ -726,12 +466,12 @@ ir_node **get_Block_cfgpred_arr(ir_node *node) int (get_Block_n_cfgpreds)(const ir_node *node) { - return _get_Block_n_cfgpreds(node); + return get_Block_n_cfgpreds_(node); } ir_node *(get_Block_cfgpred)(const ir_node *node, int pos) { - return _get_Block_cfgpred(node, pos); + return get_Block_cfgpred_(node, pos); } void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred) @@ -753,7 +493,7 @@ int get_Block_cfgpred_pos(const ir_node *block, const ir_node *pred) ir_node *(get_Block_cfgpred_block)(const ir_node *node, int pos) { - return _get_Block_cfgpred_block(node, pos); + return get_Block_cfgpred_block_(node, pos); } int get_Block_matured(const ir_node *node) @@ -770,152 +510,27 @@ void set_Block_matured(ir_node *node, int matured) ir_visited_t (get_Block_block_visited)(const ir_node *node) { - return _get_Block_block_visited(node); + return get_Block_block_visited_(node); } void (set_Block_block_visited)(ir_node *node, ir_visited_t visit) { - _set_Block_block_visited(node, visit); + set_Block_block_visited_(node, visit); } -/* For this current_ir_graph must be set. */ void (mark_Block_block_visited)(ir_node *node) { - _mark_Block_block_visited(node); + mark_Block_block_visited_(node); } int (Block_block_visited)(const ir_node *node) { - return _Block_block_visited(node); -} - -ir_node *get_Block_graph_arr(ir_node *node, int pos) -{ - assert(is_Block(node)); - return node->attr.block.graph_arr[pos+1]; -} - -void set_Block_graph_arr(ir_node *node, int pos, ir_node *value) -{ - assert(is_Block(node)); - node->attr.block.graph_arr[pos+1] = value; -} - -#ifdef INTERPROCEDURAL_VIEW -void set_Block_cg_cfgpred_arr(ir_node *node, int arity, ir_node *in[]) -{ - assert(is_Block(node)); - if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) { - node->attr.block.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1); - node->attr.block.in_cg[0] = NULL; - node->attr.block.cg_backedge = new_backedge_arr(current_ir_graph->obst, arity); - { - /* Fix backedge array. fix_backedges() operates depending on - interprocedural_view. */ - int ipv = get_interprocedural_view(); - set_interprocedural_view(1); - fix_backedges(current_ir_graph->obst, node); - set_interprocedural_view(ipv); - } - } - memcpy(node->attr.block.in_cg + 1, in, sizeof(ir_node *) * arity); -} - -void set_Block_cg_cfgpred(ir_node *node, int pos, ir_node *pred) -{ - assert(is_Block(node) && node->attr.block.in_cg && - 0 <= pos && pos < ARR_LEN(node->attr.block.in_cg) - 1); - node->attr.block.in_cg[pos + 1] = pred; -} - -ir_node **get_Block_cg_cfgpred_arr(ir_node *node) -{ - assert(is_Block(node)); - return node->attr.block.in_cg == NULL ? NULL : node->attr.block.in_cg + 1; -} - -int get_Block_cg_n_cfgpreds(const ir_node *node) -{ - assert(is_Block(node)); - return node->attr.block.in_cg == NULL ? 0 : ARR_LEN(node->attr.block.in_cg) - 1; -} - -ir_node *get_Block_cg_cfgpred(const ir_node *node, int pos) -{ - assert(is_Block(node) && node->attr.block.in_cg); - return node->attr.block.in_cg[pos + 1]; -} - -void remove_Block_cg_cfgpred_arr(ir_node *node) -{ - assert(is_Block(node)); - node->attr.block.in_cg = NULL; -} -#endif /* INTERPROCEDURAL_VIEW */ - -ir_node *(set_Block_dead)(ir_node *block) -{ - return _set_Block_dead(block); -} - -int (is_Block_dead)(const ir_node *block) -{ - return _is_Block_dead(block); -} - -ir_extblk *get_Block_extbb(const ir_node *block) -{ - ir_extblk *res; - assert(is_Block(block)); - res = block->attr.block.extblk; - assert(res == NULL || is_ir_extbb(res)); - return res; -} - -void set_Block_extbb(ir_node *block, ir_extblk *extblk) -{ - assert(is_Block(block)); - assert(extblk == NULL || is_ir_extbb(extblk)); - block->attr.block.extblk = extblk; -} - -/* Returns the macro block header of a block.*/ -ir_node *get_Block_MacroBlock(const ir_node *block) -{ - ir_node *mbh; - assert(is_Block(block)); - mbh = get_irn_n(block, -1); - /* once macro block header is respected by all optimizations, - this assert can be removed */ - assert(mbh != NULL); - return mbh; -} - -/* Sets the macro block header of a block. */ -void set_Block_MacroBlock(ir_node *block, ir_node *mbh) -{ - assert(is_Block(block)); - mbh = skip_Id(mbh); - assert(is_Block(mbh)); - set_irn_n(block, -1, mbh); -} - -/* returns the macro block header of a node. */ -ir_node *get_irn_MacroBlock(const ir_node *n) -{ - if (! is_Block(n)) { - n = get_nodes_block(n); - /* if the Block is Bad, do NOT try to get it's MB, it will fail. */ - if (is_Bad(n)) - return (ir_node *)n; - } - return get_Block_MacroBlock(n); + return Block_block_visited_(node); } -/* returns the graph of a Block. */ ir_graph *(get_Block_irg)(const ir_node *block) { - return _get_Block_irg(block); + return get_Block_irg_(block); } ir_entity *create_Block_entity(ir_node *block) @@ -925,15 +540,10 @@ ir_entity *create_Block_entity(ir_node *block) entity = block->attr.block.entity; if (entity == NULL) { - ir_label_t nr; - ir_type *glob; - - glob = get_glob_type(); - entity = new_entity(glob, id_unique("block_%u"), get_code_type()); + ir_label_t nr = get_irp_next_label_nr(); + entity = new_label_entity(nr); set_entity_visibility(entity, ir_visibility_local); set_entity_linkage(entity, IR_LINKAGE_CONSTANT); - nr = get_irp_next_label_nr(); - set_entity_label(entity, nr); set_entity_compiler_generated(entity, 1); block->attr.block.entity = entity; @@ -941,49 +551,29 @@ ir_entity *create_Block_entity(ir_node *block) return entity; } -ir_entity *get_Block_entity(const ir_node *block) -{ - assert(is_Block(block)); - return block->attr.block.entity; -} - -void set_Block_entity(ir_node *block, ir_entity *entity) -{ - assert(is_Block(block)); - assert(get_entity_type(entity) == get_code_type()); - block->attr.block.entity = entity; -} - -int has_Block_entity(const ir_node *block) -{ - return block->attr.block.entity != NULL; -} - ir_node *(get_Block_phis)(const ir_node *block) { - return _get_Block_phis(block); + return get_Block_phis_(block); } void (set_Block_phis)(ir_node *block, ir_node *phi) { - _set_Block_phis(block, phi); + set_Block_phis_(block, phi); } void (add_Block_phi)(ir_node *block, ir_node *phi) { - _add_Block_phi(block, phi); + add_Block_phi_(block, phi); } -/* Get the Block mark (single bit). */ unsigned (get_Block_mark)(const ir_node *block) { - return _get_Block_mark(block); + return get_Block_mark_(block); } -/* Set the Block mark (single bit). */ void (set_Block_mark)(ir_node *block, unsigned mark) { - _set_Block_mark(block, mark); + set_Block_mark_(block, mark); } int get_End_n_keepalives(const ir_node *end) @@ -1010,15 +600,15 @@ void set_End_keepalive(ir_node *end, int pos, ir_node *ka) set_irn_n(end, pos + END_KEEPALIVE_OFFSET, ka); } -/* Set new keep-alives */ void set_End_keepalives(ir_node *end, int n, ir_node *in[]) { - int i; + size_t e; + int i; ir_graph *irg = get_irn_irg(end); /* notify that edges are deleted */ - for (i = END_KEEPALIVE_OFFSET; i < ARR_LEN(end->in) - 1; ++i) { - edges_notify_edge(end, i, NULL, end->in[i + 1], irg); + for (e = END_KEEPALIVE_OFFSET; e < ARR_LEN(end->in) - 1; ++e) { + edges_notify_edge(end, e, NULL, end->in[e + 1], irg); } ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET); @@ -1026,27 +616,29 @@ void set_End_keepalives(ir_node *end, int n, ir_node *in[]) end->in[1 + END_KEEPALIVE_OFFSET + i] = in[i]; edges_notify_edge(end, END_KEEPALIVE_OFFSET + i, end->in[1 + END_KEEPALIVE_OFFSET + i], NULL, irg); } + + /* update irg flags */ + clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS); } -/* Set new keep-alives from old keep-alives, skipping irn */ void remove_End_keepalive(ir_node *end, ir_node *irn) { int n = get_End_n_keepalives(end); - int i, idx; ir_graph *irg; - idx = -1; - for (i = n -1; i >= 0; --i) { + int idx = -1; + for (int i = n;;) { + if (i-- == 0) + return; + ir_node *old_ka = end->in[1 + END_KEEPALIVE_OFFSET + i]; /* find irn */ if (old_ka == irn) { idx = i; - goto found; + break; } } - return; -found: irg = get_irn_irg(end); /* remove the edge */ @@ -1061,14 +653,17 @@ found: } /* now n - 1 keeps, 1 block input */ ARR_RESIZE(ir_node *, end->in, (n - 1) + 1 + END_KEEPALIVE_OFFSET); + + /* update irg flags */ + clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS); } -/* remove Bads, NoMems and doublets from the keep-alive set */ void remove_End_Bads_and_doublets(ir_node *end) { pset_new_t keeps; int idx, n = get_End_n_keepalives(end); ir_graph *irg; + bool changed = false; if (n <= 0) return; @@ -1080,6 +675,7 @@ void remove_End_Bads_and_doublets(ir_node *end) ir_node *ka = get_End_keepalive(end, idx); if (is_Bad(ka) || is_NoMem(ka) || pset_new_contains(&keeps, ka)) { + changed = true; /* remove the edge */ edges_notify_edge(end, idx, NULL, ka, irg); @@ -1099,6 +695,10 @@ void remove_End_Bads_and_doublets(ir_node *end) ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET); pset_new_destroy(&keeps); + + if (changed) { + clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS); + } } void free_End(ir_node *end) @@ -1110,167 +710,65 @@ void free_End(ir_node *end) in array afterwards ... */ } -/* Return the target address of an IJmp */ -ir_node *get_IJmp_target(const ir_node *ijmp) +size_t get_Return_n_ress(const ir_node *node) { - assert(is_IJmp(ijmp)); - return get_irn_n(ijmp, 0); + assert(is_Return(node)); + return (size_t)(get_irn_arity(node) - RETURN_RESULT_OFFSET); } -/** Sets the target address of an IJmp */ -void set_IJmp_target(ir_node *ijmp, ir_node *tgt) +ir_node **get_Return_res_arr(ir_node *node) { - assert(is_IJmp(ijmp)); - set_irn_n(ijmp, 0, tgt); + assert(is_Return(node)); + if (get_Return_n_ress(node) > 0) + return (ir_node **)&(get_irn_in(node)[1 + RETURN_RESULT_OFFSET]); + else + return NULL; } -ir_node * -get_Cond_selector(const ir_node *node) +ir_node *get_Return_res(const ir_node *node, int pos) { - assert(is_Cond(node)); - return get_irn_n(node, 0); + assert(is_Return(node)); + assert(pos >= 0); + assert(get_Return_n_ress(node) > (size_t)pos); + return get_irn_n(node, pos + RETURN_RESULT_OFFSET); } -void -set_Cond_selector(ir_node *node, ir_node *selector) +void set_Return_res(ir_node *node, int pos, ir_node *res) { - assert(is_Cond(node)); - set_irn_n(node, 0, selector); + assert(is_Return(node)); + set_irn_n(node, pos + RETURN_RESULT_OFFSET, res); } -long -get_Cond_default_proj(const ir_node *node) +int (is_Const_null)(const ir_node *node) { - assert(is_Cond(node)); - return node->attr.cond.default_proj; + return is_Const_null_(node); } -void set_Cond_default_proj(ir_node *node, long defproj) +int (is_Const_one)(const ir_node *node) { - assert(is_Cond(node)); - node->attr.cond.default_proj = defproj; + return is_Const_one_(node); } -ir_node * -get_Return_mem(const ir_node *node) +int (is_Const_all_one)(const ir_node *node) { - assert(is_Return(node)); - return get_irn_n(node, 0); + return is_Const_all_one_(node); } -void -set_Return_mem(ir_node *node, ir_node *mem) -{ - assert(is_Return(node)); - set_irn_n(node, 0, mem); -} -int -get_Return_n_ress(const ir_node *node) + +symconst_kind get_SymConst_kind(const ir_node *node) { - assert(is_Return(node)); - return (get_irn_arity(node) - RETURN_RESULT_OFFSET); + assert(is_SymConst(node)); + return node->attr.symc.kind; } -ir_node ** -get_Return_res_arr(ir_node *node) +void set_SymConst_kind(ir_node *node, symconst_kind kind) { - assert(is_Return(node)); - if (get_Return_n_ress(node) > 0) - return (ir_node **)&(get_irn_in(node)[1 + RETURN_RESULT_OFFSET]); - else - return NULL; + assert(is_SymConst(node)); + node->attr.symc.kind = kind; } -/* -void -set_Return_n_res(ir_node *node, int results) -{ - assert(is_Return(node)); -} -*/ - -ir_node * -get_Return_res(const ir_node *node, int pos) -{ - assert(is_Return(node)); - assert(get_Return_n_ress(node) > pos); - return get_irn_n(node, pos + RETURN_RESULT_OFFSET); -} - -void -set_Return_res(ir_node *node, int pos, ir_node *res) -{ - assert(is_Return(node)); - set_irn_n(node, pos + RETURN_RESULT_OFFSET, res); -} - -tarval *(get_Const_tarval)(const ir_node *node) -{ - return _get_Const_tarval(node); -} - -void -set_Const_tarval(ir_node *node, tarval *con) -{ - assert(is_Const(node)); - node->attr.con.tv = con; -} - -int (is_Const_null)(const ir_node *node) -{ - return _is_Const_null(node); -} - -int (is_Const_one)(const ir_node *node) -{ - return _is_Const_one(node); -} - -int (is_Const_all_one)(const ir_node *node) -{ - return _is_Const_all_one(node); -} - - -/* The source language type. Must be an atomic type. Mode of type must - be mode of node. For tarvals from entities type must be pointer to - entity type. */ -ir_type * -get_Const_type(ir_node *node) -{ - assert(is_Const(node)); - return node->attr.con.tp; -} - -void -set_Const_type(ir_node *node, ir_type *tp) -{ - assert(is_Const(node)); - if (tp != firm_unknown_type) { - assert(is_atomic_type(tp)); - assert(get_type_mode(tp) == get_irn_mode(node)); - } - node->attr.con.tp = tp; -} - - -symconst_kind -get_SymConst_kind(const ir_node *node) -{ - assert(is_SymConst(node)); - return node->attr.symc.kind; -} - -void -set_SymConst_kind(ir_node *node, symconst_kind kind) -{ - assert(is_SymConst(node)); - node->attr.symc.kind = kind; -} - -ir_type * -get_SymConst_type(const ir_node *node) +ir_type *get_SymConst_type(const ir_node *node) { /* the cast here is annoying, but we have to compensate for the skip_tip() */ @@ -1280,30 +778,13 @@ get_SymConst_type(const ir_node *node) return irn->attr.symc.sym.type_p; } -void -set_SymConst_type(ir_node *node, ir_type *tp) +void set_SymConst_type(ir_node *node, ir_type *tp) { assert(is_SymConst(node) && (SYMCONST_HAS_TYPE(get_SymConst_kind(node)))); node->attr.symc.sym.type_p = tp; } -ident * -get_SymConst_name(const ir_node *node) -{ - assert(is_SymConst(node) && SYMCONST_HAS_ID(get_SymConst_kind(node))); - return node->attr.symc.sym.ident_p; -} - -void -set_SymConst_name(ir_node *node, ident *name) -{ - assert(is_SymConst(node) && SYMCONST_HAS_ID(get_SymConst_kind(node))); - node->attr.symc.sym.ident_p = name; -} - - -/* Only to access SymConst of kind symconst_addr_ent. Else assertion: */ ir_entity *get_SymConst_entity(const ir_node *node) { assert(is_SymConst(node) && SYMCONST_HAS_ENT(get_SymConst_kind(node))); @@ -1316,1544 +797,432 @@ void set_SymConst_entity(ir_node *node, ir_entity *ent) node->attr.symc.sym.entity_p = ent; } -ir_enum_const *get_SymConst_enum(const ir_node *node) -{ - assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node))); - return node->attr.symc.sym.enum_p; -} - -void set_SymConst_enum(ir_node *node, ir_enum_const *ec) -{ - assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node))); - node->attr.symc.sym.enum_p = ec; -} - -union symconst_symbol -get_SymConst_symbol(const ir_node *node) -{ - assert(is_SymConst(node)); - return node->attr.symc.sym; -} - -void -set_SymConst_symbol(ir_node *node, union symconst_symbol sym) -{ - assert(is_SymConst(node)); - node->attr.symc.sym = sym; -} - -ir_type * -get_SymConst_value_type(ir_node *node) -{ - assert(is_SymConst(node)); - return node->attr.symc.tp; -} - -void -set_SymConst_value_type(ir_node *node, ir_type *tp) -{ - assert(is_SymConst(node)); - node->attr.symc.tp = tp; -} - -ir_node * -get_Sel_mem(const ir_node *node) -{ - assert(is_Sel(node)); - return get_irn_n(node, 0); -} - -void -set_Sel_mem(ir_node *node, ir_node *mem) -{ - assert(is_Sel(node)); - set_irn_n(node, 0, mem); -} - -ir_node * -get_Sel_ptr(const ir_node *node) -{ - assert(is_Sel(node)); - return get_irn_n(node, 1); -} - -void -set_Sel_ptr(ir_node *node, ir_node *ptr) -{ - assert(is_Sel(node)); - set_irn_n(node, 1, ptr); -} - -int -get_Sel_n_indexs(const ir_node *node) -{ - assert(is_Sel(node)); - return (get_irn_arity(node) - SEL_INDEX_OFFSET); -} - -ir_node ** -get_Sel_index_arr(ir_node *node) -{ - assert(is_Sel(node)); - if (get_Sel_n_indexs(node) > 0) - return (ir_node **)& get_irn_in(node)[SEL_INDEX_OFFSET + 1]; - else - return NULL; -} - -ir_node * -get_Sel_index(const ir_node *node, int pos) -{ - assert(is_Sel(node)); - return get_irn_n(node, pos + SEL_INDEX_OFFSET); -} - -void -set_Sel_index(ir_node *node, int pos, ir_node *index) -{ - assert(is_Sel(node)); - set_irn_n(node, pos + SEL_INDEX_OFFSET, index); -} - -ir_entity * -get_Sel_entity(const ir_node *node) -{ - assert(is_Sel(node)); - return node->attr.sel.entity; -} - -/* need a version without const to prevent warning */ -static ir_entity *_get_Sel_entity(ir_node *node) -{ - return get_Sel_entity(node); -} - -void -set_Sel_entity(ir_node *node, ir_entity *ent) -{ - assert(is_Sel(node)); - node->attr.sel.entity = ent; -} - - -/* For unary and binary arithmetic operations the access to the - operands can be factored out. Left is the first, right the - second arithmetic value as listed in tech report 0999-33. - unops are: Minus, Abs, Not, Conv, Cast - binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl, - Shr, Shrs, Rotate, Cmp */ - - -ir_node * -get_Call_mem(const ir_node *node) -{ - assert(is_Call(node)); - return get_irn_n(node, 0); -} - -void -set_Call_mem(ir_node *node, ir_node *mem) -{ - assert(is_Call(node)); - set_irn_n(node, 0, mem); -} - -ir_node * -get_Call_ptr(const ir_node *node) -{ - assert(is_Call(node)); - return get_irn_n(node, 1); -} - -void -set_Call_ptr(ir_node *node, ir_node *ptr) -{ - assert(is_Call(node)); - set_irn_n(node, 1, ptr); -} - -ir_node ** -get_Call_param_arr(ir_node *node) -{ - assert(is_Call(node)); - return &get_irn_in(node)[CALL_PARAM_OFFSET + 1]; -} - -int -get_Call_n_params(const ir_node *node) -{ - assert(is_Call(node)); - return (get_irn_arity(node) - CALL_PARAM_OFFSET); -} - -ir_node * -get_Call_param(const ir_node *node, int pos) -{ - assert(is_Call(node)); - return get_irn_n(node, pos + CALL_PARAM_OFFSET); -} - -void -set_Call_param(ir_node *node, int pos, ir_node *param) -{ - assert(is_Call(node)); - set_irn_n(node, pos + CALL_PARAM_OFFSET, param); -} - -ir_type * -get_Call_type(ir_node *node) -{ - assert(is_Call(node)); - return node->attr.call.type; -} - -void -set_Call_type(ir_node *node, ir_type *tp) -{ - assert(is_Call(node)); - assert((get_unknown_type() == tp) || is_Method_type(tp)); - node->attr.call.type = tp; -} - -unsigned -get_Call_tail_call(const ir_node *node) -{ - assert(is_Call(node)); - return node->attr.call.tail_call; -} - -void -set_Call_tail_call(ir_node *node, unsigned tail_call) -{ - assert(is_Call(node)); - node->attr.call.tail_call = tail_call != 0; -} - -ir_node * -get_Builtin_mem(const ir_node *node) -{ - assert(is_Builtin(node)); - return get_irn_n(node, 0); -} - -void -set_Builin_mem(ir_node *node, ir_node *mem) -{ - assert(is_Builtin(node)); - set_irn_n(node, 0, mem); -} - -ir_builtin_kind -get_Builtin_kind(const ir_node *node) -{ - assert(is_Builtin(node)); - return node->attr.builtin.kind; -} - -void -set_Builtin_kind(ir_node *node, ir_builtin_kind kind) -{ - assert(is_Builtin(node)); - node->attr.builtin.kind = kind; -} - -ir_node ** -get_Builtin_param_arr(ir_node *node) -{ - assert(is_Builtin(node)); - return &get_irn_in(node)[BUILDIN_PARAM_OFFSET + 1]; -} - -int -get_Builtin_n_params(const ir_node *node) -{ - assert(is_Builtin(node)); - return (get_irn_arity(node) - BUILDIN_PARAM_OFFSET); -} - -ir_node * -get_Builtin_param(const ir_node *node, int pos) -{ - assert(is_Builtin(node)); - return get_irn_n(node, pos + BUILDIN_PARAM_OFFSET); -} - -void -set_Builtin_param(ir_node *node, int pos, ir_node *param) -{ - assert(is_Builtin(node)); - set_irn_n(node, pos + BUILDIN_PARAM_OFFSET, param); -} - -ir_type * -get_Builtin_type(ir_node *node) -{ - assert(is_Builtin(node)); - return node->attr.builtin.type; -} - -void -set_Builtin_type(ir_node *node, ir_type *tp) -{ - assert(is_Builtin(node)); - assert((get_unknown_type() == tp) || is_Method_type(tp)); - node->attr.builtin.type = tp; -} - -/* Returns a human readable string for the ir_builtin_kind. */ -const char *get_builtin_kind_name(ir_builtin_kind kind) -{ -#define X(a) case a: return #a; - switch (kind) { - X(ir_bk_trap); - X(ir_bk_debugbreak); - X(ir_bk_return_address); - X(ir_bk_frame_address); - X(ir_bk_prefetch); - X(ir_bk_ffs); - X(ir_bk_clz); - X(ir_bk_ctz); - X(ir_bk_popcount); - X(ir_bk_parity); - X(ir_bk_bswap); - X(ir_bk_inport); - X(ir_bk_outport); - X(ir_bk_inner_trampoline); - } - return ""; -#undef X -} - - -int Call_has_callees(const ir_node *node) -{ - assert(is_Call(node)); - return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) && - (node->attr.call.callee_arr != NULL)); -} - -int get_Call_n_callees(const ir_node *node) -{ - assert(is_Call(node) && node->attr.call.callee_arr); - return ARR_LEN(node->attr.call.callee_arr); -} - -ir_entity *get_Call_callee(const ir_node *node, int pos) -{ - assert(pos >= 0 && pos < get_Call_n_callees(node)); - return node->attr.call.callee_arr[pos]; -} - -void set_Call_callee_arr(ir_node *node, const int n, ir_entity ** arr) -{ - assert(is_Call(node)); - if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) { - node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, current_ir_graph->obst, n); - } - memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *)); -} - -void remove_Call_callee_arr(ir_node *node) -{ - assert(is_Call(node)); - node->attr.call.callee_arr = NULL; -} - -ir_node *get_CallBegin_ptr(const ir_node *node) -{ - assert(is_CallBegin(node)); - return get_irn_n(node, 0); -} - -void set_CallBegin_ptr(ir_node *node, ir_node *ptr) -{ - assert(is_CallBegin(node)); - set_irn_n(node, 0, ptr); -} - -ir_node *get_CallBegin_call(const ir_node *node) -{ - assert(is_CallBegin(node)); - return node->attr.callbegin.call; -} - -void set_CallBegin_call(ir_node *node, ir_node *call) -{ - assert(is_CallBegin(node)); - node->attr.callbegin.call = call; -} - -/* - * Returns non-zero if a Call is surely a self-recursive Call. - * Beware: if this functions returns 0, the call might be self-recursive! - */ -int is_self_recursive_Call(const ir_node *call) -{ - const ir_node *callee = get_Call_ptr(call); - - if (is_SymConst_addr_ent(callee)) { - const ir_entity *ent = get_SymConst_entity(callee); - const ir_graph *irg = get_entity_irg(ent); - if (irg == get_irn_irg(call)) - return 1; - } - return 0; -} - -#define BINOP(OP) \ -ir_node * get_##OP##_left(const ir_node *node) { \ - assert(is_##OP(node)); \ - return get_irn_n(node, node->op->op_index); \ -} \ -void set_##OP##_left(ir_node *node, ir_node *left) { \ - assert(is_##OP(node)); \ - set_irn_n(node, node->op->op_index, left); \ -} \ -ir_node *get_##OP##_right(const ir_node *node) { \ - assert(is_##OP(node)); \ - return get_irn_n(node, node->op->op_index + 1); \ -} \ -void set_##OP##_right(ir_node *node, ir_node *right) { \ - assert(is_##OP(node)); \ - set_irn_n(node, node->op->op_index + 1, right); \ -} - -#define UNOP(OP) \ -ir_node *get_##OP##_op(const ir_node *node) { \ - assert(is_##OP(node)); \ - return get_irn_n(node, node->op->op_index); \ -} \ -void set_##OP##_op(ir_node *node, ir_node *op) { \ - assert(is_##OP(node)); \ - set_irn_n(node, node->op->op_index, op); \ -} - -#define BINOP_MEM(OP) \ -BINOP(OP) \ - \ -ir_node * \ -get_##OP##_mem(const ir_node *node) { \ - assert(is_##OP(node)); \ - return get_irn_n(node, 0); \ -} \ - \ -void \ -set_##OP##_mem(ir_node *node, ir_node *mem) { \ - assert(is_##OP(node)); \ - set_irn_n(node, 0, mem); \ -} - -#define DIVOP(OP) \ -BINOP_MEM(OP) \ - \ -ir_mode *get_##OP##_resmode(const ir_node *node) { \ - assert(is_##OP(node)); \ - return node->attr.divmod.resmode; \ -} \ - \ -void set_##OP##_resmode(ir_node *node, ir_mode *mode) { \ - assert(is_##OP(node)); \ - node->attr.divmod.resmode = mode; \ -} - - -BINOP(Add) -BINOP(Borrow) -BINOP(Carry) -BINOP(Sub) -UNOP(Minus) -BINOP(Mul) -BINOP(Mulh) -DIVOP(Quot) -DIVOP(DivMod) -DIVOP(Div) -DIVOP(Mod) -UNOP(Abs) -BINOP(And) -BINOP(Or) -BINOP(Eor) -UNOP(Not) -BINOP(Shl) -BINOP(Shr) -BINOP(Shrs) -BINOP(Rotl) -BINOP(Cmp) -UNOP(Conv) -UNOP(Cast) - -int get_Div_no_remainder(const ir_node *node) -{ - assert(is_Div(node)); - return node->attr.divmod.no_remainder; -} - -void set_Div_no_remainder(ir_node *node, int no_remainder) -{ - assert(is_Div(node)); - node->attr.divmod.no_remainder = no_remainder; -} - -int get_Conv_strict(const ir_node *node) -{ - assert(is_Conv(node)); - return node->attr.conv.strict; -} - -void set_Conv_strict(ir_node *node, int strict_flag) -{ - assert(is_Conv(node)); - node->attr.conv.strict = (char)strict_flag; -} - -ir_type * -get_Cast_type(ir_node *node) -{ - assert(is_Cast(node)); - return node->attr.cast.type; -} - -void -set_Cast_type(ir_node *node, ir_type *to_tp) -{ - assert(is_Cast(node)); - node->attr.cast.type = to_tp; -} - - -/* Checks for upcast. - * - * Returns true if the Cast node casts a class type to a super type. - */ -int is_Cast_upcast(ir_node *node) -{ - ir_type *totype = get_Cast_type(node); - ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node)); - - assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent); - assert(fromtype); - - while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) { - totype = get_pointer_points_to_type(totype); - fromtype = get_pointer_points_to_type(fromtype); - } - - assert(fromtype); - - if (!is_Class_type(totype)) return 0; - return is_SubClass_of(fromtype, totype); -} - -/* Checks for downcast. - * - * Returns true if the Cast node casts a class type to a sub type. - */ -int is_Cast_downcast(ir_node *node) -{ - ir_type *totype = get_Cast_type(node); - ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node)); - - assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent); - assert(fromtype); - - while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) { - totype = get_pointer_points_to_type(totype); - fromtype = get_pointer_points_to_type(fromtype); - } - - assert(fromtype); - - if (!is_Class_type(totype)) return 0; - return is_SubClass_of(totype, fromtype); -} - -int -(is_unop)(const ir_node *node) { - return _is_unop(node); -} - -ir_node * -get_unop_op(const ir_node *node) -{ - if (node->op->opar == oparity_unary) - return get_irn_n(node, node->op->op_index); - - assert(node->op->opar == oparity_unary); - return NULL; -} - -void -set_unop_op(ir_node *node, ir_node *op) -{ - if (node->op->opar == oparity_unary) - set_irn_n(node, node->op->op_index, op); - - assert(node->op->opar == oparity_unary); -} - -int -(is_binop)(const ir_node *node) { - return _is_binop(node); -} - -ir_node * -get_binop_left(const ir_node *node) -{ - assert(node->op->opar == oparity_binary); - return get_irn_n(node, node->op->op_index); -} - -void -set_binop_left(ir_node *node, ir_node *left) -{ - assert(node->op->opar == oparity_binary); - set_irn_n(node, node->op->op_index, left); -} - -ir_node * -get_binop_right(const ir_node *node) -{ - assert(node->op->opar == oparity_binary); - return get_irn_n(node, node->op->op_index + 1); -} - -void -set_binop_right(ir_node *node, ir_node *right) -{ - assert(node->op->opar == oparity_binary); - set_irn_n(node, node->op->op_index + 1, right); -} - -int is_Phi0(const ir_node *n) -{ - assert(n); - - return ((get_irn_op(n) == op_Phi) && - (get_irn_arity(n) == 0) && - (get_irg_phase_state(get_irn_irg(n)) == phase_building)); -} - -ir_node ** -get_Phi_preds_arr(ir_node *node) -{ - assert(node->op == op_Phi); - return (ir_node **)&(get_irn_in(node)[1]); -} - -int -get_Phi_n_preds(const ir_node *node) -{ - assert(is_Phi(node) || is_Phi0(node)); - return (get_irn_arity(node)); -} - -/* -void set_Phi_n_preds(ir_node *node, int n_preds) -{ - assert(node->op == op_Phi); -} -*/ - -ir_node * -get_Phi_pred(const ir_node *node, int pos) -{ - assert(is_Phi(node) || is_Phi0(node)); - return get_irn_n(node, pos); -} - -void -set_Phi_pred(ir_node *node, int pos, ir_node *pred) -{ - assert(is_Phi(node) || is_Phi0(node)); - set_irn_n(node, pos, pred); -} - -ir_node *(get_Phi_next)(const ir_node *phi) -{ - return _get_Phi_next(phi); -} - -void (set_Phi_next)(ir_node *phi, ir_node *next) -{ - _set_Phi_next(phi, next); -} - -int is_memop(const ir_node *node) -{ - ir_opcode code = get_irn_opcode(node); - return (code == iro_Load || code == iro_Store); -} - -ir_node *get_memop_mem(const ir_node *node) -{ - assert(is_memop(node)); - return get_irn_n(node, 0); -} - -void set_memop_mem(ir_node *node, ir_node *mem) -{ - assert(is_memop(node)); - set_irn_n(node, 0, mem); -} - -ir_node *get_memop_ptr(const ir_node *node) -{ - assert(is_memop(node)); - return get_irn_n(node, 1); -} - -void set_memop_ptr(ir_node *node, ir_node *ptr) -{ - assert(is_memop(node)); - set_irn_n(node, 1, ptr); -} - -ir_node * -get_Load_mem(const ir_node *node) -{ - assert(is_Load(node)); - return get_irn_n(node, 0); -} - -void -set_Load_mem(ir_node *node, ir_node *mem) -{ - assert(is_Load(node)); - set_irn_n(node, 0, mem); -} - -ir_node * -get_Load_ptr(const ir_node *node) -{ - assert(is_Load(node)); - return get_irn_n(node, 1); -} - -void -set_Load_ptr(ir_node *node, ir_node *ptr) -{ - assert(is_Load(node)); - set_irn_n(node, 1, ptr); -} - -ir_mode * -get_Load_mode(const ir_node *node) -{ - assert(is_Load(node)); - return node->attr.load.mode; -} - -void -set_Load_mode(ir_node *node, ir_mode *mode) -{ - assert(is_Load(node)); - node->attr.load.mode = mode; -} - -ir_volatility -get_Load_volatility(const ir_node *node) -{ - assert(is_Load(node)); - return node->attr.load.volatility; -} - -void -set_Load_volatility(ir_node *node, ir_volatility volatility) -{ - assert(is_Load(node)); - node->attr.load.volatility = volatility; -} - -ir_align -get_Load_align(const ir_node *node) -{ - assert(is_Load(node)); - return node->attr.load.aligned; -} - -void -set_Load_align(ir_node *node, ir_align align) -{ - assert(is_Load(node)); - node->attr.load.aligned = align; -} - - -ir_node * -get_Store_mem(const ir_node *node) -{ - assert(is_Store(node)); - return get_irn_n(node, 0); -} - -void -set_Store_mem(ir_node *node, ir_node *mem) -{ - assert(is_Store(node)); - set_irn_n(node, 0, mem); -} - -ir_node * -get_Store_ptr(const ir_node *node) -{ - assert(is_Store(node)); - return get_irn_n(node, 1); -} - -void -set_Store_ptr(ir_node *node, ir_node *ptr) -{ - assert(is_Store(node)); - set_irn_n(node, 1, ptr); -} - -ir_node * -get_Store_value(const ir_node *node) -{ - assert(is_Store(node)); - return get_irn_n(node, 2); -} - -void -set_Store_value(ir_node *node, ir_node *value) -{ - assert(is_Store(node)); - set_irn_n(node, 2, value); -} - -ir_volatility -get_Store_volatility(const ir_node *node) -{ - assert(is_Store(node)); - return node->attr.store.volatility; -} - -void -set_Store_volatility(ir_node *node, ir_volatility volatility) -{ - assert(is_Store(node)); - node->attr.store.volatility = volatility; -} - -ir_align -get_Store_align(const ir_node *node) -{ - assert(is_Store(node)); - return node->attr.store.aligned; -} - -void -set_Store_align(ir_node *node, ir_align align) -{ - assert(is_Store(node)); - node->attr.store.aligned = align; -} - - -ir_node * -get_Alloc_mem(const ir_node *node) -{ - assert(is_Alloc(node)); - return get_irn_n(node, 0); -} - -void -set_Alloc_mem(ir_node *node, ir_node *mem) -{ - assert(is_Alloc(node)); - set_irn_n(node, 0, mem); -} - -ir_node * -get_Alloc_size(const ir_node *node) -{ - assert(is_Alloc(node)); - return get_irn_n(node, 1); -} - -void -set_Alloc_size(ir_node *node, ir_node *size) -{ - assert(is_Alloc(node)); - set_irn_n(node, 1, size); -} - -ir_type * -get_Alloc_type(ir_node *node) -{ - assert(is_Alloc(node)); - return node->attr.alloc.type; -} - -void -set_Alloc_type(ir_node *node, ir_type *tp) -{ - assert(is_Alloc(node)); - node->attr.alloc.type = tp; -} - -ir_where_alloc -get_Alloc_where(const ir_node *node) -{ - assert(is_Alloc(node)); - return node->attr.alloc.where; -} - -void -set_Alloc_where(ir_node *node, ir_where_alloc where) -{ - assert(is_Alloc(node)); - node->attr.alloc.where = where; -} - - -ir_node * -get_Free_mem(const ir_node *node) -{ - assert(is_Free(node)); - return get_irn_n(node, 0); -} - -void -set_Free_mem(ir_node *node, ir_node *mem) -{ - assert(is_Free(node)); - set_irn_n(node, 0, mem); -} - -ir_node * -get_Free_ptr(const ir_node *node) -{ - assert(is_Free(node)); - return get_irn_n(node, 1); -} - -void -set_Free_ptr(ir_node *node, ir_node *ptr) -{ - assert(is_Free(node)); - set_irn_n(node, 1, ptr); -} - -ir_node * -get_Free_size(const ir_node *node) -{ - assert(is_Free(node)); - return get_irn_n(node, 2); -} - -void -set_Free_size(ir_node *node, ir_node *size) -{ - assert(is_Free(node)); - set_irn_n(node, 2, size); -} - -ir_type * -get_Free_type(ir_node *node) -{ - assert(is_Free(node)); - return node->attr.free.type; -} - -void -set_Free_type(ir_node *node, ir_type *tp) -{ - assert(is_Free(node)); - node->attr.free.type = tp; -} - -ir_where_alloc -get_Free_where(const ir_node *node) -{ - assert(is_Free(node)); - return node->attr.free.where; -} - -void -set_Free_where(ir_node *node, ir_where_alloc where) -{ - assert(is_Free(node)); - node->attr.free.where = where; -} - -ir_node **get_Sync_preds_arr(ir_node *node) -{ - assert(is_Sync(node)); - return (ir_node **)&(get_irn_in(node)[1]); -} - -int get_Sync_n_preds(const ir_node *node) -{ - assert(is_Sync(node)); - return (get_irn_arity(node)); -} - -/* -void set_Sync_n_preds(ir_node *node, int n_preds) -{ - assert(is_Sync(node)); -} -*/ - -ir_node *get_Sync_pred(const ir_node *node, int pos) -{ - assert(is_Sync(node)); - return get_irn_n(node, pos); -} - -void set_Sync_pred(ir_node *node, int pos, ir_node *pred) -{ - assert(is_Sync(node)); - set_irn_n(node, pos, pred); -} - -/* Add a new Sync predecessor */ -void add_Sync_pred(ir_node *node, ir_node *pred) -{ - assert(is_Sync(node)); - add_irn_n(node, pred); -} - -/* Returns the source language type of a Proj node. */ -ir_type *get_Proj_type(ir_node *n) -{ - ir_type *tp = firm_unknown_type; - ir_node *pred = get_Proj_pred(n); - - switch (get_irn_opcode(pred)) { - case iro_Proj: { - ir_node *pred_pred; - /* Deal with Start / Call here: we need to know the Proj Nr. */ - assert(get_irn_mode(pred) == mode_T); - pred_pred = get_Proj_pred(pred); - - if (is_Start(pred_pred)) { - ir_type *mtp = get_entity_type(get_irg_entity(get_irn_irg(pred_pred))); - tp = get_method_param_type(mtp, get_Proj_proj(n)); - } else if (is_Call(pred_pred)) { - ir_type *mtp = get_Call_type(pred_pred); - tp = get_method_res_type(mtp, get_Proj_proj(n)); - } - } break; - case iro_Start: break; - case iro_Call: break; - case iro_Load: { - ir_node *a = get_Load_ptr(pred); - if (is_Sel(a)) - tp = get_entity_type(get_Sel_entity(a)); - } break; - default: - break; - } - return tp; -} - -ir_node * -get_Proj_pred(const ir_node *node) -{ - assert(is_Proj(node)); - return get_irn_n(node, 0); -} - -void -set_Proj_pred(ir_node *node, ir_node *pred) -{ - assert(is_Proj(node)); - set_irn_n(node, 0, pred); -} - -long -get_Proj_proj(const ir_node *node) -{ -#ifdef INTERPROCEDURAL_VIEW - ir_opcode code = get_irn_opcode(node); - - if (code == iro_Proj) { - return node->attr.proj; - } - else { - assert(code == iro_Filter); - return node->attr.filter.proj; - } -#else - assert(is_Proj(node)); - return node->attr.proj; -#endif /* INTERPROCEDURAL_VIEW */ -} - -void -set_Proj_proj(ir_node *node, long proj) -{ -#ifdef INTERPROCEDURAL_VIEW - ir_opcode code = get_irn_opcode(node); - - if (code == iro_Proj) { - node->attr.proj = proj; - } - else { - assert(code == iro_Filter); - node->attr.filter.proj = proj; - } -#else - assert(is_Proj(node)); - node->attr.proj = proj; -#endif /* INTERPROCEDURAL_VIEW */ -} - -/* Returns non-zero if a node is a routine parameter. */ -int (is_arg_Proj)(const ir_node *node) -{ - return _is_arg_Proj(node); -} - -ir_node ** -get_Tuple_preds_arr(ir_node *node) -{ - assert(is_Tuple(node)); - return (ir_node **)&(get_irn_in(node)[1]); -} - -int -get_Tuple_n_preds(const ir_node *node) +ir_enum_const *get_SymConst_enum(const ir_node *node) { - assert(is_Tuple(node)); - return get_irn_arity(node); + assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node))); + return node->attr.symc.sym.enum_p; } -/* -void -set_Tuple_n_preds(ir_node *node, int n_preds) +void set_SymConst_enum(ir_node *node, ir_enum_const *ec) { - assert(is_Tuple(node)); + assert(is_SymConst(node) && SYMCONST_HAS_ENUM(get_SymConst_kind(node))); + node->attr.symc.sym.enum_p = ec; } -*/ -ir_node * -get_Tuple_pred(const ir_node *node, int pos) +union symconst_symbol +get_SymConst_symbol(const ir_node *node) { - assert(is_Tuple(node)); - return get_irn_n(node, pos); + assert(is_SymConst(node)); + return node->attr.symc.sym; } -void -set_Tuple_pred(ir_node *node, int pos, ir_node *pred) +void set_SymConst_symbol(ir_node *node, union symconst_symbol sym) { - assert(is_Tuple(node)); - set_irn_n(node, pos, pred); + assert(is_SymConst(node)); + node->attr.symc.sym = sym; } -ir_node * -get_Id_pred(const ir_node *node) +int get_Sel_n_indexs(const ir_node *node) { - assert(is_Id(node)); - return get_irn_n(node, 0); + assert(is_Sel(node)); + return (get_irn_arity(node) - SEL_INDEX_OFFSET); } -void -set_Id_pred(ir_node *node, ir_node *pred) +ir_node **get_Sel_index_arr(ir_node *node) { - assert(is_Id(node)); - set_irn_n(node, 0, pred); + assert(is_Sel(node)); + if (get_Sel_n_indexs(node) > 0) + return (ir_node **)& get_irn_in(node)[SEL_INDEX_OFFSET + 1]; + else + return NULL; } -ir_node *get_Confirm_value(const ir_node *node) +ir_node *get_Sel_index(const ir_node *node, int pos) { - assert(is_Confirm(node)); - return get_irn_n(node, 0); + assert(is_Sel(node)); + return get_irn_n(node, pos + SEL_INDEX_OFFSET); } -void set_Confirm_value(ir_node *node, ir_node *value) +void set_Sel_index(ir_node *node, int pos, ir_node *index) { - assert(is_Confirm(node)); - set_irn_n(node, 0, value); + assert(is_Sel(node)); + set_irn_n(node, pos + SEL_INDEX_OFFSET, index); } -ir_node *get_Confirm_bound(const ir_node *node) +ir_node **get_Call_param_arr(ir_node *node) { - assert(is_Confirm(node)); - return get_irn_n(node, 1); + assert(is_Call(node)); + return &get_irn_in(node)[CALL_PARAM_OFFSET + 1]; } -void set_Confirm_bound(ir_node *node, ir_node *bound) +int get_Call_n_params(const ir_node *node) { - assert(is_Confirm(node)); - set_irn_n(node, 0, bound); + assert(is_Call(node)); + return get_irn_arity(node) - CALL_PARAM_OFFSET; } -pn_Cmp get_Confirm_cmp(const ir_node *node) +ir_node *get_Call_param(const ir_node *node, int pos) { - assert(is_Confirm(node)); - return node->attr.confirm.cmp; + assert(is_Call(node)); + return get_irn_n(node, pos + CALL_PARAM_OFFSET); } -void set_Confirm_cmp(ir_node *node, pn_Cmp cmp) +void set_Call_param(ir_node *node, int pos, ir_node *param) { - assert(is_Confirm(node)); - node->attr.confirm.cmp = cmp; + assert(is_Call(node)); + set_irn_n(node, pos + CALL_PARAM_OFFSET, param); } -ir_node * -get_Filter_pred(ir_node *node) +ir_node **get_Builtin_param_arr(ir_node *node) { - assert(is_Filter(node)); - return node->in[1]; + assert(is_Builtin(node)); + return &get_irn_in(node)[BUILTIN_PARAM_OFFSET + 1]; } -void -set_Filter_pred(ir_node *node, ir_node *pred) +int get_Builtin_n_params(const ir_node *node) { - assert(is_Filter(node)); - node->in[1] = pred; + assert(is_Builtin(node)); + return (get_irn_arity(node) - BUILTIN_PARAM_OFFSET); } -long -get_Filter_proj(ir_node *node) +ir_node *get_Builtin_param(const ir_node *node, int pos) { - assert(is_Filter(node)); - return node->attr.filter.proj; + assert(is_Builtin(node)); + return get_irn_n(node, pos + BUILTIN_PARAM_OFFSET); } -void -set_Filter_proj(ir_node *node, long proj) +void set_Builtin_param(ir_node *node, int pos, ir_node *param) { - assert(is_Filter(node)); - node->attr.filter.proj = proj; + assert(is_Builtin(node)); + set_irn_n(node, pos + BUILTIN_PARAM_OFFSET, param); } -/* Don't use get_irn_arity, get_irn_n in implementation as access - shall work independent of view!!! */ -void set_Filter_cg_pred_arr(ir_node *node, int arity, ir_node ** in) +const char *get_builtin_kind_name(ir_builtin_kind kind) { - assert(is_Filter(node)); - if (node->attr.filter.in_cg == NULL || arity != ARR_LEN(node->attr.filter.in_cg) - 1) { - ir_graph *irg = get_irn_irg(node); - node->attr.filter.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1); - node->attr.filter.backedge = new_backedge_arr(irg->obst, arity); - node->attr.filter.in_cg[0] = node->in[0]; +#define X(a) case a: return #a + switch (kind) { + X(ir_bk_trap); + X(ir_bk_debugbreak); + X(ir_bk_return_address); + X(ir_bk_frame_address); + X(ir_bk_prefetch); + X(ir_bk_ffs); + X(ir_bk_clz); + X(ir_bk_ctz); + X(ir_bk_popcount); + X(ir_bk_parity); + X(ir_bk_bswap); + X(ir_bk_inport); + X(ir_bk_outport); + X(ir_bk_inner_trampoline); } - memcpy(node->attr.filter.in_cg + 1, in, sizeof(ir_node *) * arity); + return ""; +#undef X } -void set_Filter_cg_pred(ir_node * node, int pos, ir_node * pred) -{ - assert(is_Filter(node) && node->attr.filter.in_cg && - 0 <= pos && pos < ARR_LEN(node->attr.filter.in_cg) - 1); - node->attr.filter.in_cg[pos + 1] = pred; -} -int get_Filter_n_cg_preds(ir_node *node) +int Call_has_callees(const ir_node *node) { - assert(is_Filter(node) && node->attr.filter.in_cg); - return (ARR_LEN(node->attr.filter.in_cg) - 1); + assert(is_Call(node)); + return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) && + (node->attr.call.callee_arr != NULL)); } -ir_node *get_Filter_cg_pred(ir_node *node, int pos) +size_t get_Call_n_callees(const ir_node *node) { - int arity; - assert(is_Filter(node) && node->attr.filter.in_cg && - 0 <= pos); - arity = ARR_LEN(node->attr.filter.in_cg); - assert(pos < arity - 1); - return node->attr.filter.in_cg[pos + 1]; + assert(is_Call(node) && node->attr.call.callee_arr); + return ARR_LEN(node->attr.call.callee_arr); } -/* Mux support */ -ir_node *get_Mux_sel(const ir_node *node) +ir_entity *get_Call_callee(const ir_node *node, size_t pos) { - assert(is_Mux(node)); - return node->in[1]; + assert(pos < get_Call_n_callees(node)); + return node->attr.call.callee_arr[pos]; } -void set_Mux_sel(ir_node *node, ir_node *sel) +void set_Call_callee_arr(ir_node *node, size_t n, ir_entity ** arr) { - assert(is_Mux(node)); - node->in[1] = sel; -} + ir_graph *irg = get_irn_irg(node); -ir_node *get_Mux_false(const ir_node *node) -{ - assert(is_Mux(node)); - return node->in[2]; + assert(is_Call(node)); + if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) { + node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, irg->obst, n); + } + memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *)); } -void set_Mux_false(ir_node *node, ir_node *ir_false) +void remove_Call_callee_arr(ir_node *node) { - assert(is_Mux(node)); - node->in[2] = ir_false; + assert(is_Call(node)); + node->attr.call.callee_arr = NULL; } -ir_node *get_Mux_true(const ir_node *node) +int is_Cast_upcast(ir_node *node) { - assert(is_Mux(node)); - return node->in[3]; + ir_type *totype = get_Cast_type(node); + ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node)); + + assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent); + assert(fromtype); + + while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) { + totype = get_pointer_points_to_type(totype); + fromtype = get_pointer_points_to_type(fromtype); + } + + assert(fromtype); + + if (!is_Class_type(totype)) return 0; + return is_SubClass_of(fromtype, totype); } -void set_Mux_true(ir_node *node, ir_node *ir_true) +int is_Cast_downcast(ir_node *node) { - assert(is_Mux(node)); - node->in[3] = ir_true; + ir_type *totype = get_Cast_type(node); + ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node)); + + assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent); + assert(fromtype); + + while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) { + totype = get_pointer_points_to_type(totype); + fromtype = get_pointer_points_to_type(fromtype); + } + + assert(fromtype); + + if (!is_Class_type(totype)) return 0; + return is_SubClass_of(totype, fromtype); } -/* CopyB support */ -ir_node *get_CopyB_mem(const ir_node *node) +int (is_unop)(const ir_node *node) { - assert(is_CopyB(node)); - return get_irn_n(node, 0); + return is_unop_(node); } -void set_CopyB_mem(ir_node *node, ir_node *mem) +ir_node *get_unop_op(const ir_node *node) { - assert(node->op == op_CopyB); - set_irn_n(node, 0, mem); + if (node->op->opar == oparity_unary) + return get_irn_n(node, node->op->op_index); + + assert(node->op->opar == oparity_unary); + return NULL; } -ir_node *get_CopyB_dst(const ir_node *node) +void set_unop_op(ir_node *node, ir_node *op) { - assert(is_CopyB(node)); - return get_irn_n(node, 1); + if (node->op->opar == oparity_unary) + set_irn_n(node, node->op->op_index, op); + + assert(node->op->opar == oparity_unary); } -void set_CopyB_dst(ir_node *node, ir_node *dst) +int (is_binop)(const ir_node *node) { - assert(is_CopyB(node)); - set_irn_n(node, 1, dst); + return is_binop_(node); } -ir_node *get_CopyB_src(const ir_node *node) +ir_node *get_binop_left(const ir_node *node) { - assert(is_CopyB(node)); - return get_irn_n(node, 2); + assert(node->op->opar == oparity_binary); + return get_irn_n(node, node->op->op_index); } -void set_CopyB_src(ir_node *node, ir_node *src) +void set_binop_left(ir_node *node, ir_node *left) { - assert(is_CopyB(node)); - set_irn_n(node, 2, src); + assert(node->op->opar == oparity_binary); + set_irn_n(node, node->op->op_index, left); } -ir_type *get_CopyB_type(ir_node *node) +ir_node *get_binop_right(const ir_node *node) { - assert(is_CopyB(node)); - return node->attr.copyb.type; + assert(node->op->opar == oparity_binary); + return get_irn_n(node, node->op->op_index + 1); } -void set_CopyB_type(ir_node *node, ir_type *data_type) +void set_binop_right(ir_node *node, ir_node *right) { - assert(is_CopyB(node) && data_type); - node->attr.copyb.type = data_type; + assert(node->op->opar == oparity_binary); + set_irn_n(node, node->op->op_index + 1, right); } - -ir_type * -get_InstOf_type(ir_node *node) +ir_node **get_Phi_preds_arr(ir_node *node) { - assert(node->op == op_InstOf); - return node->attr.instof.type; + assert(is_Phi(node)); + return (ir_node **)&(get_irn_in(node)[1]); } -void -set_InstOf_type(ir_node *node, ir_type *type) +int get_Phi_n_preds(const ir_node *node) { - assert(node->op == op_InstOf); - node->attr.instof.type = type; + assert(is_Phi(node)); + return get_irn_arity(node); } -ir_node * -get_InstOf_store(const ir_node *node) +ir_node *get_Phi_pred(const ir_node *node, int pos) { - assert(node->op == op_InstOf); - return get_irn_n(node, 0); + assert(is_Phi(node)); + return get_irn_n(node, pos); } -void -set_InstOf_store(ir_node *node, ir_node *obj) +void set_Phi_pred(ir_node *node, int pos, ir_node *pred) { - assert(node->op == op_InstOf); - set_irn_n(node, 0, obj); + assert(is_Phi(node)); + set_irn_n(node, pos, pred); } -ir_node * -get_InstOf_obj(const ir_node *node) +ir_node *(get_Phi_next)(const ir_node *phi) { - assert(node->op == op_InstOf); - return get_irn_n(node, 1); + return get_Phi_next_(phi); } -void -set_InstOf_obj(ir_node *node, ir_node *obj) +void (set_Phi_next)(ir_node *phi, ir_node *next) { - assert(node->op == op_InstOf); - set_irn_n(node, 1, obj); + set_Phi_next_(phi, next); } -/* Returns the memory input of a Raise operation. */ -ir_node * -get_Raise_mem(const ir_node *node) +int is_memop(const ir_node *node) { - assert(is_Raise(node)); - return get_irn_n(node, 0); + return is_op_uses_memory(get_irn_op(node)); } -void -set_Raise_mem(ir_node *node, ir_node *mem) +ir_node *get_memop_mem(const ir_node *node) { - assert(is_Raise(node)); - set_irn_n(node, 0, mem); + const ir_op *op = get_irn_op(node); + assert(is_memop(node)); + return get_irn_n(node, op->memory_index); } -ir_node * -get_Raise_exo_ptr(const ir_node *node) +void set_memop_mem(ir_node *node, ir_node *mem) { - assert(is_Raise(node)); - return get_irn_n(node, 1); + const ir_op *op = get_irn_op(node); + assert(is_memop(node)); + set_irn_n(node, op->memory_index, mem); } -void -set_Raise_exo_ptr(ir_node *node, ir_node *exo_ptr) +ir_node **get_Sync_preds_arr(ir_node *node) { - assert(is_Raise(node)); - set_irn_n(node, 1, exo_ptr); + assert(is_Sync(node)); + return (ir_node **)&(get_irn_in(node)[1]); } -/* Bound support */ - -/* Returns the memory input of a Bound operation. */ -ir_node *get_Bound_mem(const ir_node *bound) +int get_Sync_n_preds(const ir_node *node) { - assert(is_Bound(bound)); - return get_irn_n(bound, 0); + assert(is_Sync(node)); + return (get_irn_arity(node)); } -void set_Bound_mem(ir_node *bound, ir_node *mem) +ir_node *get_Sync_pred(const ir_node *node, int pos) { - assert(is_Bound(bound)); - set_irn_n(bound, 0, mem); + assert(is_Sync(node)); + return get_irn_n(node, pos); } -/* Returns the index input of a Bound operation. */ -ir_node *get_Bound_index(const ir_node *bound) +void set_Sync_pred(ir_node *node, int pos, ir_node *pred) { - assert(is_Bound(bound)); - return get_irn_n(bound, 1); + assert(is_Sync(node)); + set_irn_n(node, pos, pred); } -void set_Bound_index(ir_node *bound, ir_node *idx) +void add_Sync_pred(ir_node *node, ir_node *pred) { - assert(is_Bound(bound)); - set_irn_n(bound, 1, idx); + assert(is_Sync(node)); + add_irn_n(node, pred); } -/* Returns the lower bound input of a Bound operation. */ -ir_node *get_Bound_lower(const ir_node *bound) +int (is_arg_Proj)(const ir_node *node) { - assert(is_Bound(bound)); - return get_irn_n(bound, 2); + return is_arg_Proj_(node); } -void set_Bound_lower(ir_node *bound, ir_node *lower) +int is_x_except_Proj(const ir_node *node) { - assert(is_Bound(bound)); - set_irn_n(bound, 2, lower); + ir_node *pred; + if (!is_Proj(node)) + return false; + pred = get_Proj_pred(node); + if (!is_fragile_op(pred)) + return false; + return get_Proj_proj(node) == pred->op->pn_x_except; } -/* Returns the upper bound input of a Bound operation. */ -ir_node *get_Bound_upper(const ir_node *bound) +int is_x_regular_Proj(const ir_node *node) { - assert(is_Bound(bound)); - return get_irn_n(bound, 3); + ir_node *pred; + if (!is_Proj(node)) + return false; + pred = get_Proj_pred(node); + if (!is_fragile_op(pred)) + return false; + return get_Proj_proj(node) == pred->op->pn_x_regular; } -void set_Bound_upper(ir_node *bound, ir_node *upper) +void ir_set_throws_exception(ir_node *node, int throws_exception) { - assert(is_Bound(bound)); - set_irn_n(bound, 3, upper); + except_attr *attr = &node->attr.except; + assert(is_fragile_op(node)); + attr->throws_exception = throws_exception; } -/* Return the operand of a Pin node. */ -ir_node *get_Pin_op(const ir_node *pin) +int ir_throws_exception(const ir_node *node) { - assert(is_Pin(pin)); - return get_irn_n(pin, 0); + const except_attr *attr = &node->attr.except; + assert(is_fragile_op(node)); + return attr->throws_exception; } -void set_Pin_op(ir_node *pin, ir_node *node) +ir_node **get_Tuple_preds_arr(ir_node *node) { - assert(is_Pin(pin)); - set_irn_n(pin, 0, node); + assert(is_Tuple(node)); + return (ir_node **)&(get_irn_in(node)[1]); } -/* Return the assembler text of an ASM pseudo node. */ -ident *get_ASM_text(const ir_node *node) +int get_Tuple_n_preds(const ir_node *node) { - assert(is_ASM(node)); - return node->attr.assem.asm_text; + assert(is_Tuple(node)); + return get_irn_arity(node); } -/* Return the number of input constraints for an ASM node. */ -int get_ASM_n_input_constraints(const ir_node *node) +ir_node *get_Tuple_pred(const ir_node *node, int pos) { - assert(is_ASM(node)); - return ARR_LEN(node->attr.assem.inputs); + assert(is_Tuple(node)); + return get_irn_n(node, pos); } -/* Return the input constraints for an ASM node. This is a flexible array. */ -const ir_asm_constraint *get_ASM_input_constraints(const ir_node *node) +void set_Tuple_pred(ir_node *node, int pos, ir_node *pred) { - assert(is_ASM(node)); - return node->attr.assem.inputs; + assert(is_Tuple(node)); + set_irn_n(node, pos, pred); } -/* Return the number of output constraints for an ASM node. */ -int get_ASM_n_output_constraints(const ir_node *node) +int get_ASM_n_inputs(const ir_node *node) { assert(is_ASM(node)); - return ARR_LEN(node->attr.assem.outputs); + return get_irn_arity(node) - ASM_PARAM_OFFSET; } -/* Return the output constraints for an ASM node. */ -const ir_asm_constraint *get_ASM_output_constraints(const ir_node *node) +ir_node *get_ASM_input(const ir_node *node, int pos) { - assert(is_ASM(node)); - return node->attr.assem.outputs; + return get_irn_n(node, ASM_PARAM_OFFSET + pos); } -/* Return the number of clobbered registers for an ASM node. */ -int get_ASM_n_clobbers(const ir_node *node) +size_t get_ASM_n_output_constraints(const ir_node *node) { assert(is_ASM(node)); - return ARR_LEN(node->attr.assem.clobber); + return ARR_LEN(node->attr.assem.output_constraints); } -/* Return the list of clobbered registers for an ASM node. */ -ident **get_ASM_clobbers(const ir_node *node) +size_t get_ASM_n_clobbers(const ir_node *node) { assert(is_ASM(node)); - return node->attr.assem.clobber; + return ARR_LEN(node->attr.assem.clobbers); } -/* returns the graph of a node */ -ir_graph * -get_irn_irg(const ir_node *node) +ir_graph *(get_irn_irg)(const ir_node *node) { - /* - * Do not use get_nodes_Block() here, because this - * will check the pinned state. - * However even a 'wrong' block is always in the proper - * irg. - */ - if (! is_Block(node)) - node = get_irn_n(node, -1); - /* note that get_Block_irg() can handle Bad nodes */ - return get_Block_irg(node); + return get_irn_irg_(node); } - -/*----------------------------------------------------------------*/ -/* Auxiliary routines */ -/*----------------------------------------------------------------*/ - -ir_node * -skip_Proj(ir_node *node) +ir_node *skip_Proj(ir_node *node) { /* don't assert node !!! */ if (node == NULL) @@ -2878,29 +1247,22 @@ skip_Proj_const(const ir_node *node) return node; } -ir_node * -skip_Tuple(ir_node *node) +ir_node *skip_Tuple(ir_node *node) { ir_node *pred; - ir_op *op; restart: if (is_Proj(node)) { pred = get_Proj_pred(node); - op = get_irn_op(pred); - /* - * Looks strange but calls get_irn_op() only once - * in most often cases. - */ - if (op == op_Proj) { /* nested Tuple ? */ + if (is_Proj(pred)) { /* nested Tuple ? */ pred = skip_Tuple(pred); if (is_Tuple(pred)) { node = get_Tuple_pred(pred, get_Proj_proj(node)); goto restart; } - } else if (op == op_Tuple) { + } else if (is_Tuple(pred)) { node = get_Tuple_pred(pred, get_Proj_proj(node)); goto restart; } @@ -2908,7 +1270,6 @@ restart: return node; } -/* returns operand of node if node is a Cast */ ir_node *skip_Cast(ir_node *node) { if (is_Cast(node)) @@ -2916,7 +1277,6 @@ ir_node *skip_Cast(ir_node *node) return node; } -/* returns operand of node if node is a Cast */ const ir_node *skip_Cast_const(const ir_node *node) { if (is_Cast(node)) @@ -2924,7 +1284,6 @@ const ir_node *skip_Cast_const(const ir_node *node) return node; } -/* returns operand of node if node is a Pin */ ir_node *skip_Pin(ir_node *node) { if (is_Pin(node)) @@ -2932,7 +1291,6 @@ ir_node *skip_Pin(ir_node *node) return node; } -/* returns operand of node if node is a Confirm */ ir_node *skip_Confirm(ir_node *node) { if (is_Confirm(node)) @@ -2940,7 +1298,6 @@ ir_node *skip_Confirm(ir_node *node) return node; } -/* skip all high-level ops */ ir_node *skip_HighLevel_ops(ir_node *node) { while (is_op_highlevel(get_irn_op(node))) { @@ -2950,18 +1307,15 @@ ir_node *skip_HighLevel_ops(ir_node *node) } -/* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity - * than any other approach, as Id chains are resolved and all point to the real node, or - * all id's are self loops. - * - * Note: This function takes 10% of mostly ANY the compiler run, so it's - * a little bit "hand optimized". - * - * Moreover, it CANNOT be switched off using get_opt_normalize() ... - */ -ir_node * -skip_Id(ir_node *node) +ir_node *skip_Id(ir_node *node) { + /* This should compact Id-cycles to self-cycles. It has the same (or less?) complexity + * than any other approach, as Id chains are resolved and all point to the real node, or + * all id's are self loops. + * + * Note: This function takes 10% of mostly ANY the compiler run, so it's + * a little bit "hand optimized". + */ ir_node *pred; /* don't assert node !!! */ @@ -2983,7 +1337,7 @@ skip_Id(ir_node *node) node->in[0+1] = node; /* turn us into a self referencing Id: shorten Id cycles. */ res = skip_Id(rem_pred); - if (res->op == op_Id) /* self-loop */ return node; + if (is_Id(res)) /* self-loop */ return node; node->in[0+1] = res; /* Turn Id chain into Ids all referencing the chain end. */ return res; @@ -2992,177 +1346,72 @@ skip_Id(ir_node *node) } } -void skip_Id_and_store(ir_node **node) +int (is_SymConst_addr_ent)(const ir_node *node) { - ir_node *n = *node; - - if (!n || (n->op != op_Id)) return; - - /* Don't use get_Id_pred(): We get into an endless loop for - self-referencing Ids. */ - *node = skip_Id(n); -} - -int -(is_strictConv)(const ir_node *node) { - return _is_strictConv(node); + return is_SymConst_addr_ent_(node); } -int -(is_no_Block)(const ir_node *node) { - return _is_no_Block(node); -} - -/* Returns true if node is a SymConst node with kind symconst_addr_ent. */ -int -(is_SymConst_addr_ent)(const ir_node *node) { - return _is_SymConst_addr_ent(node); -} - -/* Returns true if the operation manipulates control flow. */ int is_cfop(const ir_node *node) { + if (is_fragile_op(node) && ir_throws_exception(node)) + return true; + return is_op_cfopcode(get_irn_op(node)); } -/* Returns true if the operation manipulates interprocedural control flow: - CallBegin, EndReg, EndExcept */ -int is_ip_cfop(const ir_node *node) +int is_unknown_jump(const ir_node *node) { - return is_ip_cfopcode(get_irn_op(node)); + return is_op_unknown_jump(get_irn_op(node)); } -/* Returns true if the operation can change the control flow because - of an exception. */ -int -is_fragile_op(const ir_node *node) +int is_fragile_op(const ir_node *node) { return is_op_fragile(get_irn_op(node)); } -/* Returns the memory operand of fragile operations. */ -ir_node *get_fragile_op_mem(ir_node *node) -{ - assert(node && is_fragile_op(node)); - - switch (get_irn_opcode(node)) { - case iro_Call : - case iro_Quot : - case iro_DivMod: - case iro_Div : - case iro_Mod : - case iro_Load : - case iro_Store : - case iro_Alloc : - case iro_Bound : - case iro_CopyB : - return get_irn_n(node, pn_Generic_M); - case iro_Bad : - case iro_Unknown: - return node; - default: ; - assert(0 && "should not be reached"); - return NULL; - } -} - -/* Returns the result mode of a Div operation. */ -ir_mode *get_divop_resmod(const ir_node *node) -{ - switch (get_irn_opcode(node)) { - case iro_Quot : return get_Quot_resmode(node); - case iro_DivMod: return get_DivMod_resmode(node); - case iro_Div : return get_Div_resmode(node); - case iro_Mod : return get_Mod_resmode(node); - default: ; - assert(0 && "should not be reached"); - return NULL; - } -} - -/* Returns true if the operation is a forking control flow operation. */ int (is_irn_forking)(const ir_node *node) { - return _is_irn_forking(node); -} - -void (copy_node_attr)(const ir_node *old_node, ir_node *new_node) -{ - _copy_node_attr(old_node, new_node); + return is_irn_forking_(node); } -/* Return the type associated with the value produced by n - * if the node remarks this type as it is the case for - * Cast, Const, SymConst and some Proj nodes. */ -ir_type *(get_irn_type)(ir_node *node) +void (copy_node_attr)(ir_graph *irg, const ir_node *old_node, ir_node *new_node) { - return _get_irn_type(node); + copy_node_attr_(irg, old_node, new_node); } -/* Return the type attribute of a node n (SymConst, Call, Alloc, Free, - Cast) or NULL.*/ ir_type *(get_irn_type_attr)(ir_node *node) { - return _get_irn_type_attr(node); + return get_irn_type_attr_(node); } -/* Return the entity attribute of a node n (SymConst, Sel) or NULL. */ ir_entity *(get_irn_entity_attr)(ir_node *node) { - return _get_irn_entity_attr(node); + return get_irn_entity_attr_(node); } -/* Returns non-zero for constant-like nodes. */ int (is_irn_constlike)(const ir_node *node) { - return _is_irn_constlike(node); + return is_irn_constlike_(node); } -/* - * Returns non-zero for nodes that are allowed to have keep-alives and - * are neither Block nor PhiM. - */ int (is_irn_keep)(const ir_node *node) { - return _is_irn_keep(node); + return is_irn_keep_(node); } -/* - * Returns non-zero for nodes that are always placed in the start block. - */ int (is_irn_start_block_placed)(const ir_node *node) { - return _is_irn_start_block_placed(node); -} - -/* Returns non-zero for nodes that are machine operations. */ -int (is_irn_machine_op)(const ir_node *node) -{ - return _is_irn_machine_op(node); -} - -/* Returns non-zero for nodes that are machine operands. */ -int (is_irn_machine_operand)(const ir_node *node) -{ - return _is_irn_machine_operand(node); + return is_irn_start_block_placed_(node); } -/* Returns non-zero for nodes that have the n'th user machine flag set. */ -int (is_irn_machine_user)(const ir_node *node, unsigned n) -{ - return _is_irn_machine_user(node, n); -} - -/* Returns non-zero for nodes that are CSE neutral to its users. */ int (is_irn_cse_neutral)(const ir_node *node) { - return _is_irn_cse_neutral(node); + return is_irn_cse_neutral_(node); } -/* Gets the string representation of the jump prediction .*/ const char *get_cond_jmp_predicate_name(cond_jmp_predicate pred) { -#define X(a) case a: return #a; +#define X(a) case a: return #a switch (pred) { X(COND_JMP_PRED_NONE); X(COND_JMP_PRED_TRUE); @@ -3172,44 +1421,8 @@ const char *get_cond_jmp_predicate_name(cond_jmp_predicate pred) #undef X } -/* Returns the conditional jump prediction of a Cond node. */ -cond_jmp_predicate (get_Cond_jmp_pred)(const ir_node *cond) -{ - return _get_Cond_jmp_pred(cond); -} - -/* Sets a new conditional jump prediction. */ -void (set_Cond_jmp_pred)(ir_node *cond, cond_jmp_predicate pred) -{ - _set_Cond_jmp_pred(cond, pred); -} - -/** the get_type operation must be always implemented and return a firm type */ -static ir_type *get_Default_type(ir_node *n) -{ - (void) n; - return get_unknown_type(); -} - -/* Sets the get_type operation for an ir_op_ops. */ -ir_op_ops *firm_set_default_get_type(ir_opcode code, ir_op_ops *ops) -{ - switch (code) { - case iro_Const: ops->get_type = get_Const_type; break; - case iro_SymConst: ops->get_type = get_SymConst_value_type; break; - case iro_Cast: ops->get_type = get_Cast_type; break; - case iro_Proj: ops->get_type = get_Proj_type; break; - default: - /* not allowed to be NULL */ - if (! ops->get_type) - ops->get_type = get_Default_type; - break; - } - return ops; -} - /** Return the attribute type of a SymConst node if exists */ -static ir_type *get_SymConst_attr_type(ir_node *self) +static ir_type *get_SymConst_attr_type(const ir_node *self) { symconst_kind kind = get_SymConst_kind(self); if (SYMCONST_HAS_TYPE(kind)) @@ -3218,7 +1431,7 @@ static ir_type *get_SymConst_attr_type(ir_node *self) } /** Return the attribute entity of a SymConst node if exists */ -static ir_entity *get_SymConst_attr_entity(ir_node *self) +static ir_entity *get_SymConst_attr_entity(const ir_node *self) { symconst_kind kind = get_SymConst_kind(self); if (SYMCONST_HAS_ENT(kind)) @@ -3226,108 +1439,107 @@ static ir_entity *get_SymConst_attr_entity(ir_node *self) return NULL; } -/** the get_type_attr operation must be always implemented */ -static ir_type *get_Null_type(ir_node *n) +static void register_get_type_func(ir_op *op, get_type_attr_func func) { - (void) n; - return firm_unknown_type; + op->ops.get_type_attr = func; } -/* Sets the get_type operation for an ir_op_ops. */ -ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops) +static void register_get_entity_func(ir_op *op, get_entity_attr_func func) { - switch (code) { - case iro_SymConst: ops->get_type_attr = get_SymConst_attr_type; break; - case iro_Call: ops->get_type_attr = get_Call_type; break; - case iro_Alloc: ops->get_type_attr = get_Alloc_type; break; - case iro_Free: ops->get_type_attr = get_Free_type; break; - case iro_Cast: ops->get_type_attr = get_Cast_type; break; - default: - /* not allowed to be NULL */ - if (! ops->get_type_attr) - ops->get_type_attr = get_Null_type; - break; - } - return ops; + op->ops.get_entity_attr = func; } -/** the get_entity_attr operation must be always implemented */ -static ir_entity *get_Null_ent(ir_node *n) +void ir_register_getter_ops(void) { - (void) n; - return NULL; -} + register_get_type_func(op_Alloc, get_Alloc_type); + register_get_type_func(op_Builtin, get_Builtin_type); + register_get_type_func(op_Call, get_Call_type); + register_get_type_func(op_Cast, get_Cast_type); + register_get_type_func(op_CopyB, get_CopyB_type); + register_get_type_func(op_Free, get_Free_type); + register_get_type_func(op_InstOf, get_InstOf_type); + register_get_type_func(op_SymConst, get_SymConst_attr_type); -/* Sets the get_type operation for an ir_op_ops. */ -ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops) -{ - switch (code) { - case iro_SymConst: ops->get_entity_attr = get_SymConst_attr_entity; break; - case iro_Sel: ops->get_entity_attr = _get_Sel_entity; break; - default: - /* not allowed to be NULL */ - if (! ops->get_entity_attr) - ops->get_entity_attr = get_Null_ent; - break; - } - return ops; + register_get_entity_func(op_SymConst, get_SymConst_attr_entity); + register_get_entity_func(op_Sel, get_Sel_entity); + register_get_entity_func(op_Block, get_Block_entity); } -/* Sets the debug information of a node. */ void (set_irn_dbg_info)(ir_node *n, dbg_info *db) { - _set_irn_dbg_info(n, db); + set_irn_dbg_info_(n, db); } -/** - * Returns the debug information of an node. - * - * @param n The node. - */ dbg_info *(get_irn_dbg_info)(const ir_node *n) { - return _get_irn_dbg_info(n); + return get_irn_dbg_info_(n); } -/* checks whether a node represents a global address */ -int is_Global(const ir_node *node) +ir_switch_table *ir_new_switch_table(ir_graph *irg, size_t n_entries) { - return is_SymConst_addr_ent(node); + struct obstack *obst = get_irg_obstack(irg); + ir_switch_table *res = OALLOCFZ(obst, ir_switch_table, entries, n_entries); + res->n_entries = n_entries; + return res; } -/* returns the entity of a global address */ -ir_entity *get_Global_entity(const ir_node *node) +void ir_switch_table_set(ir_switch_table *table, size_t n, + ir_tarval *min, ir_tarval *max, long pn) { - return get_SymConst_entity(node); + ir_switch_table_entry *entry = ir_switch_table_get_entry(table, n); + entry->min = min; + entry->max = max; + entry->pn = pn; } -/* - * Calculate a hash value of a node. - */ -unsigned firm_default_hash(const ir_node *node) +size_t (ir_switch_table_get_n_entries)(const ir_switch_table *table) +{ + return ir_switch_table_get_n_entries_(table); +} + +ir_tarval *ir_switch_table_get_max(const ir_switch_table *table, size_t e) { - unsigned h; - int i, irn_arity; + return ir_switch_table_get_entry_const(table, e)->max; +} - /* hash table value = 9*(9*(9*(9*(9*arity+in[0])+in[1])+ ...)+mode)+code */ - h = irn_arity = get_irn_intra_arity(node); +ir_tarval *ir_switch_table_get_min(const ir_switch_table *table, size_t e) +{ + return ir_switch_table_get_entry_const(table, e)->min; +} - /* consider all in nodes... except the block if not a control flow. */ - for (i = is_cfop(node) ? -1 : 0; i < irn_arity; ++i) { - ir_node *pred = get_irn_intra_n(node, i); - if (is_irn_cse_neutral(pred)) - h *= 9; - else - h = 9*h + HASH_PTR(pred); - } +long ir_switch_table_get_pn(const ir_switch_table *table, size_t e) +{ + return ir_switch_table_get_entry_const(table, e)->pn; +} - /* ...mode,... */ - h = 9*h + HASH_PTR(get_irn_mode(node)); - /* ...and code */ - h = 9*h + HASH_PTR(get_irn_op(node)); +ir_switch_table *ir_switch_table_duplicate(ir_graph *irg, + const ir_switch_table *table) +{ + size_t n_entries = ir_switch_table_get_n_entries(table); + size_t e; + ir_switch_table *res = ir_new_switch_table(irg, n_entries); + for (e = 0; e < n_entries; ++e) { + const ir_switch_table_entry *entry + = ir_switch_table_get_entry_const(table, e); + ir_switch_table_entry *new_entry = ir_switch_table_get_entry(res, e); + *new_entry = *entry; + } + return res; +} - return h; -} /* firm_default_hash */ +bool only_used_by_keepalive(const ir_node *node) +{ + foreach_out_edge(node, edge) { + ir_node *succ = get_edge_src_irn(edge); + if (is_End(succ)) + continue; + if (is_Proj(succ) && only_used_by_keepalive(succ)) + return true; + /* found a real user */ + return false; + } + return true; +} /* include generated code */ #include "gen_irnode.c.inl"