8 #include "firm_config.h"
13 #include "irgraph_t.h"
16 #include "iredges_t.h"
24 #include "besched_t.h"
26 #define MAX(x, y) ((x) > (y) ? (x) : (y))
27 #define MIN(x, y) ((x) < (y) ? (x) : (y))
29 typedef struct _be_abi_call_arg_t {
34 const arch_register_t *reg;
37 struct _be_abi_call_t {
38 be_abi_call_flags_t flags;
43 struct _be_abi_irg_t {
49 ir_node *init_sp; /**< The node representing the stack pointer
50 at the start of the function. */
54 pset *stack_ops; /**< Contains all nodes modifying the stack pointer. */
60 unsigned dedicated_fp : 1;
61 unsigned left_to_right : 1;
63 firm_dbg_module_t *dbg; /**< The debugging module. */
66 static int cmp_call_arg(const void *a, const void *b, size_t n)
68 const be_abi_call_arg_t *p = a, *q = b;
69 return !(p->is_res == q->is_res && p->pos == q->pos);
72 static be_abi_call_arg_t *get_or_set_call_arg(be_abi_call_t *call, int is_res, int pos, int do_insert)
74 be_abi_call_arg_t arg;
80 hash = is_res * 100 + pos;
83 ? set_insert(call->params, &arg, sizeof(arg), hash)
84 : set_find(call->params, &arg, sizeof(arg), hash);
87 static INLINE be_abi_call_arg_t *get_call_arg(be_abi_call_t *call, int is_res, int pos)
89 return get_or_set_call_arg(call, is_res, pos, 0);
92 void be_abi_call_set_flags(be_abi_call_t *call, be_abi_call_flags_t flags, unsigned arg_gap)
95 call->arg_gap = arg_gap;
98 void be_abi_call_param_stack(be_abi_call_t *call, int arg_pos)
100 be_abi_call_arg_t *arg = get_or_set_call_arg(call, 0, arg_pos, 1);
103 void be_abi_call_param_reg(be_abi_call_t *call, int arg_pos, const arch_register_t *reg)
105 be_abi_call_arg_t *arg = get_or_set_call_arg(call, 0, arg_pos, 1);
109 void be_abi_call_res_reg(be_abi_call_t *call, int arg_pos, const arch_register_t *reg)
111 be_abi_call_arg_t *arg = get_or_set_call_arg(call, 1, arg_pos, 1);
115 be_abi_call_t *be_abi_call_new(void)
117 be_abi_call_t *call = malloc(sizeof(call[0]));
118 call->flags = BE_ABI_NONE;
119 call->params = new_set(cmp_call_arg, 16);
123 void be_abi_call_free(be_abi_call_t *call)
125 del_set(call->params);
129 static INLINE int is_on_stack(be_abi_call_t *call, int pos)
131 be_abi_call_arg_t *arg = get_call_arg(call, 0, pos);
132 return arg && !arg->in_reg;
135 static void adjust_call(be_abi_irg_t *env, ir_node *irn)
137 ir_graph *irg = env->birg->irg;
138 const arch_isa_t *isa = env->birg->main_env->arch_env->isa;
139 be_abi_call_t *call = be_abi_call_new();
140 ir_type *mt = get_Call_type(irn);
141 int n_params = get_method_n_params(mt);
142 ir_node *curr_sp = get_irg_frame(irg);
143 ir_node *curr_mem = get_Call_mem(irn);
144 ir_node *bl = get_nodes_block(irn);
145 pset *results = pset_new_ptr(8);
146 pset *caller_save = pset_new_ptr(8);
148 int stack_dir = arch_isa_stack_dir(isa);
149 const arch_register_t *sp = arch_isa_sp(isa);
150 ir_mode *mach_mode = sp->reg_class->mode;
151 struct obstack *obst = &env->obst;
152 ir_node *no_mem = get_irg_no_mem(irg);
154 ir_node *res_proj = NULL;
155 int curr_res_proj = -1;
162 const ir_edge_t *edge;
167 /* Let the isa fill out the abi description for that call node. */
168 arch_isa_get_call_abi(isa, mt, call);
170 /* Insert code to put the stack arguments on the stack. */
171 for(i = get_irn_arity(irn); i >= 0; --i) {
172 if(is_on_stack(call, i)) {
173 stack_size += get_type_size_bytes(get_method_param_type(mt, i));
174 obstack_int_grow(obst, i);
178 pos = obstack_finish(obst);
180 /* Collect all arguments which are passed in registers. */
181 for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
182 be_abi_call_arg_t *arg = get_call_arg(call, 0, i);
183 if(arg && arg->in_reg) {
184 obstack_int_grow(obst, i);
188 low_args = obstack_finish(obst);
190 /* If there are some parameters which shall be passed on the stack. */
193 int do_seq = (call->flags & BE_ABI_USE_PUSH);
195 /* Reverse list of stack parameters if call arguments are from left to right */
196 if(call->flags & BE_ABI_LEFT_TO_RIGHT) {
197 for(i = 0; i < n_pos / 2; ++i) {
198 int other = n_pos - i - 1;
206 * If the stack is decreasing and we do not want to store sequentially,
207 * we allocate as much space on the stack all parameters need, by
208 * moving the stack pointer along the stack's direction.
210 if(stack_dir < 0 && !do_seq) {
211 curr_sp = be_new_IncSP(sp, irg, bl, curr_sp, no_mem, stack_size, be_stack_dir_along);
212 pset_insert_ptr(env->stack_ops, curr_sp);
215 assert(mode_is_reference(mach_mode) && "machine mode must be pointer");
216 for(i = 0; i < n_pos; ++i) {
218 ir_node *param = get_irn_n(irn, p);
219 ir_node *addr = curr_sp;
221 type *param_type = get_method_param_type(mt, p);
222 int param_size = get_type_size_bytes(param_type);
224 /* Make the expression to compute the argument's offset. */
226 addr = new_r_Const_long(irg, bl, mode_Is, curr_ofs);
227 addr = new_r_Add(irg, bl, curr_sp, addr, mach_mode);
230 /* Insert a store for primitive arguments. */
231 if(is_atomic_type(param_type)) {
232 mem = new_r_Store(irg, bl, curr_mem, addr, param);
233 mem = new_r_Proj(irg, bl, mem, mode_M, pn_Store_M);
236 /* Make a memcopy for compound arguments. */
238 assert(mode_is_reference(get_irn_mode(param)));
239 mem = new_r_CopyB(irg, bl, curr_mem, addr, param, param_type);
240 mem = new_r_Proj(irg, bl, mem, mode_M, pn_CopyB_M_regular);
243 obstack_ptr_grow(obst, mem);
245 curr_ofs += param_size;
248 * If we wanted to build the arguments sequentially,
249 * the stack pointer for the next must be incremented,
250 * and the memory value propagated.
254 curr_sp = be_new_IncSP(sp, irg, bl, curr_sp, no_mem, param_size, be_stack_dir_along);
258 * only put the first IncSP to the stack fixup set since the other
259 * ones are correctly connected to other nodes and do not need
263 pset_insert_ptr(env->stack_ops, curr_sp);
267 in = (ir_node **) obstack_finish(obst);
269 /* We need the sync only, if we didn't build the stores sequentially. */
271 curr_mem = new_r_Sync(irg, bl, n_pos, in);
272 obstack_free(obst, in);
275 /* Collect caller save registers */
276 for(i = 0; env->birg->main_env->caller_save[i]; ++i)
277 pset_insert_ptr(caller_save, env->birg->main_env->caller_save[i]);
279 /* search the greatest result proj number */
280 foreach_out_edge(irn, edge) {
281 const ir_edge_t *res_edge;
282 ir_node *irn = get_edge_src_irn(edge);
284 if(is_Proj(irn) && get_irn_mode(irn) == mode_T) {
286 foreach_out_edge(irn, res_edge) {
288 be_abi_call_arg_t *arg;
289 ir_node *res = get_edge_src_irn(res_edge);
291 assert(is_Proj(res));
292 proj = get_Proj_proj(res);
293 arg = get_call_arg(call, 1, proj);
294 if(proj > curr_res_proj)
295 curr_res_proj = proj;
297 pset_remove_ptr(caller_save, arg->reg);
303 /* Make additional projs for the caller save registers
304 and the Keep node which keeps them alive. */
305 if(pset_count(caller_save) > 0) {
306 const arch_register_t *reg;
310 res_proj = new_r_Proj(irg, bl, irn, mode_T, pn_Call_T_result);
312 for(reg = pset_first(caller_save); reg; reg = pset_next(caller_save))
313 obstack_ptr_grow(obst, new_r_Proj(irg, bl, res_proj, reg->reg_class->mode, curr_res_proj++));
315 in = (ir_node **) obstack_finish(obst);
316 be_new_Keep(NULL, irg, bl, pset_count(caller_save), in);
317 obstack_free(obst, in);
320 /* Clean up the stack. */
322 ir_node *last_inc_sp;
324 /* Get the result ProjT */
326 res_proj = new_r_Proj(irg, bl, irn, mode_T, pn_Call_T_result);
328 /* Make a Proj for the stack pointer. */
329 sp_proj = new_r_Proj(irg, bl, res_proj, sp->reg_class->mode, curr_res_proj++);
330 last_inc_sp = be_new_IncSP(sp, irg, bl, sp_proj, no_mem, stack_size, be_stack_dir_against);
331 pset_insert_ptr(env->stack_ops, last_inc_sp);
334 /* at last make the backend call node and set its register requirements. */
335 for(i = 0; i < n_low_args; ++i)
336 obstack_ptr_grow(obst, get_irn_n(irn, low_args[i]));
337 in = obstack_finish(obst);
338 low_call = be_new_Call(irg, bl, curr_mem, curr_sp, get_Call_ptr(irn), curr_res_proj, n_low_args, in);
339 obstack_free(obst, in);
341 exchange(irn, low_call);
343 be_abi_call_free(call);
344 obstack_free(obst, pos);
346 del_pset(caller_save);
349 static void adjust_call_walker(ir_node *irn, void *data)
351 if(get_irn_opcode(irn) == iro_Call)
352 adjust_call(data, irn);
356 * Walker to implement alloca-style allocations.
357 * They are implemented using an add to the stack pointer
358 * and a copy instruction.
360 static void implement_stack_alloc(be_abi_irg_t *env, ir_node *irn)
362 const arch_isa_t *isa = env->birg->main_env->arch_env->isa;
363 ir_node *bl = get_nodes_block(irn);
364 ir_node *res = env->init_sp;
367 assert(get_irn_opcode(irn) == iro_Alloc && get_Alloc_where(irn) == stack_alloc);
369 size = get_Alloc_size(irn);
370 if(isa->stack_dir > 0)
371 res = be_new_Copy(isa->sp->reg_class, env->birg->irg, bl, res);
373 res = be_new_AddSP(isa->sp, env->birg->irg, bl, res, size);
374 pset_insert_ptr(env->stack_ops, res);
376 if(isa->stack_dir < 0)
377 res = be_new_Copy(isa->sp->reg_class, env->birg->irg, bl, res);
381 static void collect_return_walker(ir_node *irn, void *data)
383 if(get_irn_opcode(irn) == iro_Return) {
384 struct obstack *obst = data;
385 obstack_ptr_grow(obst, irn);
389 static ir_node *setup_frame(be_abi_irg_t *env)
391 const arch_isa_t *isa = env->birg->main_env->arch_env->isa;
392 const arch_register_t *sp = isa->sp;
393 const arch_register_t *bp = isa->bp;
394 ir_graph *irg = env->birg->irg;
395 ir_node *bl = get_irg_start_block(irg);
396 ir_node *no_mem = get_irg_no_mem(irg);
397 ir_node *old_frame = get_irg_frame(irg);
398 int store_old_fp = 1;
399 int omit_fp = env->omit_fp;
400 ir_node *stack = pmap_get(env->regs, (void *) sp);
401 ir_node *frame = pmap_get(env->regs, (void *) bp);
403 int stack_nr = get_Proj_proj(stack);
406 stack = be_new_IncSP(sp, irg, bl, stack, no_mem, BE_STACK_FRAME_SIZE, be_stack_dir_along);
414 irn = new_r_Store(irg, bl, get_irg_initial_mem(irg), stack, frame);
415 irn = new_r_Proj(irg, bl, irn, mode_M, pn_Store_M);
416 stack = be_new_IncSP(sp, irg, bl, stack, irn, get_mode_size_bytes(bp->reg_class->mode), be_stack_dir_along);
419 frame = be_new_Copy(bp->reg_class, irg, bl, stack);
421 if(env->dedicated_fp) {
422 be_set_constr_single_reg(frame, -1, bp);
423 be_node_set_flags(frame, -1, arch_irn_flags_ignore);
426 stack = be_new_IncSP(sp, irg, bl, stack, no_mem, BE_STACK_FRAME_SIZE, be_stack_dir_along);
429 be_node_set_flags(env->reg_params, -(stack_nr + 1), arch_irn_flags_ignore);
430 env->init_sp = stack;
431 set_irg_frame(irg, frame);
432 edges_reroute(old_frame, frame, irg);
437 static ir_node *clearup_frame(be_abi_irg_t *env, ir_node *stack, ir_node *frame)
443 * Modify the irg itself and the frame type.
445 static void modify_irg(be_abi_irg_t *env)
447 firm_dbg_module_t *dbg = env->dbg;
448 be_abi_call_t *call = be_abi_call_new();
449 const arch_isa_t *isa = env->birg->main_env->arch_env->isa;
450 const arch_register_t *sp = arch_isa_sp(isa);
451 ir_graph *irg = env->birg->irg;
452 ir_node *bl = get_irg_start_block(irg);
453 ir_node *end = get_irg_end_block(irg);
454 ir_node *arg_tuple = get_irg_args(irg);
455 ir_node *no_mem = get_irg_no_mem(irg);
456 type *method_type = get_entity_type(get_irg_entity(irg));
457 int n_params = get_method_n_params(method_type);
460 int reg_params_nr = 0;
465 ir_node *frame_pointer;
466 ir_node *reg_params, *reg_params_bl;
467 ir_node **args, **args_repl;
468 const ir_edge_t *edge;
472 env->regs = pmap_create();
474 DBG((dbg, LEVEL_1, "introducing abi on %+F\n", irg));
476 /* Find the maximum proj number of the argument tuple proj */
477 foreach_out_edge(arg_tuple, edge) {
478 ir_node *irn = get_edge_src_irn(edge);
479 int nr = get_Proj_proj(irn);
480 max_arg = MAX(max_arg, nr);
483 args = obstack_alloc(&env->obst, max_arg * sizeof(args[0]));
484 args_repl = obstack_alloc(&env->obst, max_arg * sizeof(args[0]));
485 memset(args, 0, max_arg * sizeof(args[0]));
486 memset(args_repl, 0, max_arg * sizeof(args[0]));
488 /* Fill the argument vector */
489 foreach_out_edge(arg_tuple, edge) {
490 ir_node *irn = get_edge_src_irn(edge);
491 int nr = get_Proj_proj(irn);
493 DBG((dbg, LEVEL_2, "\treading arg: %d -> %+F\n", nr, irn));
496 /* Get the ABI constraints from the ISA */
497 arch_isa_get_call_abi(isa, method_type, call);
499 /* Count the register params and add them to the number of Projs for the RegParams node */
500 for(i = 0; i < n_params; ++i) {
501 be_abi_call_arg_t *arg = get_call_arg(call, 0, i);
503 assert(arg->reg != sp && "cannot use stack pointer as parameter register");
504 pmap_insert(env->regs, (void *) arg->reg, NULL);
505 DBG((dbg, LEVEL_2, "\targ #%d -> reg %s\n", i, arg->reg->name));
509 /* Collect all callee-save registers */
510 for(i = 0, n = arch_isa_get_n_reg_class(isa); i < n; ++i) {
511 const arch_register_class_t *cls = arch_isa_get_reg_class(isa, i);
512 for(j = 0; j < cls->n_regs; ++j) {
513 const arch_register_t *reg = &cls->regs[j];
514 if(arch_register_type_is(reg, callee_save))
515 pmap_insert(env->regs, (void *) reg, NULL);
519 pmap_insert(env->regs, (void *) sp, NULL);
520 pmap_insert(env->regs, (void *) isa->bp, NULL);
521 reg_params_bl = get_irg_start_block(irg);
522 env->reg_params = reg_params = be_new_RegParams(irg, reg_params_bl, pmap_count(env->regs));
526 * make proj nodes for the callee save registers.
527 * memorize them, since Return nodes get those as inputs.
529 for(ent = pmap_first(env->regs); ent; ent = pmap_next(env->regs)) {
530 arch_register_t *reg = ent->key;
531 int pos = -(reg_params_nr + 1);
532 ent->value = new_r_Proj(irg, reg_params_bl, reg_params, reg->reg_class->mode, reg_params_nr);
533 be_set_constr_single_reg(reg_params, pos, reg);
536 * If the register is an ignore register,
537 * The Proj for that register shall also be ignored during register allocation.
539 if(arch_register_type_is(reg, ignore))
540 be_node_set_flags(reg_params, pos, arch_irn_flags_ignore);
544 DBG((dbg, LEVEL_2, "\tregister save proj #%d -> reg %s\n", reg_params_nr - 1, reg->name));
547 /* Insert the code to set up the stack frame */
548 frame_pointer = setup_frame(env);
551 proj_sp = pmap_get(regs, (void *) sp);
552 proj_bp = pmap_get(regs, (void *) bp);
553 assert(proj_sp != NULL && "There must be a Proj for the stack pointer");
554 assert(proj_sp != NULL && "There must be a Proj for the base pointer");
556 /* Set the Proj for the stack pointer to ignore. */
557 be_node_set_flags(reg_params, -(get_Proj_proj(proj_sp) + 1), arch_irn_flags_ignore);
560 * If a frame pointer is needed and the frame pointer is in a dedicated register,
561 * also exclude that from register allocation by setting the corresponding
564 if(!env->omit_fp && env->dedicated_fp)
565 be_node_set_flags(reg_params, -(get_Proj_proj(proj_bp) + 1), arch_irn_flags_ignore);
569 /* This is the stack pointer add/sub which allocates the frame. remind it for later fix up. */
570 env->init_sp = be_new_IncSP(sp, irg, reg_params_bl, proj_sp, no_mem, 0, be_stack_dir_along);
571 frame_pointer = env->init_sp;
575 env->init_sp = proj_sp;
576 frame_pointer = be_new_Copy(sp->reg_class, irg, reg_params_bl, proj_sp);
579 /* Set the new frame pointer. */
580 exchange(get_irg_frame(irg), frame_pointer);
581 set_irg_frame(irg, frame_pointer);
584 /* compute the start offset for the stack parameters. */
588 int inc_dir = isa->stack_dir * (env->left_to_right ? 1 : -1);
590 for(i = 0; i < n_params; ++i) {
591 be_abi_call_arg_t *arg = get_call_arg(call, 0, i);
593 arg_size += get_type_size_bytes(get_method_param_type(method_type, i));
596 arg_offset = -isa->stack_dir * call->arg_gap + env->left_to_right * arg_size;
598 /* Now, introduce stack param nodes for all parameters passed on the stack */
599 for(i = 0; i < max_arg; ++i) {
600 ir_node *arg_proj = args[i];
601 if(arg_proj != NULL) {
602 be_abi_call_arg_t *arg;
604 int nr = get_Proj_proj(arg_proj);
606 nr = MIN(nr, n_params);
607 arg = get_call_arg(call, 0, nr);
608 param_type = get_method_param_type(method_type, nr);
611 args_repl[i] = new_r_Proj(irg, reg_params_bl, reg_params, get_irn_mode(arg_proj), reg_params_nr);
612 be_set_constr_single_reg(reg_params, -(reg_params_nr + 1), arg->reg);
616 /* when the (stack) parameter is primitive, we insert a StackParam
617 node representing the load of that parameter */
619 int size = get_type_size_bytes(param_type) * isa->stack_dir;
624 if(is_atomic_type(param_type)) {
625 ir_mode *mode = get_type_mode(param_type);
626 const arch_register_class_t *cls = arch_isa_get_reg_class_for_mode(isa, mode);
627 args_repl[i] = be_new_StackParam(cls, irg, reg_params_bl, mode, frame_pointer, arg_offset);
630 /* The stack parameter is not primitive (it is a struct or array),
631 we thus will create a node representing the parameter's address
634 assert(0 && "struct parameters are not supported");
644 /* reroute the edges from the original argument projs to the RegParam ones. */
645 for(i = 0; i < max_arg; ++i) {
646 if(args[i] != NULL) {
647 assert(args_repl[i] != NULL);
648 edges_reroute(args[i], args_repl[i], irg);
652 /* All Return nodes hang on the End node, so look for them there. */
653 for(i = 0, n = get_irn_arity(end); i < n; ++i) {
654 ir_node *irn = get_irn_n(end, i);
656 if(get_irn_opcode(irn) == iro_Return) {
657 ir_node *bl = get_nodes_block(irn);
662 /* collect all arguments of the return */
663 for(i = 0, n = get_irn_arity(irn); i < n; ++i)
664 obstack_ptr_grow(&env->obst, get_irn_n(irn, i));
666 /* Add the Proj nodes representing the caller save registers. */
667 for(ent = pmap_first(env->regs); ent; ent = pmap_next(env->regs), ++n) {
668 const arch_register_t *reg = ent->key;
669 ir_node *irn = ent->value;
672 * If the register is the stack pointer,
673 * add the fix up code. Either add the size of the stack
674 * frame if we omitted the frame pointer or move the
675 * frame pointer back to the stack register.
678 irn = be_new_IncSP(sp, irg, bl, frame_pointer, no_mem, env->omit_fp ? BE_STACK_FRAME_SIZE : 0, be_stack_dir_against);
680 obstack_ptr_grow(&env->obst, irn);
683 /* The in array for the new back end return is now ready. */
684 in = obstack_finish(&env->obst);
685 ret = be_new_Return(irg, bl, n, in);
686 edges_reroute(irn, ret, irg);
687 obstack_free(&env->obst, in);
691 obstack_free(&env->obst, args);
692 be_abi_call_free(call);
695 static void collect_alloca_walker(ir_node *irn, void *data)
697 be_abi_irg_t *env = data;
698 if(get_irn_opcode(irn) == iro_Alloc && get_Alloc_where(irn) == stack_alloc)
699 obstack_ptr_grow(&env->obst, irn);
702 be_abi_irg_t *be_abi_introduce(be_irg_t *birg)
704 be_abi_irg_t *env = malloc(sizeof(env[0]));
707 ir_node **stack_allocs;
709 env->method_type = get_entity_type(get_irg_entity(birg->irg));
710 env->call = be_abi_call_new();
711 arch_isa_get_call_abi(birg->main_env->arch_env->isa, env->method_type, env->call);
713 env->omit_fp = (env->call->flags & BE_ABI_TRY_OMIT_FRAME_POINTER) != 0;
714 env->dedicated_fp = (env->call->flags & BE_ABI_FRAME_POINTER_DEDICATED) != 0;
715 env->left_to_right = (env->call->flags & BE_ABI_LEFT_TO_RIGHT) != 0;
717 env->stack_ops = pset_new_ptr(32);
718 env->dbg = firm_dbg_register("firm.be.abi");
719 obstack_init(&env->obst);
721 /* search for stack allocation nodes and record them */
722 irg_walk_graph(env->birg->irg, collect_alloca_walker, NULL, env);
723 obstack_ptr_grow(&env->obst, NULL);
724 stack_allocs = obstack_finish(&env->obst);
726 /* If there are stack allocations in the irg, we need a frame pointer */
727 if(stack_allocs[0] != NULL)
732 for(i = 0; stack_allocs[i] != NULL; ++i)
733 implement_stack_alloc(env, stack_allocs[i]);
735 irg_walk_graph(env->birg->irg, NULL, adjust_call_walker, env);
739 static void collect_stack_nodes(ir_node *irn, void *data)
743 switch(be_get_irn_opcode(irn)) {
746 pset_insert_ptr(s, irn);
750 void be_abi_fix_stack_nodes(be_abi_irg_t *env)
752 dom_front_info_t *df;
755 /* We need dominance frontiers for fix up */
756 df = be_compute_dominance_frontiers(env->birg->irg);
758 stack_ops = pset_new_ptr_default();
759 pset_insert_ptr(env->stack_ops, env->init_sp);
760 irg_walk_graph(env->birg->irg, collect_stack_nodes, NULL, stack_ops);
761 be_ssa_constr_set(df, stack_ops);
764 /* free these dominance frontiers */
765 be_free_dominance_frontiers(df);
768 static int get_dir(ir_node *irn)
770 return 1 - 2 * (be_get_IncSP_direction(irn) == be_stack_dir_against);
773 static int process_stack_bias(be_abi_irg_t *env, ir_node *bl, int bias)
775 const arch_env_t *aenv = env->birg->main_env->arch_env;
777 int start_bias = bias;
779 sched_foreach(bl, irn) {
780 if(be_is_IncSP(irn)) {
781 int ofs = be_get_IncSP_offset(irn);
782 int dir = get_dir(irn);
784 if(ofs == BE_STACK_FRAME_SIZE) {
785 ofs = get_type_size_bytes(get_irg_frame_type(env->birg->irg));
786 be_set_IncSP_offset(irn, ofs);
793 arch_set_stack_bias(aenv, irn, bias);
799 static void stack_bias_walker(ir_node *bl, void *data)
801 if(bl != get_irg_start_block(get_irn_irg(bl))) {
802 be_abi_irg_t *env = data;
803 process_stack_bias(env, bl, env->start_block_bias);
807 void be_abi_fix_stack_bias(be_abi_irg_t *env)
809 ir_graph *irg = env->birg->irg;
811 /* Determine the stack bias at the and of the start block. */
812 env->start_block_bias = process_stack_bias(env, get_irg_start_block(irg), 0);
814 /* fix the bias is all other blocks */
815 irg_block_walk_graph(irg, stack_bias_walker, NULL, env);
818 void be_abi_free(be_abi_irg_t *env)
820 del_pset(env->stack_ops);
821 obstack_free(&env->obst, NULL);
825 ir_node *be_abi_get_callee_save_node(be_abi_irg_t *abi, const arch_register_t *reg)
827 assert(arch_register_type_is(reg, callee_save));
828 assert(pmap_contains(abi->regs, (void *) reg));
829 return pmap_get(abi->regs, (void *) reg);