* @author Goetz Lindenmaier
* @date 22.8.2003
* @version $Id$
- * @summary
+ * @brief
* Runs most simple type analyses.
*
* We compute type information for each node. It is derived from the
* from the method type.
* The type information so far is saved in the link field.
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
#include "irtypeinfo.h"
#include "irsimpletype.h"
/**
* init type link field so that types point to their pointers.
*/
-static void precompute_pointer_types(void) {
+static void precompute_pointer_types(void)
+{
#if 0
int i;
set_type_link(firm_unknown_type, firm_unknown_type);
* Returns a pointer to type which was stored in the link field
* to speed up search.
*/
-static ir_type *find_pointer_type_to (ir_type *tp) {
+static ir_type *find_pointer_type_to (ir_type *tp)
+{
#if 0
return (ir_type *)get_type_link(tp);
#else
* Try to determine a type for a Proj node.
* If a type cannot be determined, return @p firm_none_type.
*/
-static ir_type *find_type_for_Proj(ir_node *n) {
+static ir_type *find_type_for_Proj(ir_node *n)
+{
ir_type *tp;
/* Avoid nested Tuples. */
/* 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 (get_irn_op(pred_pred) == op_Start) {
+ 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 (get_irn_op(pred_pred) == op_Call) {
+ } else if (is_Call(pred_pred)) {
ir_type *mtp = get_Call_type(pred_pred);
tp = get_method_res_type(mtp, get_Proj_proj(n));
- } else if (get_irn_op(pred_pred) == op_Tuple) {
+ } else if (is_Tuple(pred_pred)) {
panic("Encountered nested Tuple");
} else {
DB((dbg, SET_LEVEL_1, "Proj %ld from Proj from ??: unknown type\n", get_irn_node_nr(n)));
case pn_Start_P_tls:
tp = find_pointer_type_to(get_tls_type());
break;
- case pn_Start_P_value_arg_base:
- DB((dbg, SET_LEVEL_1, "Value arg base proj %ld from Start: unknown type\n", get_irn_node_nr(n)));
- tp = firm_unknown_type; /* find_pointer_type_to(get....(get_entity_type(get_irg_entity(get_irn_irg(pred))))); */
- break;
default:
DB((dbg, SET_LEVEL_1, "Proj %ld %ld from Start: unknown type\n", get_Proj_proj(n), get_irn_node_nr(n)));
tp = firm_unknown_type;
* Try to determine the type of a node.
* If a type cannot be determined, return @p firm_none_type.
*/
-static ir_type *find_type_for_node(ir_node *n) {
+static ir_type *find_type_for_node(ir_node *n)
+{
ir_type *tp = firm_unknown_type;
ir_type *tp1 = NULL, *tp2 = NULL;
ir_node *a = NULL, *b = NULL;
switch (get_irn_opcode(n)) {
- case iro_InstOf: {
+ case iro_InstOf:
assert(0 && "op_InstOf not supported");
- } break;
+ break;
/* has no type */
case iro_Return: {
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_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_Const:
+ tp = get_Const_type(n);
+ break;
case iro_SymConst:
- tp = get_SymConst_value_type(n); break;
+ tp = get_SymConst_value_type(n);
+ break;
case iro_Sel:
- tp = find_pointer_type_to(get_entity_type(get_Sel_entity(n))); break;
+ 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_Rotl:
+ tp = tp1;
+ break;
case iro_Cast:
- tp = get_Cast_type(n); break;
+ tp = get_Cast_type(n);
+ break;
case iro_Phi: {
int i;
int n_preds = get_Phi_n_preds(n);
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)));
+ DB((dbg, SET_LEVEL_2, "Phi %ld with two different types: %+F, %+F: unknown type.\n", get_irn_node_nr(n), tp1, tp2));
tp = firm_unknown_type; /* Test for supertypes? */
- } break;
+ break;
+ }
case iro_Load: {
ir_node *a = get_Load_ptr(n);
} else {
DB((dbg, SET_LEVEL_1, "Load %ld with typeless address. result: unknown type\n", get_irn_node_nr(n)));
}
- } break;
+ break;
+ }
case iro_Alloc:
- tp = find_pointer_type_to(get_Alloc_type(n)); break;
+ tp = find_pointer_type_to(get_Alloc_type(n));
+ break;
case iro_Proj:
- tp = find_type_for_Proj(n); break;
+ tp = find_type_for_Proj(n);
+ break;
case iro_Id:
- tp = compute_irn_type(get_Id_pred(n)); break;
+ 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;
+ tp = firm_unknown_type;
+ break;
/* catch special cases with fallthrough to binop/unop cases in default. */
- case iro_Sub: {
+ 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: {
+ /* 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 = tp2; break;
}
goto default_code;
- } break;
- case iro_Mul: {
+ 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: {
+ 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;
+ break;
case iro_Bound:
tp = compute_irn_type(get_Bound_index(n));
break;
default:
-default_code: {
-
+default_code:
if (is_unop(n)) {
/* It's not proper to walk past a Conv, so this case is handled above. */
tp = tp1;
tp = tp1;
break;
}
- if((tp1 == phi_cycle_type) || (tp2 == phi_cycle_type)) {
+ if ((tp1 == phi_cycle_type) || (tp2 == phi_cycle_type)) {
tp = phi_cycle_type;
break;
}
- DB((dbg, SET_LEVEL_2, "Binop %ld with two different types: %s, %s: unknown type \n", get_irn_node_nr(n),
- get_type_name(tp1), get_type_name(tp2)));
+ DB((dbg, SET_LEVEL_2, "Binop %ld with two different types: %+F, %+F: unknown type\n", get_irn_node_nr(n), tp1, tp2));
tp = firm_unknown_type;
break;
}
panic(" not implemented: %+F", n);
- } break; /* default */
} /* end switch */
return tp;
}
/** Compute the type of an IR node. */
-static ir_type *compute_irn_type(ir_node *n) {
+static ir_type *compute_irn_type(ir_node *n)
+{
ir_type *tp = get_irn_typeinfo_type(n);
if (tp == initial_type) {
* Post-walking ensures that the types for all predecessor
* nodes are already computed.
*/
-static void compute_type(ir_node *n, void *env) {
+static void compute_type(ir_node *n, void *env)
+{
ir_type *tp = get_irn_typeinfo_type(n);
(void) env;
if (tp == phi_cycle_type) {
- /* printf(" recomputing for phi_cycle_type "); DDMN(n); */
set_irn_typeinfo_type(n, initial_type);
}
compute_irn_type(n);
/**
* Compute the types for all nodes of a graph.
*/
-static void analyse_irg (ir_graph *irg) {
+static void analyse_irg (ir_graph *irg)
+{
set_irg_typeinfo_state(irg, ir_typeinfo_consistent);
irg_walk_graph(irg, NULL, compute_type, NULL);
}
* Initialize the analysis by creating a phi_cycle_type and
* computing pointer types for all class and struct types.
*/
-static void init_irsimpletype(void) {
+static void init_irsimpletype(void)
+{
init_irtypeinfo();
if (!phi_cycle_type)
phi_cycle_type = new_type_class(new_id_from_str("phi_cycle_type"));
}
/* Computes type information for each node in all ir graphs. */
-void simple_analyse_types(void) {
+void simple_analyse_types(void)
+{
int i;
FIRM_DBG_REGISTER(dbg, "firm.ana.simpletype");
set_irp_typeinfo_state(ir_typeinfo_consistent);
}
-void free_simple_type_information(void) {
+void free_simple_type_information(void)
+{
free_irtypeinfo();
if (phi_cycle_type) {