]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
amdgcn: Fix DWARF variables with alloca
authorAndrew Stubbs <ams@codesourcery.com>
Fri, 8 Jan 2021 13:56:52 +0000 (13:56 +0000)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Thu, 22 Apr 2021 17:14:31 +0000 (10:14 -0700)
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.

gcc/config/gcn/gcn.c

index c1823e8747e0a1771ba1074c28c69284cb33bae3..784bae434198e1184430481b416c4ce0e32d0efd 100644 (file)
@@ -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.