fixed DEL_ARR_F
[libfirm] / ir / be / beabi.c
index 180a59e..c0ce1e3 100644 (file)
@@ -209,14 +209,14 @@ be_abi_call_flags_t be_abi_call_get_flags(const be_abi_call_t *call)
  *
  * @return the new ABI call object
  */
-static be_abi_call_t *be_abi_call_new(void)
+static be_abi_call_t *be_abi_call_new(const arch_register_class_t *cls_addr)
 {
        be_abi_call_t *call = xmalloc(sizeof(call[0]));
 
        call->flags.val  = 0;
        call->params     = new_set(cmp_call_arg, 16);
        call->cb         = NULL;
-       call->cls_addr   = NULL;
+       call->cls_addr   = cls_addr;
 
        call->flags.bits.try_omit_fp = be_omit_fp;
 
@@ -387,7 +387,6 @@ static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp, i
 {
        ir_graph *irg             = env->birg->irg;
        const arch_isa_t *isa     = env->birg->main_env->arch_env->isa;
-       be_abi_call_t *call       = be_abi_call_new();
        ir_type *mt               = get_Call_type(irn);
        ir_node *call_ptr         = get_Call_ptr(irn);
        int n_params              = get_method_n_params(mt);
@@ -398,6 +397,7 @@ static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp, i
        int stack_size            = 0;
        int stack_dir             = arch_isa_stack_dir(isa);
        const arch_register_t *sp = arch_isa_sp(isa);
+       be_abi_call_t *call       = be_abi_call_new(sp->reg_class);
        ir_mode *mach_mode        = sp->reg_class->mode;
        struct obstack *obst      = &env->obst;
        int no_alloc              = call->flags.bits.frame_is_setup_on_call;
@@ -485,7 +485,6 @@ static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp, i
                        curr_mem = get_Call_mem(irn);
                }
 
-               assert(mode_is_reference(mach_mode) && "machine mode must be pointer");
                for(i = 0; i < n_pos; ++i) {
                        int p                  = pos[i];
                        be_abi_call_arg_t *arg = get_call_arg(call, 0, p);
@@ -515,7 +514,11 @@ static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp, i
 
                                /* Make the expression to compute the argument's offset. */
                                if(curr_ofs > 0) {
-                                       addr = new_r_Const_long(irg, bl, mode_Is, curr_ofs);
+                                       ir_mode *constmode = mach_mode;
+                                       if(mode_is_reference(mach_mode)) {
+                                               constmode = mode_Is;
+                                       }
+                                       addr = new_r_Const_long(irg, bl, constmode, curr_ofs);
                                        addr = new_r_Add(irg, bl, curr_sp, addr, mach_mode);
                                }
                        }
@@ -636,10 +639,10 @@ static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp, i
                                       get_Call_type(irn));
 
        /*
-               Set the register class of the call address to the same as the stack pointer's
-               if it's not set by the backend in the abi callback.
+               Set the register class of the call address to
+               the backend provided class (default: stack pointer class)
        */
-       be_node_set_reg_class(low_call, be_pos_Call_ptr, call->cls_addr ? call->cls_addr : sp->reg_class);
+       be_node_set_reg_class(low_call, be_pos_Call_ptr, call->cls_addr);
 
        /* Set input requirement for stack pointer. */
        be_node_set_reg_class(low_call, be_pos_Call_sp, arch_get_irn_reg_class(isa->main_env->arch_env, curr_sp, -1));
@@ -678,6 +681,11 @@ static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp, i
        for (i = 0; res_projs[i]; ++i)
                set_Proj_pred(res_projs[i], low_call);
 
+       /* set the now unnecessary projT to bad */
+       if(res_proj != NULL) {
+               set_Proj_pred(res_proj, new_Bad());
+       }
+
        /* Make additional projs for the caller save registers
           and the Keep node which keeps them alive. */
        if (pset_count(caller_save) > 0) {
@@ -1608,6 +1616,7 @@ static void modify_irg(be_abi_irg_t *env)
        ir_node *reg_params_bl;
        ir_node **args;
        ir_node *arg_tuple;
+       ir_node *value_param_base;
        const ir_edge_t *edge;
        ir_type *arg_type, *bet_type;
        lower_frame_sels_env_t ctx;
@@ -1623,6 +1632,11 @@ static void modify_irg(be_abi_irg_t *env)
        ctx.value_param_list = NULL;
        irg_walk_graph(irg, lower_frame_sels_walker, NULL, &ctx);
 
+       /* value_param_base anchor is not needed anymore now */
+       value_param_base = get_irg_value_param_base(irg);
+       set_Proj_pred(value_param_base, new_r_Bad(irg));
+       set_irg_value_param_base(irg, new_r_Bad(irg));
+
        env->frame = obstack_alloc(&env->obst, sizeof(env->frame[0]));
        env->regs  = pmap_create();
 
@@ -1675,7 +1689,7 @@ static void modify_irg(be_abi_irg_t *env)
                const arch_register_class_t *cls = arch_isa_get_reg_class(isa, i);
                for(j = 0; j < cls->n_regs; ++j) {
                        const arch_register_t *reg = &cls->regs[j];
-                       if(arch_register_type_is(reg, callee_save) || arch_register_type_is(reg, ignore))
+                       if(arch_register_type_is(reg, callee_save))
                                pmap_insert(env->regs, (void *) reg, NULL);
                }
        }
@@ -1745,6 +1759,8 @@ static void modify_irg(be_abi_irg_t *env)
        set_irg_frame(irg, frame_pointer);
        pset_insert_ptr(env->ignore_regs, fp_reg);
 
+       set_irg_initial_mem(irg, mem);
+
        /* Now, introduce stack param nodes for all parameters passed on the stack */
        for(i = 0; i < n_params; ++i) {
                ir_node *arg_proj = args[i];
@@ -1780,10 +1796,15 @@ static void modify_irg(be_abi_irg_t *env)
                        }
 
                        assert(repl != NULL);
-                       edges_reroute(args[i], repl, irg);
+                       exchange(args[i], repl);
                }
        }
 
+       /* the arg proj is not needed anymore now */
+       assert(get_irn_n_edges(arg_tuple) == 0);
+       set_irn_n(arg_tuple, 0, new_rd_Bad(irg));
+       set_irg_args(irg, new_rd_Bad(irg));
+
        /* All Return nodes hang on the End node, so look for them there. */
        for (i = 0, n = get_Block_n_cfgpreds(end); i < n; ++i) {
                ir_node *irn = get_Block_cfgpred(end, i);
@@ -1820,7 +1841,7 @@ be_abi_irg_t *be_abi_introduce(be_irg_t *birg)
 
        env->isa           = birg->main_env->arch_env->isa;
        env->method_type   = get_entity_type(get_irg_entity(irg));
-       env->call          = be_abi_call_new();
+       env->call          = be_abi_call_new(env->isa->sp->reg_class);
        arch_isa_get_call_abi(env->isa, env->method_type, env->call);
 
        env->ignore_regs      = pset_new_ptr_default();
@@ -1855,8 +1876,8 @@ be_abi_irg_t *be_abi_introduce(be_irg_t *birg)
        pmap_destroy(env->keep_map);
 
        /* reroute the stack origin of the calls to the true stack origin. */
-       edges_reroute(dummy, env->init_sp, irg);
-       edges_reroute(old_frame, get_irg_frame(irg), irg);
+       exchange(dummy, env->init_sp);
+       exchange(old_frame, get_irg_frame(irg));
 
        /* Make some important node pointers survive the dead node elimination. */
        survive_dce_register_irn(env->dce_survivor, &env->init_sp);