ada: Improve efficiency of scope stack restoration
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 6 Oct 2022 21:42:46 +0000 (23:42 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 4 Nov 2022 13:47:25 +0000 (14:47 +0100)
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.

gcc/ada/sem_ch8.adb

index c4812e2..e555de9 100644 (file)
@@ -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