From patchwork Mon May 15 09:42:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 94033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6791598vqo; Mon, 15 May 2023 02:46:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4gv4MDGrOTLFuAZLTmuxSeQZE5nV0MZWhIKle+vRjZ5bX5RxeiFtvm3lGDnqm2f49MVooX X-Received: by 2002:a17:907:7e8f:b0:969:e7da:fcb1 with SMTP id qb15-20020a1709077e8f00b00969e7dafcb1mr23976800ejc.13.1684144007233; Mon, 15 May 2023 02:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684144007; cv=none; d=google.com; s=arc-20160816; b=YQBTzbthzKEtvBK96w1TRizUn1hSF0YP07zwTqEiR8xMns8bm1UnOjDCPILb4JB1I5 E/eW9tfSUVE5tTZNg2RIL+PGoJigqWu4GoJaEG81TFusINuPhVHVfvnxgQO6z9Eh3ukd GpEUKBwK+g+jjiPrpv21gf6mMs6Os/qaFEPouhZwrWvj9FutGCmhpVi8T4J5nI41ZU6X dbZ5u+6bh1YLAd3C9w0InmJDU0V5cyrBe1DDO8YzO63i2U7Lq3yBX87o2VRFUC2wIy+K iPuC+R4jeNG1ndQp2KtrROxnlMfArLaM34idbeHI7sNPttWmdYiOmm3IdLcchF0pKMip iYXw== 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=1mpSZZeJk+6ZADBBtJAkQxA7YtWwtLfgXEelj7aaWYM=; b=OCp3/PFX7OLrok6gEn0InSe/k2zQvp12V/C4zlE8qn6LEHTDvK2XqlaLSBQBZJE73i JvzZXbbE2xQSHU8i+A3tVRej4X4iALZnyPmwGkvniLPl0dK82uXv/d/zpVBleouVGsWS vGZpQKTQDL8KLPytJb/sYccMBNRNTFVnm0w8vO/VaryICSFrotwJ52f9qHvv67BgxGVr 2uR/C8wBLOkblcyjm9CFESm/4iSeJr0ijrtv84ezCacp9+GePDHbABxHl+rUaPc5cBLy 7oMBi32jv596UJHjekuq3TDUDnuRVxx0JR9ioMaRGR5enCMEf8CQwL/ZWKbfvfnZQNex OTAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=crZa1lId; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id lb19-20020a170907785300b0096b4425ebccsi1036210ejc.782.2023.05.15.02.46.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:46:47 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=crZa1lId; 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"; 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 D99233881D3B for ; Mon, 15 May 2023 09:44:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D99233881D3B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684143879; bh=1mpSZZeJk+6ZADBBtJAkQxA7YtWwtLfgXEelj7aaWYM=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=crZa1lIdeTwm8J0qkWWoA2qd5/FXwxWG0rgQddApzwrj/FxPlNwC1nVNdyRztRaAB 1eCRV8u6i5AB1Mk97ZEj5WWPqz64APSZDbkrUEAk4d8pLzhl6hkAzvkMA8OmtasjhQ zbpAqI31R78Mw3J3fVZ39Kw4N13XOIy6nxESIWnQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 0EC783853808 for ; Mon, 15 May 2023 09:42:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EC783853808 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-30626f4d74aso8101856f8f.0 for ; Mon, 15 May 2023 02:42:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684143725; x=1686735725; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1mpSZZeJk+6ZADBBtJAkQxA7YtWwtLfgXEelj7aaWYM=; b=ZmCFdb20h9kh7pOnS8agIDviE2BqqQrjzi1AAqjTaBd2ZDdeB4SETIuDIgrgU4h63a sbU3P/ga4BoYP8WP2d/UqPIEChjKOmpla8HeHnliPYQMXwWwCMx2nTYt7SwzHGCLd33c 7YcLuraNSnKi1OnjQqUFnG0JEjMO629bxq4co+aVuNBaNYJoxq4R/Mhwp/ZoOzaEPGPq 026Xqt6s/Ro+wBj3hS4MlSO4nwySyYXAOHt9rsqEkD7iuru8Nt98JsHP3eLHuAJOvYVf gqxgE1Rx7JVoDOGoD15GlyGaCQsHgt1zmiMrHLu3Cjld3REbMhhJD9fQARKQ6YMQRb3y d0nQ== X-Gm-Message-State: AC+VfDxIm9GKOaqq+UhO6KyhCASK3hySmuM/ffus24RDtJidCKqcJ3XB itsnQmv3BL+9gdKJxsAg7GWO8U+b8GzKJYIBOX3YKQ== X-Received: by 2002:a5d:6d50:0:b0:307:83a4:5860 with SMTP id k16-20020a5d6d50000000b0030783a45860mr24529474wri.68.1684143725623; Mon, 15 May 2023 02:42:05 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id i1-20020a5d55c1000000b003062b2c5255sm31970750wrw.40.2023.05.15.02.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:42:05 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Skip dynamic interface conversion under native runtime Date: Mon, 15 May 2023 11:42:03 +0200 Message-Id: <20230515094203.1407440-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= 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?1765952986743600004?= X-GMAIL-MSGID: =?utf-8?q?1765952986743600004?= From: Javier Miranda gcc/ada/ * exp_disp.adb (Has_Dispatching_Constructor_Call): New subprogram. (Expand_Interface_Conversion): No need to perform dynamic interface conversion when the operand and the target type are interface types and the target interface type is an ancestor of the operand type. The unique exception to this rule is when the operand has a dispatching constructor call (as documented in the sources). Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_disp.adb | 98 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 7 deletions(-) diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb index 7970b792363..1fb15fb7b02 100644 --- a/gcc/ada/exp_disp.adb +++ b/gcc/ada/exp_disp.adb @@ -1222,9 +1222,93 @@ package body Exp_Disp is --------------------------------- procedure Expand_Interface_Conversion (N : Node_Id) is + + function Has_Dispatching_Constructor_Call + (Expr : Node_Id) return Boolean; + -- Determines if the expression has a dispatching constructor call + function Underlying_Record_Type (Typ : Entity_Id) return Entity_Id; -- Return the underlying record type of Typ + -------------------------------------- + -- Has_Dispatching_Constructor_Call -- + -------------------------------------- + + function Has_Dispatching_Constructor_Call (Expr : Node_Id) return Boolean + is + function Is_Dispatching_Constructor_Call (N : Node_Id) return Boolean; + -- Determines if N is a dispatching constructor call + + function Process (Nod : Node_Id) return Traverse_Result; + -- Traverse the expression searching for constructor calls + + ------------------------------------- + -- Is_Dispatching_Constructor_Call -- + ------------------------------------- + + function Is_Dispatching_Constructor_Call (N : Node_Id) return Boolean + is + Param : Node_Id; + Param_Type : Entity_Id; + Assoc_Node : Node_Id; + Gen_Func_Id : Entity_Id; + + begin + if Nkind (N) = N_Function_Call + and then Present (Parameter_Associations (N)) + then + Param := First (Parameter_Associations (N)); + + if Nkind (Param) = N_Parameter_Association then + Param := Selector_Name (Param); + end if; + + Param_Type := Etype (Param); + + if Is_Itype (Param_Type) then + Assoc_Node := Associated_Node_For_Itype (Param_Type); + + if Nkind (Assoc_Node) = N_Function_Specification + and then Present (Generic_Parent (Assoc_Node)) + then + Gen_Func_Id := Generic_Parent (Assoc_Node); + + if Is_Intrinsic_Subprogram (Gen_Func_Id) + and then Chars (Gen_Func_Id) + = Name_Generic_Dispatching_Constructor + then + return True; + end if; + end if; + end if; + end if; + + return False; + end Is_Dispatching_Constructor_Call; + + ------------- + -- Process -- + ------------- + + function Process (Nod : Node_Id) return Traverse_Result is + begin + if Nkind (Nod) = N_Function_Call + and then Is_Dispatching_Constructor_Call (Nod) + then + return Abandon; + end if; + + return OK; + end Process; + + function Traverse_Expression is new Traverse_Func (Process); + + -- Start of processing for Has_Dispatching_Constructor_Call + + begin + return Traverse_Expression (Expr) = Abandon; + end Has_Dispatching_Constructor_Call; + ---------------------------- -- Underlying_Record_Type -- ---------------------------- @@ -1327,16 +1411,16 @@ package body Exp_Disp is -- object to reference the corresponding secondary dispatch table -- (cf. Make_DT and Expand_Dispatching_Constructor_Call)). - -- At this stage we cannot identify whether the underlying object is - -- a BIP object and hence we cannot skip generating the code to try - -- displacing the pointer to the object. However, under configurable - -- runtime it is safe to skip generating code to displace the pointer - -- to the object, because generic dispatching constructors are not - -- supported. + -- Under regular runtime this is a minor optimization that improves + -- the generated code; under configurable runtime (where generic + -- dispatching constructors are not supported) this optimization + -- allows supporting this interface conversion, which otherwise + -- would require calling the runtime routine to displace the + -- pointer to the object. elsif Is_Interface (Iface_Typ) and then Is_Ancestor (Iface_Typ, Opnd, Use_Full_View => True) - and then not RTE_Available (RE_Displace) + and then not Has_Dispatching_Constructor_Call (Operand) then return; end if;