From patchwork Fri Aug 4 12:26:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 797763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-459814-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YJu4lEbb"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xP5ky4dxGz9s7g for ; Fri, 4 Aug 2017 22:26:34 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type :content-transfer-encoding:mime-version; q=dns; s=default; b=q5G WRzPI6rjovmUbbEh19z2C9I+YECwJdbMWM/njy+jzuhT20rrMBKASTwkE/rVCWr4 l0L1yLAOpFMnY95csohZDev7i0Kc7SQZk3pxpU+lWRP0dQAo5uvSMk7INA6G4WZE hei6FFaXsR1eGeaF1PmBy0r4YzQe1JVoFpgYtBl8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type :content-transfer-encoding:mime-version; s=default; bh=G5T4+WMI8 alnDjp45I9Hc8Jlfv8=; b=YJu4lEbbwBk2yrIoWBeCKDk9IXIVXGlTFscNXNVco 4Ud7KDpVYncVZ9jwo06c+i7lRIh4WPy3Q0K1XRnrkCzz8mTucWzzJHXFzbohBVWX bwl7tab3/QwYT7+Py2KJnazvcDbxOctRER0vOqTQtj8IpH9PX1ujZwowt+M1AiGo b4= Received: (qmail 129941 invoked by alias); 4 Aug 2017 12:26:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 129598 invoked by uid 89); 4 Aug 2017 12:26:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=concepts, combines, Hx-languages-length:4426 X-HELO: EUR01-DB5-obe.outbound.protection.outlook.com Received: from mail-db5eur01on0040.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (104.47.2.40) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Aug 2017 12:26:19 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com (10.168.86.22) by DB6PR08MB2664.eurprd08.prod.outlook.com (10.175.234.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1304.22; Fri, 4 Aug 2017 12:26:16 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::cd9d:80f1:82d8:5181]) by DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::cd9d:80f1:82d8:5181%18]) with mapi id 15.01.1304.025; Fri, 4 Aug 2017 12:26:16 +0000 From: Wilco Dijkstra To: GCC Patches , James Greenhalgh CC: nd Subject: [PATCH][AArch64] Introduce emit_frame_chain Date: Fri, 4 Aug 2017 12:26:15 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR08MB2664; 6:VwkCUieGzzF9vrFgSroy4s+D5dZko1gSuSZcKkNt3JgQKWbjwPIRk3Dj0ua/x0dlOYrFKYhRNB6lX4T672nUT7TXqfdENxbMpvJOQU/620O3HQRpIP1hIDPYS87HgwftSNqWWLzw6cTCkc9y85zh2wdnMeWqgJ6uxF5MK2XdQc2rZnYjNXoUq8/RpSfeqbEVIGfU8qXsIi2Y8XkcojVJgtpAe+1tgOepqttSfmoY1ovNbclG8Eh/3bFzU7MVPwaebifFAOSbZtbQSaH8ElqChva9MI/MdE39TEIH4g9clXz2qUu+NIdQ0sA7Gd0s/b4c/4fGMIlPaEHzC/AzywlmmA==; 5:eABZn+VyYN60ErfjlREJilttWXoGmmUbHyKH7yicCPOT3bH4L+jfSqgavwYKqYAr1m+0zyLAY6f5jh2G91kefhBUp2CCCauJBc4IJJeBLQWp65OKcjhAsHzygXDYex1Dvcckt7bY4mA5n3oVz8GE4A==; 24:yGUtHNWQ53j1e/kphBiCWkKfiGU2P3KBz0kmGmk2CEgS4i0oRBNt9vc5B23FY+VtWhs1QhFY+/Mfz0eM9aLsOzmuKj/wZf8UnD5tDlUPtDI=; 7:z92DkeYem4MkPNinNfplCpUOAGA4SdEPYiDThfjgT6NPrOP9NCcLsWGKI6z5ASCQKuRfnzOGES29B+rIxj21vvkjfdgKcMHye1EUD+LDs2f5jsOwnfPjyc8eXDCqYfiyKwftcuGD9QJUpXWFUNQVY9DMdboBznjorqHxoaSuzXfTtIsGTAP3tDWXnMsy+e+qn00xVoxeKd/DyCow2WaYXXwVAcX/seI27il/+KQhMtY= x-ms-office365-filtering-correlation-id: 9d093062-fa4f-4430-ba02-08d4db340099 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DB6PR08MB2664; x-ms-traffictypediagnostic: DB6PR08MB2664: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(10201501046)(6055026)(6041248)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR08MB2664; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR08MB2664; x-forefront-prvs: 0389EDA07F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39840400002)(39450400003)(39410400002)(39860400002)(39850400002)(39400400002)(377424004)(189002)(199003)(54534003)(53936002)(2900100001)(101416001)(478600001)(99286003)(102836003)(3846002)(7696004)(9686003)(81166006)(6116002)(25786009)(3660700001)(38730400002)(5250100002)(4326008)(68736007)(33656002)(8936002)(7736002)(66066001)(14454004)(189998001)(72206003)(86362001)(54356999)(6436002)(74316002)(50986999)(305945005)(55016002)(6636002)(6506006)(8676002)(106356001)(5660300001)(3280700002)(2906002)(81156014)(105586002)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR08MB2664; H:DB6PR0801MB2053.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Aug 2017 12:26:15.9377 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2664 The current frame code combines the separate concepts of a frame chain (saving old FP,LR in a record and pointing new FP to it) and a frame pointer used to access locals. Add emit_frame_chain to the aarch64_frame descriptor and use it in the prolog and epilog code. For now just initialize it as before, so generated code is identical. Also correctly set EXIT_IGNORE_STACK. The current AArch64 epilog code restores SP from FP if alloca is used. If a frame pointer is used but there is no alloca, SP must remain valid for the epilog to work correctly. ChangeLog: 2017-08-03 Wilco Dijkstra gcc/ * config/aarch64/aarch64.h (EXIT_IGNORE_STACK): Set if alloca is used. (aarch64_frame): Add emit_frame_chain boolean. * config/aarch64/aarch64.c (aarch64_frame_pointer_required) Move eh_return case to aarch64_layout_frame. (aarch64_layout_frame): Initialize emit_frame_chain. (aarch64_expand_prologue): Use emit_frame_chain. diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h index 82d270e575ca40e9786de6a4e27408a32bc09be7..ee23944b191dd17339f42ce8ea7ff9733357c3d8 100644 --- a/gcc/config/aarch64/aarch64.h +++ b/gcc/config/aarch64/aarch64.h @@ -346,9 +346,9 @@ extern unsigned aarch64_architecture_version; (epilogue_completed && (REGNO) == LR_REGNUM) /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function, - the stack pointer does not matter. The value is tested only in - functions that have frame pointers. */ -#define EXIT_IGNORE_STACK 1 + the stack pointer does not matter. This is only true if the function + uses alloca. */ +#define EXIT_IGNORE_STACK (cfun->calls_alloca) #define STATIC_CHAIN_REGNUM R18_REGNUM #define HARD_FRAME_POINTER_REGNUM R29_REGNUM @@ -604,6 +604,9 @@ struct GTY (()) aarch64_frame /* The size of the stack adjustment after saving callee-saves. */ HOST_WIDE_INT final_adjust; + /* Store FP,LR and setup a frame pointer. */ + bool emit_frame_chain; + unsigned wb_candidate1; unsigned wb_candidate2; diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index e5c6c1ca65269a209e893729ce3230f70bd4e808..0c355506e2a1605d24d1e89934a063e5f333eebf 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -2847,10 +2847,6 @@ aarch64_frame_pointer_required (void) && (!crtl->is_leaf || df_regs_ever_live_p (LR_REGNUM))) return true; - /* Force a frame pointer for EH returns so the return address is at FP+8. */ - if (crtl->calls_eh_return) - return true; - return false; } @@ -2866,6 +2862,10 @@ aarch64_layout_frame (void) if (reload_completed && cfun->machine->frame.laid_out) return; + /* Force a frame chain for EH returns so the return address is at FP+8. */ + cfun->machine->frame.emit_frame_chain + = frame_pointer_needed || crtl->calls_eh_return; + #define SLOT_NOT_REQUIRED (-2) #define SLOT_REQUIRED (-1) @@ -2900,7 +2900,7 @@ aarch64_layout_frame (void) last_fp_reg = regno; } - if (frame_pointer_needed) + if (cfun->machine->frame.emit_frame_chain) { /* FP and LR are placed in the linkage record. */ cfun->machine->frame.reg_offset[R29_REGNUM] = 0; @@ -3639,6 +3639,7 @@ aarch64_expand_prologue (void) HOST_WIDE_INT callee_offset = cfun->machine->frame.callee_offset; unsigned reg1 = cfun->machine->frame.wb_candidate1; unsigned reg2 = cfun->machine->frame.wb_candidate2; + bool emit_frame_chain = cfun->machine->frame.emit_frame_chain; rtx_insn *insn; /* Sign return address for functions. */ @@ -3669,7 +3670,7 @@ aarch64_expand_prologue (void) if (callee_adjust != 0) aarch64_push_regs (reg1, reg2, callee_adjust); - if (frame_pointer_needed) + if (emit_frame_chain) { if (callee_adjust == 0) aarch64_save_callee_saves (DImode, callee_offset, R29_REGNUM, @@ -3677,12 +3678,12 @@ aarch64_expand_prologue (void) insn = emit_insn (gen_add3_insn (hard_frame_pointer_rtx, stack_pointer_rtx, GEN_INT (callee_offset))); - RTX_FRAME_RELATED_P (insn) = 1; + RTX_FRAME_RELATED_P (insn) = frame_pointer_needed; emit_insn (gen_stack_tie (stack_pointer_rtx, hard_frame_pointer_rtx)); } aarch64_save_callee_saves (DImode, callee_offset, R0_REGNUM, R30_REGNUM, - callee_adjust != 0 || frame_pointer_needed); + callee_adjust != 0 || emit_frame_chain); aarch64_save_callee_saves (DFmode, callee_offset, V0_REGNUM, V31_REGNUM, callee_adjust != 0 || frame_pointer_needed); aarch64_sub_sp (IP1_REGNUM, final_adjust, !frame_pointer_needed);