From patchwork Mon Mar 13 21:27:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 69152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1416469wrd; Mon, 13 Mar 2023 14:28:40 -0700 (PDT) X-Google-Smtp-Source: AK7set+kxbBceg/5NzMEc7IWYp7sAIH/P3RNWh+iw07puKbPvIJsfVEMderGJMHWOAQwq9d11v9q X-Received: by 2002:a17:907:6d9e:b0:91f:7455:cb1d with SMTP id sb30-20020a1709076d9e00b0091f7455cb1dmr12955918ejc.57.1678742920867; Mon, 13 Mar 2023 14:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678742920; cv=none; d=google.com; s=arc-20160816; b=bJLubYmv5vlUeUHhSquSs3/R1rWf0XMuPtBVmpZ2oZiw2cVMAJORMgXYLmYqLQalCy X/Nc6FAFtXCLHyfj5BKqlFIALVLbyMKe0vkCzYPZPK+Mi4wk3qObYCtATZKXQFWtpLGS pvSMkBsOIFHNZt+AUoGbQvb2UESCL4nm7nAi7mT+0QKMquX6ePUAS0SkqKw06NV7rh7z 5ZdnPhWgEcvh5wHm4U9ABixnrQxeabTkKIaC3bKytgPMG5ndr2d3kM7nMWamqMMuiK5C Mz+DFQ2QIYZRcDtFRrRxwnAf6cl3dBEFIf3w6EZlQUcSb08n5Np68xXriyYxS84pEJBM 71vw== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=mWTXbiA32znDpsz7JBGFLg3EW+BNPi8uvmzAlqwYLdA=; b=DzhaBCweN63aptYE4cANaEZ1XaDC6zyDo+PJPnohLjH5DBQT4CjCGk+Me0kc3lAVtw RtJYYA8KFlX2dk/WbZgGWPafYUVBmi1WQRwI4YNXZk4nP2W7tixipjEaeW3jicVoTbfa VIHYMYG8kv3qThhfTZnF7111/NAP7nOxn8Q4LUs5jxro5zXeYg3+oyK1G+WF73P+pAnK T8Sb36sizeame9VjSjDPaiGCedTE1j6bFp7QRU0gng6KCNmiCIbksqebL43XoraS57I7 YrKo/fpwQ52MP9lUwYIJN7xNbZICKyjiQtz1/i43fwHcBwaWDE08tgsaJeoFAct4gufD 5bHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XotZkg3r; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q22-20020a1709060f9600b008bded90af7csi575474ejj.531.2023.03.13.14.28.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 14:28:40 -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=XotZkg3r; 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 F0DA2385840E for ; Mon, 13 Mar 2023 21:28:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0DA2385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678742919; bh=mWTXbiA32znDpsz7JBGFLg3EW+BNPi8uvmzAlqwYLdA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XotZkg3r5GEgfYQW7nXCRkrd16NkS+AbAAyQbqqrmzKyAu/1xCUTEAVt4PqdJOSj5 SA3LrbpL9APN29PB0w8w7yLye/LadAAhr8DscOrtlKC2+UOv1+zH3qSTS0+Memr1Y+ 6/ESIyfnZmFb49wDdok0QZ+Bn5/oIdPMs+lns4uQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050:0:465::102]) by sourceware.org (Postfix) with ESMTPS id 9E42C3858423 for ; Mon, 13 Mar 2023 21:27:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E42C3858423 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4Pb8rl14X4z9sb2; Mon, 13 Mar 2023 22:27:51 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Delay removing DECL_EXTERNAL from thunks until funcion has finished Date: Mon, 13 Mar 2023 22:27:49 +0100 Message-Id: <20230313212749.1772-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4Pb8rl14X4z9sb2 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw 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?1760289536846804369?= X-GMAIL-MSGID: =?utf-8?q?1760289536846804369?= Hi, This is the second part to fixing PR109108, don't blindly generate the associated function definition of all referenced thunks in the compilation. Just delay finishing a thunk until the function gets codegen itself. If the function never gets a definition, then the thunk is left as "extern". Bootstrapped and regression tested on x86_64-linux/-m32/-mx32, committed to mainline and backported to the releases/gcc-11 and gcc-12 branches. Regards, Iain. --- gcc/d/ChangeLog: * decl.cc (finish_thunk): Unset DECL_EXTERNAL on thunk. (make_thunk): Set DECL_EXTERNAL on thunk, don't call build_decl_tree. (finish_function): Call finish_thunk on forward referenced thunks. --- gcc/d/decl.cc | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index d4e936d0f83..c451805639d 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -1858,6 +1858,7 @@ finish_thunk (tree thunk, tree function) TREE_ADDRESSABLE (function) = 1; TREE_USED (function) = 1; + DECL_EXTERNAL (thunk) = 0; if (flag_syntax_only) { @@ -1929,21 +1930,14 @@ make_thunk (FuncDeclaration *decl, int offset) if (!DECL_ARGUMENTS (function) || !DECL_RESULT (function)) { - /* Compile the function body before generating the thunk, this is done - even if the decl is external to the current module. */ - if (decl->fbody) - build_decl_tree (decl); - else - { - /* Build parameters for functions that are not being compiled, - so that they can be correctly cloned in finish_thunk. */ - tree function = get_symbol_decl (decl); - DECL_ARGUMENTS (function) = get_fndecl_arguments (decl); - - /* Also build the result decl, which is needed when force creating - the thunk in gimple inside cgraph_node::expand_thunk. */ - DECL_RESULT (function) = get_fndecl_result (decl); - } + /* Build parameters for functions that are not being compiled, + so that they can be correctly cloned in finish_thunk. */ + tree function = get_symbol_decl (decl); + DECL_ARGUMENTS (function) = get_fndecl_arguments (decl); + + /* Also build the result decl, which is needed when force creating + the thunk in gimple inside cgraph_node::expand_thunk. */ + DECL_RESULT (function) = get_fndecl_result (decl); } /* Don't build the thunk if the compilation step failed. */ @@ -1969,11 +1963,10 @@ make_thunk (FuncDeclaration *decl, int offset) DECL_CONTEXT (thunk) = d_decl_context (decl); - /* Thunks inherit the public access of the function they are targeting. - Thunks are connected to the definitions of the functions, so thunks are - not produced for external functions. */ + /* Thunks inherit the public access of the function they are targeting. */ TREE_PUBLIC (thunk) = TREE_PUBLIC (function); - DECL_EXTERNAL (thunk) = DECL_EXTERNAL (function); + /* The thunk has not been defined -- yet. */ + DECL_EXTERNAL (thunk) = 1; /* Thunks are always addressable. */ TREE_ADDRESSABLE (thunk) = 1; @@ -2013,6 +2006,8 @@ make_thunk (FuncDeclaration *decl, int offset) if (decl->resolvedLinkage () != LINK::cpp) free (CONST_CAST (char *, ident)); + /* Thunks are connected to the definitions of the functions, so thunks are + not produced for external functions. */ if (!DECL_EXTERNAL (function)) finish_thunk (thunk, function); @@ -2122,6 +2117,10 @@ finish_function (tree old_context) DECL_SAVED_TREE (fndecl) = bind; + /* Finish any forward referenced thunks for the function. */ + for (tree t = DECL_LANG_THUNKS (fndecl); t; t = DECL_CHAIN (t)) + finish_thunk (t, fndecl); + if (!errorcount && !global.errors) { /* Dump the D-specific tree IR. */