Fixed name mangling for private entities
[libfirm] / ir / be / bespillbelady3.c
index f0a016a..a8c70fa 100644 (file)
@@ -47,8 +47,8 @@
 #include "bemodule.h"
 #include "bespill.h"
 #include "beutil.h"
-#include "bespilloptions.h"
-#include "besched_t.h"
+#include "bespillutil.h"
+#include "besched.h"
 #include "be_t.h"
 
 #ifndef NDEBUG
@@ -80,6 +80,8 @@ struct worklist_entry_t {
        ir_loop          *unused_livethrough_loop;
 };
 
+#define foreach_worklist(entry, wl) list_for_each_entry(worklist_entry_t, entry, &(wl)->live_values, head)
+
 typedef struct worklist_t worklist_t;
 struct worklist_t {
        struct list_head  live_values;
@@ -100,16 +102,17 @@ static spill_env_t                 *senv;
 static size_t                       n_regs;
 static size_t                       max_register_pressure;
 static bool                         tentative_mode;
-static bool                         should_have_reached_fixpoint;
 static bool                         do_push_unused_livethroughs;
 /** Execution frequency for the current graph. */
 static ir_exec_freq                *exec_freq;
 static ir_visited_t                 worklist_visited;
+#ifdef DEBUG_libfirm
+static bool                         should_have_reached_fixpoint;
+#endif
 
 static worklist_t *new_worklist(void)
 {
-       worklist_t *worklist = obstack_alloc(&obst, sizeof(worklist[0]));
-       memset(worklist, 0, sizeof(worklist[0]));
+       worklist_t *worklist = OALLOCZ(&obst, worklist_t);
 
        INIT_LIST_HEAD(&worklist->live_values);
        worklist->n_live_values    = 0;
@@ -133,35 +136,30 @@ static block_info_t *get_block_info(ir_node *block)
        if (info != NULL)
                return info;
 
-       info = obstack_alloc(&obst, sizeof(info[0]));
-       memset(info, 0, sizeof(info[0]));
+       info = OALLOCZ(&obst, block_info_t);
        set_irn_link(block, info);
        return info;
 }
 
 static void deactivate_worklist(const worklist_t *worklist)
 {
-       struct list_head *entry;
+       worklist_entry_t *entry;
 
-       list_for_each(entry, &worklist->live_values) {
-               worklist_entry_t *wl_entry
-                       = list_entry(entry, worklist_entry_t, head);
-               assert(worklist_contains(wl_entry->value));
-               mark_irn_not_visited(wl_entry->value);
-               set_irn_link(wl_entry->value, NULL);
+       foreach_worklist(entry, worklist) {
+               assert(worklist_contains(entry->value));
+               mark_irn_not_visited(entry->value);
+               set_irn_link(entry->value, NULL);
        }
 }
 
 static void activate_worklist(const worklist_t *worklist)
 {
-       struct list_head *entry;
+       worklist_entry_t *entry;
 
-       list_for_each(entry, &worklist->live_values) {
-               worklist_entry_t *wl_entry
-                       = list_entry(entry, worklist_entry_t, head);
-               assert(!worklist_contains(wl_entry->value));
-               mark_irn_visited(wl_entry->value);
-               set_irn_link(wl_entry->value, wl_entry);
+       foreach_worklist(entry, worklist) {
+               assert(!worklist_contains(entry->value));
+               mark_irn_visited(entry->value);
+               set_irn_link(entry->value, entry);
        }
 }
 
@@ -174,7 +172,7 @@ static void fill_and_activate_worklist(worklist_t *new_worklist,
 {
        ir_node          *reload_point  = NULL;
        size_t            n_live_values = 0;
-       struct list_head *entry;
+       worklist_entry_t *entry;
 
        if (succ_block != NULL &&
                        (get_Block_n_cfgpreds(succ_block) > 1
@@ -182,9 +180,8 @@ static void fill_and_activate_worklist(worklist_t *new_worklist,
                reload_point = be_get_end_of_block_insertion_point(block);
        }
 
-       list_for_each(entry, &worklist->live_values) {
-               worklist_entry_t *wl_entry  = list_entry(entry, worklist_entry_t, head);
-               ir_node          *value     = wl_entry->value;
+       foreach_worklist(entry, worklist) {
+               ir_node          *value = entry->value;
                worklist_entry_t *new_entry;
 
                if (new_worklist->n_live_values >= n_regs)
@@ -201,14 +198,13 @@ static void fill_and_activate_worklist(worklist_t *new_worklist,
                if (irn_visited_else_mark(value))
                        continue;
 
-               new_entry = obstack_alloc(&obst, sizeof(new_entry[0]));
-               memset(new_entry, 0, sizeof(new_entry[0]));
+               new_entry = OALLOCZ(&obst, worklist_entry_t);
 
                new_entry->value = value;
                if (reload_point != NULL) {
                        new_entry->reload_point = reload_point;
                } else {
-                       new_entry->reload_point = wl_entry->reload_point;
+                       new_entry->reload_point = entry->reload_point;
                }
 
                list_add_tail(&new_entry->head, &new_worklist->live_values);
@@ -224,15 +220,13 @@ static worklist_t *duplicate_worklist(const worklist_t *worklist)
        worklist_t       *new_worklist;
        struct list_head *entry;
 
-       new_worklist = obstack_alloc(&obst, sizeof(new_worklist[0]));
-       memset(new_worklist, 0, sizeof(new_worklist[0]));
+       new_worklist = OALLOCZ(&obst, worklist_t);
        INIT_LIST_HEAD(&new_worklist->live_values);
        new_worklist->n_live_values = worklist->n_live_values;
 
        list_for_each(entry, &worklist->live_values) {
                worklist_entry_t *wl_entry  = list_entry(entry, worklist_entry_t, head);
-               worklist_entry_t *new_entry
-                       = obstack_alloc(&obst, sizeof(new_entry[0]));
+               worklist_entry_t *new_entry     = OALLOC(&obst, worklist_entry_t);
 
                memcpy(new_entry, wl_entry, sizeof(new_entry[0]));
                list_add_tail(&new_entry->head, &new_worklist->live_values);
@@ -284,8 +278,7 @@ static loop_info_t *get_loop_info(ir_loop *loop)
        if (info != NULL)
                return info;
 
-       info = obstack_alloc(&obst, sizeof(info[0]));
-       memset(info, 0, sizeof(info[0]));
+       info = OALLOCZ(&obst, loop_info_t);
        info->loop = loop;
        loop->link = info;
        return info;
@@ -331,8 +324,7 @@ static void construct_loop_edges(ir_node *block, void *data)
                do {
                        loop_info_t *l_info = get_loop_info(l);
 
-                       edge = obstack_alloc(&obst, sizeof(edge[0]));
-                       memset(edge, 0, sizeof(edge[0]));
+                       edge = OALLOCZ(&obst, loop_edge_t);
                        edge->block = block;
                        edge->pos   = i;
 
@@ -411,9 +403,7 @@ static void val_used(worklist_t *worklist, ir_node *value, ir_node *sched_point)
                list_del(&entry->head);
        } else {
                if (entry == NULL) {
-                       entry        = obstack_alloc(&obst, sizeof(entry[0]));
-                       memset(entry, 0, sizeof(entry[0]));
-
+                       entry        = OALLOCZ(&obst, worklist_entry_t);
                        entry->value = value;
                        set_irn_link(value, entry);
                }
@@ -559,7 +549,7 @@ static bool fill_start_worklist(worklist_t *new_worklist, ir_node *block)
        double           best_execfreq   = -1;
        worklist_t      *best_worklist   = NULL;
        ir_node         *best_succ_block = NULL;
-       int              best_pos;
+       int              best_pos        = -1;
        const ir_edge_t *edge;
 
        /* construct worklist */
@@ -740,20 +730,15 @@ static void worklist_append(worklist_t *worklist, ir_node *value,
                             ir_node *reload_point,
                                                        ir_loop *unused_livethrough_loop)
 {
-       worklist_entry_t *entry     = obstack_alloc(&obst, sizeof(entry[0]));
-       memset(entry, 0, sizeof(entry[0]));
+       worklist_entry_t *entry;
 
 #ifdef EXPENSIVE_CHECKS
-       {
-               struct list_head *entry;
-               list_for_each(entry, &worklist->live_values) {
-                       worklist_entry_t *wl_entry
-                               = list_entry(entry, worklist_entry_t, head);
-                       assert(wl_entry->value != value);
-               }
+       foreach_worklist(entry, worklist) {
+               assert(entry->value != value);
        }
 #endif
 
+       entry = OALLOCZ(&obst, worklist_entry_t);
        entry->value                   = value;
        entry->reload_point            = reload_point;
        entry->unused_livethrough_loop = unused_livethrough_loop;
@@ -903,7 +888,7 @@ static void process_loop(ir_loop *loop)
                some_block = get_irg_start_block(current_ir_graph);
        }
 
-       loop_blocks  = NEW_ARR_F(block_or_loop_t,0);
+       loop_blocks  = NEW_ARR_F(block_or_loop_t, 0);
        current_loop = loop;
 
        ir_reserve_resources(current_ir_graph, IR_RESOURCE_BLOCK_VISITED);
@@ -983,7 +968,7 @@ static void fix_block_borders(ir_node *block, void *data)
                worklist_t   *end_worklist    = pred_block_info->end_worklist;
                ir_loop      *pred_loop       = get_irn_loop(pred_block);
                bool          is_loop_entry   = false;
-               struct list_head *entry;
+               worklist_entry_t *entry;
 
                assert(end_worklist != NULL);
 
@@ -994,10 +979,11 @@ static void fix_block_borders(ir_node *block, void *data)
                /* reload missing values */
                activate_worklist(end_worklist);
 
-               list_for_each(entry, &start_worklist->live_values) {
-                       worklist_entry_t *wl_entry
-                               = list_entry(entry, worklist_entry_t, head);
-                       ir_node          *value = wl_entry->value;
+               foreach_worklist(entry, start_worklist) {
+                       ir_node *value = entry->value;
+
+                       if (!is_loop_entry && entry->unused_livethrough_loop != NULL)
+                               continue;
 
                        if (is_Phi(value) && get_nodes_block(value) == block) {
                                value = get_irn_n(value, i);
@@ -1006,12 +992,8 @@ static void fix_block_borders(ir_node *block, void *data)
                                if (!arch_irn_consider_in_reg_alloc(cls, value))
                                        continue;
                        }
-
                        if (worklist_contains(value))
                                continue;
-                       if (wl_entry->unused_livethrough_loop != NULL && !is_loop_entry)
-                               continue;
-
                        be_add_reload_on_edge(senv, value, block, i, cls, 1);
                }