removed unitialized used vartiable
[libfirm] / ir / be / bespill.c
index 40c467f..20b3915 100644 (file)
@@ -38,7 +38,7 @@
 #include "benodesets.h"
 #include "bespilloptions.h"
 #include "bestatevent.h"
-#include "beirgmod.h"
+#include "bessaconstr.h"
 
 // only rematerialise when costs are less than REMAT_COST_LIMIT
 // TODO determine a good value here...
@@ -125,12 +125,12 @@ static spill_info_t *get_spillinfo(const spill_env_t *env, ir_node *value) {
        return res;
 }
 
-DEBUG_ONLY(
+#ifdef DEBUG_libfirm
 /* Sets the debug module of a spill environment. */
 void be_set_spill_env_dbg_module(spill_env_t *env, firm_dbg_module_t *dbg) {
        env->dbg = dbg;
 }
-)
+#endif
 
 /* Creates a new spill environment. */
 spill_env_t *be_new_spill_env(be_irg_t *birg) {
@@ -406,7 +406,7 @@ static void spill_phi(spill_env_t *env, spill_info_t *spillinfo) {
 
                set_irn_n(spillinfo->spill, i, arg_info->spill);
        }
-       DBG((env->dbg, LEVEL_1, "... done spilling Phi %+F\n", phi));
+       DBG((env->dbg, LEVEL_1, "... done spilling Phi %+F, created PhiM %+F\n", phi, spillinfo->spill));
 
        // rewire reloads from old_spill to phi
        if (spillinfo->old_spill != NULL) {
@@ -676,6 +676,15 @@ void be_insert_spills_reloads(spill_env_t *env) {
        int              reloads   = 0;
        int              spills    = 0;
        spill_info_t     *si;
+       ir_nodeset_iterator_t iter;
+       ir_node          *node;
+
+       /* create all phi-ms first, this is needed so, that phis, hanging on
+          spilled phis work correctly */
+       foreach_ir_nodeset(&env->mem_phis, node, iter) {
+               spill_info_t *info = get_spillinfo(env, node);
+               spill_node(env, info);
+       }
 
        /* process each spilled node */
        for (si = set_first(env->spills); si; si = set_next(env->spills)) {
@@ -718,14 +727,25 @@ void be_insert_spills_reloads(spill_env_t *env) {
                /* if we had any reloads or remats, then we need to reconstruct the
                 * SSA form for the spilled value */
                if (ARR_LEN(copies) > 0) {
-                       /* Matze: used mem_phis as ignore uses in the past, I don't see how
-                          one of the mem_phis can be a use of the spilled value...
-                          so I changed this to NULL now */
-                       be_ssa_construction(
-                                       be_get_birg_dom_front(env->birg),
-                                       be_get_birg_liveness(env->birg),
-                                       spilled_node, ARR_LEN(copies), copies,
-                                       NULL, 0);
+                       be_ssa_construction_env_t senv;
+                       /* be_lv_t *lv = be_get_birg_liveness(env->birg); */
+
+                       be_ssa_construction_init(&senv, env->birg);
+                       be_ssa_construction_add_copy(&senv, spilled_node);
+                       be_ssa_construction_add_copies(&senv, copies, ARR_LEN(copies));
+                       be_ssa_construction_fix_users(&senv, spilled_node);
+
+#if 0
+                       /* no need to enable this as long as we invalidate liveness
+                          after this function... */
+                       be_ssa_construction_update_liveness_phis(&senv);
+                       be_liveness_update(spilled_node);
+                       len = ARR_LEN(copies);
+                       for(i = 0; i < len; ++i) {
+                               be_liveness_update(lv, copies[i]);
+                       }
+#endif
+                       be_ssa_construction_destroy(&senv);
                }
 
                DEL_ARR_F(copies);