public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Fix performance regression related to references in Refined_State
@ 2022-11-07  8:41 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2022-11-07  8:41 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

From: Piotr Trojanek <trojanek@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 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;
 
    ------------------------------
-- 
2.34.1


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

only message in thread, other threads:[~2022-11-07  8:41 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:41 [COMMITTED] 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).