From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x42f.google.com with SMTP id cl5so7147842wrb.9 for ; Fri, 04 Nov 2022 06:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vYo5VrTKoLEmtLfMI7CBc8Tk64xEJxJiLWCMV+2mXy8=; b=LdG+WIVfj9uY4CQ0eJ+pHdYAHFOE7RBc39wTDFbPhzuVuE6xM+YY+AXXgt3hpZHzea CdsGwOozkAUsKPDjVy75SfN8O4GZp6FBMIzgxz1r0CkD1iac29RoKv7iGuOoK1DlbYvb dJ0LAhuI9QSIlZZ/5NiG5crhHDFw76UO2NTjwa2ig7YIcibsnNUR5/+XQRkWVXl1CGyl 0xkGe6Ui4q8uobeXHnSi2D8j+5ovGMNoznV3+v9NaRc/Mohw0x/jQ2j8+7b7RjUsfhB2 NMfw/kdXO6P8HlHMHGKKkhggM9WE5fdzgcyBehY5vccGERGz++saIufy7qtV40ivWola h3+Q== 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-Google-Smtp-Source: AMsMyM7Vn9EUxLZmE5ERSPHEtb8AJ+SI22SHHj0YoNQhiiOOSJhj1xFr+lK6/PjVn9HUhs0b5xP/7Q== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.34.1