public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch,Aarch64] Make frame grow downwards
@ 2013-06-28 11:46 Christophe Lyon
  2013-08-30 15:21 ` Christophe Lyon
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christophe Lyon @ 2013-06-28 11:46 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 666 bytes --]

Hi,
Following the discussion on
http://gcc.gnu.org/ml/gcc/2013-05/msg00208.html
here is a patch to change the frame direction.

Passed 'make check' with no regression on aarch64-none-linux-gnu and
with a few UNSUPPORTED -> PASS on aarch64-none-elf (pr34225, pr38616,
pr38902, pr40971, pr46440, pr47766, pr49307, all of which are guarded
by dg-require-effective-target fstack_protector).

OK for trunk?

Thanks,

Christophe.
2013-06-28  Christophe Lyon  <christophe.lyon@linaro.org>

* config/aarch64/aarch64.h (FRAME_GROWS_DOWNWARD): Define to 1.
* config/aarch64/aarch64.c (aarch64_initial_elimination_offset):
Add get_frame_size () when eliminating frame pointer.

[-- Attachment #2: aarch64-frame.txt --]
[-- Type: text/plain, Size: 2148 bytes --]

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 527b00d..d8f2801 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -1943,7 +1943,7 @@ aarch64_save_or_restore_callee_save_registers (HOST_WIDE_INT offset,
    Establish the stack frame by decreasing the stack pointer with a
    properly calculated size and, if necessary, create a frame record
    filled with the values of LR and previous frame pointer.  The
-   current FP is also set up is it is in use.  */
+   current FP is also set up if it is in use.  */
 
 void
 aarch64_expand_prologue (void)
@@ -4031,7 +4031,7 @@ aarch64_initial_elimination_offset (unsigned from, unsigned to)
 	 return offset - crtl->outgoing_args_size;
 
        if (from == FRAME_POINTER_REGNUM)
-	 return cfun->machine->frame.saved_regs_size;
+	 return cfun->machine->frame.saved_regs_size + get_frame_size ();
      }
 
    if (to == STACK_POINTER_REGNUM)
@@ -4040,6 +4040,7 @@ aarch64_initial_elimination_offset (unsigned from, unsigned to)
          {
            HOST_WIDE_INT elim = crtl->outgoing_args_size
                               + cfun->machine->frame.saved_regs_size
+                              + get_frame_size ()
                               - cfun->machine->frame.fp_lr_offset;
            elim = AARCH64_ROUND_UP (elim, STACK_BOUNDARY / BITS_PER_UNIT);
            return elim;
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index a08797b..5048258 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -434,7 +434,7 @@ enum reg_class
 #define INDEX_REG_CLASS	CORE_REGS
 #define BASE_REG_CLASS  POINTER_REGS
 
-/* Register pairs used to eliminate unneeded registers that point intoi
+/* Register pairs used to eliminate unneeded registers that point into
    the stack frame.  */
 #define ELIMINABLE_REGS							\
 {									\
@@ -475,7 +475,7 @@ extern enum aarch64_processor aarch64_tune;
 /* Stack layout; function entry, exit and calling.  */
 #define STACK_GROWS_DOWNWARD	1
 
-#define FRAME_GROWS_DOWNWARD	0
+#define FRAME_GROWS_DOWNWARD	1
 
 #define STARTING_FRAME_OFFSET	0
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch,Aarch64] Make frame grow downwards
  2013-06-28 11:46 [Patch,Aarch64] Make frame grow downwards Christophe Lyon
@ 2013-08-30 15:21 ` Christophe Lyon
  2013-11-12  4:40 ` Christophe Lyon
  2013-11-12 17:38 ` Richard Earnshaw
  2 siblings, 0 replies; 4+ messages in thread
From: Christophe Lyon @ 2013-08-30 15:21 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]

Hi,

Following our discussions about changing the frame direction on
aarch64, I have written a small test case using a large frame which
shows similar code generation with and without my patch. There
are small differences in register allocation which lead to larger
prologue/epilogue with my patch, but I think this could (should) be
improved independently.

I have attached the sample C source and the code generated with
(frane64.s.O2) and without (frame64.s.O2.ref) my patch when compiling
at -O2.

What do you think?

Thanks,

Christophe.

On 28 June 2013 13:41, Christophe Lyon <christophe.lyon@linaro.org> wrote:
> Hi,
> Following the discussion on
> http://gcc.gnu.org/ml/gcc/2013-05/msg00208.html
> here is a patch to change the frame direction.
>
> Passed 'make check' with no regression on aarch64-none-linux-gnu and
> with a few UNSUPPORTED -> PASS on aarch64-none-elf (pr34225, pr38616,
> pr38902, pr40971, pr46440, pr47766, pr49307, all of which are guarded
> by dg-require-effective-target fstack_protector).
>
> OK for trunk?
>
> Thanks,
>
> Christophe.
> 2013-06-28  Christophe Lyon  <christophe.lyon@linaro.org>
>
> * config/aarch64/aarch64.h (FRAME_GROWS_DOWNWARD): Define to 1.
> * config/aarch64/aarch64.c (aarch64_initial_elimination_offset):
> Add get_frame_size () when eliminating frame pointer.

[-- Attachment #2: frame64.c --]
[-- Type: text/x-csrc, Size: 347 bytes --]

#define SIZE1 100000

extern int func2(int);

int func1(int arg1, int arg2)
{
  int var1;
  int array1[SIZE1];
  int var2 = 0;

  for (var1 = arg1; var1 < arg2; var1++) {
    array1[var1] = func2(var1);
  }

  for (var1 = arg1; var1 < arg2; var1++) {
    var2 += array1[var1];
  }

  var2 += (array1[arg1] + array1[arg2-1]) / 2;

  return var2;
}

[-- Attachment #3: frame64.s.O2 --]
[-- Type: application/octet-stream, Size: 969 bytes --]

	.cpu generic
	.file	"frame64.c"
	.text
	.align	2
	.global	func1
	.type	func1, %function
func1:
	sub	sp, sp, #397312
	sub	sp, sp, #2688
	stp	x29, x30, [sp, -64]!
	add	x29, sp, 0
	stp	x19, x20, [sp,16]
	stp	x21, x22, [sp,32]
	str	x23, [sp,48]
	cmp	w0, w1
	mov	w22, w0
	mov	w20, w1
	bge	.L6
	add	x23, x29, 2752
	mov	w19, w0
	sub	x21, x23, #2688
.L4:
	mov	w0, w19
	bl	func2
	str	w0, [x21,w19,sxtw 2]
	add	w19, w19, 1
	cmp	w19, w20
	bne	.L4
	mov	w2, w22
	mov	w1, 0
	sub	x4, x23, #2688
.L5:
	ldr	w3, [x4,w2,sxtw 2]
	add	w2, w2, 1
	cmp	w2, w20
	add	w1, w1, w3
	bne	.L5
.L2:
	sub	x23, x23, #2688
	sub	w20, w20, #1
	ldr	w2, [x23,w22,sxtw 2]
	ldr	w0, [x23,w20,sxtw 2]
	ldp	x21, x22, [sp,32]
	ldp	x19, x20, [sp,16]
	ldr	x23, [sp,48]
	ldp	x29, x30, [sp], 64
	add	w0, w2, w0
	add	sp, sp, 2688
	add	w0, w0, w0, lsr 31
	add	w0, w1, w0, asr 1
	add	sp, sp, 397312
	ret
.L6:
	mov	w1, 0
	add	x23, x29, 2752
	b	.L2
	.size	func1, .-func1
	.ident	"GCC: (GNU) 4.9.0 20130523 (experimental)"

[-- Attachment #4: frame64.s.O2.ref --]
[-- Type: application/octet-stream, Size: 869 bytes --]

	.cpu generic
	.file	"frame64.c"
	.text
	.align	2
	.global	func1
	.type	func1, %function
func1:
	sub	sp, sp, #397312
	sub	sp, sp, #2688
	stp	x29, x30, [sp, -48]!
	add	x29, sp, 0
	stp	x19, x20, [sp,16]
	str	x21, [sp,32]
	cmp	w0, w1
	mov	w21, w0
	mov	w20, w1
	bge	.L6
	mov	w19, w0
.L4:
	mov	w0, w19
	bl	func2
	add	x1, x29, 48
	str	w0, [x1,w19,sxtw 2]
	add	w19, w19, 1
	cmp	w19, w20
	bne	.L4
	mov	w2, w21
	mov	w1, 0
.L5:
	add	x0, x29, 48
	ldr	w3, [x0,w2,sxtw 2]
	add	w2, w2, 1
	cmp	w2, w20
	add	w1, w1, w3
	bne	.L5
.L2:
	add	x3, x29, 48
	sub	w20, w20, #1
	ldr	w2, [x3,w21,sxtw 2]
	ldr	w0, [x3,w20,sxtw 2]
	ldr	x21, [sp,32]
	ldp	x19, x20, [sp,16]
	ldp	x29, x30, [sp], 48
	add	w0, w2, w0
	add	sp, sp, 2688
	add	w0, w0, w0, lsr 31
	add	w0, w1, w0, asr 1
	add	sp, sp, 397312
	ret
.L6:
	mov	w1, 0
	b	.L2
	.size	func1, .-func1
	.ident	"GCC: (GNU) 4.9.0 20130523 (experimental)"

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch,Aarch64] Make frame grow downwards
  2013-06-28 11:46 [Patch,Aarch64] Make frame grow downwards Christophe Lyon
  2013-08-30 15:21 ` Christophe Lyon
@ 2013-11-12  4:40 ` Christophe Lyon
  2013-11-12 17:38 ` Richard Earnshaw
  2 siblings, 0 replies; 4+ messages in thread
From: Christophe Lyon @ 2013-11-12  4:40 UTC (permalink / raw)
  To: gcc-patches, Richard Earnshaw, Patch Tracking

Ping?

The original post is here:
http://gcc.gnu.org/ml/gcc-patches/2013-06/msg01588.html

Thanks,

Christophe.


On 28 June 2013 13:41, Christophe Lyon <christophe.lyon@linaro.org> wrote:
> Hi,
> Following the discussion on
> http://gcc.gnu.org/ml/gcc/2013-05/msg00208.html
> here is a patch to change the frame direction.
>
> Passed 'make check' with no regression on aarch64-none-linux-gnu and
> with a few UNSUPPORTED -> PASS on aarch64-none-elf (pr34225, pr38616,
> pr38902, pr40971, pr46440, pr47766, pr49307, all of which are guarded
> by dg-require-effective-target fstack_protector).
>
> OK for trunk?
>
> Thanks,
>
> Christophe.
> 2013-06-28  Christophe Lyon  <christophe.lyon@linaro.org>
>
> * config/aarch64/aarch64.h (FRAME_GROWS_DOWNWARD): Define to 1.
> * config/aarch64/aarch64.c (aarch64_initial_elimination_offset):
> Add get_frame_size () when eliminating frame pointer.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch,Aarch64] Make frame grow downwards
  2013-06-28 11:46 [Patch,Aarch64] Make frame grow downwards Christophe Lyon
  2013-08-30 15:21 ` Christophe Lyon
  2013-11-12  4:40 ` Christophe Lyon
@ 2013-11-12 17:38 ` Richard Earnshaw
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Earnshaw @ 2013-11-12 17:38 UTC (permalink / raw)
  To: Christophe Lyon; +Cc: gcc-patches

On 28/06/13 12:41, Christophe Lyon wrote:
> Hi,
> Following the discussion on
> http://gcc.gnu.org/ml/gcc/2013-05/msg00208.html
> here is a patch to change the frame direction.
> 
> Passed 'make check' with no regression on aarch64-none-linux-gnu and
> with a few UNSUPPORTED -> PASS on aarch64-none-elf (pr34225, pr38616,
> pr38902, pr40971, pr46440, pr47766, pr49307, all of which are guarded
> by dg-require-effective-target fstack_protector).
> 
> OK for trunk?
> 
> Thanks,
> 
> Christophe.
> 2013-06-28  Christophe Lyon  <christophe.lyon@linaro.org>
> 
> * config/aarch64/aarch64.h (FRAME_GROWS_DOWNWARD): Define to 1.
> * config/aarch64/aarch64.c (aarch64_initial_elimination_offset):
> Add get_frame_size () when eliminating frame pointer.

In general, when the files changed are same as the name of the port,
it's ok to write:

  * aarch64.h (...): ...

For aarch64_initial_elimination_offset, I suggest "Update offset
calculations."

Otherwise OK.

R.

> 
> 
> aarch64-frame.txt
> 
> 
> diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
> index 527b00d..d8f2801 100644
> --- a/gcc/config/aarch64/aarch64.c
> +++ b/gcc/config/aarch64/aarch64.c
> @@ -1943,7 +1943,7 @@ aarch64_save_or_restore_callee_save_registers (HOST_WIDE_INT offset,
>     Establish the stack frame by decreasing the stack pointer with a
>     properly calculated size and, if necessary, create a frame record
>     filled with the values of LR and previous frame pointer.  The
> -   current FP is also set up is it is in use.  */
> +   current FP is also set up if it is in use.  */
>  
>  void
>  aarch64_expand_prologue (void)
> @@ -4031,7 +4031,7 @@ aarch64_initial_elimination_offset (unsigned from, unsigned to)
>  	 return offset - crtl->outgoing_args_size;
>  
>         if (from == FRAME_POINTER_REGNUM)
> -	 return cfun->machine->frame.saved_regs_size;
> +	 return cfun->machine->frame.saved_regs_size + get_frame_size ();
>       }
>  
>     if (to == STACK_POINTER_REGNUM)
> @@ -4040,6 +4040,7 @@ aarch64_initial_elimination_offset (unsigned from, unsigned to)
>           {
>             HOST_WIDE_INT elim = crtl->outgoing_args_size
>                                + cfun->machine->frame.saved_regs_size
> +                              + get_frame_size ()
>                                - cfun->machine->frame.fp_lr_offset;
>             elim = AARCH64_ROUND_UP (elim, STACK_BOUNDARY / BITS_PER_UNIT);
>             return elim;
> diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
> index a08797b..5048258 100644
> --- a/gcc/config/aarch64/aarch64.h
> +++ b/gcc/config/aarch64/aarch64.h
> @@ -434,7 +434,7 @@ enum reg_class
>  #define INDEX_REG_CLASS	CORE_REGS
>  #define BASE_REG_CLASS  POINTER_REGS
>  
> -/* Register pairs used to eliminate unneeded registers that point intoi
> +/* Register pairs used to eliminate unneeded registers that point into
>     the stack frame.  */
>  #define ELIMINABLE_REGS							\
>  {									\
> @@ -475,7 +475,7 @@ extern enum aarch64_processor aarch64_tune;
>  /* Stack layout; function entry, exit and calling.  */
>  #define STACK_GROWS_DOWNWARD	1
>  
> -#define FRAME_GROWS_DOWNWARD	0
> +#define FRAME_GROWS_DOWNWARD	1
>  
>  #define STARTING_FRAME_OFFSET	0
>  
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-12 16:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-28 11:46 [Patch,Aarch64] Make frame grow downwards Christophe Lyon
2013-08-30 15:21 ` Christophe Lyon
2013-11-12  4:40 ` Christophe Lyon
2013-11-12 17:38 ` Richard Earnshaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).