static heights_t *ir_heights;
-/* Flag: if set, try to omit the frame pointer if called by the backend */
+/** Flag: if set, try to omit the frame pointer in all routines. */
static int be_omit_fp = 1;
+/** Flag: if set, try to omit the frame pointer in leaf routines only. */
+static int be_omit_leaf_fp = 1;
+
/*
_ ____ ___ ____ _ _ _ _
/ \ | __ )_ _| / ___|__ _| | | |__ __ _ ___| | _____
call->cb = NULL;
call->cls_addr = cls_addr;
- call->flags.bits.try_omit_fp = be_omit_fp;
+ call->flags.bits.try_omit_fp = be_omit_fp | be_omit_leaf_fp;
return call;
}
ir_node *new_alloc, *size, *addr, *ins[2];
unsigned stack_alignment;
- if (get_Alloc_where(alloc) != stack_alloc) {
- assert(0);
- return alloc;
- }
+ assert(get_Alloc_where(alloc) == stack_alloc);
block = get_nodes_block(alloc);
irg = get_irn_irg(block);
ir_node *irn = get_edge_src_irn(edge);
assert(is_Proj(irn));
- switch(get_Proj_proj(irn)) {
+ switch (get_Proj_proj(irn)) {
case pn_Alloc_M:
alloc_mem = irn;
break;
dbg = get_irn_dbg_info(alloc);
/* we might need to multiply the size with the element size */
- if(type != get_unknown_type() && get_type_size_bytes(type) != 1) {
+ if (type != firm_unknown_type && get_type_size_bytes(type) != 1) {
tarval *tv = new_tarval_from_long(get_type_size_bytes(type),
mode_Iu);
ir_node *cnst = new_rd_Const(dbg, irg, block, mode_Iu, tv);
We cannot omit it. */
env->call->flags.bits.try_omit_fp = 0;
- stack_alignment = env->arch_env->stack_alignment;
+ stack_alignment = 1 << env->arch_env->stack_alignment;
size = adjust_alloc_size(stack_alignment, size, irg, block, dbg);
new_alloc = be_new_AddSP(env->arch_env->sp, irg, block, curr_sp, size);
set_irn_dbg_info(new_alloc, dbg);
unsigned stack_alignment;
dbg_info *dbg;
- if (get_Free_where(free) != stack_alloc) {
- assert(0);
- return free;
- }
+ assert(get_Free_where(free) == stack_alloc);
block = get_nodes_block(free);
irg = get_irn_irg(block);
dbg = get_irn_dbg_info(free);
/* we might need to multiply the size with the element size */
- if(type != get_unknown_type() && get_type_size_bytes(type) != 1) {
+ if (type != firm_unknown_type && get_type_size_bytes(type) != 1) {
tarval *tv = new_tarval_from_long(get_type_size_bytes(type), mode_Iu);
ir_node *cnst = new_rd_Const(dbg, irg, block, mode_Iu, tv);
ir_node *mul = new_rd_Mul(dbg, irg, block, get_Free_size(free),
size = get_Free_size(free);
}
- stack_alignment = env->arch_env->stack_alignment;
+ stack_alignment = 1 << env->arch_env->stack_alignment;
size = adjust_alloc_size(stack_alignment, size, irg, block, dbg);
/* The stack pointer will be modified in an unknown manner.
}
/**
- * Walker: links all Call/alloc/Free nodes to the Block they are contained.
+ * Walker: links all Call/Alloc/Free nodes to the Block they are contained.
+ * Clears the irg_is_leaf flag if a Call is detected.
*/
-static void link_calls_in_block_walker(ir_node *irn, void *data)
+static void link_ops_in_block_walker(ir_node *irn, void *data)
{
ir_opcode code = get_irn_opcode(irn);
if (code == iro_Call ||
- (code == iro_Alloc && get_Alloc_where(irn) == stack_alloc) ||
- (code == iro_Free && get_Free_where(irn) == stack_alloc)) {
+ (code == iro_Alloc && get_Alloc_where(irn) == stack_alloc) ||
+ (code == iro_Free && get_Free_where(irn) == stack_alloc)) {
be_abi_irg_t *env = data;
ir_node *bl = get_nodes_block(irn);
void *save = get_irn_link(bl);
/**
* Block-walker:
- * Process all Call nodes inside a basic block.
+ * Process all Call/Alloc/Free nodes inside a basic block.
* Note that the link field of the block must contain a linked list of all
* Call nodes inside the Block. We first order this list according to data dependency
* and that connect the calls together.
*/
-static void process_calls_in_block(ir_node *bl, void *data)
+static void process_ops_in_block(ir_node *bl, void *data)
{
be_abi_irg_t *env = data;
ir_node *curr_sp = env->init_sp;
ir_node *irn;
int n;
- for(irn = get_irn_link(bl), n = 0; irn; irn = get_irn_link(irn), ++n)
+ for (irn = get_irn_link(bl), n = 0; irn; irn = get_irn_link(irn), ++n)
obstack_ptr_grow(&env->obst, irn);
/* If there were call nodes in the block. */
- if(n > 0) {
+ if (n > 0) {
ir_node *keep;
ir_node **nodes;
int i;
/* order the call nodes according to data dependency */
qsort(nodes, n, sizeof(nodes[0]), cmp_call_dependency);
- for(i = n - 1; i >= 0; --i) {
+ for (i = n - 1; i >= 0; --i) {
ir_node *irn = nodes[i];
DBG((env->dbg, LEVEL_3, "\tprocessing call %+F\n", irn));
- switch(get_irn_opcode(irn)) {
+ switch (get_irn_opcode(irn)) {
case iro_Call:
+ if (! be_omit_fp) {
+ /* The stack pointer will be modified due to a call. */
+ env->call->flags.bits.try_omit_fp = 0;
+ }
curr_sp = adjust_call(env, irn, curr_sp);
break;
case iro_Alloc:
- curr_sp = adjust_alloc(env, irn, curr_sp);
+ if (get_Alloc_where(irn) == stack_alloc)
+ curr_sp = adjust_alloc(env, irn, curr_sp);
break;
case iro_Free:
- curr_sp = adjust_free(env, irn, curr_sp);
+ if (get_Free_where(irn) == stack_alloc)
+ curr_sp = adjust_free(env, irn, curr_sp);
break;
default:
panic("invalid call");
/* Keep the last stack state in the block by tying it to Keep node,
* the proj from calls is already kept */
- if(curr_sp != env->init_sp
- && !(is_Proj(curr_sp) && be_is_Call(get_Proj_pred(curr_sp)))) {
+ if (curr_sp != env->init_sp &&
+ !(is_Proj(curr_sp) && be_is_Call(get_Proj_pred(curr_sp)))) {
nodes[0] = curr_sp;
keep = be_new_Keep(env->arch_env->sp->reg_class,
get_irn_irg(bl), bl, 1, nodes);
ir_graph *irg = env->birg->irg;
env->call->flags.bits.irg_is_leaf = 1;
- irg_walk_graph(irg, firm_clear_link, link_calls_in_block_walker, env);
+ irg_walk_graph(irg, firm_clear_link, link_ops_in_block_walker, env);
ir_heights = heights_new(env->birg->irg);
- irg_block_walk_graph(irg, NULL, process_calls_in_block, env);
+ irg_block_walk_graph(irg, NULL, process_ops_in_block, env);
heights_free(ir_heights);
}
optimization_state_t state;
unsigned *limited_bitset;
- be_omit_fp = birg->main_env->options->omit_fp;
+ be_omit_fp = birg->main_env->options->omit_fp;
+ be_omit_leaf_fp = birg->main_env->options->omit_leaf_fp;
obstack_init(&env->obst);
/* patch IncSP to produce an aligned stack pointer */
ir_type *between_type = env->frame->between_type;
int between_size = get_type_size_bytes(between_type);
- int alignment = env->arch_env->stack_alignment;
- int delta = (real_bias + ofs + between_size) % env->arch_env->stack_alignment;
+ int alignment = 1 << env->arch_env->stack_alignment;
+ int delta = (real_bias + ofs + between_size) & (alignment - 1);
assert(ofs >= 0);
if (delta > 0) {
be_set_IncSP_offset(irn, ofs + alignment - delta);