X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firnode.c;h=f2314c395c187e98739f5eb09827f1f6946eb0ab;hb=08b30f43eef4fca6e1455842b34f1f7b62ecf5b2;hp=bb4ac8047db5c6ab802f82d7c4fd25187007b466;hpb=9bfd2490a75017a78d969ce8812d61379fcd3633;p=libfirm diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index bb4ac8047..f2314c395 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -223,6 +223,7 @@ get_irn_in (const ir_node *node) { void set_irn_in (ir_node *node, int arity, ir_node **in) { + int i; ir_node *** arr; assert(node); if (get_interprocedural_view()) { /* handle Filter and Block specially */ @@ -237,12 +238,24 @@ set_irn_in (ir_node *node, int arity, ir_node **in) { } else { arr = &node->in; } - if (arity != ARR_LEN(*arr) - 1) { + + for (i = 0; i < arity; i++) { + if (i < ARR_LEN(*arr)-1) + edges_notify_edge(node, i, in[i], (*arr)[i+1], current_ir_graph); + else + edges_notify_edge(node, i, in[i], NULL, current_ir_graph); + } + for(;i < ARR_LEN(*arr)-1; i++) { + edges_notify_edge(node, i, NULL, (*arr)[i+1], current_ir_graph); + } + + if (arity != ARR_LEN(*arr) - 1) { ir_node * block = (*arr)[0]; *arr = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1); (*arr)[0] = block; } fix_backedges(current_ir_graph->obst, node); + memcpy((*arr) + 1, in, sizeof(ir_node *) * arity); } @@ -497,7 +510,7 @@ get_irn_symconst_attr (ir_node *node) return node->attr.i; } -type * +ir_type * get_irn_call_attr (ir_node *node) { assert (node->op == op_Call); @@ -547,6 +560,11 @@ get_irn_except_attr (ir_node *node) return node->attr.except; } +void * +get_irn_generic_attr (ir_node *node) { + return &node->attr; +} + /** manipulate fields of individual nodes **/ /* this works for all except Block */ @@ -565,7 +583,7 @@ set_nodes_block (ir_node *node, ir_node *block) { /* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base) * from Start. If so returns frame type, else Null. */ -type *is_frame_pointer(ir_node *n) { +ir_type *is_frame_pointer(ir_node *n) { if ((get_irn_op(n) == op_Proj) && (get_Proj_proj(n) == pn_Start_P_frame_base)) { ir_node *start = get_Proj_pred(n); @@ -578,7 +596,7 @@ type *is_frame_pointer(ir_node *n) { /* Test whether arbitrary node is globals pointer, i.e. Proj(pn_Start_P_globals) * from Start. If so returns global type, else Null. */ -type *is_globals_pointer(ir_node *n) { +ir_type *is_globals_pointer(ir_node *n) { if ((get_irn_op(n) == op_Proj) && (get_Proj_proj(n) == pn_Start_P_globals)) { ir_node *start = get_Proj_pred(n); @@ -631,14 +649,14 @@ ir_node * return _get_Block_cfgpred_block(node, pos); } -bool +int get_Block_matured (ir_node *node) { assert (node->op == op_Block); - return node->attr.block.matured; + return (int)node->attr.block.matured; } void -set_Block_matured (ir_node *node, bool matured) { +set_Block_matured (ir_node *node, int matured) { assert (node->op == op_Block); node->attr.block.matured = matured; } @@ -683,10 +701,10 @@ void set_Block_cg_cfgpred_arr(ir_node * node, int arity, ir_node ** in) { 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 + /* Fix backedge array. fix_backedges() operates depending on interprocedural_view. */ int ipv = get_interprocedural_view(); - set_interprocedural_view(true); + set_interprocedural_view(1); fix_backedges(current_ir_graph->obst, node); set_interprocedural_view(ipv); } @@ -943,14 +961,14 @@ cnst_classify_t (classify_Const)(ir_node *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. */ -type * +ir_type * get_Const_type (ir_node *node) { assert (node->op == op_Const); return node->attr.con.tp; } void -set_Const_type (ir_node *node, type *tp) { +set_Const_type (ir_node *node, ir_type *tp) { assert (node->op == op_Const); if (tp != firm_unknown_type) { assert (is_atomic_type(tp)); @@ -972,7 +990,7 @@ set_SymConst_kind (ir_node *node, symconst_kind num) { node->attr.i.num = num; } -type * +ir_type * get_SymConst_type (ir_node *node) { assert ( (node->op == op_SymConst) && ( get_SymConst_kind(node) == symconst_type_tag @@ -981,7 +999,7 @@ get_SymConst_type (ir_node *node) { } void -set_SymConst_type (ir_node *node, type *tp) { +set_SymConst_type (ir_node *node, ir_type *tp) { assert ( (node->op == op_SymConst) && ( get_SymConst_kind(node) == symconst_type_tag || get_SymConst_kind(node) == symconst_size)); @@ -1029,7 +1047,7 @@ set_SymConst_symbol (ir_node *node, union symconst_symbol sym) { node->attr.i.sym = sym; } -type * +ir_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); @@ -1037,7 +1055,7 @@ get_SymConst_value_type (ir_node *node) { } void -set_SymConst_value_type (ir_node *node, type *tp) { +set_SymConst_value_type (ir_node *node, ir_type *tp) { assert (node->op == op_SymConst); node->attr.i.tp = tp; } @@ -1106,16 +1124,16 @@ set_Sel_entity (ir_node *node, entity *ent) { node->attr.s.ent = ent; } -type * -get_InstOf_ent (ir_node *node) { +ir_type * +get_InstOf_type (ir_node *node) { assert (node->op = op_InstOf); - return (node->attr.io.ent); + return (node->attr.io.type); } void -set_InstOf_ent (ir_node *node, type *ent) { +set_InstOf_type (ir_node *node, ir_type *type) { assert (node->op = op_InstOf); - node->attr.io.ent = ent; + node->attr.io.type = type; } ir_node * @@ -1211,14 +1229,14 @@ set_Call_param (ir_node *node, int pos, ir_node *param) { set_irn_n(node, pos + CALL_PARAM_OFFSET, param); } -type * +ir_type * get_Call_type (ir_node *node) { assert (node->op == op_Call); return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp); } void -set_Call_type (ir_node *node, type *tp) { +set_Call_type (ir_node *node, ir_type *tp) { assert (node->op == op_Call); assert ((get_unknown_type() == tp) || is_Method_type(tp)); node->attr.call.cld_tp = tp; @@ -1372,14 +1390,14 @@ BINOP(Cmp) UNOP(Conv) UNOP(Cast) -type * +ir_type * get_Cast_type (ir_node *node) { assert (node->op == op_Cast); return node->attr.cast.totype; } void -set_Cast_type (ir_node *node, type *to_tp) { +set_Cast_type (ir_node *node, ir_type *to_tp) { assert (node->op == op_Cast); node->attr.cast.totype = to_tp; } @@ -1390,8 +1408,8 @@ set_Cast_type (ir_node *node, type *to_tp) { * Returns true if the Cast node casts a class type to a super type. */ int is_Cast_upcast(ir_node *node) { - type *totype = get_Cast_type(node); - type *fromtype = get_irn_typeinfo_type(get_Cast_op(node)); + ir_type *totype = get_Cast_type(node); + ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node)); ir_graph *myirg = get_irn_irg(node); assert(get_irg_typeinfo_state(myirg) == ir_typeinfo_consistent); @@ -1404,8 +1422,8 @@ int is_Cast_upcast(ir_node *node) { assert(fromtype); - if (!is_Class_type(totype)) return false; - return is_subclass_of(fromtype, totype); + if (!is_Class_type(totype)) return 0; + return is_SubClass_of(fromtype, totype); } /* Checks for downcast. @@ -1413,8 +1431,8 @@ int is_Cast_upcast(ir_node *node) { * Returns true if the Cast node casts a class type to a sub type. */ int is_Cast_downcast(ir_node *node) { - type *totype = get_Cast_type(node); - type *fromtype = get_irn_typeinfo_type(get_Cast_op(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); @@ -1426,8 +1444,8 @@ int is_Cast_downcast(ir_node *node) { assert(fromtype); - if (!is_Class_type(totype)) return false; - return is_subclass_of(totype, fromtype); + if (!is_Class_type(totype)) return 0; + return is_SubClass_of(totype, fromtype); } int @@ -1691,14 +1709,14 @@ set_Alloc_size (ir_node *node, ir_node *size) { set_irn_n(node, 1, size); } -type * +ir_type * get_Alloc_type (ir_node *node) { assert (node->op == op_Alloc); return node->attr.a.type = skip_tid(node->attr.a.type); } void -set_Alloc_type (ir_node *node, type *tp) { +set_Alloc_type (ir_node *node, ir_type *tp) { assert (node->op == op_Alloc); node->attr.a.type = tp; } @@ -1752,14 +1770,14 @@ set_Free_size (ir_node *node, ir_node *size) { set_irn_n(node, 2, size); } -type * +ir_type * get_Free_type (ir_node *node) { assert (node->op == op_Free); return node->attr.f.type = skip_tid(node->attr.f.type); } void -set_Free_type (ir_node *node, type *tp) { +set_Free_type (ir_node *node, ir_type *tp) { assert (node->op == op_Free); node->attr.f.type = tp; } @@ -1807,9 +1825,9 @@ set_Sync_pred (ir_node *node, int pos, ir_node *pred) { set_irn_n(node, pos, pred); } -type *get_Proj_type(ir_node *n) +ir_type *get_Proj_type(ir_node *n) { - type *tp = NULL; + ir_type *tp = NULL; ir_node *pred = get_Proj_pred(n); switch (get_irn_opcode(pred)) { @@ -1819,10 +1837,10 @@ type *get_Proj_type(ir_node *n) assert(get_irn_mode(pred) == mode_T); pred_pred = get_Proj_pred(pred); if (get_irn_op(pred_pred) == op_Start) { - type *mtp = get_entity_type(get_irg_entity(get_irn_irg(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 (get_irn_op(pred_pred) == op_Call) { - type *mtp = get_Call_type(pred_pred); + ir_type *mtp = get_Call_type(pred_pred); tp = get_method_res_type(mtp, get_Proj_proj(n)); } } break; @@ -2017,6 +2035,94 @@ void set_Mux_true (ir_node *node, ir_node *ir_true) { node->in[3] = ir_true; } +/* CopyB support */ +ir_node *get_CopyB_mem (ir_node *node) { + assert (node->op == op_CopyB); + return get_irn_n(node, 0); +} + +void set_CopyB_mem (ir_node *node, ir_node *mem) { + assert (node->op == op_CopyB); + set_irn_n(node, 0, mem); +} + +ir_node *get_CopyB_dst (ir_node *node) { + assert (node->op == op_CopyB); + return get_irn_n(node, 1); +} + +void set_CopyB_dst (ir_node *node, ir_node *dst) { + assert (node->op == op_CopyB); + set_irn_n(node, 1, dst); +} + +ir_node *get_CopyB_src (ir_node *node) { + assert (node->op == op_CopyB); + return get_irn_n(node, 2); +} + +void set_CopyB_src (ir_node *node, ir_node *src) { + assert (node->op == op_CopyB); + set_irn_n(node, 2, src); +} + +ir_type *get_CopyB_type(ir_node *node) { + assert (node->op == op_CopyB); + return node->attr.copyb.data_type; +} + +void set_CopyB_type(ir_node *node, ir_type *data_type) { + assert (node->op == op_CopyB && data_type); + node->attr.copyb.data_type = data_type; +} + +/* Bound support */ + +/* Returns the memory input of a Bound operation. */ +ir_node *get_Bound_mem(ir_node *bound) { + assert (bound->op == op_Bound); + return get_irn_n(bound, 0); +} + +void set_Bound_mem (ir_node *bound, ir_node *mem) { + assert (bound->op == op_Bound); + set_irn_n(bound, 0, mem); +} + +/* Returns the index input of a Bound operation. */ +ir_node *get_Bound_index(ir_node *bound) { + assert (bound->op == op_Bound); + return get_irn_n(bound, 1); +} + +void set_Bound_index(ir_node *bound, ir_node *idx) { + assert (bound->op == op_Bound); + set_irn_n(bound, 1, idx); +} + +/* Returns the lower bound input of a Bound operation. */ +ir_node *get_Bound_lower(ir_node *bound) { + assert (bound->op == op_Bound); + return get_irn_n(bound, 2); +} + +void set_Bound_lower(ir_node *bound, ir_node *lower) { + assert (bound->op == op_Bound); + set_irn_n(bound, 2, lower); +} + +/* Returns the upper bound input of a Bound operation. */ +ir_node *get_Bound_upper(ir_node *bound) { + assert (bound->op == op_Bound); + return get_irn_n(bound, 3); +} + +void set_Bound_upper(ir_node *bound, ir_node *upper) { + assert (bound->op == op_Bound); + set_irn_n(bound, 3, upper); +} + +/* returns the graph of a node */ ir_graph * get_irn_irg(const ir_node *node) { /* @@ -2105,14 +2211,15 @@ ir_node *skip_HighLevel(ir_node *node) { #if 0 /* 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. */ + * than any other approach, as Id chains are resolved and all point to the real node, or + * all id's are self loops. + * + * Moreover, it CANNOT be switched off using get_opt_normalize() ... + */ ir_node * skip_Id (ir_node *node) { /* don't assert node !!! */ - if (!get_opt_normalize()) return node; - /* Don't use get_Id_pred: We get into an endless loop for self-referencing Ids. */ if (node && (node->op == op_Id) && (node != node->in[0+1])) { @@ -2133,8 +2240,14 @@ skip_Id (ir_node *node) { } #else /* 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. */ + * 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 *pred; @@ -2142,9 +2255,7 @@ skip_Id (ir_node *node) { if (!node || (node->op != op_Id)) return node; - if (!get_opt_normalize()) return node; - - /* Don't use get_Id_pred: We get into an endless loop for + /* Don't use get_Id_pred(): We get into an endless loop for self-referencing Ids. */ pred = node->in[0+1]; @@ -2170,6 +2281,16 @@ skip_Id (ir_node *node) { } #endif +void skip_Id_and_store(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_Bad)(const ir_node *node) { return _is_Bad(node); @@ -2246,31 +2367,141 @@ 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)); +int (is_irn_forking)(const ir_node *node) { + return _is_irn_forking(node); } -type *(get_irn_type)(ir_node *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) { return _get_irn_type(node); } -/** the get_type operation must be always implemented */ -static type *get_Null_type(ir_node *n) { +/* 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 the entity attribute of a node n (SymConst, Sel) or NULL. */ +entity *(get_irn_entity_attr)(ir_node *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); +} + +/* + * 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); +} + +/* Gets the string representation of the jump prediction .*/ +const char *get_cond_jmp_predicate_name(cond_jmp_predicate pred) +{ + 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"; + } +} + +/* Returns the conditional jump prediction of a Cond node. */ +cond_jmp_predicate (get_Cond_jmp_pred)(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) { + return get_unknown_type(); +} + +/* Sets the get_type operation for an ir_op_ops. */ +ir_op_ops *firm_set_default_get_type(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) { + symconst_kind kind = get_SymConst_kind(self); + if (kind == symconst_type_tag || kind == symconst_size) + return get_SymConst_type(self); + return NULL; +} + +/** Return the attribute entity of a SymConst node if exists */ +static entity *get_SymConst_attr_entity(ir_node *self) { + symconst_kind kind = get_SymConst_kind(self); + if (kind == symconst_addr_ent) + return get_SymConst_entity(self); return NULL; } -/* set the get_type operation */ -ir_op *firm_set_default_get_type(ir_op *op) +/** the get_type_attr operation must be always implemented */ +static ir_type *get_Null_type(ir_node *n) { + return firm_unknown_type; +} + +/* Sets the get_type operation for an ir_op_ops. */ +ir_op_ops *firm_set_default_get_type_attr(opcode code, ir_op_ops *ops) { - switch (op->code) { - case iro_Const: op->get_type = get_Const_type; break; - case iro_SymConst: op->get_type = get_SymConst_value_type; break; - case iro_Cast: op->get_type = get_Cast_type; break; - case iro_Proj: op->get_type = get_Proj_type; break; - default: op->get_type = get_Null_type; break; + 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; +} + +/** the get_entity_attr operation must be always implemented */ +static entity *get_Null_ent(ir_node *n) { + return NULL; +} + +/* Sets the get_type operation for an ir_op_ops. */ +ir_op_ops *firm_set_default_get_entity_attr(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 op; + return ops; } #ifdef DEBUG_libfirm