X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firnode.c;h=8334e4fee9d8a20931363648e98eaff635753f9d;hb=8399216d8aebc713bbda04b6e3e250a1d52b20bf;hp=fcd49ef0accad3fd17b6dcf03522ccb3b6463fa3;hpb=dddcc630819f338c3b45e2bc646233e6872d5bb6;p=libfirm diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index fcd49ef0a..8334e4fee 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -11,9 +11,12 @@ */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" +#endif + +#ifdef HAVE_STRING_H +# include #endif -#include #include "ident.h" #include "irnode_t.h" @@ -84,9 +87,34 @@ const char *symconst_name_arr [] = { "type_tag", "size", "addr_name", "addr_ent" }; +/** + * 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 register_additional_node_data(unsigned size) { + assert(!forbid_new_data && "Too late to register additional node data"); + + if (forbid_new_data) + return 0; + + return firm_add_node_size += size; +} + + void -init_irnode (void) -{ +init_irnode(void) { + /* Forbid the addition of new data to an ir node. */ + forbid_new_data = 1; } /* @@ -100,17 +128,19 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo int arity, ir_node **in) { ir_node *res; - int node_size = offsetof (ir_node, attr) + op->attr_size; + size_t node_size = offsetof(ir_node, attr) + op->attr_size + firm_add_node_size; + char *p; assert(irg && op && mode); - res = (ir_node *) obstack_alloc (irg->obst, node_size); - memset((void *)res, 0, node_size); + p = obstack_alloc (irg->obst, node_size); + memset(p, 0, node_size); + res = (ir_node *) (p + firm_add_node_size); - res->kind = k_ir_node; - res->op = op; - res->mode = mode; + res->kind = k_ir_node; + res->op = op; + res->mode = mode; res->visited = 0; - res->link = NULL; + res->link = NULL; if (arity < 0) { res->in = NEW_ARR_F (ir_node *, 1); /* 1: space for block */ } else { @@ -130,14 +160,6 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo return res; } -/* Copies all attributes stored in the old node to the new node. - Assumes both have the same opcode and sufficient size. */ -void -copy_attrs (const ir_node *old_node, ir_node *new_node) { - assert(get_irn_op(old_node) == get_irn_op(new_node)); - memcpy(&new_node->attr, &old_node->attr, get_op_attr_size(get_irn_op(old_node))); -} - /*-- getting some parameters from ir_nodes --*/ int @@ -155,6 +177,8 @@ int return __get_irn_inter_arity(node); } +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); @@ -169,7 +193,7 @@ int ir_node ** get_irn_in (const ir_node *node) { assert(node); - if (interprocedural_view) { /* handle Filter and Block specially */ + 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; @@ -185,7 +209,7 @@ void set_irn_in (ir_node *node, int arity, ir_node **in) { ir_node *** arr; assert(node); - if (interprocedural_view) { /* handle Filter and Block specially */ + if (get_interprocedural_view()) { /* handle Filter and Block specially */ if (get_irn_opcode(node) == iro_Filter) { assert(node->attr.filter.in_cg); arr = &node->attr.filter.in_cg; @@ -207,23 +231,26 @@ set_irn_in (ir_node *node, int arity, ir_node **in) { } ir_node * -(get_irn_intra_n)(ir_node *node, int n) { +(get_irn_intra_n)(const ir_node *node, int n) { return __get_irn_intra_n (node, n); } ir_node * -(get_irn_inter_n)(ir_node *node, int n) { +(get_irn_inter_n)(const ir_node *node, int n) { return __get_irn_inter_n (node, n); } +ir_node *(*__get_irn_n)(const ir_node *node, int n) = __get_irn_intra_n; + ir_node * -(get_irn_n)(ir_node *node, int n) { - return __get_irn_n (node, n); +(get_irn_n)(const ir_node *node, int n) { + return __get_irn_n(node, n); } void set_irn_n (ir_node *node, int n, ir_node *in) { - assert(node && -1 <= n && n < get_irn_arity(node)); + assert(node && node->kind == k_ir_node && -1 <= n && n < get_irn_arity(node)); + assert(in && in->kind == k_ir_node); if ((n == -1) && (get_irn_opcode(node) == iro_Filter)) { /* Change block pred in both views! */ node->in[n + 1] = in; @@ -231,7 +258,7 @@ set_irn_n (ir_node *node, int n, ir_node *in) { node->attr.filter.in_cg[n + 1] = in; return; } - if (interprocedural_view) { /* handle Filter and Block specially */ + 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; @@ -352,6 +379,21 @@ void * return __get_irn_link(node); } +op_pin_state +(get_irn_pinned)(const ir_node *node) { + return __get_irn_pinned(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) + return; + + assert(node && get_op_pinned(get_irn_op(node)) >= op_pin_state_exc_pinned); + assert(state == op_pin_state_pinned || state == op_pin_state_floats); + + node->attr.except.pin_state = state; +} #ifdef DO_HEAPANALYSIS /* Access the abstract interpretation information of a node. @@ -369,6 +411,12 @@ struct section *firm_get_irn_section(ir_node *n) { 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) { return NULL; } +void set_irn_abst_value(ir_node *n, struct abstval *os) {} +struct section *firm_get_irn_section(ir_node *n) { return NULL; } +void firm_set_irn_section(ir_node *n, struct section *s) {} #endif /* DO_HEAPANALYSIS */ @@ -379,7 +427,7 @@ get_irn_node_nr(const ir_node *node) { #ifdef DEBUG_libfirm return node->node_nr; #else - return (long)&node; + return (long)node; #endif } @@ -425,13 +473,6 @@ get_irn_call_attr (ir_node *node) return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp); } -type * -get_irn_funccall_attr (ir_node *node) -{ - assert (node->op == op_FuncCall); - return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp); -} - sel_attr get_irn_sel_attr (ir_node *node) { @@ -453,11 +494,33 @@ get_irn_block_attr (ir_node *node) return node->attr.block; } +load_attr +get_irn_load_attr (ir_node *node) +{ + assert (node->op == op_Load); + return node->attr.load; +} + +store_attr +get_irn_store_attr (ir_node *node) +{ + assert (node->op == op_Store); + 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); + return node->attr.except; +} + /** manipulate fields of individual nodes **/ /* this works for all except Block */ ir_node * -get_nodes_block (ir_node *node) { +get_nodes_block (const ir_node *node) { assert (!(node->op == op_Block)); return get_irn_n(node, -1); } @@ -524,9 +587,8 @@ get_Block_n_cfgpreds (ir_node *node) { ir_node * get_Block_cfgpred (ir_node *node, int pos) { - assert(node); - assert (node->op == op_Block); assert(-1 <= pos && pos < get_irn_arity(node)); + assert(node->op == op_Block); return get_irn_n(node, pos); } @@ -584,52 +646,6 @@ set_Block_graph_arr (ir_node *node, int pos, ir_node *value) { node->attr.block.graph_arr[pos+1] = value; } -/* handler handling for Blocks * / -void -set_Block_handler (ir_node *block, ir_node *handler) { - assert ((block->op == op_Block)); - assert ((handler->op == op_Block)); - block->attr.block.handler_entry = handler; -} - -ir_node * -get_Block_handler (ir_node *block) { - assert ((block->op == op_Block)); - return (block->attr.block.handler_entry); -} - -/ * handler handling for Nodes * / -void -set_Node_handler (ir_node *node, ir_node *handler) { - set_Block_handler (get_nodes_block (node), handler); -} - -ir_node * -get_Node_handler (ir_node *node) { - return (get_Block_handler (get_nodes_block (node))); -} - -/ * exc_t handling for Blocks * / -void set_Block_exc (ir_node *block, exc_t exc) { - assert ((block->op == op_Block)); - block->attr.block.exc = exc; -} - -exc_t get_Block_exc (ir_node *block) { - assert ((block->op == op_Block)); - return (block->attr.block.exc); -} - -/ * exc_t handling for Nodes * / -void set_Node_exc (ir_node *node, exc_t exc) { - set_Block_exc (get_nodes_block (node), exc); -} - -exc_t get_Node_exc (ir_node *node) { - return (get_Block_exc (get_nodes_block (node))); -} -*/ - void set_Block_cg_cfgpred_arr(ir_node * node, int arity, ir_node ** in) { assert(node->op == op_Block); if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) { @@ -639,10 +655,10 @@ void set_Block_cg_cfgpred_arr(ir_node * node, int arity, ir_node ** in) { { /* Fix backedge array. fix_backedges operates depending on interprocedural_view. */ - bool ipv = interprocedural_view; - interprocedural_view = true; + int ipv = get_interprocedural_view(); + set_interprocedural_view(true); fix_backedges(current_ir_graph->obst, node); - interprocedural_view = ipv; + set_interprocedural_view(ipv); } } memcpy(node->attr.block.in_cg + 1, in, sizeof(ir_node *) * arity); @@ -675,6 +691,14 @@ void remove_Block_cg_cfgpred_arr(ir_node * node) { node->attr.block.in_cg = NULL; } +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); +} + void set_Start_irg(ir_node *node, ir_graph *irg) { assert(node->op == op_Start); @@ -873,11 +897,10 @@ get_Const_type (ir_node *node) { void set_Const_type (ir_node *node, type *tp) { assert (node->op == op_Const); - if (tp != unknown_type) { + if (tp != firm_unknown_type) { assert (is_atomic_type(tp)); assert (get_type_mode(tp) == get_irn_mode(node)); } - node->attr.con.tp = tp; } @@ -938,7 +961,6 @@ void set_SymConst_entity (ir_node *node, entity *ent) { node->attr.i.sym.entity_p = ent; } - union symconst_symbol get_SymConst_symbol (ir_node *node) { assert (node->op == op_SymConst); @@ -952,6 +974,19 @@ set_SymConst_symbol (ir_node *node, union symconst_symbol sym) { node->attr.i.sym = sym; } +type * +get_SymConst_value_type (ir_node *node) { + assert (node->op == op_SymConst); + if (node->attr.i.tp) node->attr.i.tp = skip_tid(node->attr.i.tp); + return node->attr.i.tp; +} + +void +set_SymConst_value_type (ir_node *node, type *tp) { + assert (node->op == op_SymConst); + node->attr.i.tp = tp; +} + ir_node * get_Sel_mem (ir_node *node) { assert (node->op == op_Sel); @@ -1130,25 +1165,27 @@ get_Call_type (ir_node *node) { void set_Call_type (ir_node *node, type *tp) { assert (node->op == op_Call); - assert (is_method_type(tp)); + assert ((get_unknown_type() == tp) || is_method_type(tp)); node->attr.call.cld_tp = tp; } int Call_has_callees(ir_node *node) { - return (node->attr.call.callee_arr != NULL); + assert(node && node->op == op_Call); + 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(ir_node * node) { - assert(node->op == op_Call && node->attr.call.callee_arr); + assert(node && node->op == op_Call && node->attr.call.callee_arr); return ARR_LEN(node->attr.call.callee_arr); } entity * get_Call_callee(ir_node * node, int pos) { - assert(node->op == op_Call && node->attr.call.callee_arr); + assert(pos >= 0 && pos < get_Call_n_callees(node)); return node->attr.call.callee_arr[pos]; } -void set_Call_callee_arr(ir_node * node, int n, entity ** arr) { +void set_Call_callee_arr(ir_node * node, const int n, entity ** arr) { assert(node->op == op_Call); if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) { node->attr.call.callee_arr = NEW_ARR_D(entity *, current_ir_graph->obst, n); @@ -1178,94 +1215,6 @@ void set_CallBegin_call (ir_node *node, ir_node *call) { node->attr.callbegin.call = call; } -ir_node * -get_FuncCall_ptr (ir_node *node) { - assert (node->op == op_FuncCall); - return get_irn_n(node, 0); -} - -void -set_FuncCall_ptr (ir_node *node, ir_node *ptr) { - assert (node->op == op_FuncCall); - set_irn_n(node, 0, ptr); -} - -ir_node ** -get_FuncCall_param_arr (ir_node *node) { - assert (node->op == op_FuncCall); - return (ir_node **)&get_irn_in(node)[FUNCCALL_PARAM_OFFSET]; -} - -int -get_FuncCall_n_params (ir_node *node) { - assert (node->op == op_FuncCall); - return (get_irn_arity(node) - FUNCCALL_PARAM_OFFSET); -} - -int -get_FuncCall_arity (ir_node *node) { - assert (node->op == op_FuncCall); - return get_FuncCall_n_params(node); -} - -/* void -set_FuncCall_arity (ir_node *node, ir_node *arity) { - assert (node->op == op_FuncCall); -} -*/ - -ir_node * -get_FuncCall_param (ir_node *node, int pos) { - assert (node->op == op_FuncCall); - return get_irn_n(node, pos + FUNCCALL_PARAM_OFFSET); -} - -void -set_FuncCall_param (ir_node *node, int pos, ir_node *param) { - assert (node->op == op_FuncCall); - set_irn_n(node, pos + FUNCCALL_PARAM_OFFSET, param); -} - -type * -get_FuncCall_type (ir_node *node) { - assert (node->op == op_FuncCall); - return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp); -} - -void -set_FuncCall_type (ir_node *node, type *tp) { - assert (node->op == op_FuncCall); - assert (is_method_type(tp)); - node->attr.call.cld_tp = tp; -} - -int FuncCall_has_callees(ir_node *node) { - return (node->attr.call.callee_arr != NULL); -} - -int get_FuncCall_n_callees(ir_node * node) { - assert(node->op == op_FuncCall && node->attr.call.callee_arr); - return ARR_LEN(node->attr.call.callee_arr); -} - -entity * get_FuncCall_callee(ir_node * node, int pos) { - assert(node->op == op_FuncCall && node->attr.call.callee_arr); - return node->attr.call.callee_arr[pos]; -} - -void set_FuncCall_callee_arr(ir_node * node, int n, entity ** arr) { - assert(node->op == op_FuncCall); - if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) { - node->attr.call.callee_arr = NEW_ARR_D(entity *, current_ir_graph->obst, n); - } - memcpy(node->attr.call.callee_arr, arr, n * sizeof(entity *)); -} - -void remove_FuncCall_callee_arr(ir_node * node) { - assert(node->op == op_FuncCall); - node->attr.call.callee_arr = NULL; -} - #define BINOP(OP) \ ir_node * get_##OP##_left(ir_node *node) { \ @@ -1381,8 +1330,8 @@ set_Cast_type (ir_node *node, type *to_tp) { } int -is_unop (ir_node *node) { - return (node->op->opar == oparity_unary); +(is_unop)(const ir_node *node) { + return __is_unop(node); } ir_node * @@ -1403,8 +1352,8 @@ set_unop_op (ir_node *node, ir_node *op) { } int -is_binop (ir_node *node) { - return (node->op->opar == oparity_binary); +(is_binop)(const ir_node *node) { + return __is_binop(node); } ir_node * @@ -1441,13 +1390,13 @@ set_binop_right (ir_node *node, ir_node *right) { assert (node->op->opar == oparity_binary); } -int is_Phi (ir_node *n) { +int is_Phi (const ir_node *n) { ir_op *op; assert(n); op = get_irn_op(n); - if (op == op_Filter) return interprocedural_view; + if (op == op_Filter) return get_interprocedural_view(); if (op == op_Phi) return ((get_irg_phase_state(get_irn_irg(n)) != phase_building) || @@ -1456,7 +1405,7 @@ int is_Phi (ir_node *n) { return 0; } -int is_Phi0 (ir_node *n) { +int is_Phi0 (const ir_node *n) { assert(n); return ((get_irn_op(n) == op_Phi) && @@ -1494,6 +1443,31 @@ set_Phi_pred (ir_node *node, int pos, ir_node *pred) { set_irn_n(node, pos, pred); } + +int is_memop(ir_node *node) { + return ((get_irn_op(node) == op_Load) || (get_irn_op(node) == op_Store)); +} + +ir_node *get_memop_mem (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 (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 (ir_node *node) { assert (node->op == op_Load); @@ -1518,6 +1492,30 @@ set_Load_ptr (ir_node *node, ir_node *ptr) { set_irn_n(node, 1, ptr); } +ir_mode * +get_Load_mode (ir_node *node) { + assert (node->op == op_Load); + return node->attr.load.load_mode; +} + +void +set_Load_mode (ir_node *node, ir_mode *mode) { + assert (node->op == op_Load); + node->attr.load.load_mode = mode; +} + +ent_volatility +get_Load_volatility (ir_node *node) { + assert (node->op == op_Load); + return node->attr.load.volatility; +} + +void +set_Load_volatility (ir_node *node, ent_volatility volatility) { + assert (node->op == op_Load); + node->attr.load.volatility = volatility; +} + ir_node * get_Store_mem (ir_node *node) { @@ -1555,6 +1553,19 @@ set_Store_value (ir_node *node, ir_node *value) { set_irn_n(node, 2, value); } +ent_volatility +get_Store_volatility (ir_node *node) { + assert (node->op == op_Store); + return node->attr.store.volatility; +} + +void +set_Store_volatility (ir_node *node, ent_volatility volatility) { + assert (node->op == op_Store); + node->attr.store.volatility = volatility; +} + + ir_node * get_Alloc_mem (ir_node *node) { assert (node->op == op_Alloc); @@ -1833,10 +1844,38 @@ ir_node *get_Filter_cg_pred(ir_node *node, int pos) { return node->attr.filter.in_cg[pos + 1]; } +/* Mux support */ +ir_node *get_Mux_sel (ir_node *node) { + assert(node->op == op_Mux); + return node->in[1]; +} +void set_Mux_sel (ir_node *node, ir_node *sel) { + assert(node->op == op_Mux); + node->in[1] = sel; +} + +ir_node *get_Mux_false (ir_node *node) { + assert(node->op == op_Mux); + return node->in[2]; +} +void set_Mux_false (ir_node *node, ir_node *ir_false) { + assert(node->op == op_Mux); + node->in[2] = ir_false; +} + +ir_node *get_Mux_true (ir_node *node) { + assert(node->op == op_Mux); + return node->in[3]; +} +void set_Mux_true (ir_node *node, ir_node *ir_true) { + assert(node->op == op_Mux); + node->in[3] = ir_true; +} + ir_graph * -get_irn_irg(ir_node *node) { - if (get_irn_op(node) != op_Block) +get_irn_irg(const ir_node *node) { + if (! is_Block(node)) node = get_nodes_block(node); if (is_Bad(node)) /* sometimes bad is predecessor of nodes instead of block: in case of optimization */ node = get_nodes_block(node); @@ -1953,55 +1992,50 @@ skip_Id (ir_node *node) { #endif int -is_Bad (ir_node *node) { - assert(node); - if ((node) && get_irn_opcode(node) == iro_Bad) - return 1; - return 0; +(is_Bad)(const ir_node *node) { + return __is_Bad(node); } int -is_no_Block (ir_node *node) { - assert(node); - return (get_irn_opcode(node) != iro_Block); +(is_no_Block)(const ir_node *node) { + return __is_no_Block(node); } int -is_Block (ir_node *node) { - assert(node); - return (get_irn_opcode(node) == iro_Block); +(is_Block)(const ir_node *node) { + return __is_Block(node); } /* returns true if node is a Unknown node. */ int -is_Unknown (ir_node *node) { +is_Unknown (const ir_node *node) { assert(node); - return (get_irn_opcode(node) == iro_Unknown); + return (get_irn_op(node) == op_Unknown); } int is_Proj (const ir_node *node) { assert(node); return node->op == op_Proj - || (!interprocedural_view && node->op == op_Filter); + || (!get_interprocedural_view() && node->op == op_Filter); } /* Returns true if the operation manipulates control flow. */ int -is_cfop(ir_node *node) { +is_cfop(const ir_node *node) { return is_cfopcode(get_irn_op(node)); } /* Returns true if the operation manipulates interprocedural control flow: CallBegin, EndReg, EndExcept */ -int is_ip_cfop(ir_node *node) { +int is_ip_cfop(const ir_node *node) { return is_ip_cfopcode(get_irn_op(node)); } /* Returns true if the operation can change the control flow because of an exception. */ int -is_fragile_op(ir_node *node) { +is_fragile_op(const ir_node *node) { return is_op_fragile(get_irn_op(node)); } @@ -2028,6 +2062,13 @@ ir_node *get_fragile_op_mem(ir_node *node) { } } +/* Returns true if the operation is a forking control flow operation. */ +int +is_forking_op(const ir_node *node) { + return is_op_forking(get_irn_op(node)); +} + + #ifdef DEBUG_libfirm void dump_irn (ir_node *n) { int i, arity = get_irn_arity(n);