From patchwork Fri Nov 4 13:57:08 2022 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: 15544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp420722wru; Fri, 4 Nov 2022 07:02:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6n1VkU+gdeVRcEdqTvCiXhNNxnrmcYuv75JSJ0cY8UOtwpZrHHgBATIf4TlRxGLpiOFkhv X-Received: by 2002:a17:906:8a73:b0:7ae:3962:47e7 with SMTP id hy19-20020a1709068a7300b007ae396247e7mr2394192ejc.502.1667570571238; Fri, 04 Nov 2022 07:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667570571; cv=none; d=google.com; s=arc-20160816; b=QfXXpGfRwoImGL+LfRD2IY4r66Uvh4f18Et3RAkBzJMhaSb7NkPyFE8G6bNz6Y+uOm XoByFM4Ig9WUWiducfGnrbW43EegyRH4BAXCSEYE4OZ10Myv7+6t5IINmzcUFoJRsvkj kuJvtNTZQttdNn3UVS9jdtruytaxgLfe6/xGoobN226F6oG0sb288hRm378e2Z8R3CuJ W0Z1k14pD+TNhiCXbqd9WqGc0yr+E6NF1L2H17ydEGeWjDdXb9iSKnI9vjihaivr//gE 2Z+MmGQ51/i33l0OjZRoeY3hIrIQWNeFSIzVpDYy89/u5+0NoHuUIZuVx7Da1UwQLobH lTMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=fDsHWCB4iGYQJ0GMyMKZo1QBtJ3vUArYAftWxF8Gugo=; b=e6RAUnL+R8bKShirH99HecnpcFV4snTVeKeECyJijf6tN+pgLwL9liESRwOm1gHHfk jtkJcMLAlWzgxRgE/BcvlvPvO/pLFfMQU4oVrRCzCWxZXoeg6/i7Lvn5IGvZARk8WsNM hjQGiNmTxGwKynqlAuQkWeDMYCPU9ZgT/uCIKgOp2K+4b267CggHddHgSFK0WSjgf3FO FjnRgm8gnwNexVF+NPiQ/gVXTJwUbjgjmguNK3AxEygN+jeKjym6FuxLL9tuJmJ7CRrS d3CFGy3KJi9263CM8NG7s4jfMN0Zbi5k9PdrT0u+tOkEce4zyKAFr2cHuJC2kvDNvkqk jflQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eWKggVLj; 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 qa10-20020a170907868a00b007addc76341csi5175418ejc.25.2022.11.04.07.02.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 07:02:51 -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=eWKggVLj; 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 B0E473854147 for ; Fri, 4 Nov 2022 13:59:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0E473854147 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667570365; bh=fDsHWCB4iGYQJ0GMyMKZo1QBtJ3vUArYAftWxF8Gugo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=eWKggVLj7tAZCNkOHwWn7Y7p3xjoYeETkw11I6IFGmtJAKkb9liYYjVAbovuOFgeV QqYNIMngPqdk9Mp4tsa45iq3ctDaJ7FC+aF7yw2ypOo7zJENK+F3jQ3znqNeKKfr7X wfScQZHUqizDz3TfOR0sv8atv5EsJFDC0lZjuVsI= 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 8D318385558C for ; Fri, 4 Nov 2022 13:57:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D318385558C Received: by mail-wr1-x434.google.com with SMTP id v1so7141083wrt.11 for ; Fri, 04 Nov 2022 06:57:13 -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:message-id :reply-to; bh=fDsHWCB4iGYQJ0GMyMKZo1QBtJ3vUArYAftWxF8Gugo=; b=JvdV05kGIpbe1arcneK5/d6HS9Ycug6zp4vQc8buJI2haN6XKuJwRxwvAyC6FbcE6B YT6zoErwJoNkgDvXvXZxjLQ6fEhTc3EtJfvRlFoVm1SLLxektS6fQB1i1HQQZ+hwrip8 FtJpkh7LB//GlsaxnyUsh6SrS6KHRwFsQZl320PHpjbBA5uGv6vLixsBLWzekIG1RKZp 2tuePICfnbv7r8OR9RSO8u7qluwXPIqzeb0RHxb0AnniLe7sybMCIRsITTuRh8c6Gwlq 2XbUuiJSq0o0en7t/hwxd9pyZMxo8vVDd1kGZrln1/C2sKv/XxIWBHv9lYbrOt9PKPBj T54w== X-Gm-Message-State: ACrzQf0A1jF3r3SBAmTT0MqDBHLfmpUxZ1cqbw9QtKpMXcqlH2DzLVtZ QA7BggfU/Onzxgzp35hpT4c7WwKK8r8EGA== X-Received: by 2002:adf:e484:0:b0:236:6a2e:154e with SMTP id i4-20020adfe484000000b002366a2e154emr22387793wrm.664.1667570232451; Fri, 04 Nov 2022 06:57:12 -0700 (PDT) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id k39-20020a05600c1ca700b003b47b913901sm1210218wms.1.2022.11.04.06.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:57:12 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [COMMITTED] ada: Skip dynamic interface conversion under configurable runtime Date: Fri, 4 Nov 2022 14:57:08 +0100 Message-Id: <20221104135708.86262-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , 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?= Cc: Javier Miranda 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?1748574478810809625?= X-GMAIL-MSGID: =?utf-8?q?1748574478810809625?= From: Javier Miranda gcc/ada/ * exp_disp.adb (Expand_Interface_Conversion): Under configurable runtime, when the target type is an interface that is an ancestor of the operand type, skip generating code to displace the pointer to reference the target dispatch table. * sem_disp.adb (Propagate_Tag): Handle class-wide types when checking for the addition of an implicit interface conversion. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_disp.adb | 32 +++++++++++++++++++++----------- gcc/ada/sem_disp.adb | 15 ++++++++++++--- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb index 43ae2e0f34d..d8a45ffb7c9 100644 --- a/gcc/ada/exp_disp.adb +++ b/gcc/ada/exp_disp.adb @@ -1304,17 +1304,24 @@ package body Exp_Disp is and then Is_Ancestor (Iface_Typ, Opnd, Use_Full_View => True) then return; - end if; - -- When the type of the operand and the target interface type match, - -- it is generally safe to skip generating code to displace the - -- pointer to the object to reference the secondary dispatch table - -- associated with the target interface type. The exception to this - -- general rule is when the underlying object of the type conversion - -- is an object built by means of a dispatching constructor (since in - -- such case the expansion of the constructor call is a direct call - -- to an object primitive, i.e. without thunks, and the expansion of - -- the constructor call adds an explicit conversion to the target + -- When the target type is an interface type that is an ancestor of + -- the operand type, it is generally safe to skip generating code to + -- displace the pointer to the object to reference the secondary + -- dispatch table of the target interface type. Two scenaries are + -- possible here: + -- 1) The operand type is a regular tagged type + -- 2) The operand type is an interface type + -- In the former case the target interface and the regular tagged + -- type share the primary dispatch table of the object; in the latter + -- case the operand interface has all the primitives of the ancestor + -- interface type (and exactly in the same dispatch table slots). + -- + -- The exception to this general rule is when the underlying object + -- is built by means of a dispatching constructor (since in such case + -- the expansion of the constructor call is a direct call to an + -- object primitive, i.e. without thunks, and the expansion of + -- the constructor call adds this explicit conversion to the target -- interface type to force the displacement of the pointer to the -- object to reference the corresponding secondary dispatch table -- (cf. Make_DT and Expand_Dispatching_Constructor_Call)). @@ -1326,7 +1333,10 @@ package body Exp_Disp is -- to the object, because generic dispatching constructors are not -- supported. - if Opnd = Iface_Typ and then not RTE_Available (RE_Displace) then + elsif Is_Interface (Iface_Typ) + and then Is_Ancestor (Iface_Typ, Opnd, Use_Full_View => True) + and then not RTE_Available (RE_Displace) + then return; end if; end; diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb index ee1d96ec389..af260136bc0 100644 --- a/gcc/ada/sem_disp.adb +++ b/gcc/ada/sem_disp.adb @@ -3072,18 +3072,27 @@ package body Sem_Disp is if Tagged_Type_Expansion then declare - Call_Typ : constant Entity_Id := Etype (Call_Node); + Call_Typ : Entity_Id := Etype (Call_Node); + Ctrl_Typ : Entity_Id := Etype (Control); begin Expand_Dispatching_Call (Call_Node); + if Is_Class_Wide_Type (Call_Typ) then + Call_Typ := Root_Type (Call_Typ); + end if; + + if Is_Class_Wide_Type (Ctrl_Typ) then + Ctrl_Typ := Root_Type (Ctrl_Typ); + end if; + -- If the controlling argument is an interface type and the type -- of Call_Node differs then we must add an implicit conversion to -- force displacement of the pointer to the object to reference -- the secondary dispatch table of the interface. - if Is_Interface (Etype (Control)) - and then Etype (Control) /= Call_Typ + if Is_Interface (Ctrl_Typ) + and then Ctrl_Typ /= Call_Typ then -- Cannot use Convert_To because the previous call to -- Expand_Dispatching_Call leaves decorated the Call_Node