public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Kwok Yeung <kcy@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-11] amdgcn: Fix DWARF variables with alloca
Date: Thu, 13 May 2021 16:18:40 +0000 (GMT)	[thread overview]
Message-ID: <20210513161840.B4B3F3AA7C9B@sourceware.org> (raw)

https://gcc.gnu.org/g:2e1eeae22bcbec6e17275417d7b8bc97300b7cb0

commit 2e1eeae22bcbec6e17275417d7b8bc97300b7cb0
Author: Andrew Stubbs <ams@codesourcery.com>
Date:   Fri Jan 8 13:56:52 2021 +0000

    amdgcn: Fix DWARF variables with alloca
    
    Require a frame pointer for entry functions that use alloca because it isn't
    possible to encode the DWARF frame otherwise.  Adjust the CFA definition
    expressions accordingly.
    
    gcc/ChangeLog:
    
            * config/gcn/gcn.c (gcn_expand_prologue): Use the frame pointer for
            the DWARF CFA, if it exists.
            (gcn_frame_pointer_rqd): Require a frame pointer for entry functions
            that use alloca.

Diff:
---
 gcc/config/gcn/gcn.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c
index c1823e8747e..784bae43419 100644
--- a/gcc/config/gcn/gcn.c
+++ b/gcc/config/gcn/gcn.c
@@ -3033,6 +3033,16 @@ gcn_expand_prologue ()
 		    gen_rtx_SET (sp, gen_rtx_PLUS (DImode, sp,
 						   dbg_adjustment)));
 
+      if (offsets->need_frame_pointer)
+	{
+	  /* Set the CFA to the entry stack address, as an offset from the
+	     frame pointer.  This is necessary when alloca is used, and
+	     harmless otherwise.  */
+	  rtx neg_adjust = gen_int_mode (-offsets->callee_saves, DImode);
+	  add_reg_note (insn, REG_CFA_DEF_CFA,
+			gen_rtx_PLUS (DImode, fp, neg_adjust));
+	}
+
       /* Make sure the flat scratch reg doesn't get optimised away.  */
       emit_insn (gen_prologue_use (gen_rtx_REG (DImode, FLAT_SCRATCH_REG)));
     }
@@ -3144,10 +3154,13 @@ bool
 gcn_frame_pointer_rqd (void)
 {
   /* GDB needs the frame pointer in order to unwind properly,
-     but that's not important for the entry point.
-     We should also repect the -fomit-frame-pointer flag.  */
-  return (cfun && cfun->machine && cfun->machine->normal_function
-	  && !flag_omit_frame_pointer);
+     but that's not important for the entry point, unless alloca is used.
+     It's not important for code execution, so we should repect the
+     -fomit-frame-pointer flag.  */
+  return (!flag_omit_frame_pointer
+	  && cfun
+	  && (cfun->calls_alloca
+	      || (cfun->machine && cfun->machine->normal_function)));
 }
 
 /* Implement TARGET_CAN_ELIMINATE.


                 reply	other threads:[~2021-05-13 16:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210513161840.B4B3F3AA7C9B@sourceware.org \
    --to=kcy@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).