libcore: Check, that a pointer to a char array is passed to LC_OPT_ENT_STR().
[libfirm] / ir / be / bestate.c
index adf7859..e14633c 100644 (file)
 #include "irgmod.h"
 #include "irnodeset.h"
 #include "irnodehashmap.h"
-#include "adt/cpset.h"
+#include "cpset.h"
 
 #include "bearch.h"
+#include "beirg.h"
 #include "beuses.h"
 #include "besched.h"
 #include "belive_t.h"
 #include "bemodule.h"
 #include "benode.h"
 #include "beirgmod.h"
+#include "bespillutil.h"
 #include "bessaconstr.h"
 
 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
@@ -110,8 +112,7 @@ static inline spill_info_t *create_spill_info(minibelady_env_t *env, ir_node *st
 
 static inline spill_info_t *get_spill_info(minibelady_env_t *env, const ir_node *node)
 {
-       spill_info_t *spill_info
-               = (spill_info_t*) ir_nodehashmap_get(&env->spill_infos, node);
+       spill_info_t *spill_info = ir_nodehashmap_get(spill_info_t, &env->spill_infos, node);
        //ir_fprintf(stderr, "Get %+F -> %p\n", node, spill_info);
        return spill_info;
 }
@@ -134,7 +135,7 @@ 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_Phi(next) || be_is_Keep(next));
        } else {
                after = state;
        }
@@ -218,7 +219,6 @@ static block_info_t *compute_block_start_state(minibelady_env_t *env, ir_node *b
        int            n_cfgpreds;
        unsigned       best_time;
        int            outer_loop_allowed;
-       int            i;
 
        /* Create the block info for this block. */
        block_info = new_block_info(&env->obst, block);
@@ -301,12 +301,7 @@ static block_info_t *compute_block_start_state(minibelady_env_t *env, ir_node *b
        }
 
        /* check all Live-Ins */
-       be_lv_foreach(env->lv, block, be_lv_state_in, i) {
-               ir_node *const node = be_lv_get_irn(env->lv, block, i);
-
-               if (!mode_is_data(get_irn_mode(node)))
-                       continue;
-
+       be_lv_foreach_cls(env->lv, block, be_lv_state_in, env->reg->reg_class, node) {
                if (arch_get_irn_register(node) != env->reg)
                        continue;
 
@@ -381,11 +376,9 @@ static void belady(minibelady_env_t *env, ir_node *block)
                int i, arity;
                ir_node *need_val = NULL;
 
-               /* projs are handled with the tuple value.
-                * Phis are no real instr (see insert_starters()) */
-               if (is_Proj(node) || is_Phi(node)) {
+               /* Phis are no real instr (see insert_starters()) */
+               if (is_Phi(node))
                        continue;
-               }
 
                /* check which state is desired for the node */
                arity = get_irn_arity(node);
@@ -414,29 +407,15 @@ static void belady(minibelady_env_t *env, ir_node *block)
                DBG((dbg, LEVEL_3, "  ...%+F\n", node));
 
                /* record state changes by the node */
-               if (get_irn_mode(node) == mode_T) {
-                       foreach_out_edge(node, edge) {
-                               const arch_register_t *reg;
-                               ir_node *proj = get_edge_src_irn(edge);
-
-                               if (!mode_is_data(get_irn_mode(proj)))
-                                       continue;
-
-                               reg = arch_get_irn_register(proj);
-                               if (reg == env->reg) {
-                                       current_state = proj;
-                                       DBG((dbg, LEVEL_3, "\t... current_state <- %+F\n", current_state));
-                               }
-                       }
-               } else {
-                       if (mode_is_data(get_irn_mode(node))) {
-                               const arch_register_t *reg = arch_get_irn_register(node);
-                               if (reg == env->reg) {
-                                       current_state = node;
-                                       DBG((dbg, LEVEL_3, "\t... current_state <- %+F\n", current_state));
-                               }
-                       }
-               }
+               be_foreach_value(node, value,
+                       if (!mode_is_data(get_irn_mode(value)))
+                               continue;
+                       arch_register_t const *const reg = arch_get_irn_register(value);
+                       if (reg != env->reg)
+                               continue;
+                       current_state = value;
+                       DBG((dbg, LEVEL_3, "\t... current_state <- %+F\n", current_state));
+               );
        }
 
        /* Remember end-workset for this block */
@@ -449,39 +428,16 @@ static void belady_walker(ir_node *block, void *data)
        belady((minibelady_env_t*) data, block);
 }
 
-static ir_node *get_end_of_block_insertion_point(ir_node *block)
-{
-       ir_node *last = sched_last(block);
-
-       /* skip Projs and Keep-alikes behind the jump... */
-       while (is_Proj(last) || be_is_Keep(last)) {
-               last = sched_prev(last);
-       }
-
-       if (!is_cfop(last)) {
-               last = sched_next(last);
-               /* last node must be a cfop, only exception is the start block */
-               assert(last == get_irg_start_block(get_irn_irg(block)));
-       }
-
-       return last;
-}
-
 /**
  * We must adapt the live-outs to the live-ins at each block-border.
  */
 static void fix_block_borders(ir_node *block, void *data)
 {
        minibelady_env_t *env = (minibelady_env_t*)data;
-       ir_graph *irg = get_irn_irg(block);
-       ir_node *startblock = get_irg_start_block(irg);
        int i;
        int arity;
        block_info_t *block_info;
 
-       if (block == startblock)
-               return;
-
        DBG((dbg, LEVEL_3, "\n"));
 
        block_info = get_block_info(block);
@@ -507,10 +463,8 @@ static void fix_block_borders(ir_node *block, void *data)
                     pred_info->end_state, need_state));
 
                if (pred_info->end_state != need_state) {
-                       ir_node *insert_point = get_end_of_block_insertion_point(pred);
-
-
                        DBG((dbg, LEVEL_3, "  Creating reload for %+F\n", need_state));
+                       ir_node *const insert_point = be_get_end_of_block_insertion_point(pred);
                        create_reload(env, need_state, insert_point, pred_info->end_state);
                }
        }