public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-2195] [Ada] Avoid repeated computing of type of expression functions
Date: Fri,  9 Jul 2021 12:38:07 +0000 (GMT)	[thread overview]
Message-ID: <20210709123807.5B35D3AAB461@sourceware.org> (raw)

https://gcc.gnu.org/g:640ba4c1a33cb7e4ad854985f7d95882f8ed2260

commit r12-2195-g640ba4c1a33cb7e4ad854985f7d95882f8ed2260
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Fri May 28 15:01:18 2021 +0200

    [Ada] Avoid repeated computing of type of expression functions
    
    gcc/ada/
    
            * sem_ch6.adb (Analyze_Expression_Function): Add variable to
            avoid repeated calls to Etype.

Diff:
---
 gcc/ada/sem_ch6.adb | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index a0680b79f23..a3240143702 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -300,6 +300,7 @@ package body Sem_Ch6 is
       New_Spec : Node_Id;
       Orig_N   : Node_Id;
       Ret      : Node_Id;
+      Typ      : Entity_Id;
 
       Def_Id : Entity_Id := Empty;
       Prev   : Entity_Id;
@@ -333,6 +334,8 @@ package body Sem_Ch6 is
          Def_Id := Analyze_Subprogram_Specification (Spec);
          Prev   := Find_Corresponding_Spec (N);
 
+         Typ := Etype (Def_Id);
+
          --  The previous entity may be an expression function as well, in
          --  which case the redeclaration is illegal.
 
@@ -406,7 +409,7 @@ package body Sem_Ch6 is
          if not Inside_A_Generic then
             Freeze_Expr_Types
               (Def_Id => Def_Id,
-               Typ    => Etype (Def_Id),
+               Typ    => Typ,
                Expr   => Expr,
                N      => N);
          end if;
@@ -496,6 +499,8 @@ package body Sem_Ch6 is
          Def_Id := Defining_Entity (N);
          Set_Is_Inlined (Def_Id);
 
+         Typ := Etype (Def_Id);
+
          --  Establish the linkages between the spec and the body. These are
          --  used when the expression function acts as the prefix of attribute
          --  'Access in order to freeze the original expression which has been
@@ -517,7 +522,7 @@ package body Sem_Ch6 is
             Set_Has_Completion (Def_Id, not Is_Ignored_Ghost_Entity (Def_Id));
             Push_Scope (Def_Id);
             Install_Formals (Def_Id);
-            Preanalyze_Spec_Expression (Expr, Etype (Def_Id));
+            Preanalyze_Spec_Expression (Expr, Typ);
             End_Scope;
          end if;
 
@@ -531,9 +536,8 @@ package body Sem_Ch6 is
          --  place at the point of declaration.
 
          declare
-            Decls : List_Id            := List_Containing (N);
-            Par   : constant Node_Id   := Parent (Decls);
-            Typ   : constant Entity_Id := Etype (Def_Id);
+            Decls : List_Id          := List_Containing (N);
+            Par   : constant Node_Id := Parent (Decls);
 
          begin
             --  If this is a wrapper created in an instance for a formal
@@ -624,12 +628,11 @@ package body Sem_Ch6 is
       --  nodes that don't come from source.
 
       if Present (Def_Id)
-        and then Nkind (Def_Id) in N_Has_Etype
-        and then Is_Tagged_Type (Etype (Def_Id))
+        and then Is_Tagged_Type (Typ)
       then
          Check_Dynamically_Tagged_Expression
            (Expr        => Expr,
-            Typ         => Etype (Def_Id),
+            Typ         => Typ,
             Related_Nod => Orig_N);
       end if;


                 reply	other threads:[~2021-07-09 12:38 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=20210709123807.5B35D3AAB461@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).