3 * File name: ir/opt/ldstopt.c
4 * Purpose: load store optimizations
8 * Copyright: (c) 1998-2004 Universit
\81ät Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
25 # include "irnode_t.h"
26 # include "irgraph_t.h"
27 # include "irmode_t.h"
29 # include "ircons_t.h"
34 # include "dbginfo_t.h"
35 # include "iropt_dbg.h"
36 # include "irflag_t.h"
40 # include "opt_polymorphy.h"
43 #include "cacheopt/cachesim.h"
47 #define IMAX(a,b) ((a) > (b) ? (a) : (b))
49 #define MAX_PROJ IMAX(pn_Load_max, pn_Store_max)
52 DF_CHANGED = 1, /**< data flow changed */
53 CF_CHANGED = 2, /**< control flow changed */
59 typedef struct _walk_env_t {
60 struct obstack obst; /**< list of all stores */
61 unsigned changes; /**< a bitmask of graph changes */
65 * flags for Load/Store
68 LDST_VISITED = 1 /**< if set, this Load/Store is already visited */
74 typedef struct _ldst_info_t {
75 ir_node *projs[MAX_PROJ]; /**< list of Proj's of this node */
76 ir_node *exc_block; /**< the exception block if available */
77 int exc_idx; /**< predecessor index in the exception block */
78 unsigned flags; /**< flags */
82 * flags for control flow
85 BLOCK_HAS_COND = 1, /**< Block has conditional control flow */
86 BLOCK_HAS_EXC = 2 /**< Block has exceptional control flow */
92 typedef struct _block_info_t {
93 unsigned flags; /**< flags for the block */
97 * get the Load/Store info of a node
99 static ldst_info_t *get_ldst_info(ir_node *node, walk_env_t *env)
101 ldst_info_t *info = get_irn_link(node);
104 info = obstack_alloc(&env->obst, sizeof(*info));
106 memset(info, 0, sizeof(*info));
108 set_irn_link(node, info);
114 * get the Block info of a node
116 static block_info_t *get_block_info(ir_node *node, walk_env_t *env)
118 block_info_t *info = get_irn_link(node);
121 info = obstack_alloc(&env->obst, sizeof(*info));
123 memset(info, 0, sizeof(*info));
125 set_irn_link(node, info);
131 * update the projection info for a Load/Store
133 static unsigned update_projs(ldst_info_t *info, ir_node *proj)
135 long nr = get_Proj_proj(proj);
137 assert(0 <= nr && nr <= MAX_PROJ && "Wrong proj from LoadStore");
139 if (info->projs[nr]) {
140 /* there is already one, do CSE */
141 exchange(proj, info->projs[nr]);
145 info->projs[nr] = proj;
151 * update the exception block info for a Load/Store node.
153 * @param info the load/store info struct
154 * @param block the exception handler block for this load/store
155 * @param pos the control flow input of the block
157 static unsigned update_exc(ldst_info_t *info, ir_node *block, int pos)
159 assert(info->exc_block == NULL && "more than one exception block found");
161 info->exc_block = block;
166 #define get_irn_out_n(node) (unsigned)PTR_TO_INT(get_irn_link(node))
167 #define set_irn_out_n(node, n) set_irn_link(adr, INT_TO_PTR(n))
170 * walker, collects all Load/Store/Proj nodes
172 * walks from Start -> End
174 static void collect_nodes(ir_node *node, void *env)
176 ir_op *op = get_irn_op(node);
177 ir_node *pred, *blk, *pred_blk;
178 ldst_info_t *ldst_info;
179 walk_env_t *wenv = env;
185 pred = get_Proj_pred(node);
186 op = get_irn_op(pred);
189 ldst_info = get_ldst_info(pred, wenv);
191 wenv->changes |= update_projs(ldst_info, node);
193 if ((ldst_info->flags & LDST_VISITED) == 0) {
194 adr = get_Load_ptr(pred);
195 set_irn_out_n(adr, get_irn_out_n(adr) + 1);
197 ldst_info->flags |= LDST_VISITED;
201 * Place the Proj's to the same block as the
202 * predecessor Load. This is always ok and prevents
203 * "non-SSA" form after optimizations if the Proj
204 * is in a wrong block.
206 blk = get_nodes_block(node);
207 pred_blk = get_nodes_block(pred);
208 if (blk != pred_blk) {
209 wenv->changes |= DF_CHANGED;
210 set_nodes_block(node, pred_blk);
213 else if (op == op_Store) {
214 ldst_info = get_ldst_info(pred, wenv);
216 wenv->changes |= update_projs(ldst_info, node);
218 if ((ldst_info->flags & LDST_VISITED) == 0) {
219 adr = get_Store_ptr(pred);
220 set_irn_out_n(adr, get_irn_out_n(adr) + 1);
222 ldst_info->flags |= LDST_VISITED;
226 * Place the Proj's to the same block as the
227 * predecessor Store. This is always ok and prevents
228 * "non-SSA" form after optimizations if the Proj
229 * is in a wrong block.
231 blk = get_nodes_block(node);
232 pred_blk = get_nodes_block(pred);
233 if (blk != pred_blk) {
234 wenv->changes |= DF_CHANGED;
235 set_nodes_block(node, pred_blk);
239 else if (op == op_Block) { /* check, if it's an exception block */
242 for (i = get_Block_n_cfgpreds(node) - 1; i >= 0; --i) {
244 block_info_t *bl_info;
246 pred = skip_Proj(get_Block_cfgpred(node, i));
248 /* ignore Bad predecessors, they will be removed later */
252 pred_block = get_nodes_block(pred);
253 bl_info = get_block_info(pred_block, wenv);
255 if (is_fragile_op(pred))
256 bl_info->flags |= BLOCK_HAS_EXC;
257 else if (is_irn_forking(pred))
258 bl_info->flags |= BLOCK_HAS_COND;
260 if (get_irn_op(pred) == op_Load || get_irn_op(pred) == op_Store) {
261 ldst_info = get_ldst_info(pred, wenv);
263 wenv->changes |= update_exc(ldst_info, node, i);
270 * Returns an entity if the address ptr points to a constant one.
272 static entity *find_constant_entity(ir_node *ptr)
275 ir_op *op = get_irn_op(ptr);
277 if (op == op_SymConst && (get_SymConst_kind(ptr) == symconst_addr_ent)) {
278 return get_SymConst_entity(ptr);
280 else if (op == op_Sel) {
281 entity *ent = get_Sel_entity(ptr);
282 type *tp = get_entity_owner(ent);
284 /* Do not fiddle about polymorphy. */
285 if (is_Class_type(get_entity_owner(ent)) &&
286 ((get_entity_n_overwrites(ent) != 0) ||
287 (get_entity_n_overwrittenby(ent) != 0) ) )
290 if (variability_constant == get_entity_variability(ent))
293 if (is_Array_type(tp)) {
297 for (i = 0, n = get_Sel_n_indexs(ptr); i < n; ++i) {
299 tarval *tlower, *tupper;
300 ir_node *index = get_Sel_index(ptr, i);
301 tarval *tv = computed_value(index);
303 /* check if the index is constant */
304 if (tv == tarval_bad)
307 bound = get_array_lower_bound(tp, i);
308 tlower = computed_value(bound);
309 bound = get_array_upper_bound(tp, i);
310 tupper = computed_value(bound);
312 if (tlower == tarval_bad || tupper == tarval_bad)
315 if (tarval_cmp(tv, tlower) & pn_Cmp_Lt)
317 if (tarval_cmp(tupper, tv) & pn_Cmp_Lt)
320 /* ok, bounds check finished */
325 ptr = get_Sel_ptr(ptr);
333 * Return the Selection index of a Sel node from dimension n
335 static long get_Sel_array_index_long(ir_node *n, int dim) {
336 ir_node *index = get_Sel_index(n, dim);
337 assert(get_irn_op(index) == op_Const);
338 return get_tarval_long(get_Const_tarval(index));
342 * Returns the accessed component graph path for an
343 * node computing an address.
345 * @param ptr the node computing the address
346 * @param depth current depth in steps upward from the root
349 static compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth) {
350 compound_graph_path *res = NULL;
351 entity *root, *field;
354 if (get_irn_op(ptr) == op_SymConst) {
355 /* a SymConst. If the depth is 0, this is an access to a global
356 * entity and we don't need a component path, else we know
357 * at least it's length.
359 assert(get_SymConst_kind(ptr) == symconst_addr_ent);
360 root = get_SymConst_entity(ptr);
361 res = (depth == 0) ? NULL : new_compound_graph_path(get_entity_type(root), depth);
364 assert(get_irn_op(ptr) == op_Sel);
365 /* it's a Sel, go up until we find the root */
366 res = rec_get_accessed_path(get_Sel_ptr(ptr), depth+1);
368 /* fill up the step in the path at the current position */
369 field = get_Sel_entity(ptr);
370 path_len = get_compound_graph_path_length(res);
371 pos = path_len - depth - 1;
372 set_compound_graph_path_node(res, pos, field);
374 if (is_Array_type(get_entity_owner(field))) {
375 assert(get_Sel_n_indexs(ptr) == 1 && "multi dim arrays not implemented");
376 set_compound_graph_path_array_index(res, pos, get_Sel_array_index_long(ptr, 0));
382 /** Returns an access path or NULL. The access path is only
383 * valid, if the graph is in phase_high and _no_ address computation is used.
385 static compound_graph_path *get_accessed_path(ir_node *ptr) {
386 return rec_get_accessed_path(ptr, 0);
392 static unsigned optimize_load(ir_node *load)
394 ldst_info_t *info = get_irn_link(load);
395 ir_mode *load_mode = get_Load_mode(load);
396 ir_node *pred, *mem, *ptr, *new_node;
400 /* do NOT touch volatile loads for now */
401 if (get_Load_volatility(load) == volatility_is_volatile)
404 /* the address of the load to be optimized */
405 ptr = get_Load_ptr(load);
408 * Check if we can remove the exception from a Load:
409 * This can be done, if the address is from an Sel(Alloc) and
410 * the Sel type is a subtype of the allocated type.
412 * This optimizes some often used OO constructs,
413 * like x = new O; x->t;
415 if (info->projs[pn_Load_X_except]) {
416 if (get_irn_op(ptr) == op_Sel) {
417 ir_node *mem = get_Sel_mem(ptr);
419 if (get_irn_op(skip_Proj(mem)) == op_Alloc) {
420 /* ok, check the types */
421 entity *ent = get_Sel_entity(ptr);
422 type *s_type = get_entity_type(ent);
423 type *a_type = get_Alloc_type(mem);
425 if (is_subclass_of(s_type, a_type)) {
426 /* ok, condition met: there can't be an exception because
427 * Alloc guarantees that enough memory was allocated */
429 exchange(info->projs[pn_Load_X_except], new_Bad());
430 info->projs[pn_Load_X_except] = NULL;
435 else if ((get_irn_op(skip_Proj(ptr)) == op_Alloc) ||
436 ((get_irn_op(ptr) == op_Cast) && (get_irn_op(skip_Proj(get_Cast_op(ptr))) == op_Alloc))) {
437 /* simple case: a direct load after an Alloc. Firm Alloc throw
438 * an exception in case of out-of-memory. So, there is no way for an
439 * exception in this load.
440 * This code is constructed by the "exception lowering" in the Jack compiler.
442 exchange(info->projs[pn_Load_X_except], new_Bad());
443 info->projs[pn_Load_X_except] = NULL;
448 /* the mem of the Load. Must still be returned after optimization */
449 mem = get_Load_mem(load);
451 if (! info->projs[pn_Load_res] && ! info->projs[pn_Load_X_except]) {
452 /* a Load which value is neither used nor exception checked, remove it */
453 exchange(info->projs[pn_Load_M], mem);
455 return res | DF_CHANGED;
458 /* Load from a constant polymorphic field, where we can resolve
460 new_node = transform_node_Load(load);
461 if (new_node != load) {
462 if (info->projs[pn_Load_M]) {
463 exchange(info->projs[pn_Load_M], mem);
464 info->projs[pn_Load_M] = NULL;
466 if (info->projs[pn_Load_X_except]) {
467 exchange(info->projs[pn_Load_X_except], new_Bad());
468 info->projs[pn_Load_X_except] = NULL;
470 if (info->projs[pn_Load_res])
471 exchange(info->projs[pn_Load_res], new_node);
472 return res | DF_CHANGED;
475 /* check if we can determine the entity that will be loaded */
476 ent = find_constant_entity(ptr);
478 if ((allocation_static == get_entity_allocation(ent)) &&
479 (visibility_external_allocated != get_entity_visibility(ent))) {
480 /* a static allocation that is not external: there should be NO exception
483 /* no exception, clear the info field as it might be checked later again */
484 if (info->projs[pn_Load_X_except]) {
485 exchange(info->projs[pn_Load_X_except], new_Bad());
486 info->projs[pn_Load_X_except] = NULL;
490 if (variability_constant == get_entity_variability(ent)
491 && is_atomic_entity(ent)) {
492 /* Might not be atomic after
493 lowering of Sels. In this
494 case we could also load, but
495 it's more complicated. */
496 /* more simpler case: we load the content of a constant value:
497 * replace it by the constant itself
501 if (info->projs[pn_Load_M]) {
502 exchange(info->projs[pn_Load_M], mem);
507 if (info->projs[pn_Load_res]) {
508 if (is_atomic_entity(ent)) {
509 ir_node *c = copy_const_value(get_atomic_ent_value(ent));
512 exchange(info->projs[pn_Load_res], c);
513 return DF_CHANGED | res;
517 else if (variability_constant == get_entity_variability(ent)) {
518 compound_graph_path *path = get_accessed_path(ptr);
523 assert(is_proper_compound_graph_path(path, get_compound_graph_path_length(path)-1));
527 for (j = 0; j < get_compound_graph_path_length(path); ++j) {
528 entity *node = get_compound_graph_path_node(path, j);
529 fprintf(stdout, ".%s", get_entity_name(node));
530 if (is_Array_type(get_entity_owner(node)))
531 fprintf(stdout, "[%d]", get_compound_graph_path_array_index(path, j));
537 c = get_compound_ent_value_by_path(ent, path);
538 free_compound_graph_path(path);
540 /* printf(" cons: "); DDMN(c); */
542 if (info->projs[pn_Load_M]) {
543 exchange(info->projs[pn_Load_M], mem);
546 if (info->projs[pn_Load_res]) {
547 exchange(info->projs[pn_Load_res], copy_const_value(c));
548 return res | DF_CHANGED;
552 /* We can not determine a correct access path. E.g., in jack, we load
553 a byte from an object to generate an exception. Happens in test program
555 printf(">>>>>>>>>>>>> Found access to constant entity %s in function %s\n", get_entity_name(ent),
556 get_entity_name(get_irg_entity(current_ir_graph)));
557 printf(" load: "); DDMN(load);
558 printf(" ptr: "); DDMN(ptr);
565 /* Check, if the address of this load is used more than once.
566 * If not, this load cannot be removed in any case. */
567 if (get_irn_out_n(ptr) <= 1)
570 /* follow the memory chain as long as there are only Loads
571 * and try to replace current Load or Store by a previous one
573 for (pred = skip_Proj(mem); ; pred = skip_Proj(get_Load_mem(pred))) {
575 * BEWARE: one might think that checking the modes is useless, because
576 * if the pointers are identical, they refer to the same object.
577 * This is only true in strong typed languages, not in C were the following
578 * is possible a = *(type1 *)p; b = *(type2 *)p ...
581 if (get_irn_op(pred) == op_Store && get_Store_ptr(pred) == ptr &&
582 get_irn_mode(get_Store_value(pred)) == load_mode) {
583 ldst_info_t *pred_info = get_irn_link(pred);
586 * a Load immediately after a Store -- a read after write.
587 * We may remove the Load, if both Load & Store does not have an exception handler
588 * OR they are in the same block. In the latter case the Load cannot
589 * throw an exception when the previous Store was quiet.
591 * Why we need to check for Store Exception? If the Store cannot
592 * be executed (ROM) the exception handler might simply jump into
594 * We could make it a little bit better if we would know that the exception
595 * handler of the Store jumps directly to the end...
597 if ((!pred_info->projs[pn_Store_X_except] && !info->projs[pn_Load_X_except]) ||
598 get_nodes_block(load) == get_nodes_block(pred)) {
599 ir_node *value = get_Store_value(pred);
601 DBG_OPT_RAW(load, value);
602 if (info->projs[pn_Load_M])
603 exchange(info->projs[pn_Load_M], mem);
606 if (info->projs[pn_Load_X_except]) {
607 exchange( info->projs[pn_Load_X_except], new_Bad());
611 if (info->projs[pn_Load_res])
612 exchange(info->projs[pn_Load_res], value);
614 return res | DF_CHANGED;
617 else if (get_irn_op(pred) == op_Load && get_Load_ptr(pred) == ptr &&
618 get_Load_mode(pred) == load_mode) {
620 * a Load after a Load -- a read after read.
621 * We may remove the second Load, if it does not have an exception handler
622 * OR they are in the same block. In the later case the Load cannot
623 * throw an exception when the previous Load was quiet.
625 * Here, there is no need to check if the previous Load has an exception
626 * hander because they would have exact the same exception...
628 if (! info->projs[pn_Load_X_except] || get_nodes_block(load) == get_nodes_block(pred)) {
629 ldst_info_t *pred_info = get_irn_link(pred);
631 DBG_OPT_RAR(load, pred);
633 if (pred_info->projs[pn_Load_res]) {
634 /* we need a data proj from the previous load for this optimization */
635 if (info->projs[pn_Load_res])
636 exchange(info->projs[pn_Load_res], pred_info->projs[pn_Load_res]);
638 if (info->projs[pn_Load_M])
639 exchange(info->projs[pn_Load_M], mem);
642 if (info->projs[pn_Load_res]) {
643 set_Proj_pred(info->projs[pn_Load_res], pred);
644 set_nodes_block(info->projs[pn_Load_res], get_nodes_block(pred));
645 pred_info->projs[pn_Load_res] = info->projs[pn_Load_res];
647 if (info->projs[pn_Load_M]) {
648 /* Actually, this if should not be necessary. Construct the Loads
650 exchange(info->projs[pn_Load_M], mem);
655 if (info->projs[pn_Load_X_except]) {
656 exchange(info->projs[pn_Load_X_except], new_Bad());
660 return res |= DF_CHANGED;
664 /* follow only Load chains */
665 if (get_irn_op(pred) != op_Load)
674 static unsigned optimize_store(ir_node *store)
676 ldst_info_t *info = get_irn_link(store);
677 ir_node *pred, *mem, *ptr, *value, *block;
681 if (get_Store_volatility(store) == volatility_is_volatile)
685 * BEWARE: one might think that checking the modes is useless, because
686 * if the pointers are identical, they refer to the same object.
687 * This is only true in strong typed languages, not is C were the following
688 * is possible *(type1 *)p = a; *(type2 *)p = b ...
691 ptr = get_Store_ptr(store);
693 /* Check, if the address of this load is used more than once.
694 * If not, this load cannot be removed in any case. */
695 if (get_irn_out_n(ptr) <= 1)
698 block = get_nodes_block(store);
699 mem = get_Store_mem(store);
700 value = get_Store_value(store);
701 mode = get_irn_mode(value);
703 /* follow the memory chain as long as there are only Loads */
704 for (pred = skip_Proj(mem); ; pred = skip_Proj(get_Load_mem(pred))) {
705 ldst_info_t *pred_info = get_irn_link(pred);
707 if (get_irn_op(pred) == op_Store && get_Store_ptr(pred) == ptr &&
708 get_nodes_block(pred) == block && get_irn_mode(get_Store_value(pred)) == mode) {
710 * a Store after a Store in the same block -- a write after write.
711 * We may remove the first Store, if it does not have an exception handler.
713 * TODO: What, if both have the same exception handler ???
715 if (get_Store_volatility(pred) != volatility_is_volatile && !pred_info->projs[pn_Store_X_except]) {
716 DBG_OPT_WAW(pred, store);
717 exchange( pred_info->projs[pn_Store_M], get_Store_mem(pred) );
721 else if (get_irn_op(pred) == op_Load && get_Load_ptr(pred) == ptr &&
722 value == pred_info->projs[pn_Load_res]) {
724 * a Store of a value after a Load -- a write after read.
725 * We may remove the second Store, if it does not have an exception handler.
727 if (! info->projs[pn_Store_X_except]) {
728 DBG_OPT_WAR(store, pred);
729 exchange( info->projs[pn_Store_M], mem );
734 /* follow only Load chains */
735 if (get_irn_op(pred) != op_Load)
742 * walker, optimizes Phi after Stores:
743 * Does the following optimization:
745 * val1 val2 val3 val1 val2 val3
753 * This reduces the number of stores and allows for predicated execution.
754 * Moves Stores back to the end of a function which may be bad.
756 * This is only possible if the predecessor blocks have only one successor.
758 static unsigned optimize_phi(ir_node *phi, void *env)
760 walk_env_t *wenv = env;
762 ir_node *store, *old_store, *ptr, *block, *phiM, *phiD, *exc, *projM;
764 ir_node **inM, **inD;
768 block_info_t *bl_info;
771 /* Must be a memory Phi */
772 if (get_irn_mode(phi) != mode_M)
775 n = get_Phi_n_preds(phi);
779 store = skip_Proj(get_Phi_pred(phi, 0));
781 if (get_irn_op(store) != op_Store)
784 /* abort on dead blocks */
785 if (is_Block_dead(get_nodes_block(store)))
788 /* check if the block has only one successor */
789 bl_info = get_irn_link(get_nodes_block(store));
793 /* this is the address of the store */
794 ptr = get_Store_ptr(store);
795 mode = get_irn_mode(get_Store_value(store));
796 info = get_irn_link(store);
797 exc = info->exc_block;
799 for (i = 1; i < n; ++i) {
800 ir_node *pred = skip_Proj(get_Phi_pred(phi, i));
802 if (get_irn_op(pred) != op_Store)
805 if (mode != get_irn_mode(get_Store_value(pred)) || ptr != get_Store_ptr(pred))
808 info = get_irn_link(pred);
810 /* check, if all stores have the same exception flow */
811 if (exc != info->exc_block)
814 /* abort on dead blocks */
815 if (is_Block_dead(get_nodes_block(store)))
818 /* check if the block has only one successor */
819 bl_info = get_irn_link(get_nodes_block(store));
825 * ok, when we are here, we found all predecessors of a Phi that
826 * are Stores to the same address. That means whatever we do before
827 * we enter the block of the Phi, we do a Store.
828 * So, we can move the store to the current block:
830 * val1 val2 val3 val1 val2 val3
832 * | Str | | Str | | Str | \ | /
838 * Is only allowed if the predecessor blocks have only one successor.
841 /* first step: collect all inputs */
842 NEW_ARR_A(ir_node *, inM, n);
843 NEW_ARR_A(ir_node *, inD, n);
844 NEW_ARR_A(int, idx, n);
846 for (i = 0; i < n; ++i) {
847 ir_node *pred = skip_Proj(get_Phi_pred(phi, i));
848 info = get_irn_link(pred);
850 inM[i] = get_Store_mem(pred);
851 inD[i] = get_Store_value(pred);
852 idx[i] = info->exc_idx;
854 block = get_nodes_block(phi);
856 /* second step: create a new memory Phi */
857 phiM = new_rd_Phi(get_irn_dbg_info(phi), current_ir_graph, block, n, inM, mode_M);
859 /* third step: create a new data Phi */
860 phiD = new_rd_Phi(get_irn_dbg_info(phi), current_ir_graph, block, n, inD, mode);
862 /* fourth step: create the Store */
863 store = new_rd_Store(db, current_ir_graph, block, phiM, ptr, phiD);
865 co_set_irn_name(store, co_get_irn_ident(old_store));
868 projM = new_rd_Proj(NULL, current_ir_graph, block, store, mode_M, pn_Store_M);
870 info = get_ldst_info(store, wenv);
871 info->projs[pn_Store_M] = projM;
873 /* fifths step: repair exception flow */
875 ir_node *projX = new_rd_Proj(NULL, current_ir_graph, block, store, mode_X, pn_Store_X_except);
877 info->projs[pn_Store_X_except] = projX;
878 info->exc_block = exc;
879 info->exc_idx = idx[0];
881 for (i = 0; i < n; ++i) {
882 set_Block_cfgpred(exc, idx[i], projX);
886 /* the exception block should be optimized as some inputs are identical now */
892 /* sixth step: replace old Phi */
893 exchange(phi, projM);
895 return res | DF_CHANGED;
899 * walker, collects all Load/Store/Proj nodes
901 static void do_load_store_optimize(ir_node *n, void *env)
903 walk_env_t *wenv = env;
905 switch (get_irn_opcode(n)) {
908 wenv->changes |= optimize_load(n);
912 wenv->changes |= optimize_store(n);
916 wenv->changes |= optimize_phi(n, env);
924 * do the load store optimization
926 void optimize_load_store(ir_graph *irg)
930 assert(get_irg_phase_state(irg) != phase_building);
931 assert(get_irg_pinned(irg) != op_pin_state_floats &&
932 "LoadStore optimization needs pinned graph");
934 if (!get_opt_redundant_LoadStore())
937 obstack_init(&env.obst);
940 /* init the links, then collect Loads/Stores/Proj's in lists */
941 irg_walk_graph(irg, firm_clear_link, collect_nodes, &env);
943 /* now we have collected enough information, optimize */
944 irg_walk_graph(irg, NULL, do_load_store_optimize, &env);
946 obstack_free(&env.obst, NULL);
948 /* Handle graph state */
950 if (get_irg_outs_state(current_ir_graph) == outs_consistent)
951 set_irg_outs_inconsistent(current_ir_graph);
954 if (env.changes & CF_CHANGED) {
955 /* is this really needed: Yes, control flow changed, block might get Bad. */
956 if (get_irg_dom_state(current_ir_graph) == dom_consistent)
957 set_irg_dom_inconsistent(current_ir_graph);