- else if (get_irn_op(pred) == op_Store && get_Store_ptr(pred) == ptr &&
- get_irn_mode(get_Store_value(pred)) == load_mode) {
- /*
- * a load immediately after a store -- a read after write.
- * We may remove the Load, if it does not have an exception handler
- * OR they are in the same block. In the latter case the Load cannot
- * throw an exception when the previous Store was quiet.
- */
- if (! info->projs[pn_Load_X_except] || get_nodes_block(load) == get_nodes_block(pred)) {
- exchange( info->projs[pn_Load_res], get_Store_value(pred) );
- if (info->projs[pn_Load_M])
- exchange(info->projs[pn_Load_M], mem);
-
- /* no exception */
- if (info->projs[pn_Load_X_except])
- exchange( info->projs[pn_Load_X_except], new_Bad());
+
+ /* the mem of the Load. Must still be returned after optimization */
+ mem = get_Load_mem(load);
+
+ /* Load from a constant polymorphic field, where we can resolve
+ polymorphy. */
+ new_node = transform_node_Load(load);
+ if (new_node != load) {
+ if (info->projs[pn_Load_M]) {
+ exchange(info->projs[pn_Load_M], mem);
+ info->projs[pn_Load_M] = NULL;
+ }
+ if (info->projs[pn_Load_X_except]) {
+ exchange(info->projs[pn_Load_X_except], new_Bad());
+ info->projs[pn_Load_X_except] = NULL;
+ }
+ if (info->projs[pn_Load_res])
+ exchange(info->projs[pn_Load_res], new_node);
+ return 1;
+ }
+
+ /* 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
+ printf("cannot optimize.\n");
+ }
+
+ /* we changed the irg, but try further */