From patchwork Fri Nov 4 13:56:28 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: 15545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp420803wru; Fri, 4 Nov 2022 07:02:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7y9A2V0zEiOvM0syTXi97mmjrXc6jT7ZPe67u0+2W3FGf9mgx8ZBwo6grvTb4QtTW1J2zO X-Received: by 2002:a17:906:195b:b0:7ae:108:9729 with SMTP id b27-20020a170906195b00b007ae01089729mr14289288eje.604.1667570575924; Fri, 04 Nov 2022 07:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667570575; cv=none; d=google.com; s=arc-20160816; b=p57YE+lYCzYUrNm+bmi4OfHCww6eTMR0Gu6clIWib2u1UHjBonC/3gwVBydYcRDO9L Ykn+C/PH2O32J8sro/ua1slSMcOWhJcvZ+G7XBQMo8aVF+9hsvUlBpc3kuvp5dVCT3C9 RmfyQHzoQEguVRfpJzWLGoWxNV0TGIYh3UpKdg8YSnOS5tBkLd+NG779d+/L38ErjaG9 +eZpUXjgpZ3BstldDA/VK2ey1uyokFprKWNIOzxifknqTAO6gvQlK0piLRKkhBFk7D2x KSDGx2CT6eow9cFkkXOzSeSCMZKKkzhO+t9uGoTXNO9T7DdrA3Qbn+qzUOlbwY8UrFD0 woLw== 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=vYo5VrTKoLEmtLfMI7CBc8Tk64xEJxJiLWCMV+2mXy8=; b=odHdpRgqcDzihFujWn/6Al32lGvbACWiVpPz6NiyrXZEMzy+uJA7x++YfY10xwBnyy 4IN6lGmfc3Gvapzn9MIpT2jc3S67O1C1tRINu0uNtbg59mLfMYyRX0RtYjh7d/Az2tIO obW3jUneIxidJRt2+vDsSWsTcTm+mh+VhjXTya0aIuSDDpZPF+0Aggd3q2Fv1n/xSXUz WMytZ8fcCWfWUkpT21Hx2NaPhPc4zbUbm3kgHFlxcYjMi4HxaeTrW6Tx3MNCnvCh/PIA qeKOeF5K0LMqyZNfGUQ7XLC/o2/ZMYhF9GwJ1T//NL1nm39WheKqhn8mrxnzFV6AKJis TB5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WRjZw9JG; 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 k14-20020a170906a38e00b007a45e4f4ff2si14148ejz.853.2022.11.04.07.02.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 07:02:55 -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=WRjZw9JG; 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 6C4FB3882754 for ; Fri, 4 Nov 2022 13:59:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C4FB3882754 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667570367; bh=vYo5VrTKoLEmtLfMI7CBc8Tk64xEJxJiLWCMV+2mXy8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=WRjZw9JGMw9jrlRFafSVwudqSmTqOhsnzdYuohA2F8Ia8s0b3COUlOrjq/E1tonIw 6rx2X8vEVDTcxuiDTQV9lOmmvWX7DzptQBS977+fjoapKPtptR6w9uu/n4tS2g1M2d vQThZxGgVpthfCYaK2tpWFAFgghz+fIAfGWhszRQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 5EE013856092 for ; Fri, 4 Nov 2022 13:56:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5EE013856092 Received: by mail-wr1-x42f.google.com with SMTP id cl5so7147842wrb.9 for ; Fri, 04 Nov 2022 06:56:34 -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=vYo5VrTKoLEmtLfMI7CBc8Tk64xEJxJiLWCMV+2mXy8=; b=ezbMsX46Uoy2VVTLFq57/yjxheIoF9++Fy1IUh0BlK5KrjXDmUnG72AJoenrEeTDDh 3iTdmsWelUD5+6OuWHO6JwSj8HT4VdbVof5E1pVdK4CrJ373bywvUDhX88qc8ZJKZv+8 OedqmOIJwxDuSLhrr9nuBvn95y2mxjjlYdhyXRU062J0JPVUyGBG+s0tSTNiscg1Ju5q nZq99/30iTR799MjY1vYaH2QU1/O5gi9Ieu7lQUeKugFOCl6R4Q5H+sArS8WHjVF+WXR XKtrwE/bV83QhOX51aR7pdfiVKU4Q/r5AoiUz91qt5n0Te0vDzc2DAhRmGU2tRpv59Kw poLQ== X-Gm-Message-State: ACrzQf0za6U3h4YEVxMTYFsLFTbjx2EXNu/GbgymAYK2kgT9EwA4NfFv tyvRBsklK0AKDqLcYuImGmFJaFoWEKuUqQ== X-Received: by 2002:a05:6000:1566:b0:236:6a6f:6c27 with SMTP id 6-20020a056000156600b002366a6f6c27mr22564679wrz.553.1667570193230; Fri, 04 Nov 2022 06:56:33 -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 n17-20020a05600c4f9100b003c701c12a17sm3234017wmq.12.2022.11.04.06.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:56:32 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [COMMITTED] ada: Improve efficiency of scope stack restoration Date: Fri, 4 Nov 2022 14:56:28 +0100 Message-Id: <20221104135628.85893-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 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: Piotr Trojanek 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?1748574484596589920?= X-GMAIL-MSGID: =?utf-8?q?1748574484596589920?= From: Piotr Trojanek We save/restore visibility by setting the Is_Immediately_Visible flag and appending entities to / removing them from the tail of an element list. However, the Is_Immediately_Visible flag can be restored in any order, while the element list is singly-linked and removal from the tail is inefficient. This change removes a performance hot spot, which accounted for up to 10% of compilation time of complex applications (e.g. QGen), at least as measured on GNAT built with profiling support. gcc/ada/ * sem_ch8.adb (Restore_Scope_Stack): Remove elements from the head and not the tail of an element list. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch8.adb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index c4812e2a563..e555de915e6 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -9717,10 +9717,10 @@ package body Sem_Ch8 is -- we saved (we use Remove, since this list will not be used again). loop - Elmt := Last_Elmt (List); + Elmt := First_Elmt (List); exit when Elmt = No_Elmt; Set_Is_Immediately_Visible (Node (Elmt)); - Remove_Last_Elmt (List); + Remove_Elmt (List, Elmt); end loop; -- Restore use clauses