C99 feature removed.
[libfirm] / ir / be / bestate.c
index 2a9b067..32d0c14 100644 (file)
@@ -47,6 +47,7 @@
 #include "belive_t.h"
 #include "bemodule.h"
 #include "benode.h"
+#include "beirgmod.h"
 #include "bessaconstr.h"
 
 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
@@ -134,7 +135,8 @@ static spill_info_t *create_spill(minibelady_env_t *env, ir_node *state, int for
                do {
                        after = next;
                        next = sched_next(after);
-               } while (is_Proj(next) || is_Phi(next) || be_is_Keep(next));
+               } while (is_Proj(next) || is_Phi(next) || be_is_Keep(next)
+                       || (arch_irn_get_flags(next) & arch_irn_flags_prolog));
        } else {
                after = state;
        }
@@ -182,7 +184,8 @@ static void spill_phi(minibelady_env_t *env, ir_node *phi)
        DBG((dbg, LEVEL_2, "\tcreate Phi-M for %+F\n", phi));
 
        /* create a Phi-M */
-       spill_info->spill = new_r_Phi(block, arity, in, mode_M);
+       spill_info->spill = be_new_Phi(block, arity, in, mode_M, NULL);
+       sched_add_after(block, spill_info->spill);
 
        if (spill_to_kill != NULL) {
                exchange(spill_to_kill, spill_info->spill);
@@ -349,6 +352,17 @@ static block_info_t *compute_block_start_state(minibelady_env_t *env, ir_node *b
        return block_info;
 }
 
+static ir_node *get_reload_point(ir_node *before)
+{
+       while (true) {
+               ir_node *prev = sched_prev(before);
+               if (! (arch_irn_get_flags(prev) & arch_irn_flags_epilog))
+                       break;
+               before = prev;
+       }
+       return before;
+}
+
 /**
  * For the given block @p block, decide for each values
  * whether it is used from a register or is reloaded
@@ -405,8 +419,9 @@ static void belady(minibelady_env_t *env, ir_node *block)
                }
                /* create a reload to match state if necessary */
                if (need_val != NULL && need_val != current_state) {
+                       ir_node *before = get_reload_point(node);
                        DBG((dbg, LEVEL_3, "\t... reloading %+F\n", need_val));
-                       create_reload(env, need_val, node, current_state);
+                       create_reload(env, need_val, before, current_state);
                        current_state = need_val;
                }