This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[stack]: Allow to reduce alignment of caller-save stack slot


setup_save_areas calls assign_stack_local to allocate a stack slot
for a caller-save register in the widest mode. But at that stage,
we know the largest stack alignment needed for the function and
we can't increase the stack alignment for the caller-save stack
slot. We have 2 choices:

1. Change reload only to allocate a stack slot for the caller-save
register in the mode actually used in the function.
2. Allow assign_stack_local to reduce the alignment of the caller-save
stack slot.

#1 is a non-trivial change. This patch implemented #2.  The patch
for PR middle-end/36253:

http://gcc.gnu.org/ml/gcc-patches/2008-05/msg01029.html

will make sure that our approach provides the correct alignment to
store caller-save registers. I am checking this into stack branch.


H.J.
----
2008-05-17  Joey Ye  <joey.ye@intel.com>
	    H.J. Lu  <hongjiu.lu@intel.com>

	* caller-save.c (setup_save_areas): Call assign_stack_local_1
	instead of assign_stack_local to allow alignment reduction.

	* function.c (assign_stack_local_1): New function to implement
	original assign_stack_local with one additional parameter.
	(assign_stack_local): Wrap assign_stack_local_1 with one
	additional parameter.

	* rtl.h (assign_stack_local_1): Declare new funtion.

Index: caller-save.c
===================================================================
--- caller-save.c	(revision 135492)
+++ caller-save.c	(working copy)
@@ -358,8 +358,9 @@ setup_save_areas (void)
 
 	/* We have found an acceptable mode to store in.  */
 	regno_save_mem[i][j]
-	  = assign_stack_local (regno_save_mode[i][j],
-				GET_MODE_SIZE (regno_save_mode[i][j]), 0);
+	  = assign_stack_local_1 (regno_save_mode[i][j],
+				GET_MODE_SIZE (regno_save_mode[i][j]),
+				0, true);
 
 	/* Setup single word save area just in case...  */
 	for (k = 0; k < j; k++)
Index: function.c
===================================================================
--- function.c	(revision 135492)
+++ function.c	(working copy)
@@ -350,10 +350,14 @@ get_stack_local_alignment (tree type, en
    -2 means use BITS_PER_UNIT,
    positive specifies alignment boundary in bits.
 
+   If REDUCE_ALIGNMENT_OK is true, it is OK to reduce alignment.
+
    We do not round to stack_boundary here.  */
 
 rtx
-assign_stack_local (enum machine_mode mode, HOST_WIDE_INT size, int align)
+assign_stack_local_1 (enum machine_mode mode, HOST_WIDE_INT size,
+		      int align,
+		      bool reduce_alignment_ok ATTRIBUTE_UNUSED)
 {
   rtx x, addr;
   int bigend_correction = 0;
@@ -394,7 +398,8 @@ assign_stack_local (enum machine_mode mo
 		  /* It is OK to reduce the alignment as long as the
 		     requested size is 0 or the estimated stack
 		     alignment >= mode alignment.  */
-		  gcc_assert (size == 0
+		  gcc_assert (reduce_alignment_ok
+		              || size == 0
 			      || (crtl->stack_alignment_estimated
 				  >= GET_MODE_ALIGNMENT (mode)));
 		  alignment_in_bits = crtl->stack_alignment_estimated;
@@ -480,6 +485,14 @@ assign_stack_local (enum machine_mode mo
 
   return x;
 }
+
+/* Wrap up assign_stack_local_1 with last parameter as false.  */
+
+rtx
+assign_stack_local (enum machine_mode mode, HOST_WIDE_INT size, int align)
+{
+  return assign_stack_local_1 (mode, size, align, false);
+}
 
 /* Removes temporary slot TEMP from LIST.  */
 
Index: rtl.h
===================================================================
--- rtl.h	(revision 135492)
+++ rtl.h	(working copy)
@@ -1572,6 +1572,7 @@ extern rtx simplify_subtraction (rtx);
 
 /* In function.c  */
 extern rtx assign_stack_local (enum machine_mode, HOST_WIDE_INT, int);
+extern rtx assign_stack_local_1 (enum machine_mode, HOST_WIDE_INT, int, bool);
 extern rtx assign_stack_temp (enum machine_mode, HOST_WIDE_INT, int);
 extern rtx assign_stack_temp_for_type (enum machine_mode,
 				       HOST_WIDE_INT, int, tree);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]