added a few benchmarks/testapps from http://shootout.alioth.debian.org
[libfirm] / ir / be / beabi.c
index 34e3f29..55aab00 100644 (file)
@@ -118,7 +118,7 @@ static const arch_irn_handler_t abi_irn_handler;
 static heights_t *ir_heights;
 
 /* Flag: if set, try to omit the frame pointer if called by the backend */
-int be_omit_fp = 1;
+static int be_omit_fp = 1;
 
 /*
      _    ____ ___    ____      _ _ _                _
@@ -338,6 +338,7 @@ static be_stack_layout_t *stack_frame_init(be_stack_layout_t *frame, ir_type *ar
        return frame;
 }
 
+#if 0
 /** Dumps the stack layout to file. */
 static void stack_layout_dump(FILE *file, be_stack_layout_t *frame)
 {
@@ -354,6 +355,7 @@ static void stack_layout_dump(FILE *file, be_stack_layout_t *frame)
                }
        }
 }
+#endif
 
 /**
  * Returns non-zero if the call argument at given position
@@ -400,7 +402,6 @@ static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp, i
        const arch_register_t *sp = arch_isa_sp(isa);
        ir_mode *mach_mode        = sp->reg_class->mode;
        struct obstack *obst      = &env->obst;
-       ir_node *no_mem           = get_irg_no_mem(irg);
        int no_alloc              = call->flags.bits.frame_is_setup_on_call;
 
        ir_node *res_proj = NULL;
@@ -749,6 +750,7 @@ static ir_node *adjust_alloc(be_abi_irg_t *env, ir_node *alloc, ir_node *curr_sp
                ir_node *new_alloc;
                ir_node *addr;
                ir_node *copy;
+               ir_node *ins[2];
 
                foreach_out_edge(alloc, edge) {
                        ir_node *irn = get_edge_src_irn(edge);
@@ -779,10 +781,22 @@ static ir_node *adjust_alloc(be_abi_irg_t *env, ir_node *alloc, ir_node *curr_sp
                env->call->flags.bits.try_omit_fp = 0;
                new_alloc = be_new_AddSP(env->isa->sp, irg, bl, curr_sp, get_Alloc_size(alloc));
 
-               exchange(alloc, new_alloc);
+               if(alloc_mem != NULL) {
+                       ir_node *addsp_mem;
+                       ir_node *sync;
 
-               if(alloc_mem != NULL)
-                       set_Proj_proj(alloc_mem, pn_be_AddSP_M);
+                       addsp_mem = new_r_Proj(irg, bl, new_alloc, mode_M, pn_be_AddSP_M);
+
+                       // We need to sync the output mem of the AddSP with the input mem
+                       // edge into the alloc node
+                       ins[0] = get_Alloc_mem(alloc);
+                       ins[1] = addsp_mem;
+                       sync = new_r_Sync(irg, bl, 2, ins);
+
+                       exchange(alloc_mem, sync);
+               }
+
+               exchange(alloc, new_alloc);
 
                /* fix projnum of alloca res */
                set_Proj_proj(alloc_res, pn_be_AddSP_res);
@@ -961,14 +975,6 @@ static void process_calls(be_abi_irg_t *env)
        heights_free(ir_heights);
 }
 
-static void collect_return_walker(ir_node *irn, void *data)
-{
-       if(get_irn_opcode(irn) == iro_Return) {
-               struct obstack *obst = data;
-               obstack_ptr_grow(obst, irn);
-       }
-}
-
 #if 0 /*
 static ir_node *setup_frame(be_abi_irg_t *env)
 {
@@ -1105,6 +1111,7 @@ static ir_type *compute_arg_type(be_abi_irg_t *env, be_abi_call_t *call, ir_type
        return res;
 }
 
+#if 0
 static void create_register_perms(const arch_isa_t *isa, ir_graph *irg, ir_node *bl, pmap *regs)
 {
        int i, j, n;
@@ -1146,6 +1153,7 @@ static void create_register_perms(const arch_isa_t *isa, ir_graph *irg, ir_node
 
        obstack_free(&obst, NULL);
 }
+#endif
 
 typedef struct {
        const arch_register_t *reg;
@@ -1504,7 +1512,6 @@ static void modify_irg(be_abi_irg_t *env)
        ir_graph *irg             = env->birg->irg;
        ir_node *bl               = get_irg_start_block(irg);
        ir_node *end              = get_irg_end_block(irg);
-       ir_node *no_mem           = get_irg_no_mem(irg);
        ir_node *mem              = get_irg_initial_mem(irg);
        ir_type *method_type      = get_entity_type(get_irg_entity(irg));
        pset *dont_save           = pset_new_ptr(8);
@@ -1710,16 +1717,6 @@ static void modify_irg(be_abi_irg_t *env)
        obstack_free(&env->obst, args);
 }
 
-/**
- * Walker: puts all Alloc(stack_alloc) on a obstack
- */
-static void collect_alloca_walker(ir_node *irn, void *data)
-{
-       be_abi_irg_t *env = data;
-       if(get_irn_opcode(irn) == iro_Alloc && get_Alloc_where(irn) == stack_alloc)
-               obstack_ptr_grow(&env->obst, irn);
-}
-
 be_abi_irg_t *be_abi_introduce(be_irg_t *birg)
 {
        be_abi_irg_t *env  = xmalloc(sizeof(env[0]));
@@ -1730,6 +1727,8 @@ be_abi_irg_t *be_abi_introduce(be_irg_t *birg)
        ir_node *dummy;
        optimization_state_t state;
 
+       be_omit_fp = birg->main_env->options->omit_fp;
+
        obstack_init(&env->obst);
 
        env->isa           = birg->main_env->arch_env->isa;