From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED] ada: Fix performance regression related to references in Refined_State
Date: Mon, 7 Nov 2022 09:41:40 +0100 [thread overview]
Message-ID: <20221107084140.151953-1-poulhies@adacore.com> (raw)
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
reply other threads:[~2022-11-07 8:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221107084140.151953-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=trojanek@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).