From patchwork Tue Sep 13 21:57:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp2545307wrt; Tue, 13 Sep 2022 14:58:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR5f6CFZcAk+y0j7Wp5qaRM9KgSWGNqzSJYJwVoBtgN00nglBsI+UuGCXVK4CCKTEcQy62eG X-Received: by 2002:a17:907:2d2a:b0:77e:def7:65e9 with SMTP id gs42-20020a1709072d2a00b0077edef765e9mr6589111ejc.85.1663106327783; Tue, 13 Sep 2022 14:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663106327; cv=none; d=google.com; s=arc-20160816; b=nfb49uJtZOBXad5Bsy7uGFyUKzgKOIYVC0Ip2v+UtuvNDxIU4Zmi1Rd+EU+HOrXn4o 3zOtw3AWUM9FvfnntGefqitQP3t2lcZJ/RdMJU4+chcNMhvNrgEncJAMZ4Qy8JXpWP8M wFvGf7v5BYUDsyDAzfYsTZWQDQ+kwDzIfExXRuSgs8O4hn5y1MChHSVb9nHogjcUhXrY p3J/u7g3fu73TDrcXUr9woIkkQh9D2oHVERJBMLTFSWVQmMEbC7kHjlxIw/7R+MhbcvO g0k0xMfW5Q4+7NxKvv3g1T8M4JSubQZ/Zp0SaZ1pAKZVsp2Rwpj/F7qNSpZdAfs1fHh7 f0Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xY3qNeYGhG9jmuBNCgsHi0X5VXPYaCkgYKJBdesJ4/8=; b=o16tBqKSbkuFm8XD/O6nk22wmizWL88tIiKOi+rD013FQaFVtU2nbTJBi5a5rxfqvM GXmZAoVOdK/1/FST71flXvSAsU5QbXbMUq/Ey/TjVmJhkyV0mMtoWd7lBynSOYJmiwwV yoxQXnIqCto4thwSnJRq87ZHraMveLLp8phgUej7D5hFQaoNWlddG5N6YdvLi/40+cnW CWHdJtsGdtcOzpRgsenrPiK9yfZjzPeo8XjZGIxug93P6GzPOks7C4INkLs+XBmjuiyb E45aRm0Fd1D9CI6L2ggtBlARw0n2qbc/sCOv8KogNAgBj1+/yWJjIAIBneJUIAwwUGRg lyYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RocsUDGc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u22-20020a170906781600b007306307b9bbsi9354886ejm.788.2022.09.13.14.58.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 14:58:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RocsUDGc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7082A3856246 for ; Tue, 13 Sep 2022 21:58:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7082A3856246 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663106326; bh=xY3qNeYGhG9jmuBNCgsHi0X5VXPYaCkgYKJBdesJ4/8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RocsUDGcnz8SkxDoRAtuCZc6GlHfi8D8nDqvWmxcIohtunVHld3L2WgY4lOv1DgLy hNqM9OfHSn5c53TpnbfUeEB8ZpWxNekjqGNnJQGreW+ewSm2CSpUvBGb+Ke2Eb8BM6 bsjxn+aZZ+lelEiU4i/yB58IAOfPzYzq4Yy1G8dg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 652323858407 for ; Tue, 13 Sep 2022 21:58:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 652323858407 Received: by mail-pl1-x629.google.com with SMTP id l10so13183181plb.10 for ; Tue, 13 Sep 2022 14:58:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=xY3qNeYGhG9jmuBNCgsHi0X5VXPYaCkgYKJBdesJ4/8=; b=oSm1uYYsy5Qhgzdl1d9kp70Lmbv/+H6kKp6aqcg570YWWRlPTE7Z51s3gOwj8XQhDq Uq0pp6X3ymbKPI0cDF61lDbe2Sk32Rkm6SA5mnZBqJMeyToMIGzdKr+0RYQ4jB9fNj2H cIhvU2XQegSgp8xwmBHeFjrbCCTPDriZEzNrzX97TOuF7nFfkYt+DenkQkhNHCaMzx7g PEV4RU7GcxjvvudC2syqyIRg/iD/z3Xa6iXrOYWoheQMj3/zF+zUnQZF1IoLRnRaZ7ul V0JgTtRoMkb1A4p1GmPsFQiKtbnjvKS1Bh4/u1jGnwQZyehyr73nryMGHOST2MCRZVYv txvg== X-Gm-Message-State: ACrzQf1pfHm4CYf6RkstT+UgXPGgC4B2NEUeTphJlTN065TjZGcaZbTH raDp5AW7KgKF0wyeSakDcwujpfJnCdEM/g== X-Received: by 2002:a17:90b:1e0a:b0:202:e897:9bb3 with SMTP id pg10-20020a17090b1e0a00b00202e8979bb3mr1299619pjb.169.1663106280977; Tue, 13 Sep 2022 14:58:00 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id e2-20020a170902784200b001754a3c5404sm8858277pln.212.2022.09.13.14.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 14:58:00 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] xtensa: gcc: implement MI thunk generation for call0 ABI Date: Tue, 13 Sep 2022 14:57:43 -0700 Message-Id: <20220913215743.2712390-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, GIT_PATCH_0, HK_RANDOM_ENVFROM, HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , X-Patchwork-Original-From: Max Filippov via Gcc-patches From: Max Filippov Reply-To: Max Filippov 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?1743893381014660858?= X-GMAIL-MSGID: =?utf-8?q?1743893381014660858?= Suwa-san, could you please take a look? This change fixes the fowllowing testsuite failures when building for call0 ABI: g++.dg/ipa/pr60640-4.C g++.dg/ipa/pr83549.C g++.dg/ipa/pr83667.C g++.dg/torture/pr81812.C gcc/ * config/xtensa/xtensa.cc (xtensa_can_output_mi_thunk) (xtensa_output_mi_thunk): New functions. (TARGET_ASM_CAN_OUTPUT_MI_THUNK) (TARGET_ASM_OUTPUT_MI_THUNK): New macro definitions. (xtensa_prepare_expand_call): Use fixed register a8 as temporary when called with reload_completed set to 1. --- gcc/config/xtensa/xtensa.cc | 116 +++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index f1b3331ea558..e5abd356a745 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -191,6 +191,15 @@ static bool xtensa_can_eliminate (const int from ATTRIBUTE_UNUSED, static HOST_WIDE_INT xtensa_starting_frame_offset (void); static unsigned HOST_WIDE_INT xtensa_asan_shadow_offset (void); static bool xtensa_function_ok_for_sibcall (tree, tree); +static bool xtensa_can_output_mi_thunk (const_tree thunk_fndecl ATTRIBUTE_UNUSED, + HOST_WIDE_INT delta ATTRIBUTE_UNUSED, + HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED, + const_tree function ATTRIBUTE_UNUSED); +static void xtensa_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, + HOST_WIDE_INT delta, + HOST_WIDE_INT vcall_offset, + tree function); + static rtx xtensa_delegitimize_address (rtx); @@ -351,6 +360,12 @@ static rtx xtensa_delegitimize_address (rtx); #undef TARGET_FUNCTION_OK_FOR_SIBCALL #define TARGET_FUNCTION_OK_FOR_SIBCALL xtensa_function_ok_for_sibcall +#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK +#define TARGET_ASM_CAN_OUTPUT_MI_THUNK xtensa_can_output_mi_thunk + +#undef TARGET_ASM_OUTPUT_MI_THUNK +#define TARGET_ASM_OUTPUT_MI_THUNK xtensa_output_mi_thunk + struct gcc_target targetm = TARGET_INITIALIZER; @@ -2173,7 +2188,16 @@ xtensa_prepare_expand_call (int callop, rtx *operands) addr = gen_sym_PLT (addr); if (!call_insn_operand (addr, VOIDmode)) - XEXP (operands[callop], 0) = copy_to_mode_reg (Pmode, addr); + { + /* This may be called while generating MI thunk when we pretend + that reload is over. Use a8 as a temporary register in that case. */ + rtx reg = can_create_pseudo_p () + ? copy_to_mode_reg (Pmode, addr) + : copy_to_suggested_reg (addr, + gen_rtx_REG (Pmode, A8_REG), + Pmode); + XEXP (operands[callop], 0) = reg; + } } @@ -4983,6 +5007,96 @@ xtensa_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED, tree exp ATTRIBUTE_U return true; } +static bool +xtensa_can_output_mi_thunk (const_tree thunk_fndecl ATTRIBUTE_UNUSED, + HOST_WIDE_INT delta ATTRIBUTE_UNUSED, + HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED, + const_tree function ATTRIBUTE_UNUSED) +{ + if (TARGET_WINDOWED_ABI) + return false; + + return true; +} + +/* Output code to add DELTA to the first argument, and then jump + to FUNCTION. Used for C++ multiple inheritance. */ +static void +xtensa_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, + HOST_WIDE_INT delta, + HOST_WIDE_INT vcall_offset, + tree function) +{ + rtx this_rtx; + rtx funexp; + rtx_insn *insn; + int this_reg_no; + rtx temp0 = gen_rtx_REG (Pmode, A9_REG); + const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk)); + + reload_completed = 1; + + if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)) + this_reg_no = 3; + else + this_reg_no = 2; + + this_rtx = gen_rtx_REG (Pmode, A0_REG + this_reg_no); + + if (delta) + { + if (xtensa_simm8 (delta)) + emit_insn (gen_addsi3 (this_rtx, this_rtx, GEN_INT (delta))); + else + { + emit_move_insn (temp0, GEN_INT (delta)); + emit_insn (gen_addsi3 (this_rtx, this_rtx, temp0)); + } + } + + if (vcall_offset) + { + rtx temp1 = gen_rtx_REG (Pmode, A0_REG + 10); + rtx addr = temp1; + + emit_move_insn (temp0, gen_rtx_MEM (Pmode, this_rtx)); + if (xtensa_uimm8x4 (vcall_offset)) + addr = plus_constant (Pmode, temp0, vcall_offset); + else if (xtensa_simm8 (vcall_offset)) + emit_insn (gen_addsi3 (temp1, temp0, GEN_INT (vcall_offset))); + else + { + emit_move_insn (temp1, GEN_INT (vcall_offset)); + emit_insn (gen_addsi3 (temp1, temp0, temp1)); + } + emit_move_insn (temp1, gen_rtx_MEM (Pmode, addr)); + emit_insn (gen_add2_insn (this_rtx, temp1)); + } + + /* Generate a tail call to the target function. */ + if (!TREE_USED (function)) + { + assemble_external (function); + TREE_USED (function) = 1; + } + + funexp = XEXP (DECL_RTL (function), 0); + funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); + insn = emit_call_insn (gen_sibcall (funexp, const0_rtx)); + SIBLING_CALL_P (insn) = 1; + + insn = get_insns (); + shorten_branches (insn); + assemble_start_function (thunk, fnname); + final_start_function (insn, file, 1); + final (insn, file, 1); + final_end_function (); + assemble_end_function (thunk, fnname); + + /* Stop pretending to be a post-reload pass. */ + reload_completed = 0; +} + static rtx xtensa_delegitimize_address (rtx op) {