removed dependency of type.h
[libfirm] / ir / be / benode.c
index dd13391..e4c257b 100644 (file)
@@ -30,6 +30,7 @@
 #include "irnode_t.h"
 #include "ircons_t.h"
 #include "irprintf.h"
+#include "irgwalk.h"
 
 #include "be_t.h"
 #include "belive_t.h"
@@ -156,7 +157,7 @@ void be_node_init(void) {
        op_be_Perm       = new_ir_op(beo_base + beo_Perm,       "Perm",       op_pin_state_pinned,     N, oparity_variable, 0, sizeof(be_node_attr_t),  &be_node_op_ops);
        op_be_Copy       = new_ir_op(beo_base + beo_Copy,       "Copy",       op_pin_state_floats,     N, oparity_unary,    0, sizeof(be_node_attr_t),  &be_node_op_ops);
        op_be_Keep       = new_ir_op(beo_base + beo_Keep,       "Keep",       op_pin_state_pinned,     K, oparity_variable, 0, sizeof(be_node_attr_t),  &be_node_op_ops);
-       op_be_Call       = new_ir_op(beo_base + beo_Call,       "Call",       op_pin_state_pinned,     N, oparity_variable, 0, sizeof(be_node_attr_t),  &be_node_op_ops);
+       op_be_Call       = new_ir_op(beo_base + beo_Call,       "Call",       op_pin_state_pinned,     N, oparity_variable, 0, sizeof(be_call_attr_t),  &be_node_op_ops);
        op_be_Return     = new_ir_op(beo_base + beo_Return,     "Return",     op_pin_state_pinned,     X, oparity_variable, 0, sizeof(be_node_attr_t),  &be_node_op_ops);
        op_be_Alloca     = new_ir_op(beo_base + beo_Alloca,     "Alloca",     op_pin_state_pinned,     N, oparity_unary,    0, sizeof(be_node_attr_t),  &be_node_op_ops);
        op_be_SetSP      = new_ir_op(beo_base + beo_SetSP,      "SetSP",      op_pin_state_pinned,     N, oparity_binary,   0, sizeof(be_stack_attr_t), &be_node_op_ops);
@@ -287,7 +288,7 @@ ir_node *be_new_Reload(const arch_register_class_t *cls, const arch_register_cla
 ir_node *(be_get_Reload_mem)(const ir_node *irn)
 {
        assert(be_is_Reload(irn));
-       return get_irn_n(irn, 1);
+       return get_irn_n(irn, be_pos_Reload_mem);
 }
 
 ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
@@ -732,19 +733,26 @@ entity *be_get_spill_entity(const ir_node *irn)
        return NULL;
 }
 
-static void entity_copy_walker(ir_node *irn, void *data)
+static void link_reload_walker(ir_node *irn, void *data)
 {
+       ir_node **root = (ir_node **) data;
        if(be_is_Reload(irn)) {
-               be_frame_attr_t *a = get_irn_attr(irn);
-               entity *ent        = be_get_spill_entity(irn);
-
-               a->ent = ent;
+               set_irn_link(irn, *root);
+               *root = irn;
        }
 }
 
 void be_copy_entities_to_reloads(ir_graph *irg)
 {
-       irg_walk_graph(irg, entity_copy_walker, NULL, NULL);
+       ir_node *irn = NULL;
+       irg_walk_graph(irg, link_reload_walker, NULL, (void *) &irn);
+
+       while(irn) {
+               be_frame_attr_t *a = get_irn_attr(irn);
+               entity *ent        = be_get_spill_entity(irn);
+               a->ent = ent;
+               irn    = get_irn_link(irn);
+       }
 }
 
 ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn, ir_node *ctx)
@@ -774,8 +782,10 @@ ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn, ir_node *ctx)
         * Here's one special case:
         * If the spill is in the start block, the spill must be after the frame
         * pointer is set up. This is checked here and fixed.
+        * If the insertion point is already the block, everything is fine, since
+        * the Spill gets inserted at the end of the block.
         */
-       if(bl == get_irg_start_block(irg))
+       if(bl == get_irg_start_block(irg) && insert != bl && sched_comes_after(insert, frame))
                insert = sched_next(frame);
 
        sched_add_before(insert, spill);