public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3744] ada: Fix performance regression related to references in Refined_State
@ 2022-11-07  8:40 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2022-11-07  8:40 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dc3208e698b2f424d892d3c9e5d5562ccde9e4cf

commit r13-3744-gdc3208e698b2f424d892d3c9e5d5562ccde9e4cf
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Mon Oct 17 22:08:37 2022 +0200

    ada: Fix performance regression related to references in Refined_State
    
    Recently added call to In_Pragma_Expression caused a performance
    regression. It might require climbing syntax trees of arbitrarily deep
    expressions, while previously references within pragmas were detected in
    bounded time.
    
    This patch restores the previous efficiency. However, while the original
    code only detected references directly within pragma argument
    associations, now we also detect references inside aggregates, e.g.
    like those in pragma Refined_State.
    
    gcc/ada/
    
            * sem_prag.adb (Non_Significant_Pragma_Reference): Detect
            references with aggregates; only assign local variables Id and C
            when necessary.

Diff:
---
 gcc/ada/sem_prag.adb | 56 +++++++++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index f33d858062d..2a3aca85a79 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -31719,43 +31719,45 @@ package body Sem_Prag is
    --  Start of processing for Non_Significant_Pragma_Reference
 
    begin
-      P := Parent (N);
-
-      if Nkind (P) /= N_Pragma_Argument_Association then
+      --  Reference might appear either directly as expression of a pragma
+      --  argument association, e.g. pragma Export (...), or within an
+      --  aggregate with component associations, e.g. pragma Refined_State
+      --  ((... => ...)).
 
-         --  References within pragma Refined_State are not significant. They
-         --  can't be recognized using pragma argument number, because they
-         --  appear inside refinement clauses that rely on aggregate syntax.
+      P := Parent (N);
+      loop
+         case Nkind (P) is
+            when N_Pragma_Argument_Association =>
+               exit;
+            when N_Aggregate | N_Component_Association =>
+               P := Parent (P);
+            when others =>
+               return False;
+         end case;
+      end loop;
 
-         if In_Pragma_Expression (N, Name_Refined_State) then
-            return True;
-         end if;
+      AN := Arg_No;
 
+      if AN = 0 then
          return False;
+      end if;
 
-      else
-         Id := Get_Pragma_Id (Parent (P));
-         C := Sig_Flags (Id);
-         AN := Arg_No;
+      Id := Get_Pragma_Id (Parent (P));
+      C := Sig_Flags (Id);
 
-         if AN = 0 then
+      case C is
+         when -1 =>
             return False;
-         end if;
-
-         case C is
-            when -1 =>
-               return False;
 
-            when 0 =>
-               return True;
+         when 0 =>
+            return True;
 
-            when 92 .. 99 =>
-               return AN < (C - 90);
+         when 92 .. 99 =>
+            return AN < (C - 90);
 
-            when others =>
-               return AN /= C;
-         end case;
-      end if;
+         when others =>
+            return AN /= C;
+      end case;
    end Is_Non_Significant_Pragma_Reference;
 
    ------------------------------

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-07  8:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07  8:40 [gcc r13-3744] ada: Fix performance regression related to references in Refined_State Marc Poulhi?s

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).