-/* Returns the entity that contains the implementation of the inherited
- entity if available, else returns the entity passed. */
-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_Const) {
- impl_meth = tarval_to_entity(get_Const_tarval(addr));
- } else {
- assert(0 && "Complex constant values not supported -- adress of method should be straight constant!");
- }
- if (impl_meth && (get_entity_peculiarity(impl_meth) != peculiarity_existent)) {
- printf("this_meth: "); DDMEO(inh_meth);
- printf("impl meth: "); DDMEO(impl_meth);
- assert(!impl_meth || get_entity_peculiarity(impl_meth) == peculiarity_existent);
- }
- return impl_meth? impl_meth : inh_meth;
+/** Analyze address computations.
+ *
+ * Compute for all Sel nodes the set of methods that can be selected.
+ * For each entity we store the set of subentities in the link field.
+ *
+ * Further do some optimizations:
+ * - Call standard optimizations for Sel nodes: this removes polymorphic
+ * calls.
+ * - If the node is a SymConst(name) replace it by SymConst(ent) if possible.
+ * For this we precomputed a map name->entity. Nowadays, we no more support
+ * this and assert.
+ * - If the node is a Sel:
+ * If we found only a single method that can be called, replace the Sel
+ * by a SymConst. This is more powerful than the analysis in opt_polymorphy,
+ * as here we walk the type graph. In opt_polymorphy we only apply a local
+ * pattern.
+ *
+ * @param node The node to analyze
+ * @param env A map that maps names of entities to the entities.
+ */
+static void sel_methods_walker(ir_node *node, void *env)
+{
+ ir_entity **arr;
+ (void)env;
+
+ /* 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;
+ }
+ }
+
+ 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)));
+
+ 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_irg(ent) == NULL);
+ }
+ 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_irg(arr[0]) != NULL);
+ 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);
+ }
+ }