From patchwork Mon Dec 19 01:08:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 34356 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2133208wrn; Sun, 18 Dec 2022 17:12:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf6jE0peAjIvk6C+Eo4fMhAlPztKvcXZn/G7OtrviArnq4WbQhu4IXvv3AdkhLUNOU3PDOlO X-Received: by 2002:a17:906:704d:b0:7b9:62ab:dc3f with SMTP id r13-20020a170906704d00b007b962abdc3fmr51097187ejj.1.1671412359145; Sun, 18 Dec 2022 17:12:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671412359; cv=none; d=google.com; s=arc-20160816; b=DMcqMHT7kIZFBO7OrYqalT8DNa5nPRFuJhYEiUTc39b95t20Fpfs6Uprxkj8sPzZi9 znxg8vqV6IY57DyE8OnkfpKO2yh77lgMYgIFxheYkurPtPj0fjwb5dESAmOoOtirYSGt PkVhJ1/xwJBRo3VAOD1aKaz+KfKuK+KemYGMWOi0MvkilZOgAl/7kyGfsnjHmo0QFygk DlaS2AZFNj4cT68W1xawRzEaULouML1orYdnFtujU0P5iKgFMookouj8XAyXPIK5QMRm i8jJzgN509XHQlRTy7vLBzKZjGdKkRT1Sg2SZM/op7yil11gdE5SmDGTOKKbZgmvjBS5 9/tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=lh+zxEIWJBqquCtSwUtBl6+u5FWf/VWLRsOsKrXCteY=; b=0qJi7hHHKpCgBHtYiod96TqWFv3f3CqayCmprtCu+xJ5MLK9eqVHsmYgL8+CQnNPYd Te+eC9VdV4uQ3fO2gDmDzVRj+8xJbCew+YPr+ejvJRjJWv5HOAJ1mEpRB56jX+vfzzfE zyFDQcNV0hbiKjBgeHueQ7ocbOxO7LIEvSO2XgueHVNDKtNkWDLzbIbPMiCtmigoD1My XQStxuzQMUZoQjljd3C4HVT+pvbVZpx2RtAFcL13vL67DlllmskBW2uLfYgaMXx7/jEB 3IUM/M+9RHvzPdkqi3uC2v79YnxQFfh8Th7tHE2vNuZQs+Tpf4abnj0IwwTZ3m17/fRt ShKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=SAgA5tOH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qw25-20020a1709066a1900b0080f0493b9c2si3127428ejc.249.2022.12.18.17.12.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 17:12:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=SAgA5tOH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 354303A70B2E for ; Mon, 19 Dec 2022 01:10:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 5ADAD39578D0 for ; Mon, 19 Dec 2022 01:08:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5ADAD39578D0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-ed1-x52c.google.com with SMTP id i9so10915845edj.4 for ; Sun, 18 Dec 2022 17:08:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lh+zxEIWJBqquCtSwUtBl6+u5FWf/VWLRsOsKrXCteY=; b=SAgA5tOHfVyIqkWAMvGv9AdlZJCVsEX+bM+3d14b81iMjPKlJ7kckkTsU86yoA9kqt /y8jXuN6aS7L4Fpp0nKwXXfsYUpEd1qpjBW3On8FaC7G/OUqoNtrrt4xEqsYsCSjtxiF fVz9ZiT9g9+iAXYqf1syUEZeGlIwOC9XsnkQjNtlCohwsdWybv2Tl+QKTmbGD8WWLc+l fLD/rpiZlR6Z4Q+jJfdjVnxqhJmyHCrIAMTRne2z2eaanM/oFmLhbf/FsClf2KPS+4Xs d1QjkSAgHr/5it/MPFHgFodb9Hptj3fYbWKeQSNapv4de1lZrmgdGoX0oH4osuAZvOJA nW/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lh+zxEIWJBqquCtSwUtBl6+u5FWf/VWLRsOsKrXCteY=; b=dlrFSCyIwEHYqFIi8Jp2siJjxohLWLVJIJlbmAPtTHDUNKqT6eHmkT9WsfqugCl0BT HX/gO48dwr7MwV54eTTa3I5ZhizNmCPn2mMrB6UG+HZNTWWVM7S3Ozav76A9/Dy9puak mHuofImpDDHB455izXFbqndcqKJEvCg1yDp8kNiImA63ijN2WJSTBqocCx1YOKr+1oSw 92hF2386yu8njbzjTrbsMFk+kibG4dEY2MOA96dajcbjb4SHxhwAd9yiuBYkvXjXnGpy IrfZocKPtXyJ2vOWD1P3XYQ6u5TFNj1neL+ZoB8Y35obgEXjPppFPfhgBKlta0JqtqgR /Cng== X-Gm-Message-State: ANoB5pljSH4BIfp0HRKLwG6rNm+50KamZ1Iw0eE0OZhqf5HINqFKT09h gKyPQtVSZOdM7GUToAtaRHtYU9YrwaupcdGR X-Received: by 2002:aa7:dc14:0:b0:46d:e3f8:4ed1 with SMTP id b20-20020aa7dc14000000b0046de3f84ed1mr42678794edu.35.1671412124722; Sun, 18 Dec 2022 17:08:44 -0800 (PST) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id eg53-20020a05640228b500b0044dbecdcd29sm3744648edb.12.2022.12.18.17.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 17:08:44 -0800 (PST) From: Christoph Muellner To: gcc-patches@gcc.gnu.org, Kito Cheng , Jim Wilson , Palmer Dabbelt , Andrew Waterman , Philipp Tomsich , Jeff Law , Cooper Qu , Lifang Xia , Yunhai Shang , Zhiwei Liu Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 02/11] riscv: Restructure callee-saved register save/restore code Date: Mon, 19 Dec 2022 02:08:29 +0100 Message-Id: <20221219010838.3878675-3-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221219010838.3878675-1-christoph.muellner@vrull.eu> References: <20221219010838.3878675-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752602885622243223?= X-GMAIL-MSGID: =?utf-8?q?1752602885622243223?= From: Christoph Müllner This patch restructures the loop over the GP registers which saves/restores then as part of the prologue/epilogue. No functional change is intended by this patch, but it offers the possibility to use load-pair/store-pair instructions. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_next_saved_reg): New function. (riscv_is_eh_return_data_register): New function. (riscv_for_each_saved_reg): Restructure loop. Signed-off-by: Christoph Müllner --- gcc/config/riscv/riscv.cc | 94 +++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 6dd2ab2d11e..a8d5e1dac7f 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -4835,6 +4835,49 @@ riscv_save_restore_reg (machine_mode mode, int regno, fn (gen_rtx_REG (mode, regno), mem); } +/* Return the next register up from REGNO up to LIMIT for the callee + to save or restore. OFFSET will be adjusted accordingly. + If INC is set, then REGNO will be incremented first. */ + +static unsigned int +riscv_next_saved_reg (unsigned int regno, unsigned int limit, + HOST_WIDE_INT *offset, bool inc = true) +{ + if (inc) + regno++; + + while (regno <= limit) + { + if (BITSET_P (cfun->machine->frame.mask, regno - GP_REG_FIRST)) + { + *offset = *offset - UNITS_PER_WORD; + break; + } + + regno++; + } + return regno; +} + +/* Return TRUE if provided REGNO is eh return data register. */ + +static bool +riscv_is_eh_return_data_register (unsigned int regno) +{ + unsigned int i, regnum; + + if (!crtl->calls_eh_return) + return false; + + for (i = 0; (regnum = EH_RETURN_DATA_REGNO (i)) != INVALID_REGNUM; i++) + if (regno == regnum) + { + return true; + } + + return false; +} + /* Call FN for each register that is saved by the current function. SP_OFFSET is the offset of the current stack pointer from the start of the frame. */ @@ -4844,36 +4887,31 @@ riscv_for_each_saved_reg (poly_int64 sp_offset, riscv_save_restore_fn fn, bool epilogue, bool maybe_eh_return) { HOST_WIDE_INT offset; + unsigned int regno; + unsigned int start = GP_REG_FIRST; + unsigned int limit = GP_REG_LAST; /* Save the link register and s-registers. */ - offset = (cfun->machine->frame.gp_sp_offset - sp_offset).to_constant (); - for (unsigned int regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++) - if (BITSET_P (cfun->machine->frame.mask, regno - GP_REG_FIRST)) - { - bool handle_reg = !cfun->machine->reg_is_wrapped_separately[regno]; - - /* If this is a normal return in a function that calls the eh_return - builtin, then do not restore the eh return data registers as that - would clobber the return value. But we do still need to save them - in the prologue, and restore them for an exception return, so we - need special handling here. */ - if (epilogue && !maybe_eh_return && crtl->calls_eh_return) - { - unsigned int i, regnum; - - for (i = 0; (regnum = EH_RETURN_DATA_REGNO (i)) != INVALID_REGNUM; - i++) - if (regno == regnum) - { - handle_reg = FALSE; - break; - } - } - - if (handle_reg) - riscv_save_restore_reg (word_mode, regno, offset, fn); - offset -= UNITS_PER_WORD; - } + offset = (cfun->machine->frame.gp_sp_offset - sp_offset).to_constant () + + UNITS_PER_WORD; + for (regno = riscv_next_saved_reg (start, limit, &offset, false); + regno <= limit; + regno = riscv_next_saved_reg (regno, limit, &offset)) + { + if (cfun->machine->reg_is_wrapped_separately[regno]) + continue; + + /* If this is a normal return in a function that calls the eh_return + builtin, then do not restore the eh return data registers as that + would clobber the return value. But we do still need to save them + in the prologue, and restore them for an exception return, so we + need special handling here. */ + if (epilogue && !maybe_eh_return + && riscv_is_eh_return_data_register (regno)) + continue; + + riscv_save_restore_reg (word_mode, regno, offset, fn); + } /* This loop must iterate over the same space as its companion in riscv_compute_frame_info. */