- ir_type *tp = firm_unknown_type;
- ir_type *tp1 = NULL, *tp2 = NULL;
- ir_node *a = NULL, *b = NULL;
-
- /* DDMN(n); */
-
- if (is_unop(n)) {
- a = get_unop_op(n);
- tp1 = compute_irn_type(a);
- }
- if (is_binop(n)) {
- a = get_binop_left(n);
- b = get_binop_right(n);
- tp1 = compute_irn_type(a);
- tp2 = compute_irn_type(b);
- }
-
- switch (get_irn_opcode(n)) {
-
- case iro_InstOf: {
- assert(0 && "op_InstOf not supported");
- } break;
-
- /* has no type */
- case iro_Return: {
- /* Check returned type. */
- /*
- int i;
- ir_type *meth_type = get_entity_type(get_irg_entity(current_ir_graph));
- for (i = 0; i < get_method_n_ress(meth_type); i++) {
- ir_type *res_type = get_method_res_type(meth_type, i);
- ir_type *ana_res_type = get_irn_type(get_Return_res(n, i));
- if (ana_res_type == firm_unknown_type) continue;
- if (res_type != ana_res_type && "return value has wrong type") {
- DDMN(n);
- assert(res_type == ana_res_type && "return value has wrong type");
- }
- }
- */
- }
- case iro_Block:
- case iro_Start:
- case iro_End:
- case iro_Jmp:
- case iro_Cond:
- case iro_Raise:
- case iro_Call:
- case iro_Cmp:
- case iro_Store:
- case iro_Free:
- case iro_Sync:
- case iro_Tuple:
- case iro_Bad:
- case iro_NoMem:
- case iro_Break:
- case iro_CallBegin:
- case iro_EndReg:
- case iro_EndExcept:
- break;
-
- /* compute the type */
- case iro_Const: tp = get_Const_type(n); break;
- case iro_SymConst:
- tp = get_SymConst_value_type(n); break;
- case iro_Sel:
- tp = find_pointer_type_to(get_entity_type(get_Sel_entity(n))); break;
- /* asymmetric binops */
- case iro_Shl:
- case iro_Shr:
- case iro_Shrs:
- case iro_Rot:
- tp = tp1; break;
- case iro_Cast:
- tp = get_Cast_type(n); break;
- case iro_Phi: {
- int i;
- int n_preds = get_Phi_n_preds(n);
-
- if (n_preds == 0)
- break;
-
- /* initialize this Phi */
- set_irn_typeinfo_type(n, phi_cycle_type);
-
- /* find a first real type */
- for (i = 0; i < n_preds; ++i) {
- tp1 = compute_irn_type(get_Phi_pred(n, i));
- assert(tp1 != initial_type);
- if ((tp1 != phi_cycle_type) && (tp1 != firm_none_type))
- break;
- }
-
- /* find a second real type */
- tp2 = tp1;
- for (; (i < n_preds); ++i) {
- tp2 = compute_irn_type(get_Phi_pred(n, i));
- if ((tp2 == phi_cycle_type) || (tp2 == firm_none_type)) {
- tp2 = tp1;
- continue;
- }
- if (tp2 != tp1) break;
- }
-
- /* printf("Types in Phi %s and %s \n", get_type_name(tp1), get_type_name(tp2)); */
-
- if (tp1 == tp2) { tp = tp1; break; }
-
- if (get_firm_verbosity() > 55) { // Do not commit 55! should be 1.
- VERBOSE_UNKNOWN_TYPE(("Phi %ld with two different types: %s, %s: unknown type.\n", get_irn_node_nr(n),
- get_type_name(tp1), get_type_name(tp2)));
- }
- tp = firm_unknown_type; /* Test for supertypes? */
- } break;
- case iro_Load: {
- ir_node *a = get_Load_ptr(n);
- if (is_Sel(a))
- tp = get_entity_type(get_Sel_entity(a));
- else if (is_Pointer_type(compute_irn_type(a))) {
- tp = get_pointer_points_to_type(get_irn_typeinfo_type(a));
- if (is_Array_type(tp))
- tp = get_array_element_type(tp);
- } else {
- VERBOSE_UNKNOWN_TYPE(("Load %ld with typeless address. result: unknown type\n", get_irn_node_nr(n)));
- }
- } break;
- case iro_Alloc:
- tp = find_pointer_type_to(get_Alloc_type(n)); break;
- case iro_Proj:
- tp = find_type_for_Proj(n); break;
- case iro_Id:
- tp = compute_irn_type(get_Id_pred(n)); break;
- case iro_Unknown:
- tp = firm_unknown_type; break;
- case iro_Filter:
- assert(0 && "Filter not implemented"); break;
-
- /* catch special cases with fallthrough to binop/unop cases in default. */
- case iro_Sub: {
- if (mode_is_int(get_irn_mode(n)) &&
- mode_is_reference(get_irn_mode(a)) &&
- mode_is_reference(get_irn_mode(b)) ) {
- VERBOSE_UNKNOWN_TYPE(("Sub %ld ptr - ptr = int: unknown type\n", get_irn_node_nr(n)));
- tp = firm_unknown_type; break;
- }
- } /* fall through to Add. */
- case iro_Add: {
- if (mode_is_reference(get_irn_mode(n)) &&
- mode_is_reference(get_irn_mode(a)) &&
- mode_is_int(get_irn_mode(b)) ) {
- tp = tp1; break;
- }
- if (mode_is_reference(get_irn_mode(n)) &&
- mode_is_int(get_irn_mode(a)) &&
- mode_is_reference(get_irn_mode(b)) ) {
- tp = tp2; break;
- }
- goto default_code;
- } break;
- case iro_Mul: {
- if (get_irn_mode(n) != get_irn_mode(a)) {
- VERBOSE_UNKNOWN_TYPE(("Mul %ld int1 * int1 = int2: unknown type\n", get_irn_node_nr(n)));
- tp = firm_unknown_type; break;
- }
- goto default_code;
- } break;
- case iro_Mux: {
- a = get_Mux_true(n);
- b = get_Mux_false(n);
- tp1 = compute_irn_type(a);
- tp2 = compute_irn_type(b);
- if (tp1 == tp2)
- tp = tp1;
- } break;
- case iro_Psi: {
- int i, n_conds = get_Psi_n_conds(n);
- tp1 = compute_irn_type(get_Psi_default(n));
-
- for (i = 0; i < n_conds; ++i) {
- tp2 = compute_irn_type(get_Psi_val(n, i));
- if (tp2 != tp1)
- break;
- }
- if (tp1 == tp2)
- tp = tp1;
- } break;
- case iro_Bound:
- tp = compute_irn_type(get_Bound_index(n));
- break;
- case iro_Confirm:
- tp = compute_irn_type(get_Confirm_value(n));
- break;
- case iro_Conv:
- /* Conv is a unop, but changing the mode implies
- changing the type. */
- break;
-
- default:
+ ir_type *tp = firm_unknown_type;
+ ir_type *tp1 = NULL, *tp2 = NULL;
+ ir_node *a = NULL, *b = NULL;
+
+ if (is_unop(n)) {
+ a = get_unop_op(n);
+ tp1 = compute_irn_type(a);
+ }
+ if (is_binop(n)) {
+ a = get_binop_left(n);
+ b = get_binop_right(n);
+ tp1 = compute_irn_type(a);
+ tp2 = compute_irn_type(b);
+ }
+
+ switch (get_irn_opcode(n)) {
+
+ case iro_InstOf: {
+ assert(0 && "op_InstOf not supported");
+ } break;
+
+ /* has no type */
+ case iro_Return: {
+ /* Check returned type. */
+ /*
+ int i;
+ ir_type *meth_type = get_entity_type(get_irg_entity(current_ir_graph));
+ for (i = 0; i < get_method_n_ress(meth_type); i++) {
+ ir_type *res_type = get_method_res_type(meth_type, i);
+ ir_type *ana_res_type = get_irn_type(get_Return_res(n, i));
+ if (ana_res_type == firm_unknown_type) continue;
+ if (res_type != ana_res_type && "return value has wrong type") {
+ DDMN(n);
+ assert(res_type == ana_res_type && "return value has wrong type");
+ }
+ }
+ */
+ }
+ case iro_Block:
+ case iro_Start:
+ case iro_End:
+ case iro_Jmp:
+ case iro_Cond:
+ case iro_Raise:
+ case iro_Call:
+ case iro_Cmp:
+ case iro_Store:
+ case iro_Free:
+ case iro_Sync:
+ case iro_Tuple:
+ case iro_Bad:
+ case iro_NoMem:
+ case iro_Break:
+ case iro_CallBegin:
+ case iro_EndReg:
+ case iro_EndExcept:
+ break;
+
+ /* compute the type */
+ case iro_Const: tp = get_Const_type(n); break;
+ case iro_SymConst:
+ tp = get_SymConst_value_type(n); break;
+ case iro_Sel:
+ tp = find_pointer_type_to(get_entity_type(get_Sel_entity(n))); break;
+ /* asymmetric binops */
+ case iro_Shl:
+ case iro_Shr:
+ case iro_Shrs:
+ case iro_Rotl:
+ tp = tp1; break;
+ case iro_Cast:
+ tp = get_Cast_type(n); break;
+ case iro_Phi: {
+ int i;
+ int n_preds = get_Phi_n_preds(n);
+
+ if (n_preds == 0)
+ break;
+
+ /* initialize this Phi */
+ set_irn_typeinfo_type(n, phi_cycle_type);
+
+ /* find a first real type */
+ for (i = 0; i < n_preds; ++i) {
+ tp1 = compute_irn_type(get_Phi_pred(n, i));
+ assert(tp1 != initial_type);
+ if ((tp1 != phi_cycle_type) && (tp1 != firm_none_type))
+ break;
+ }
+
+ /* find a second real type */
+ tp2 = tp1;
+ for (; (i < n_preds); ++i) {
+ tp2 = compute_irn_type(get_Phi_pred(n, i));
+ if ((tp2 == phi_cycle_type) || (tp2 == firm_none_type)) {
+ tp2 = tp1;
+ continue;
+ }
+ if (tp2 != tp1) break;
+ }
+
+ /* printf("Types in Phi %s and %s \n", get_type_name(tp1), get_type_name(tp2)); */
+
+ if (tp1 == tp2) { tp = tp1; break; }
+
+ DB((dbg, SET_LEVEL_2, "Phi %ld with two different types: %s, %s: unknown type.\n", get_irn_node_nr(n),
+ get_type_name(tp1), get_type_name(tp2)));
+ tp = firm_unknown_type; /* Test for supertypes? */
+ } break;
+
+ case iro_Load: {
+ ir_node *a = get_Load_ptr(n);
+ if (is_Sel(a))
+ tp = get_entity_type(get_Sel_entity(a));
+ else if (is_Pointer_type(compute_irn_type(a))) {
+ tp = get_pointer_points_to_type(get_irn_typeinfo_type(a));
+ if (is_Array_type(tp))
+ tp = get_array_element_type(tp);
+ } else {
+ DB((dbg, SET_LEVEL_1, "Load %ld with typeless address. result: unknown type\n", get_irn_node_nr(n)));
+ }
+ } break;
+ case iro_Alloc:
+ tp = find_pointer_type_to(get_Alloc_type(n)); break;
+ case iro_Proj:
+ tp = find_type_for_Proj(n); break;
+ case iro_Id:
+ tp = compute_irn_type(get_Id_pred(n)); break;
+ case iro_Unknown:
+ tp = firm_unknown_type; break;
+ case iro_Filter:
+ assert(0 && "Filter not implemented"); break;
+
+ /* catch special cases with fallthrough to binop/unop cases in default. */
+ case iro_Sub: {
+ if (mode_is_int(get_irn_mode(n)) &&
+ mode_is_reference(get_irn_mode(a)) &&
+ mode_is_reference(get_irn_mode(b)) ) {
+ DB((dbg, SET_LEVEL_1, "Sub %ld ptr - ptr = int: unknown type\n", get_irn_node_nr(n)));
+ tp = firm_unknown_type; break;
+ }
+ } /* fall through to Add. */
+ case iro_Add: {
+ if (mode_is_reference(get_irn_mode(n)) &&
+ mode_is_reference(get_irn_mode(a)) &&
+ mode_is_int(get_irn_mode(b)) ) {
+ tp = tp1; break;
+ }
+ if (mode_is_reference(get_irn_mode(n)) &&
+ mode_is_int(get_irn_mode(a)) &&
+ mode_is_reference(get_irn_mode(b)) ) {
+ tp = tp2; break;
+ }
+ goto default_code;
+ } break;
+
+ case iro_Mul: {
+ if (get_irn_mode(n) != get_irn_mode(a)) {
+ DB((dbg, SET_LEVEL_1, "Mul %ld int1 * int1 = int2: unknown type\n", get_irn_node_nr(n)));
+ tp = firm_unknown_type; break;
+ }
+ goto default_code;
+ } break;
+
+ case iro_Mux: {
+ a = get_Mux_true(n);
+ b = get_Mux_false(n);
+ tp1 = compute_irn_type(a);
+ tp2 = compute_irn_type(b);
+ if (tp1 == tp2)
+ tp = tp1;
+ } break;
+
+ case iro_Psi: {
+ int i, n_conds = get_Psi_n_conds(n);
+ tp1 = compute_irn_type(get_Psi_default(n));
+
+ for (i = 0; i < n_conds; ++i) {
+ tp2 = compute_irn_type(get_Psi_val(n, i));
+ if (tp2 != tp1)
+ break;
+ }
+ if (tp1 == tp2)
+ tp = tp1;
+ } break;
+
+ case iro_Bound:
+ tp = compute_irn_type(get_Bound_index(n));
+ break;
+ case iro_Confirm:
+ tp = compute_irn_type(get_Confirm_value(n));
+ break;
+ case iro_Conv:
+ /* Conv is a unop, but changing the mode implies
+ changing the type. */
+ break;
+
+ default: