* @param curr_sp The stack pointer node to use.
* @return The stack pointer after the call.
*/
-static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp)
+static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp, ir_node *alloca_copy)
{
ir_graph *irg = env->birg->irg;
const arch_isa_t *isa = env->birg->main_env->arch_env->isa;
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;
* moving the stack pointer along the stack's direction.
*/
if(stack_dir < 0 && !do_seq && !no_alloc) {
- curr_sp = be_new_IncSP(sp, irg, bl, curr_sp, no_mem, stack_size);
+ curr_sp = be_new_IncSP(sp, irg, bl, curr_sp, stack_size);
+ if(alloca_copy) {
+ add_irn_dep(curr_sp, alloca_copy);
+ alloca_copy = NULL;
+ }
+ }
+
+ if(!do_seq) {
+ obstack_ptr_grow(obst, get_Call_mem(irn));
+ curr_mem = new_NoMem();
+ } else {
+ curr_mem = get_Call_mem(irn);
}
assert(mode_is_reference(mach_mode) && "machine mode must be pointer");
*/
if (do_seq) {
curr_ofs = 0;
- addr = curr_sp = be_new_IncSP(sp, irg, bl, curr_sp, curr_mem,
- param_size + arg->space_before);
+ addr = curr_sp = be_new_IncSP(sp, irg, bl, curr_sp, param_size + arg->space_before);
+ if(alloca_copy) {
+ add_irn_dep(curr_sp, alloca_copy);
+ alloca_copy = NULL;
+ }
+ add_irn_dep(curr_sp, curr_mem);
}
else {
curr_ofs += arg->space_before;
/* Insert a store for primitive arguments. */
if (is_atomic_type(param_type)) {
- mem = new_r_Store(irg, bl, curr_mem, addr, param);
- mem = new_r_Proj(irg, bl, mem, mode_M, pn_Store_M);
+ ir_node *store;
+ store = new_r_Store(irg, bl, curr_mem, addr, param);
+ mem = new_r_Proj(irg, bl, store, mode_M, pn_Store_M);
}
/* Make a mem copy for compound arguments. */
else {
+ ir_node *copy;
+
assert(mode_is_reference(get_irn_mode(param)));
- mem = new_r_CopyB(irg, bl, curr_mem, addr, param, param_type);
- mem = new_r_Proj(irg, bl, mem, mode_M, pn_CopyB_M_regular);
+ copy = new_r_CopyB(irg, bl, curr_mem, addr, param, param_type);
+ mem = new_r_Proj(irg, bl, copy, mode_M, pn_CopyB_M_regular);
}
curr_ofs += param_size;
in = (ir_node **) obstack_finish(obst);
/* We need the sync only, if we didn't build the stores sequentially. */
- if(!do_seq)
- curr_mem = new_r_Sync(irg, bl, n_pos, in);
+ if(!do_seq) {
+ if(n_pos >= 1) {
+ curr_mem = new_r_Sync(irg, bl, n_pos + 1, in);
+ } else {
+ curr_mem = get_Call_mem(irn);
+ }
+ }
obstack_free(obst, in);
}
}
}
- if(!mem_proj)
+ if(!mem_proj) {
mem_proj = new_r_Proj(irg, bl, low_call, mode_M, pn_Call_M);
+ keep_alive(mem_proj);
+ }
/* Clean up the stack frame if we allocated it */
- if(!no_alloc)
- curr_sp = be_new_IncSP(sp, irg, bl, curr_sp, mem_proj, -stack_size);
+ if(!no_alloc) {
+ curr_sp = be_new_IncSP(sp, irg, bl, curr_sp, -stack_size);
+ add_irn_dep(curr_sp, mem_proj);
+ if(alloca_copy) {
+ add_irn_dep(curr_sp, alloca_copy);
+ alloca_copy = NULL;
+ }
+ }
}
be_abi_call_free(call);
* Adjust an alloca.
* The alloca is transformed into a back end alloca node and connected to the stack nodes.
*/
-static ir_node *adjust_alloc(be_abi_irg_t *env, ir_node *alloc, ir_node *curr_sp)
+static ir_node *adjust_alloc(be_abi_irg_t *env, ir_node *alloc, ir_node *curr_sp, ir_node **result_copy)
{
if (get_Alloc_where(alloc) == stack_alloc) {
ir_node *bl = get_nodes_block(alloc);
addr = env->isa->stack_dir < 0 ? alloc_res : curr_sp;
- /* copy the address away, since it could be used after further stack pointer modifictions. */
+ /* copy the address away, since it could be used after further stack pointer modifications. */
/* Let it point curr_sp just for the moment, I'll reroute it in a second. */
- copy = be_new_Copy(env->isa->sp->reg_class, irg, bl, curr_sp);
+ *result_copy = copy = be_new_Copy(env->isa->sp->reg_class, irg, bl, curr_sp);
/* Let all users of the Alloc() result now point to the copy. */
edges_reroute(alloc_res, copy, irg);
if(n > 0) {
ir_node *keep;
ir_node **nodes;
+ ir_node *copy = NULL;
int i;
nodes = obstack_finish(&env->obst);
DBG((env->dbg, LEVEL_3, "\tprocessing call %+F\n", irn));
switch(get_irn_opcode(irn)) {
case iro_Call:
- curr_sp = adjust_call(env, irn, curr_sp);
+ curr_sp = adjust_call(env, irn, curr_sp, copy);
break;
case iro_Alloc:
- curr_sp = adjust_alloc(env, irn, curr_sp);
+ curr_sp = adjust_alloc(env, irn, curr_sp, ©);
break;
default:
break;
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);
/* do the stack allocation BEFORE the barrier, or spill code
might be added before it */
env->init_sp = be_abi_reg_map_get(env->regs, sp);
- env->init_sp = be_new_IncSP(sp, irg, bl, env->init_sp, no_mem, BE_STACK_FRAME_SIZE_EXPAND);
+ env->init_sp = be_new_IncSP(sp, irg, bl, env->init_sp, BE_STACK_FRAME_SIZE_EXPAND);
be_abi_reg_map_set(env->regs, sp, env->init_sp);
barrier = create_barrier(env, bl, &mem, env->regs, 0);