+ /* check if we can determine the entity that will be loaded */
+ ent = find_constant_entity(ptr);
+ if (ent) {
+ if ((allocation_static == get_entity_allocation(ent)) &&
+ (visibility_external_allocated != get_entity_visibility(ent))) {
+ /* a static allocation that is not external: there should be NO exception
+ * when loading. */
+
+ /* no exception, clear the info field as it might be checked later again */
+ if (info->projs[pn_Load_X_except]) {
+ exchange(info->projs[pn_Load_X_except], new_Bad());
+ info->projs[pn_Load_X_except] = NULL;
+ }
+
+ if (variability_constant == get_entity_variability(ent)
+ && is_atomic_entity(ent)) {
+ /* Might not be atomic after
+ lowering of Sels. In this
+ case we could also load, but
+ it's more complicated. */
+ /* more simpler case: we load the content of a constant value:
+ * replace it by the constant itself
+ */
+
+ /* no memory */
+ if (info->projs[pn_Load_M])
+ exchange(info->projs[pn_Load_M], mem);
+
+ /* no result :-) */
+ if (info->projs[pn_Load_res]) {
+ if (is_atomic_entity(ent)) {
+ ir_node *c = copy_const_value(get_atomic_ent_value(ent));
+
+ DBG_OPT_RC(load, c);
+ exchange(info->projs[pn_Load_res], c);
+
+ return 1;
+ }
+ }
+ }
+ else if (variability_constant == get_entity_variability(ent)) {
+ compound_graph_path *path;
+ /*
+ printf(">>>>>>>>>>>>> Found access to constant entity %s in function %s\n", get_entity_name(ent),
+ get_entity_name(get_irg_entity(current_ir_graph)));
+ printf(" load: "); DDMN(load);
+ printf(" ptr: "); DDMN(ptr);
+ */
+ path = get_accessed_path(ptr);
+ if (path) {
+ ir_node *c;
+
+ assert(is_proper_compound_graph_path(path, get_compound_graph_path_length(path)-1));
+ c = get_compound_ent_value_by_path(ent, path);
+
+ /* printf(" cons: "); DDMN(c); */
+
+ if (info->projs[pn_Load_M])
+ exchange(info->projs[pn_Load_M], mem);
+ if (info->projs[pn_Load_res])
+ exchange(info->projs[pn_Load_res], copy_const_value(c));
+ /*
+ {
+ int j;
+ for (j = 0; j < get_compound_graph_path_length(path); ++j) {
+ entity *node = get_compound_graph_path_node(path, j);
+ fprintf(stdout, ".%s", get_entity_name(node));
+ if (is_Array_type(get_entity_owner(node)))
+ fprintf(stdout, "[%d]", get_compound_graph_path_array_index(path, j));
+ }
+ printf("\n");
+ }
+ */
+ } else {
+ /* We can not determine a correct access path. E.g., in jack, we load
+ a byte from an object to generate an exception. Happens in test program
+ Reflectiontest.
+ printf(">>>>>>>>>>>>> Found access to constant entity %s in function %s\n", get_entity_name(ent),
+ get_entity_name(get_irg_entity(current_ir_graph)));
+ printf(" load: "); DDMN(load);
+ printf(" ptr: "); DDMN(ptr);
+ if (get_irn_op(ptr) == op_SymConst &&
+ get_SymConst_kind(ptr) == symconst_addr_ent) { printf(" "); DDMEO(get_SymConst_entity(ptr)); }
+ printf("cannot optimize.\n");
+ */
+ }
+ }
+
+ /* we changed the irg, but try further */
+ res = 1;
+ }
+ }
+
+ /* Check, if the address of this load is used more than once.
+ * If not, this load cannot be removed in any case. */
+ if (get_irn_out_n(ptr) <= 1)
+ return 0;
+
+ /* follow the memory chain as long as there are only Loads */
+ for (pred = skip_Proj(mem); ; pred = skip_Proj(get_Load_mem(pred))) {