From patchwork Fri Oct 27 13:23:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 117340 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp769055qgn; Fri, 27 Oct 2017 06:23:52 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SyieGSDFbyBsgxEIQO4t7YRdXHNjfXfAESzDr5EKx03fWsRnjlmuaXfPGlVdcvBkWDsX1c X-Received: by 10.99.175.80 with SMTP id s16mr277887pgo.161.1509110632460; Fri, 27 Oct 2017 06:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509110632; cv=none; d=google.com; s=arc-20160816; b=he6GaXoSCMhAAVDSMDb9Utx/MfXHwi7ZzwNMr9nZBDNsjlAQYBjrka4Q9dHfIPz0Fd dRtNU2QOrqo6Rx6GJsYwLp4VGH4Qu/AMhn/p8YN80POy2YzNZ4XUjGKNtFC9GCmSDcgB dnFfzm1xcvC0yP6RTpD2us/lN4aScH0eJw7iHeojSFDFyO6WV0ieLbdT852r4YOnskp8 x1x5eFDboSTvRs60JgwNU46fufN2HJodiseU31F6h4OaxCTUUtr84hmfcJBeiqlF43C0 AwnCG3cd0PuRVkj1aidApdkVagEjuzSexyvygChTSkNmGiDFocPi6S24WQTRJD7E66MY FQfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=ShKrOcKBQWIMQ59KZ5cyJCPKTFH3NreFaXmS/lP8SiQ=; b=YR1gvXf8UoW0yoz3NZqYXg4N2nOI9XZGwjhEOSm8FsJv0T6I9bTnFOdy9SjYvW+8ES BqWUpCcvVp/Ne6kkiaFfm5YCU3wjPkXvDaIiu4k3nLsZWZwCF/voXn8f+LjmPP2FsF/m RskJO1c/eWPPqYT85DqsL9gKuuRSQ6B9YF5msTaX2mFgcpNVAYr7fwpSnD6Fu/I7Q4jq +8ZHV7LdKuicAbI91GAAZ2aoP7bMxDmBVsekYzqAtVz9MxkmLhV2OG01JRdf4cFkEx2P K7xTgUXJcpKxRWrc+dPfy/bwG8FdywlHXzmvB7vWGc2aMDc9rfYuAEJe7pErThEpJ6lN F0og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tzaaY0E7; spf=pass (google.com: domain of gcc-patches-return-465341-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465341-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id g12si4382220plo.435.2017.10.27.06.23.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Oct 2017 06:23:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-465341-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tzaaY0E7; spf=pass (google.com: domain of gcc-patches-return-465341-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465341-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:references:date:in-reply-to:message-id :mime-version:content-type; q=dns; s=default; b=ewQmrqcZZ4Kjv6g+ 6bnRcFzoY5MkWFJggNH1GX4RkJ4FyzQwyDcBAiCWJ1H/fDHlw7OqVOE2pYhPYX6A x4pL9Z7wKSUic1HDfnpkr7ho2ug4A+ZzPIlEluprOZxQykidttMxsvW1hYPTjjjj dIY4bnQzEEIUQXFwSMwguEAry9g= 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:references:date:in-reply-to:message-id :mime-version:content-type; s=default; bh=0K5wokzrQ6LMF/0G4lBb/w JC/zk=; b=tzaaY0E7UHiWrQPYAwDrymT+CjHDe7QuVg4soS1YGrkguGjzPZ2tdg eWVUZnLIeAlX/yuAc+OJAE/Q7ly9tKMWTEkB0Sj757oPboufiLUFxrydE+q4Yeqe HLcZYbNQpGfUEEMxWzEX9Rqby4SlznoDakqGrtjf61QJ3vqs/9tWo= Received: (qmail 37349 invoked by alias); 27 Oct 2017 13:23:39 -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 35075 invoked by uid 89); 27 Oct 2017 13:23:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Oct 2017 13:23:36 +0000 Received: by mail-wm0-f51.google.com with SMTP id t139so3821580wmt.1 for ; Fri, 27 Oct 2017 06:23:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version; bh=ShKrOcKBQWIMQ59KZ5cyJCPKTFH3NreFaXmS/lP8SiQ=; b=dW3QvfZK8XRsB0oZRDlPvyFnJEZu71qJIJGNU5JHH2G5/cvAunkaYNweL77aXQCiM2 T4pq+PLD4+nPuIHtNEG0l5CJpVMOwOKCufOaU4F0HIv64GvV+YDXtNgzOehynxhT27JG HSKXrPyBQ346565HfCnZO9U3RtaedbMGuRORjRBrQnwjouq08PlC8Kfiqbw0hbGU+PWS K7CCNsq6JoVqlPsI3SqP1jI0/IFjW1T/+wYmcM10Jd2oLBXKSoQw1IzWJR0Yu5hPxJcO q7/f2lkAjugJPZogbkIdq//EYy/ovY7Pzq2qVW20qKPE0z2nXv2ncl1l0hDm3G7hZFjJ Ud+A== X-Gm-Message-State: AMCzsaVmqD4SMPSSDRPO/Dxh4HFP4qgtDuHA9HyCCo78GbK1PyFQrmT8 gA8c2C2WjGEJx+hFpw4brxlfUA== X-Received: by 10.28.114.17 with SMTP id n17mr415895wmc.57.1509110614387; Fri, 27 Oct 2017 06:23:34 -0700 (PDT) Received: from localhost (188.29.164.51.threembb.co.uk. [188.29.164.51]) by smtp.gmail.com with ESMTPSA id h185sm3721293wma.19.2017.10.27.06.23.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 Oct 2017 06:23:33 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.earnshaw@arm.com, james.greenhalgh@arm.com, marcus.shawcroft@arm.com, richard.sandiford@linaro.org Cc: richard.earnshaw@arm.com, james.greenhalgh@arm.com, marcus.shawcroft@arm.com Subject: [02/nn] [AArch64] Move code around References: <873764d8y3.fsf@linaro.org> Date: Fri, 27 Oct 2017 14:23:30 +0100 In-Reply-To: <873764d8y3.fsf@linaro.org> (Richard Sandiford's message of "Fri, 27 Oct 2017 14:19:48 +0100") Message-ID: <87r2tobu7h.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch simply moves code around, in order to make the later patches easier to read, and to avoid forward declarations. It doesn't add the missing function comments because the interfaces will change in a later patch. 2017-10-26 Richard Sandiford Alan Hayward David Sherwood gcc/ * config/aarch64/aarch64.c (aarch64_add_constant_internal) (aarch64_add_constant, aarch64_add_sp, aarch64_sub_sp): Move earlier in file. Reviewed-by: James Greenhalgh Index: gcc/config/aarch64/aarch64.c =================================================================== --- gcc/config/aarch64/aarch64.c 2017-10-27 14:10:14.622293803 +0100 +++ gcc/config/aarch64/aarch64.c 2017-10-27 14:10:17.740863052 +0100 @@ -1966,6 +1966,87 @@ aarch64_internal_mov_immediate (rtx dest return num_insns; } +/* Add DELTA to REGNUM in mode MODE. SCRATCHREG can be used to hold a + temporary value if necessary. FRAME_RELATED_P should be true if + the RTX_FRAME_RELATED flag should be set and CFA adjustments added + to the generated instructions. If SCRATCHREG is known to hold + abs (delta), EMIT_MOVE_IMM can be set to false to avoid emitting the + immediate again. + + Since this function may be used to adjust the stack pointer, we must + ensure that it cannot cause transient stack deallocation (for example + by first incrementing SP and then decrementing when adjusting by a + large immediate). */ + +static void +aarch64_add_constant_internal (scalar_int_mode mode, int regnum, + int scratchreg, HOST_WIDE_INT delta, + bool frame_related_p, bool emit_move_imm) +{ + HOST_WIDE_INT mdelta = abs_hwi (delta); + rtx this_rtx = gen_rtx_REG (mode, regnum); + rtx_insn *insn; + + if (!mdelta) + return; + + /* Single instruction adjustment. */ + if (aarch64_uimm12_shift (mdelta)) + { + insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (delta))); + RTX_FRAME_RELATED_P (insn) = frame_related_p; + return; + } + + /* Emit 2 additions/subtractions if the adjustment is less than 24 bits. + Only do this if mdelta is not a 16-bit move as adjusting using a move + is better. */ + if (mdelta < 0x1000000 && !aarch64_move_imm (mdelta, mode)) + { + HOST_WIDE_INT low_off = mdelta & 0xfff; + + low_off = delta < 0 ? -low_off : low_off; + insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (low_off))); + RTX_FRAME_RELATED_P (insn) = frame_related_p; + insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (delta - low_off))); + RTX_FRAME_RELATED_P (insn) = frame_related_p; + return; + } + + /* Emit a move immediate if required and an addition/subtraction. */ + rtx scratch_rtx = gen_rtx_REG (mode, scratchreg); + if (emit_move_imm) + aarch64_internal_mov_immediate (scratch_rtx, GEN_INT (mdelta), true, mode); + insn = emit_insn (delta < 0 ? gen_sub2_insn (this_rtx, scratch_rtx) + : gen_add2_insn (this_rtx, scratch_rtx)); + if (frame_related_p) + { + RTX_FRAME_RELATED_P (insn) = frame_related_p; + rtx adj = plus_constant (mode, this_rtx, delta); + add_reg_note (insn , REG_CFA_ADJUST_CFA, gen_rtx_SET (this_rtx, adj)); + } +} + +static inline void +aarch64_add_constant (scalar_int_mode mode, int regnum, int scratchreg, + HOST_WIDE_INT delta) +{ + aarch64_add_constant_internal (mode, regnum, scratchreg, delta, false, true); +} + +static inline void +aarch64_add_sp (int scratchreg, HOST_WIDE_INT delta, bool emit_move_imm) +{ + aarch64_add_constant_internal (Pmode, SP_REGNUM, scratchreg, delta, + true, emit_move_imm); +} + +static inline void +aarch64_sub_sp (int scratchreg, HOST_WIDE_INT delta, bool frame_related_p) +{ + aarch64_add_constant_internal (Pmode, SP_REGNUM, scratchreg, -delta, + frame_related_p, true); +} void aarch64_expand_mov_immediate (rtx dest, rtx imm) @@ -2077,88 +2158,6 @@ aarch64_expand_mov_immediate (rtx dest, as_a (mode)); } -/* Add DELTA to REGNUM in mode MODE. SCRATCHREG can be used to hold a - temporary value if necessary. FRAME_RELATED_P should be true if - the RTX_FRAME_RELATED flag should be set and CFA adjustments added - to the generated instructions. If SCRATCHREG is known to hold - abs (delta), EMIT_MOVE_IMM can be set to false to avoid emitting the - immediate again. - - Since this function may be used to adjust the stack pointer, we must - ensure that it cannot cause transient stack deallocation (for example - by first incrementing SP and then decrementing when adjusting by a - large immediate). */ - -static void -aarch64_add_constant_internal (scalar_int_mode mode, int regnum, - int scratchreg, HOST_WIDE_INT delta, - bool frame_related_p, bool emit_move_imm) -{ - HOST_WIDE_INT mdelta = abs_hwi (delta); - rtx this_rtx = gen_rtx_REG (mode, regnum); - rtx_insn *insn; - - if (!mdelta) - return; - - /* Single instruction adjustment. */ - if (aarch64_uimm12_shift (mdelta)) - { - insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (delta))); - RTX_FRAME_RELATED_P (insn) = frame_related_p; - return; - } - - /* Emit 2 additions/subtractions if the adjustment is less than 24 bits. - Only do this if mdelta is not a 16-bit move as adjusting using a move - is better. */ - if (mdelta < 0x1000000 && !aarch64_move_imm (mdelta, mode)) - { - HOST_WIDE_INT low_off = mdelta & 0xfff; - - low_off = delta < 0 ? -low_off : low_off; - insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (low_off))); - RTX_FRAME_RELATED_P (insn) = frame_related_p; - insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (delta - low_off))); - RTX_FRAME_RELATED_P (insn) = frame_related_p; - return; - } - - /* Emit a move immediate if required and an addition/subtraction. */ - rtx scratch_rtx = gen_rtx_REG (mode, scratchreg); - if (emit_move_imm) - aarch64_internal_mov_immediate (scratch_rtx, GEN_INT (mdelta), true, mode); - insn = emit_insn (delta < 0 ? gen_sub2_insn (this_rtx, scratch_rtx) - : gen_add2_insn (this_rtx, scratch_rtx)); - if (frame_related_p) - { - RTX_FRAME_RELATED_P (insn) = frame_related_p; - rtx adj = plus_constant (mode, this_rtx, delta); - add_reg_note (insn , REG_CFA_ADJUST_CFA, gen_rtx_SET (this_rtx, adj)); - } -} - -static inline void -aarch64_add_constant (scalar_int_mode mode, int regnum, int scratchreg, - HOST_WIDE_INT delta) -{ - aarch64_add_constant_internal (mode, regnum, scratchreg, delta, false, true); -} - -static inline void -aarch64_add_sp (int scratchreg, HOST_WIDE_INT delta, bool emit_move_imm) -{ - aarch64_add_constant_internal (Pmode, SP_REGNUM, scratchreg, delta, - true, emit_move_imm); -} - -static inline void -aarch64_sub_sp (int scratchreg, HOST_WIDE_INT delta, bool frame_related_p) -{ - aarch64_add_constant_internal (Pmode, SP_REGNUM, scratchreg, -delta, - frame_related_p, true); -} - static bool aarch64_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED, tree exp ATTRIBUTE_UNUSED)