/*
- * File name: ir/ana/irsimpletype.c
- * Purpose: Run most simple type analyses.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created: 22.8.2003
- * CVS-ID: $Id$
- * Copyright: (c) 2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
*/
/**
- * @file irsimpletype.c
- *
- * Runs most simple type analyses.
+ * @file
+ * @brief Run most simple type analyses.
+ * @author Goetz Lindenmaier
+ * @date 22.8.2003
+ * @version $Id$
+ * @summary
+ * Runs most simple type analyses.
*
- * We compute type information for each node. It is derived from the
- * types of the origines of values, e.g. parameter types can be derived
- * from the method type.
- * The type information so far is saved in the link field.
- *
- * @author Goetz Lindenmaier
+ * We compute type information for each node. It is derived from the
+ * types of the origines of values, e.g. parameter types can be derived
+ * from the method type.
+ * The type information so far is saved in the link field.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
-# include "irtypeinfo.h"
-# include "irsimpletype.h"
+#include "irtypeinfo.h"
+#include "irsimpletype.h"
-# include "irnode_t.h"
-# include "irprog_t.h"
-# include "irgwalk.h"
-# include "ident.h"
-# include "trouts.h"
+#include "irnode_t.h"
+#include "irprog_t.h"
+#include "irgwalk.h"
+#include "ident.h"
+#include "trouts.h"
+#include "error.h"
#define VERBOSE_UNKNOWN_TYPE(s) printf s
static ir_type *compute_irn_type(ir_node *n);
+/**
+ * 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) {
ir_type *tp;
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) {
- assert(0 && "Encountered nested Tuple");
+ panic("Encountered nested Tuple");
} else {
VERBOSE_UNKNOWN_TYPE(("Proj %ld from Proj from ??: unknown type\n", get_irn_node_nr(n)));
tp = firm_unknown_type;
}
} break;
case iro_Start: {
- /* globals and frame pointer */
- if (get_Proj_proj(n) == pn_Start_P_frame_base)
+ /* frame pointer, globals and tls */
+ switch (get_Proj_proj(n)) {
+ case pn_Start_P_frame_base:
tp = find_pointer_type_to(get_irg_frame_type(get_irn_irg(pred)));
- else if (get_Proj_proj(n) == pn_Start_P_globals)
+ break;
+ case pn_Start_P_globals:
tp = find_pointer_type_to(get_glob_type());
- else if (get_Proj_proj(n) == pn_Start_P_value_arg_base) {
+ break;
+ case pn_Start_P_tls:
+ tp = find_pointer_type_to(get_tls_type());
+ break;
+ case pn_Start_P_value_arg_base:
VERBOSE_UNKNOWN_TYPE(("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))))); */
- } else {
+ break;
+ default:
VERBOSE_UNKNOWN_TYPE(("Proj %ld %ld from Start: unknown type\n", get_Proj_proj(n), get_irn_node_nr(n)));
tp = firm_unknown_type;
}
* If a type cannot be determined, return @p firm_none_type.
*/
static ir_type *find_type_for_node(ir_node *n) {
- ir_type *tp = NULL;
+ ir_type *tp = firm_unknown_type;
ir_type *tp1 = NULL, *tp2 = NULL;
ir_node *a = NULL, *b = NULL;
tp2 = compute_irn_type(b);
}
- switch(get_irn_opcode(n)) {
+ switch (get_irn_opcode(n)) {
case iro_InstOf: {
assert(0 && "op_InstOf not supported");
case iro_CallBegin:
case iro_EndReg:
case iro_EndExcept:
- tp = firm_none_type; break;
+ break;
/* compute the type */
case iro_Const: tp = get_Const_type(n); break;
int i;
int n_preds = get_Phi_n_preds(n);
- if (n_preds == 0) {tp = firm_none_type; break; }
+ if (n_preds == 0)
+ break;
/* initialize this Phi */
set_irn_typeinfo_type(n, phi_cycle_type);
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);
+ 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)));
- tp = firm_unknown_type;
}
} break;
case iro_Alloc:
tp2 = compute_irn_type(b);
if (tp1 == tp2)
tp = tp1;
- else
- tp = firm_unknown_type;
} 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:
default_code: {
if (is_unop(n)) {
- /* Is is proper to walk past a Conv??? */
+ /* It's not proper to walk past a Conv, so this case is handled above. */
tp = tp1;
break;
}
break;
}
- printf(" not implemented: "); DDMN(n);
+ panic(" not implemented: %+F", n);
} break; /* default */
} /* end switch */
- /* printf (" found %s ", get_type_name(tp)); DDM; */
-
return tp;
}
-
+/** Compute the type of an IR node. */
static ir_type *compute_irn_type(ir_node *n) {
ir_type *tp = get_irn_typeinfo_type(n);
set_irn_typeinfo_type(n, tp);
}
- /* printf (" found %s ", get_type_name(tp)); DDM; */
-
return tp;
}
+/**
+ * Post-Walker: computes the type for every node
+ * and store it into a map.
+ * Post-walking ensures that the types for all predecessor
+ * nodes are already computed.
+ */
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) {
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) {
init_irtypeinfo();
if (!phi_cycle_type)
precompute_pointer_types();
}
+/* Computes type information for each node in all ir graphs. */
void simple_analyse_types(void) {
int i;
init_irsimpletype();
- for (i = 0; i < get_irp_n_irgs(); i++) {
- current_ir_graph = get_irp_irg(i);
- analyse_irg(current_ir_graph);
+ for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+ ir_graph *irg = get_irp_irg(i);
+ analyse_irg(irg);
}
set_irp_typeinfo_state(ir_typeinfo_consistent);
}