public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4030] ada: Do not perform local-exception-to-goto optimization on barrier functions
@ 2023-09-15 13:05 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2023-09-15 13:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2578936b341585230d8554bb9c822c3d6f46f6ad

commit r14-4030-g2578936b341585230d8554bb9c822c3d6f46f6ad
Author: Patrick Bernardi <bernardi@adacore.com>
Date:   Tue Aug 15 15:52:57 2023 -0400

    ada: Do not perform local-exception-to-goto optimization on barrier functions
    
    The local-exception-to-goto optimization is no longer applied to entry
    barrier functions as entry barriers cannot contain exception handlers and
    this optimization interferes with another optimization that occurs for
    simple barrier functions.
    
    In particular, the simple barrier optimization removes the push error label
    statements generated by the local-exception-to-goto optimization. This
    causes a Storage_Error in GIGI when the restriction No_Exception_Propagation
    is  active and a protected object contains more than one simple entry
    barrier.
    
    gcc/ada/
    
            * exp_ch6.adb (Expand_N_Subprogram_Body): Do not perform
            local-exception-to- goto optimization on barrier functions.
            * exp_ch9.adb (Expand_Entry_Barrier): Simplify the if statement
            around the simple barrier optimization and remove an old, no
            longer relevant comment.

Diff:
---
 gcc/ada/exp_ch6.adb | 12 +++++++-----
 gcc/ada/exp_ch9.adb | 38 ++++++++++++++------------------------
 2 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index da1c9e66102..a16dfe2d57e 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -6008,16 +6008,18 @@ package body Exp_Ch6 is
 
       --  If local-exception-to-goto optimization active, insert dummy push
       --  statements at start, and dummy pop statements at end, but inhibit
-      --  this if we have No_Exception_Handlers, since they are useless and
-      --  interfere with analysis, e.g. by CodePeer. We also don't need these
-      --  if we're unnesting subprograms because the only purpose of these
-      --  nodes is to ensure we don't set a label in one subprogram and branch
-      --  to it in another.
+      --  this if we have No_Exception_Handlers or expanding a entry barrier
+      --  function, since they are useless and interfere with analysis (e.g. by
+      --  CodePeer) and other optimizations. We also don't need these if we're
+      --  unnesting subprograms because the only purpose of these nodes is to
+      --  ensure we don't set a label in one subprogram and branch to it in
+      --  another.
 
       if (Debug_Flag_Dot_G
            or else Restriction_Active (No_Exception_Propagation))
         and then not Restriction_Active (No_Exception_Handlers)
         and then not CodePeer_Mode
+        and then not Is_Entry_Barrier_Function (N)
         and then not Unnest_Subprogram_Mode
         and then Is_Non_Empty_List (L)
       then
diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index 5dcd890c33c..cfdab114c9b 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -6124,7 +6124,6 @@ package body Exp_Ch9 is
 
       --  Local variables
 
-      Cond_Id    : Entity_Id;
       Entry_Body : Node_Id;
       Func_Body  : Node_Id := Empty;
 
@@ -6191,30 +6190,21 @@ package body Exp_Ch9 is
          Check_Unprotected_Barrier (Cond);
       end if;
 
-      if Is_Entity_Name (Cond) then
-         Cond_Id := Entity (Cond);
+      --  Perform a small optimization of simple barrier functions. If the
+      --  scope of the condition's entity is not the barrier function, then
+      --  the condition does not depend on any of the generated renamings.
+      --  If this is the case, eliminate the renamings as they are useless.
+      --  This optimization is not performed when the condition was folded
+      --  and validity checks are in effect because the original condition
+      --  may have produced at least one check that depends on the generated
+      --  renamings.
 
-         --  Perform a small optimization of simple barrier functions. If the
-         --  scope of the condition's entity is not the barrier function, then
-         --  the condition does not depend on any of the generated renamings.
-         --  If this is the case, eliminate the renamings as they are useless.
-         --  This optimization is not performed when the condition was folded
-         --  and validity checks are in effect because the original condition
-         --  may have produced at least one check that depends on the generated
-         --  renamings.
-
-         if Expander_Active
-           and then Scope (Cond_Id) /= Func_Id
-           and then not Validity_Check_Operands
-         then
-            Set_Declarations (Func_Body, Empty_List);
-         end if;
-
-         --  Note that after analysis variables in this context will be
-         --  replaced by the corresponding prival, that is to say a renaming
-         --  of a selected component of the form _Object.Var. If expansion is
-         --  disabled, as within a generic, we check that the entity appears in
-         --  the current scope.
+      if Expander_Active
+        and then Is_Entity_Name (Cond)
+        and then Scope (Entity (Cond)) /= Func_Id
+        and then not Validity_Check_Operands
+      then
+         Set_Declarations (Func_Body, Empty_List);
       end if;
    end Expand_Entry_Barrier;

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

only message in thread, other threads:[~2023-09-15 13:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-15 13:05 [gcc r14-4030] ada: Do not perform local-exception-to-goto optimization on barrier functions 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).