From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id DD15B3948A51 for ; Tue, 22 Jun 2021 17:15:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD15B3948A51 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: ugOqRGTKv+4uWcooKUs8YhCjI7SPIBC7glJRQQ1q0hnUHgxF1lQwcxcMESXtcpi5dbrDjqJSym S+0/L38q6ww8OZrQwTCjziOSOMbj6CBVbhfp7SqWPlSwnSPpZszAqHWcF4i2NZxt6jCnIiSpa8 w7yOKt8zRmP6BXNWb+3FcjaISuPlwYK6BBQOAUB/i5nX853cRrsYCy5Rifi7UllFx+wpj5sLuE DD9bpzmh0APMy9ECqxI2z5yTvAa/QGMMmhWrqCVH7o4psUxcUqRgRMfiz1OB/W6tnghuohp+c8 YRg= X-IronPort-AV: E=Sophos;i="5.83,291,1616486400"; d="scan'208";a="62667451" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 22 Jun 2021 09:15:14 -0800 IronPort-SDR: GUlLQEWFSFvc6SlsFwcAlEfHuUAc9+GOyX4lzmZ9UmyKnzLABP0ywT71a4O6UrC1MzQDvjLU47 NL3rNyEgOJwvfOFHTOHvRLdWm35i9WUhiU1zNDNXzJp5bmBORGm8zpjwF1g6ryOv5a1mIyD8Uu HXSLrn6uUcdEzh9YIrC4uVV7tdsM5ZjEght0AbFt6kn0gxuYFTy4sY4Fzzzj01Q9PedCNBF+Ng NRC7aDe7dV8DfxhHBeYj3MkiUYt+vVDVz0VRRrsD2wg0qy7FnoGg4ebEsigUn5pzVyrvBfO0UU BOQ= From: Hafiz Abid Qadeer To: CC: , Subject: [PATCH 2/3] [amdgcn] Use frame pointer for CFA expressions. Date: Tue, 22 Jun 2021 18:14:42 +0100 Message-ID: <20210622171443.1287801-3-abidh@codesourcery.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210622171443.1287801-1-abidh@codesourcery.com> References: <20210622171443.1287801-1-abidh@codesourcery.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jun 2021 17:15:17 -0000 As size of address is bigger than registers in amdgcn, we are forced to use DW_CFA_def_cfa_expression to make an expression that concatenates multiple registers for the value of the CFA. This then prohibits us from using many of the dwarf ops which expect CFA rule to be a single regsiter plus an offset. Using frame pointer in the CFA rule is only real possibility as it is saved in every frame and it is easy to unwind its value. So unless user gives fomit-frame-pointer, we use frame pointer for the cfi information. This options also has a different default now. gcc/ * common/config/gcn/gcn-common.c (gcn_option_optimization_table): Change OPT_fomit_frame_pointer to -O3. (gcn_expand_prologue): Prefer the frame pointer when emitting CFI. (gcn_frame_pointer_rqd): New function. (TARGET_FRAME_POINTER_REQUIRED): New hook. --- gcc/common/config/gcn/gcn-common.c | 2 +- gcc/config/gcn/gcn.c | 60 +++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/gcc/common/config/gcn/gcn-common.c b/gcc/common/config/gcn/gcn-common.c index 305c310f940..695eb467e34 100644 --- a/gcc/common/config/gcn/gcn-common.c +++ b/gcc/common/config/gcn/gcn-common.c @@ -27,7 +27,7 @@ /* Set default optimization options. */ static const struct default_options gcn_option_optimization_table[] = { - { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 }, + { OPT_LEVELS_3_PLUS, OPT_fomit_frame_pointer, NULL, 1 }, { OPT_LEVELS_NONE, 0, NULL, 0 } }; diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c index 3ab16548aad..0eac3aa3844 100644 --- a/gcc/config/gcn/gcn.c +++ b/gcc/config/gcn/gcn.c @@ -2900,10 +2900,14 @@ gcn_expand_prologue () rtx adjustment = gen_int_mode (sp_adjust, SImode); rtx insn = emit_insn (gen_addsi3_scalar_carry (sp_lo, sp_lo, adjustment, scc)); - RTX_FRAME_RELATED_P (insn) = 1; - add_reg_note (insn, REG_FRAME_RELATED_EXPR, - gen_rtx_SET (sp, - gen_rtx_PLUS (DImode, sp, adjustment))); + if (!offsets->need_frame_pointer) + { + RTX_FRAME_RELATED_P (insn) = 1; + add_reg_note (insn, REG_FRAME_RELATED_EXPR, + gen_rtx_SET (sp, + gen_rtx_PLUS (DImode, sp, + adjustment))); + } emit_insn (gen_addcsi3_scalar_zero (sp_hi, sp_hi, scc)); } @@ -2917,25 +2921,24 @@ gcn_expand_prologue () rtx adjustment = gen_int_mode (fp_adjust, SImode); rtx insn = emit_insn (gen_addsi3_scalar_carry(fp_lo, sp_lo, adjustment, scc)); - RTX_FRAME_RELATED_P (insn) = 1; - add_reg_note (insn, REG_FRAME_RELATED_EXPR, - gen_rtx_SET (fp, - gen_rtx_PLUS (DImode, sp, adjustment))); emit_insn (gen_addcsi3_scalar (fp_hi, sp_hi, (fp_adjust < 0 ? GEN_INT (-1) : const0_rtx), scc, scc)); + + /* Set the CFA to the entry stack address, as an offset from the + frame pointer. This is preferred because the frame pointer is + saved in each frame, whereas the stack pointer is not. */ + RTX_FRAME_RELATED_P (insn) = 1; + add_reg_note (insn, REG_CFA_DEF_CFA, + gen_rtx_PLUS (DImode, fp, + GEN_INT (-(offsets->pretend_size + + offsets->callee_saves)))); } rtx_insn *seq = get_insns (); end_sequence (); - /* FIXME: Prologue insns should have this flag set for debug output, etc. - but it causes issues for now. - for (insn = seq; insn; insn = NEXT_INSN (insn)) - if (INSN_P (insn)) - RTX_FRAME_RELATED_P (insn) = 1;*/ - emit_insn (seq); } else @@ -3011,6 +3014,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))); } @@ -3114,6 +3127,23 @@ gcn_expand_epilogue (void) emit_jump_insn (gen_gcn_return ()); } +/* Implement TARGET_FRAME_POINTER_REQUIRED. + + Return true if the frame pointer should not be eliminated. */ + +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, 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. Return true if the compiler is allowed to try to replace register number @@ -6373,6 +6403,8 @@ gcn_dwarf_register_span (rtx rtl) #define TARGET_EMUTLS_VAR_INIT gcn_emutls_var_init #undef TARGET_EXPAND_BUILTIN #define TARGET_EXPAND_BUILTIN gcn_expand_builtin +#undef TARGET_FRAME_POINTER_REQUIRED +#define TARGET_FRAME_POINTER_REQUIRED gcn_frame_pointer_rqd #undef TARGET_FUNCTION_ARG #undef TARGET_FUNCTION_ARG_ADVANCE #define TARGET_FUNCTION_ARG_ADVANCE gcn_function_arg_advance -- 2.25.1