This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
ARM ATPCS stack alignment
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Richard dot Earnshaw at arm dot com
- Date: Thu, 21 Nov 2002 10:25:55 +0000
- Subject: ARM ATPCS stack alignment
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
This small tweak optimizes the leaf-function case so that we can avoid
unnecessarily padding out a stack frame to eight-byte alignment when there
is no need.
2002-11-21 Richard Earnshaw <rearnsha@arm.com>
* arm.c (arm_get_frame_size): A leaf function does not need its
stack padding to an aligned boundary if it has no frame.
(thumb_get_frame_size): Likewise.
Index: config/arm/arm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.242
diff -p -r1.242 arm.c
*** config/arm/arm.c 15 Nov 2002 11:21:35 -0000 1.242
--- config/arm/arm.c 21 Nov 2002 10:19:37 -0000
*************** arm_get_frame_size ()
*** 8252,8257 ****
--- 8252,8258 ----
int base_size = ROUND_UP (get_frame_size ());
int entry_size = 0;
unsigned long func_type = arm_current_func_type ();
+ int leaf;
if (! TARGET_ARM)
abort();
*************** arm_get_frame_size ()
*** 8259,8264 ****
--- 8260,8290 ----
if (! TARGET_ATPCS)
return base_size;
+ /* We need to know if we are a leaf function. Unfortunately, it
+ is possible to be called after start_sequence has been called,
+ which causes get_insns to return the insns for the sequence,
+ not the function, which will cause leaf_function_p to return
+ the incorrect result.
+
+ To work around this, we cache the computed frame size. This
+ works because we will only be calling RTL expanders that need
+ to know about leaf functions once reload has completed, and the
+ frame size cannot be changed after that time, so we can safely
+ use the cached value. */
+
+ if (reload_completed)
+ return cfun->machine->frame_size;
+
+ leaf = leaf_function_p ();
+
+ /* A leaf function does not need any stack alignment if it has nothing
+ on the stack. */
+ if (leaf && base_size == 0)
+ {
+ cfun->machine->frame_size = 0;
+ return 0;
+ }
+
/* We know that SP will be word aligned on entry, and we must
preserve that condition at any subroutine call. But those are
the only constraints. */
*************** arm_get_frame_size ()
*** 8283,8288 ****
--- 8309,8316 ----
if ((entry_size + base_size + current_function_outgoing_args_size) & 7)
abort ();
+ cfun->machine->frame_size = base_size;
+
return base_size;
}
*************** thumb_get_frame_size ()
*** 10278,10283 ****
--- 10306,10312 ----
int base_size = ROUND_UP (get_frame_size ());
int count_regs = 0;
int entry_size = 0;
+ int leaf;
if (! TARGET_THUMB)
abort ();
*************** thumb_get_frame_size ()
*** 10300,10305 ****
--- 10329,10344 ----
if (reload_completed)
return cfun->machine->frame_size;
+ leaf = leaf_function_p ();
+
+ /* A leaf function does not need any stack alignment if it has nothing
+ on the stack. */
+ if (leaf && base_size == 0)
+ {
+ cfun->machine->frame_size = 0;
+ return 0;
+ }
+
/* We know that SP will be word aligned on entry, and we must
preserve that condition at any subroutine call. But those are
the only constraints. */
*************** thumb_get_frame_size ()
*** 10322,10328 ****
entry_size += 16;
}
! if (count_regs || !leaf_function_p () || thumb_far_jump_used_p (1))
count_regs++; /* LR */
entry_size += count_regs * 4;
--- 10361,10367 ----
entry_size += 16;
}
! if (count_regs || !leaf || thumb_far_jump_used_p (1))
count_regs++; /* LR */
entry_size += count_regs * 4;