-static void sel_methods_walker(ir_node * node, pmap * ldname_map) {
-
- if (get_irn_op(node) == op_SymConst) {
- /* Wenn möglich SymConst-Operation durch Const-Operation
- * ersetzen. */
- if (get_SymConst_kind(node) == linkage_ptr_info) {
- pmap_entry *entry = pmap_find(ldname_map, (void *) get_SymConst_ptrinfo(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;
- assert(get_entity_irg(ent));
- set_irg_current_block(current_ir_graph, get_nodes_Block(node));
- new_node = new_d_Const(get_irn_dbg_info(node),
- mode_P_mach, new_tarval_from_entity(ent, mode_P_mach)); DBG_OPT_NORMALIZE;
- exchange(node, new_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);
- 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 {
- assert(get_entity_peculiarity(ent) != peculiarity_inherited);
- if (!eset_contains(entities, ent)) {
- /* Entity noch nicht behandelt. Alle (intern oder extern)
- * implementierten Methoden suchen, die diese Entity
- * überschreiben. Die Menge an entity.link speichern. */
- set_entity_link(ent, get_impl_methods(ent));
- eset_insert(entities, ent);
- }
- if (get_entity_link(ent) == NULL) {
- /* Die Sel-Operation kann nie einen Zeiger auf eine aufrufbare
- * Methode zurückgeben. Damit ist sie insbesondere nicht
- * ausführbar und nicht erreichbar. */
- /* 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_ent(current_ir_graph)),
- get_type_name(get_entity_owner(get_irg_ent(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");
- } else {
- exchange(node, new_Bad());
- }
- } else {
- entity ** arr = get_entity_link(ent);
-
-#if 0
- int i;
- printf("\nCall site "); DDMN(node);
- printf(" in "); DDME(get_irg_ent(current_ir_graph));
- printf(" can call:\n");
- for (i = 0; i < ARR_LEN(arr); i++) {
- printf(" - "); DDME(arr[i]);
- printf(" with owner "); DDMT(get_entity_owner(arr[i]));
- }
- printf("\n");
-#endif
-
- 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
- * 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); */
- new_node = copy_const_value(get_atomic_ent_value(arr[0])); DBG_OPT_POLY;
- exchange (node, new_node);
- }
- }
- }
- }
+static void sel_methods_walker(ir_node *node, void *env) {
+ pmap *ldname_map = env;
+ ir_entity **arr;
+
+ /* Call standard optimizations */
+ if (is_Sel(node)) {
+ ir_node *new_node = optimize_in_place(node);
+ if (node != new_node) {
+ exchange(node, new_node);
+ node = new_node;
+ }
+ }
+
+ /* replace SymConst(name)-operations by SymConst(ent) */
+ if (is_SymConst(node)) {
+ if (get_SymConst_kind(node) == symconst_addr_name) {
+ pmap_entry *entry = pmap_find(ldname_map, get_SymConst_name(node));
+ if (entry != NULL) { /* Method is declared in the compiled code */
+ assert(!"There should not be a SymConst[addr_name] addressing a method with an implementation"
+ "in this compilation unit. Use a SymConst[addr_ent].");
+ }
+ }
+ } else if (is_Sel(node) && is_Method_type(get_entity_type(get_Sel_entity(node)))) {
+ ir_entity *ent = get_SymConst_entity(get_atomic_ent_value(get_Sel_entity(node)));
+ assert(get_entity_peculiarity(ent) != peculiarity_inherited);
+
+ if (!eset_contains(entities, ent)) {
+ /* Entity not yet handled. Find all (internal or external)
+ * implemented methods that overwrites this entity.
+ * This set is stored in the entity link. */
+ set_entity_link(ent, get_impl_methods(ent));
+ eset_insert(entities, ent);
+ }
+
+ /* -- As an add on we get an optimization that removes polymorphic calls.
+ This optimization is more powerful than that in transform_node_Sel(). -- */
+ arr = get_entity_link(ent);
+ if (arr == NULL) {
+ /*
+ * The Sel node never returns a pointer to a usable method.
+ * We could not call it, but it may be description:
+ * We call a method in a dead part of the program.
+ */
+ assert(get_entity_peculiarity(ent) == peculiarity_description);
+ }
+ else if (get_opt_closed_world() && get_opt_dyn_meth_dispatch() &&
+ (ARR_LEN(arr) == 1 && arr[0] != NULL)) {
+ ir_node *new_node;
+
+ /*
+ * The Sel node returns only one possible method.
+ * So we could replace the Sel node by a SymConst.
+ * This method must exists.
+ */
+ set_irg_current_block(current_ir_graph, get_nodes_block(node));
+ assert(get_entity_peculiarity(get_SymConst_entity(get_atomic_ent_value(arr[0]))) ==
+ peculiarity_existent);
+ new_node = copy_const_value(get_irn_dbg_info(node), get_atomic_ent_value(arr[0]));
+ DBG_OPT_POLY(node, new_node);
+ exchange(node, new_node);
+ }
+ }