#include "pmap.h"
#include "array.h"
+#include "irdump.h"
+
/* Eindeutige Adresse zur Markierung von besuchten Knoten und zur
* Darstellung der unbekannten Methode. */
static void * MARK = &MARK;
/** Bestimmt die eindeutige Methode, die die Methode für den
- * übergebenen (dynamischen) Typ überschreibt. */
+ * übergebenen (dynamischen) Typ überschreibt. */
static entity * get_implementation(type * class, entity * method) {
int i;
if (get_entity_peculiarity(method) != peculiarity_description &&
static entity *get_inherited_methods_implementation(entity *inh_meth) {
entity *impl_meth = NULL;
ir_node *addr = get_atomic_ent_value(inh_meth);
+
assert(addr && "constant entity without value");
+
if ((get_irn_op(addr) == op_SymConst) &&
- (get_SymConst_kind(addr) == symconst_addr_ent)) {
+ (get_SymConst_kind(addr) == symconst_addr_ent)) {
impl_meth = get_SymConst_entity(addr);
} else {
assert(0 && "Complex constant values not supported -- address of method should be straight constant!");
}
+
if (impl_meth && (get_entity_peculiarity(impl_meth) != peculiarity_existent)) {
/*
printf("this_meth: "); DDMEO(inh_meth);
int i;
if (get_entity_peculiarity(method) == peculiarity_existent) {
- if (get_entity_visibility(method) == visibility_external_allocated) {
- assert(get_entity_irg(method) == NULL);
+ if ((get_entity_visibility(method) == visibility_external_allocated)
+ && (NULL == get_entity_irg(method))) {
*open = true;
} else {
assert(get_entity_irg(method) != NULL);
/** Analyse address computations.
*
- * - If the node is a SymConst replace it by Const(ent) if possible.
+ * - If the node is a SymConst(name) replace it by SymConst(ent) if possible.
* - If the node is a Sel:
* * If the pointer to the Sel comes directly from an Alloc node
- * replace the Sel by a Const(ent).
+ * replace the Sel by a SymConst(ent).
*
*
* @param node The node to analyze
*/
static void sel_methods_walker(ir_node * node, pmap * ldname_map) {
+ /* replace SymConst(name)-operations by SymConst(ent) */
if (get_irn_op(node) == op_SymConst) {
- /* Wenn möglich SymConst-Operation durch Const-Operation
- * ersetzen. */
if (get_SymConst_kind(node) == symconst_addr_name) {
pmap_entry * entry = pmap_find(ldname_map, (void *) get_SymConst_name(node));
if (entry != NULL) { /* Method is declared in the compiled code */
- entity * ent = entry->value;
- if (get_opt_normalize() && (get_entity_visibility(ent) != visibility_external_allocated)) { /* Meth. is defined */
- ir_node *new_node;
- symconst_symbol sym;
- assert(get_entity_irg(ent));
- sym.entity_p = ent;
- set_irg_current_block(current_ir_graph, get_nodes_block(node));
- new_node = new_d_SymConst(get_irn_dbg_info(node), sym, symconst_addr_ent); DBG_OPT_NORMALIZE;
- DDMN(new_node);
- exchange(node, new_node);
- }
+ entity * ent = entry->value;
+ if (get_opt_normalize() && (get_entity_visibility(ent) != visibility_external_allocated)) { /* Meth. is defined */
+ set_irg_current_block(current_ir_graph, get_nodes_block(node));
+ ir_node *new_node = copy_const_value(get_atomic_ent_value(ent));
+ DBG_OPT_NORMALIZE;
+ assert(get_entity_irg(ent));
+ DDMN(new_node);
+ exchange(node, new_node);
+ }
}
}
- } else if (get_irn_op(node) == op_Sel &&
- is_method_type(get_entity_type(get_Sel_entity(node)))) {
+ }
+
+ else if (get_irn_op(node) == op_Sel &&
+ is_method_type(get_entity_type(get_Sel_entity(node)))) {
entity * ent = get_Sel_entity(node);
+
+ /* Sel from Alloc: replace by constant */
if (get_opt_optimize() && get_opt_dyn_meth_dispatch() &&
(get_irn_op(skip_Proj(get_Sel_ptr(node))) == op_Alloc)) {
ir_node *new_node;
entity *called_ent;
/* We know which method will be called, no dispatch necessary. */
-#if 0
- assert(get_entity_peculiarity(ent) != peculiarity_description);
- set_irg_current_block(current_ir_graph, get_nodes_block(node));
- /* @@@ Is this correct?? Alloc could reference a subtype of the owner
- of Sel that overwrites the method referenced in Sel. */
- /* @@@ Yes, this is wrong. GL, 10.3.04 */
- new_node = copy_const_value(get_atomic_ent_value(ent)); DBG_OPT_POLY_ALLOC;
-#else
called_ent = resolve_ent_polymorphy(get_Alloc_type(skip_Proj(get_Sel_ptr(node))), ent);
set_irg_current_block(current_ir_graph, get_nodes_block(node));
/* called_ent may not be description: has no Address/Const to Call! */
assert(get_entity_peculiarity(called_ent) != peculiarity_description);
new_node = copy_const_value(get_atomic_ent_value(called_ent)); DBG_OPT_POLY_ALLOC;
-#endif
exchange (node, new_node);
- } else {
+ }
+
+ else {
assert(get_entity_peculiarity(ent) != peculiarity_inherited);
if (!eset_contains(entities, ent)) {
/* Entity noch nicht behandelt. Alle (intern oder extern)
/* Gib eine Warnung aus wenn die Entitaet eine Beschreibung ist
fuer die es keine Implementierung gibt. */
if (get_entity_peculiarity(ent) == peculiarity_description) {
- /* @@@ GL Methode um Fehler anzuzeigen aufrufen! */
- printf("WARNING: Calling method description %s\n in method %s\n of class %s\n which has "
- "no implementation!\n", get_entity_name(ent),
- get_entity_name(get_irg_entity(current_ir_graph)),
- get_type_name(get_entity_owner(get_irg_entity(current_ir_graph))));
- printf("This happens when compiling a Java Interface that's never really used, i.e., "
- "no class implementing the interface is ever used.\n");
+ /* This is possible: We call a method in a dead part of the program. */
} else {
- exchange(node, new_Bad());
+ DDMN(node);
+ assert(0); /* Why should this happen ??? */
+ //exchange(node, new_Bad());
}
} else {
entity ** arr = get_entity_link(ent);
if (get_opt_optimize() && get_opt_dyn_meth_dispatch() &&
(ARR_LEN(arr) == 1 && arr[0] != NULL)) {
ir_node *new_node;
- /* Die Sel-Operation kann immer nur einen Wert auf eine
+ /* Die Sel-Operation kann immer nur _einen_ Wert auf eine
* interne Methode zurückgeben. Wir können daher die
* Sel-Operation durch eine Const- bzw. SymConst-Operation
* ersetzen. */
set_irg_current_block(current_ir_graph, get_nodes_block(node));
- /* assert(get_entity_peculiarity(tarval_to_entity(get_Const_tarval(get_atomic_ent_value(arr[0])))) == peculiarity_existent); */
+ assert(get_entity_peculiarity(get_SymConst_entity(get_atomic_ent_value(arr[0]))) ==
+ peculiarity_existent);
new_node = copy_const_value(get_atomic_ent_value(arr[0])); DBG_OPT_POLY;
exchange (node, new_node);
}
/** Datenstruktur initialisieren. Zusätzlich werden alle
- * SymConst-Operationen, die auf interne Methoden verweisen, durch
- * Const-Operationen ersetzt. */
+ * SymConst(name)-Operationen, die auf interne Methoden verweisen, durch
+ * SymConst(entity)-Operationen ersetzt. */
static void sel_methods_init(void) {
int i;
- pmap * ldname_map = pmap_create(); /* Map entitiy names to entities: to replace SymConst by Const(ent). */
+ pmap * ldname_map = pmap_create(); /* Map entitiy names to entities: to replace SymConst(name) by SymConst(ent). */
+
assert(entities == NULL);
entities = eset_create();
for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
entity * ent = get_SymConst_entity(node);
assert(ent && is_method_type(get_entity_type(ent)));
if (get_entity_visibility(ent) != visibility_external_allocated) {
- assert(get_entity_irg(ent));
- eset_insert(methods, ent);
+ assert(get_entity_irg(ent));
+ eset_insert(methods, ent);
} else {
- eset_insert(methods, MARK); /* free method -> unknown */
+ eset_insert(methods, MARK); /* free method -> unknown */
}
} else {
assert(get_SymConst_kind(node) == symconst_addr_name);
}
for (ent = eset_first(methods); ent; ent = eset_next(methods)) {
if (ent != MARK) {
- ARR_APP1(entity *, arr, ent);
+ ARR_APP1(entity *, arr, ent);
}
}
- if (ARR_LEN(arr) == 0) {
+#if 0 /* This generates Bad nodes when we don't want it.
+ Call it with a check for valid cgana information in local_optimize. */
+ if (ARR_LEN(arr) == 0 && get_opt_optimize() && get_opt_dyn_meth_dispatch()) {
/* Kann vorkommen, wenn der Vorgänger beispielsweise eine
* Sel-Operation war, die keine Methoden zurückgeben
* konnte. Wir ersetzen die Call-Operation ebenfalls durch
* eine Bad-Operation. Die Verlinkung muss wiederhergestellt
* werden! */
- /* exchange(call, new_Bad()); invalid firm */
-
ir_node *mem = get_Call_mem(call);
turn_into_tuple (call, 5 /* pn_Call_max */);
set_Tuple_pred(call, pn_Call_M_regular , mem);
set_Tuple_pred(call, pn_Call_T_result , new_Bad());
set_Tuple_pred(call, pn_Call_P_value_res_base, new_Bad());
set_Tuple_pred(call, pn_Call_X_except , new_Bad()); /* new_Jmp() ?? new_Raise() ?? */
- set_Tuple_pred(call, pn_Call_M_except , mem);
+ set_Tuple_pred(call, pn_Call_M_except , new_Bad());
- } else {
+ } else
+#endif
+ {
set_Call_callee_arr(call, ARR_LEN(arr), arr);
}
DEL_ARR_F(arr);
}
+static void remove_Tuples(ir_node * proj, void * env) {
+ ir_node *new;
+ if (get_irn_opcode(proj) != iro_Proj) return;
+
+ new = skip_Tuple(proj);
+ if (new != proj) exchange(proj, new);
+}
+
+
/* Bestimmt für jede Call-Operation die Menge der aufrufbaren Methode
* und speichert das Ergebnis in der Call-Operation. (siehe
* "set_Call_callee"). "sel_methods" wird für den Aufbau benötigt und
int i;
/* Alle Graphen analysieren. */
for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
- irg_walk_graph(get_irp_irg(i), callee_walker, NULL, NULL);
+ irg_walk_graph(get_irp_irg(i), callee_walker, remove_Tuples, NULL);
set_irg_callee_info_state(get_irp_irg(i), irg_callee_info_consistent);
}
+ set_irp_callee_info_state(irg_callee_info_consistent);
}
static void free_mark(ir_node * node, eset * set) {
int i;
- assert(mode_is_reference(get_irn_mode(node)));
+// assert(mode_is_reference(get_irn_mode(node)));
if (get_irn_link(node) == MARK) {
return; /* already visited */
}
* SymConst-Operationen müssen in passende Const-Operationen
* umgewandelt worden sein, d.h. SymConst-Operationen verweisen immer
* auf eine echt externe Methode. */
-static entity ** get_free_methods(int whole)
+static entity ** get_free_methods(void)
{
eset * set = eset_create();
int i;
entity ** arr = NEW_ARR_F(entity *, 0);
entity * ent;
- if (! whole) {
- for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
- ir_graph * irg = get_irp_irg(i);
- entity * ent = get_irg_entity(irg);
- /* insert "external visible" methods. */
- if (get_entity_visibility(ent) != visibility_local) {
- eset_insert(set, ent);
- }
- /* Finde alle Methoden die in dieser Methode extern sichtbar werden,
- z.B. da die Adresse einer Methode abgespeichert wird. */
- irg_walk_graph(irg, NULL, (irg_walk_func *) free_ana_walker, set);
+ for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+ ir_graph * irg = get_irp_irg(i);
+ entity * ent = get_irg_entity(irg);
+ /* insert "external visible" methods. */
+ if (get_entity_visibility(ent) != visibility_local) {
+ eset_insert(set, ent);
}
+ /* Finde alle Methoden die in dieser Methode extern sichtbar werden,
+ z.B. da die Adresse einer Methode abgespeichert wird. */
+ irg_walk_graph(irg, NULL, (irg_walk_func *) free_ana_walker, set);
}
/* insert sticky methods, too */
return arr;
}
-void cgana(int *length, entity ***free_methods, int whole) {
- entity ** free_meths;
- int i;
+void cgana(int *length, entity ***free_methods) {
+ entity ** free_meths, **p;
sel_methods_init();
- free_meths = get_free_methods(whole);
+ free_meths = get_free_methods();
callee_ana();
sel_methods_dispose();
/* Convert the flexible array to an array that can be handled
by standard C. */
- *length = ARR_LEN(free_meths);
- *free_methods = (entity **)malloc(sizeof(entity *) * (*length));
- for (i = 0; i < (*length); i++) (*free_methods)[i] = free_meths[i];
+ p = (entity **)malloc(sizeof(*p) * ARR_LEN(free_meths));
+ memcpy(p, free_meths, ARR_LEN(free_meths) * sizeof(*p));
+
+ *length = ARR_LEN(free_meths);
+ *free_methods = p;
+
DEL_ARR_F(free_meths);
}