X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firnode.c;h=bf07359e0777d8f26cdc04ac9d62bc77a8c84e1a;hb=79b409329e8b6e9f43ac71df6599372fa0dbe497;hp=505d61ede8b6de99b67b512dee7e9f982b944e8b;hpb=c0b2acecb95ade6bec10f03ad4c0d50a8aafeeac;p=libfirm diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index 505d61ede..bf07359e0 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -23,14 +23,11 @@ * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck * @version $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" -#ifdef HAVE_STRING_H -# include -#endif +#include +#include "pset_new.h" #include "ident.h" #include "irnode_t.h" #include "irgraph_t.h" @@ -46,10 +43,12 @@ #include "irhooks.h" #include "irtools.h" +#include "beinfo.h" + /* some constants fixing the positions of nodes predecessors in the in array */ #define CALL_PARAM_OFFSET 2 -#define FUNCCALL_PARAM_OFFSET 1 +#define BUILDIN_PARAM_OFFSET 1 #define SEL_INDEX_OFFSET 2 #define RETURN_RESULT_OFFSET 1 /* mem is not a result */ #define END_KEEPALIVE_OFFSET 0 @@ -138,7 +137,9 @@ new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mod char *p; int i; - assert(irg && op && mode); + 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); @@ -162,13 +163,10 @@ new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mod memcpy(&res->in[1], in, sizeof(ir_node *) * arity); } - res->in[0] = block; + res->in[0] = block; set_irn_dbg_info(res, db); - res->out = NULL; - -#ifdef DEBUG_libfirm + res->out = NULL; res->node_nr = get_irp_new_node_nr(); -#endif for (i = 0; i < EDGE_KIND_LAST; ++i) INIT_LIST_HEAD(&res->edge_info[i].outs_head); @@ -179,6 +177,9 @@ 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); + } return res; } @@ -443,11 +444,11 @@ ident *get_irn_opident(const ir_node *node) { return node->op->name; } -unsigned long (get_irn_visited)(const ir_node *node) { +ir_visited_t (get_irn_visited)(const ir_node *node) { return _get_irn_visited(node); } -void (set_irn_visited)(ir_node *node, unsigned long visited) { +void (set_irn_visited)(ir_node *node, ir_visited_t visited) { _set_irn_visited(node, visited); } @@ -455,14 +456,14 @@ void (mark_irn_visited)(ir_node *node) { _mark_irn_visited(node); } -int (irn_not_visited)(const ir_node *node) { - return _irn_not_visited(node); -} - int (irn_visited)(const ir_node *node) { return _irn_visited(node); } +int (irn_visited_else_mark)(ir_node *node) { + return _irn_visited_else_mark(node); +} + void (set_irn_link)(ir_node *node, void *link) { _set_irn_link(node, link); } @@ -481,7 +482,7 @@ op_pin_state (is_irn_pinned_in_irg) (const ir_node *node) { void set_irn_pinned(ir_node *node, op_pin_state state) { /* due to optimization an opt may be turned into a Tuple */ - if (get_irn_op(node) == op_Tuple) + if (is_Tuple(node)) return; assert(node && get_op_pinned(get_irn_op(node)) >= op_pin_state_exc_pinned); @@ -490,51 +491,10 @@ void set_irn_pinned(ir_node *node, op_pin_state state) { node->attr.except.pin_state = state; } -#ifdef DO_HEAPANALYSIS -/* Access the abstract interpretation information of a node. - Returns NULL if no such information is available. */ -struct abstval *get_irn_abst_value(ir_node *n) { - return n->av; -} -/* Set the abstract interpretation information of a node. */ -void set_irn_abst_value(ir_node *n, struct abstval *os) { - n->av = os; -} -struct section *firm_get_irn_section(ir_node *n) { - return n->sec; -} -void firm_set_irn_section(ir_node *n, struct section *s) { - n->sec = s; -} -#else -/* Dummies needed for firmjni. */ -struct abstval *get_irn_abst_value(ir_node *n) { - (void) n; - return NULL; -} -void set_irn_abst_value(ir_node *n, struct abstval *os) { - (void) n; - (void) os; -} -struct section *firm_get_irn_section(ir_node *n) { - (void) n; - return NULL; -} -void firm_set_irn_section(ir_node *n, struct section *s) { - (void) n; - (void) s; -} -#endif /* DO_HEAPANALYSIS */ - - /* Outputs a unique number for this node */ long get_irn_node_nr(const ir_node *node) { assert(node); -#ifdef DEBUG_libfirm return node->node_nr; -#else - return (long)PTR_TO_INT(node); -#endif } const_attr *get_irn_const_attr(ir_node *node) { @@ -565,7 +525,7 @@ symconst_attr *get_irn_symconst_attr(ir_node *node) { ir_type *get_irn_call_attr(ir_node *node) { assert(is_Call(node)); - return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp); + return node->attr.call.type = skip_tid(node->attr.call.type); } sel_attr *get_irn_sel_attr(ir_node *node) { @@ -604,6 +564,11 @@ divmod_attr *get_irn_divmod_attr(ir_node *node) { 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); @@ -671,20 +636,6 @@ ir_type *is_tls_pointer(const ir_node *n) { return NULL; } -/* Test whether arbitrary node is value arg base, i.e. Proj(pn_Start_P_value_arg_base) - * from Start. If so returns 1, else 0. */ -int is_value_arg_pointer(const ir_node *n) { - if (is_Proj(n) && - (get_Proj_proj(n) == pn_Start_P_value_arg_base) && - is_Start(get_Proj_pred(n))) - return 1; - return 0; -} - -/* Returns an array with the predecessors of the Block. Depending on - the implementation of the graph data structure this can be a copy of - the internal representation of predecessors as well as the internal - array itself. Therefore writing to this array might obstruct the ir. */ ir_node **get_Block_cfgpred_arr(ir_node *node) { assert(is_Block(node)); return (ir_node **)&(get_irn_in(node)[1]); @@ -703,6 +654,16 @@ void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred) { set_irn_n(node, pos, pred); } +int get_Block_cfgpred_pos(const ir_node *block, const ir_node *pred) { + int i; + + for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) { + if (get_Block_cfgpred_block(block, i) == pred) + return i; + } + return -1; +} + ir_node *(get_Block_cfgpred_block)(const ir_node *node, int pos) { return _get_Block_cfgpred_block(node, pos); } @@ -717,11 +678,11 @@ void set_Block_matured(ir_node *node, int matured) { node->attr.block.is_matured = matured; } -unsigned long (get_Block_block_visited)(const ir_node *node) { +ir_visited_t (get_Block_block_visited)(const ir_node *node) { return _get_Block_block_visited(node); } -void (set_Block_block_visited)(ir_node *node, unsigned long visit) { +void (set_Block_block_visited)(ir_node *node, ir_visited_t visit) { _set_Block_block_visited(node, visit); } @@ -730,10 +691,6 @@ void (mark_Block_block_visited)(ir_node *node) { _mark_Block_block_visited(node); } -int (Block_not_block_visited)(const ir_node *node) { - return _Block_not_block_visited(node); -} - int (Block_block_visited)(const ir_node *node) { return _Block_block_visited(node); } @@ -901,7 +858,6 @@ ir_node *get_End_keepalive(const ir_node *end, int pos) { void add_End_keepalive(ir_node *end, ir_node *ka) { assert(is_End(end)); - assert((is_Phi(ka) || is_Proj(ka) || is_Block(ka) || is_irn_keep(ka)) && "Only Phi, Block or Keep nodes can be kept alive!"); add_irn_n(end, ka); } @@ -957,11 +913,48 @@ found: end->in[1 + END_KEEPALIVE_OFFSET + idx] = old; edges_notify_edge(end, idx, old, NULL, irg); } + /* now n - 1 keeps, 1 block input */ ARR_RESIZE(ir_node *, end->in, (n - 1) + 1 + END_KEEPALIVE_OFFSET); } -void -free_End(ir_node *end) { +/* 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; + + if (n <= 0) + return; + + irg = get_irn_irg(end); + pset_new_init(&keeps); + + for (idx = n - 1; idx >= 0; --idx) { + ir_node *ka = get_End_keepalive(end, idx); + + if (is_Bad(ka) || is_NoMem(ka) || pset_new_contains(&keeps, ka)) { + /* remove the edge */ + edges_notify_edge(end, idx, NULL, ka, irg); + + if (idx != n - 1) { + /* exchange with the last one */ + ir_node *old = end->in[1 + END_KEEPALIVE_OFFSET + n - 1]; + edges_notify_edge(end, n - 1, NULL, old, irg); + end->in[1 + END_KEEPALIVE_OFFSET + idx] = old; + edges_notify_edge(end, idx, old, NULL, irg); + } + --n; + } else { + pset_new_insert(&keeps, ka); + } + } + /* n keeps, 1 block input */ + ARR_RESIZE(ir_node *, end->in, n + 1 + END_KEEPALIVE_OFFSET); + + pset_new_destroy(&keeps); +} + +void free_End(ir_node *end) { assert(is_End(end)); end->kind = k_BAD; DEL_ARR_F(end->in); @@ -1012,6 +1005,18 @@ I don't want to choose 3) as 2a) seems to have advantages for dataflow analysis and 3) does not allow to convert the representation to 2a). */ + +const char *get_cond_kind_name(cond_kind kind) +{ +#define X(a) case a: return #a; + switch (kind) { + X(dense); + X(fragmentary); + } + return ""; +#undef X +} + ir_node * get_Cond_selector(const ir_node *node) { assert(is_Cond(node)); @@ -1037,11 +1042,16 @@ set_Cond_kind(ir_node *node, cond_kind kind) { } long -get_Cond_defaultProj(const ir_node *node) { +get_Cond_default_proj(const ir_node *node) { assert(is_Cond(node)); return node->attr.cond.default_proj; } +void set_Cond_default_proj(ir_node *node, long defproj) { + assert(is_Cond(node)); + node->attr.cond.default_proj = defproj; +} + ir_node * get_Return_mem(const ir_node *node) { assert(is_Return(node)); @@ -1285,7 +1295,7 @@ set_Sel_index(ir_node *node, int pos, ir_node *index) { ir_entity * get_Sel_entity(const ir_node *node) { assert(is_Sel(node)); - return node->attr.sel.ent; + return node->attr.sel.entity; } /* need a version without const to prevent warning */ @@ -1296,7 +1306,7 @@ static ir_entity *_get_Sel_entity(ir_node *node) { void set_Sel_entity(ir_node *node, ir_entity *ent) { assert(is_Sel(node)); - node->attr.sel.ent = ent; + node->attr.sel.entity = ent; } @@ -1344,18 +1354,6 @@ get_Call_n_params(const ir_node *node) { return (get_irn_arity(node) - CALL_PARAM_OFFSET); } -int -get_Call_arity(const ir_node *node) { - assert(is_Call(node)); - return get_Call_n_params(node); -} - -/* void -set_Call_arity(ir_node *node, ir_node *arity) { - assert(is_Call(node)); -} -*/ - ir_node * get_Call_param(const ir_node *node, int pos) { assert(is_Call(node)); @@ -1371,16 +1369,101 @@ set_Call_param(ir_node *node, int pos, ir_node *param) { ir_type * get_Call_type(ir_node *node) { assert(is_Call(node)); - return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp); + return node->attr.call.type = skip_tid(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.cld_tp = tp; + node->attr.call.type = tp; +} + +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 = skip_tid(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) && @@ -1494,16 +1577,17 @@ BINOP_MEM(OP) \ \ ir_mode *get_##OP##_resmode(const ir_node *node) { \ assert(is_##OP(node)); \ - return node->attr.divmod.res_mode; \ + return node->attr.divmod.resmode; \ } \ \ void set_##OP##_resmode(ir_node *node, ir_mode *mode) { \ assert(is_##OP(node)); \ - node->attr.divmod.res_mode = mode; \ + node->attr.divmod.resmode = mode; \ } BINOP(Add) +BINOP(Borrow) BINOP(Carry) BINOP(Sub) UNOP(Minus) @@ -1526,11 +1610,16 @@ BINOP(Cmp) UNOP(Conv) UNOP(Cast) -int is_Div_remainderless(const ir_node *node) { +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; @@ -1544,14 +1633,14 @@ void set_Conv_strict(ir_node *node, int strict_flag) { ir_type * get_Cast_type(ir_node *node) { assert(is_Cast(node)); - node->attr.cast.totype = skip_tid(node->attr.cast.totype); - return node->attr.cast.totype; + node->attr.cast.type = skip_tid(node->attr.cast.type); + return node->attr.cast.type; } void set_Cast_type(ir_node *node, ir_type *to_tp) { assert(is_Cast(node)); - node->attr.cast.totype = to_tp; + node->attr.cast.type = to_tp; } @@ -1753,13 +1842,13 @@ set_Load_ptr(ir_node *node, ir_node *ptr) { ir_mode * get_Load_mode(const ir_node *node) { assert(is_Load(node)); - return node->attr.load.load_mode; + return node->attr.load.mode; } void set_Load_mode(ir_node *node, ir_mode *mode) { assert(is_Load(node)); - node->attr.load.load_mode = mode; + node->attr.load.mode = mode; } ir_volatility @@ -2269,12 +2358,12 @@ void set_CopyB_src(ir_node *node, ir_node *src) { ir_type *get_CopyB_type(ir_node *node) { assert(is_CopyB(node)); - return node->attr.copyb.data_type = skip_tid(node->attr.copyb.data_type); + return node->attr.copyb.type = skip_tid(node->attr.copyb.type); } void set_CopyB_type(ir_node *node, ir_type *data_type) { assert(is_CopyB(node) && data_type); - node->attr.copyb.data_type = data_type; + node->attr.copyb.type = data_type; } @@ -2451,7 +2540,7 @@ get_irn_irg(const ir_node *node) { node = get_irn_n(node, -1); if (is_Bad(node)) /* sometimes bad is predecessor of nodes instead of block: in case of optimization */ node = get_irn_n(node, -1); - assert(get_irn_op(node) == op_Block); + assert(is_Block(node)); return node->attr.block.irg; } @@ -2489,10 +2578,8 @@ skip_Tuple(ir_node *node) { ir_node *pred; ir_op *op; - if (!get_opt_normalize()) return node; - restart: - if (get_irn_op(node) == op_Proj) { + if (is_Proj(node)) { pred = get_Proj_pred(node); op = get_irn_op(pred); @@ -2502,9 +2589,8 @@ restart: */ if (op == op_Proj) { /* nested Tuple ? */ pred = skip_Tuple(pred); - op = get_irn_op(pred); - if (op == op_Tuple) { + if (is_Tuple(pred)) { node = get_Tuple_pred(pred, get_Proj_proj(node)); goto restart; } @@ -2530,9 +2616,16 @@ 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)) + return get_Pin_op(node); + return node; +} + /* returns operand of node if node is a Confirm */ ir_node *skip_Confirm(ir_node *node) { - if (get_irn_op(node) == op_Confirm) + if (is_Confirm(node)) return get_Confirm_value(node); return node; } @@ -2765,6 +2858,12 @@ int return _is_Call(node); } +/* returns true if node is a Builtin node. */ +int +(is_Builtin)(const ir_node *node) { + return _is_Builtin(node); +} + /* returns true if node is a CallBegin node. */ int (is_CallBegin)(const ir_node *node) { @@ -2878,6 +2977,12 @@ int return _is_ASM(node); } +/* returns true if a node is an Dummy node. */ +int +(is_Dummy)(const ir_node *node) { + return _is_Dummy(node); +} + int (is_Proj)(const ir_node *node) { return _is_Proj(node); @@ -3006,12 +3111,14 @@ int (is_irn_machine_user)(const ir_node *node, unsigned n) { /* 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; switch (pred) { - default: - case COND_JMP_PRED_NONE: return "no prediction"; - case COND_JMP_PRED_TRUE: return "true taken"; - case COND_JMP_PRED_FALSE: return "false taken"; + X(COND_JMP_PRED_NONE); + X(COND_JMP_PRED_TRUE); + X(COND_JMP_PRED_FALSE); } + return ""; +#undef X } /* Returns the conditional jump prediction of a Cond node. */ @@ -3119,30 +3226,6 @@ dbg_info *(get_irn_dbg_info)(const ir_node *n) { return _get_irn_dbg_info(n); } -#if 0 /* allow the global pointer */ - -/* checks whether a node represents a global address */ -int is_Global(const ir_node *node) { - ir_node *ptr; - - if (is_SymConst_addr_ent(node)) - return 1; - if (! is_Sel(node)) - return 0; - - ptr = get_Sel_ptr(node); - return is_globals_pointer(ptr) != NULL; -} - -/* returns the entity of a global address */ -ir_entity *get_Global_entity(const ir_node *node) { - if (is_SymConst(node)) - return get_SymConst_entity(node); - else - return get_Sel_entity(node); -} -#else - /* checks whether a node represents a global address */ int is_Global(const ir_node *node) { return is_SymConst_addr_ent(node); @@ -3152,7 +3235,6 @@ int is_Global(const ir_node *node) { ir_entity *get_Global_entity(const ir_node *node) { return get_SymConst_entity(node); } -#endif /* * Calculate a hash value of a node.