ad-hoc fix for lfoat compares (this is not mallons optimal solution yet)
[libfirm] / ir / be / bespillslots.c
index a60d6c2..6ec5fcd 100644 (file)
@@ -1,8 +1,28 @@
 /*
- * Author:      Matthias Braun
- * Date:               26.7.06
- * Copyright:   (c) Universitaet Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+/**
+ * @file
+ * @brief       Spillslot coalescer.
+ * @author      Matthias Braun
+ * @date        26.07.2006
+ * @version     $Id$
  */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #include <stdlib.h>
 
 #include "set.h"
-
+#include "array.h"
 #include "irgwalk.h"
 #include "ircons.h"
 #include "irprintf.h"
 #include "execfreq.h"
 #include "unionfind.h"
-#include "type.h"
 #include "irdump_t.h"
 
 #include "benode_t.h"
@@ -29,6 +48,9 @@
 #include "bestatevent.h"
 #include "bespilloptions.h"
 #include "bemodule.h"
+#include "beintlive_t.h"
+#include "beirg_t.h"
+#include "bearch_t.h"
 
 #define DBG_COALESCING         1
 #define DBG_INTERFERENCES      2
@@ -76,6 +98,8 @@ static int cmp_spill(const void* d1, const void* d2, size_t size)
 {
        const spill_t* s1 = d1;
        const spill_t* s2 = d2;
+       (void) size;
+
        return s1->spill != s2->spill;
 }
 
@@ -252,7 +276,6 @@ static void do_greedy_coalescing(be_fec_env_t *env)
        int affinity_edge_count;
        bitset_t **interferences;
        int* spillslot_unionfind;
-       const be_lv_t *lv = be_get_birg_liveness(env->birg);
 
        spillcount = set_count(env->spills);
        if(spillcount == 0)
@@ -279,10 +302,20 @@ static void do_greedy_coalescing(be_fec_env_t *env)
                interferences[i] = bitset_alloca(spillcount);
        }
 
-       // construct interferences
-       for(i = 0; i < spillcount; ++i) {
+       /* construct interferences */
+       for (i = 0; i < spillcount; ++i) {
+               ir_node *spill1 = spilllist[i]->spill;
+
+               if (is_NoMem(spill1))
+                       continue;
+
                for(i2 = i+1; i2 < spillcount; ++i2) {
-                       if(values_interfere(lv, spilllist[i]->spill, spilllist[i2]->spill)) {
+                       ir_node *spill2 = spilllist[i2]->spill;
+
+                       if (is_NoMem(spill2))
+                               continue;
+
+                       if (values_interfere(env->birg, spill1, spill2)) {
                                DBG((dbg, DBG_INTERFERENCES, "Slot %d and %d interfere\n", i, i2));
                                bitset_set(interferences[i], i2);
                                bitset_set(interferences[i2], i);
@@ -290,20 +323,20 @@ static void do_greedy_coalescing(be_fec_env_t *env)
                }
        }
 
-       // sort affinity edges
+       /* sort affinity edges */
        affinity_edge_count = ARR_LEN(env->affinity_edges);
        qsort(env->affinity_edges, affinity_edge_count, sizeof(env->affinity_edges[0]), cmp_affinity);
 
        //dump_interference_graph(env, interferences, "before");
 
-       // try to merge affine nodes
+       /* try to merge affine nodes */
        for(i = 0; i < affinity_edge_count; ++i) {
                const affinity_edge_t *edge = env->affinity_edges[i];
                int s1 = uf_find(spillslot_unionfind, edge->slot1);
                int s2 = uf_find(spillslot_unionfind, edge->slot2);
 
                /* test if values interfere */
-               if(bitset_is_set(interferences[s1], s2)) {
+               if (bitset_is_set(interferences[s1], s2)) {
                        assert(bitset_is_set(interferences[s2], s1));
                        continue;
                }
@@ -386,6 +419,8 @@ static int cmp_memperm(const void* d1, const void* d2, size_t size)
 {
        const memperm_t* e1 = d1;
        const memperm_t* e2 = d2;
+       (void) size;
+
        return e1->block != e2->block;
 }
 
@@ -414,7 +449,7 @@ static ir_entity* create_stack_entity(be_fec_env_t *env, spill_slot_t *slot)
        ir_type *frame = get_irg_frame_type(irg);
        ir_entity *res = frame_alloc_area(frame, slot->size, slot->align, 0);
 
-       // adjust size of the entity type...
+       /* adjust size of the entity type... */
        ir_type *enttype = get_entity_type(res);
        set_type_size_bytes(enttype, slot->size);
 
@@ -523,7 +558,8 @@ static void assign_spillslots(be_fec_env_t *env)
                                }
                        }
                } else {
-                       arch_set_frame_entity(arch_env, node, slot->entity);
+                       if(!is_NoMem(node))
+                               arch_set_frame_entity(arch_env, node, slot->entity);
                }
        }
 
@@ -588,7 +624,7 @@ static void create_memperms(be_fec_env_t *env)
                // insert node into schedule
                blockend = get_end_of_block_insertion_point(memperm->block);
                sched_add_before(blockend, mempermnode);
-               be_stat_ev("mem_perm", memperm->entrycount);
+               stat_ev_dbl("mem_perm", memperm->entrycount);
 
                i = 0;
                for(entry = memperm->entries; entry != NULL; entry = entry->next, ++i) {
@@ -599,7 +635,6 @@ static void create_memperms(be_fec_env_t *env)
                        be_set_MemPerm_out_entity(mempermnode, i, entry->out);
                        set_irg_current_block(irg, memperm->block);
                        proj = new_Proj(mempermnode, get_irn_mode(arg), i);
-                       sched_add_before(blockend, proj);
 
                        set_irn_n(entry->node, entry->pos, proj);
                }
@@ -629,18 +664,17 @@ static int count_spillslots(const be_fec_env_t *env)
 be_fec_env_t *be_new_frame_entity_coalescer(be_irg_t *birg)
 {
        const arch_env_t *arch_env = birg->main_env->arch_env;
+       be_fec_env_t     *env      = xmalloc(sizeof(env[0]));
 
-       be_fec_env_t *env = xmalloc(sizeof(env[0]));
-
-       be_assure_liveness(birg);
+       be_liveness_assure_chk(be_assure_liveness(birg));
 
        obstack_init(&env->obst);
-       env->arch_env = arch_env;
-       env->birg = birg;
-       env->spills = new_set(cmp_spill, 10);
-       env->reloads = NEW_ARR_F(ir_node*, 0);
+       env->arch_env       = arch_env;
+       env->birg           = birg;
+       env->spills         = new_set(cmp_spill, 10);
+       env->reloads        = NEW_ARR_F(ir_node*, 0);
        env->affinity_edges = NEW_ARR_F(affinity_edge_t*, 0);
-       env->memperms = new_set(cmp_memperm, 10);
+       env->memperms       = new_set(cmp_memperm, 10);
 
        return env;
 }
@@ -658,19 +692,13 @@ void be_free_frame_entity_coalescer(be_fec_env_t *env)
 
 void be_assign_entities(be_fec_env_t *env)
 {
-       if(be_stat_ev_is_active()) {
-               int count = set_count(env->spills);
-               be_stat_ev("spillslots", count);
-       }
+       stat_ev_dbl("spillslots", set_count(env->spills));
 
        if(be_coalesce_spill_slots) {
                do_greedy_coalescing(env);
        }
 
-       if(be_stat_ev_is_active()) {
-               int count = count_spillslots(env);
-               be_stat_ev("spillslots_after_coalescing", count);
-       }
+       stat_ev_dbl("spillslots_after_coalescing", count_spillslots(env));
 
        assign_spillslots(env);
 
@@ -696,8 +724,8 @@ static void collect_spills_walker(ir_node *node, void *data)
        if (!arch_irn_class_is(arch_env, node, reload))
                return;
 
-       mode = get_irn_mode(node);
-       cls = arch_get_irn_reg_class(arch_env, node, -1);
+       mode  = get_irn_mode(node);
+       cls   = arch_get_irn_reg_class(arch_env, node, -1);
        align = arch_isa_get_reg_class_alignment(arch_env_get_isa(arch_env), cls);
 
        be_node_needs_frame_entity(env, node, mode, align);