public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed][OG10] amdgcn: Fix DWARF variables with alloca
@ 2021-01-15 11:51 Andrew Stubbs
  0 siblings, 0 replies; only message in thread
From: Andrew Stubbs @ 2021-01-15 11:51 UTC (permalink / raw)
  To: gcc-patches

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

This patch fixes DWARF frame calculations for functions that use alloca 
on AMD GCN.

Like many other platforms, it achieves this by switching to 
frame-pointer mode for this function.

The frame pointer is necessary for debugability only, so if the user 
specifies -fomit-frame-pointer then this is honoured.

Committed to devel/omp/gcc-10. The prerequisite CFI patches don't exist 
on mainline yet.

Andrew

[-- Attachment #2: 210115-og10-fix-dwarf-alloca.patch --]
[-- Type: text/x-patch, Size: 1926 bytes --]

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 --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c
index ea88b5e9124..1cb92714f24 100644
--- a/gcc/config/gcn/gcn.c
+++ b/gcc/config/gcn/gcn.c
@@ -3009,6 +3009,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)));
     }
@@ -3120,10 +3130,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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-15 11:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 11:51 [committed][OG10] amdgcn: Fix DWARF variables with alloca Andrew Stubbs

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).