]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Clean up handling of inlining of finalizer procedures
authorRichard Kenner <kenner@adacore.com>
Fri, 12 Jul 2024 13:45:26 +0000 (09:45 -0400)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 2 Aug 2024 07:08:07 +0000 (09:08 +0200)
Change Is_Finalizer from synthesized attribute into flag. Remove duplicate
Is_Finalizer_Proc. Add new Try_Inline_Always for backend usage.

gcc/ada/

* einfo-utils.ads (Is_Finalizer): Delete.
* einfo-utils.adb (Is_Finalizer): Delete.
* einfo.ads: Adjust comment.
* gen_il-fields.ads, gen_il-gen-gen_entities.adb: Add Is_Finalizer
flag.
* exp_ch3.adb (Build_Init_Procedure): Set it.
* exp_ch7.adb (Create_Finalizer): Likewise.
* exp_util.adb (Try_Inline_Always): New function.
* exp_util.ads (Try_Inline_Always): New function.
* sem_elab.adb (Is_Finalizer_Proc): Replace with Is_Finalizer.

gcc/ada/einfo-utils.adb
gcc/ada/einfo-utils.ads
gcc/ada/einfo.ads
gcc/ada/exp_ch3.adb
gcc/ada/exp_ch7.adb
gcc/ada/exp_util.adb
gcc/ada/exp_util.ads
gcc/ada/gen_il-fields.ads
gcc/ada/gen_il-gen-gen_entities.adb
gcc/ada/sem_elab.adb

index c0c79f92e136a7b478398db5d5c9bfde64b808af..3dc25b36ad4149275e9626bc22a1bc2975f63ca3 100644 (file)
@@ -1567,15 +1567,6 @@ package body Einfo.Utils is
                     Has_Option (Id, Name_Synchronous));
    end Is_External_State;
 
-   ------------------
-   -- Is_Finalizer --
-   ------------------
-
-   function Is_Finalizer (Id : E) return B is
-   begin
-      return Ekind (Id) = E_Procedure and then Chars (Id) = Name_uFinalizer;
-   end Is_Finalizer;
-
    ----------------------
    -- Is_Full_Access --
    ----------------------
index 8207576fb89f13528ad553535b3accf3b4e21db1..c0480c71cb861bf1f3252c713fb624511bc7c00a 100644 (file)
@@ -190,7 +190,6 @@ package Einfo.Utils is
    function Is_Dynamic_Scope (Id : E) return B;
    function Is_Elaboration_Target (Id : E) return B;
    function Is_External_State (Id : E) return B;
-   function Is_Finalizer (Id : E) return B with Inline;
    function Is_Full_Access (Id : E) return B with Inline;
    function Is_Null_State (Id : E) return B;
    function Is_Package_Or_Generic_Package (Id : E) return B with Inline;
index 9d0f2ee3c0281c4e0935d26fb5f0f96e1605a9dc..4486ab3636fd04d059751245bf3f8929c3989db3 100644 (file)
@@ -2647,7 +2647,7 @@ package Einfo is
 --       the transient finalization mechanisms. The flag prevents the double
 --       finalization of the object.
 
---    Is_Finalizer (synthesized)
+--    Is_Finalizer
 --       Applies to all entities, true for procedures containing finalization
 --       code to process local or library level objects.
 
index 6fee2b41bac627123f49e022e79d815ab4ef81e5..bf04ea9d70a56c48b5f714c279b9b55008357c8f 100644 (file)
@@ -3532,6 +3532,7 @@ package body Exp_Ch3 is
                DF_Id :=
                  Make_Defining_Identifier (Loc,
                    Chars => New_External_Name (Name_uFinalizer));
+               Set_Is_Finalizer (DF_Id);
 
                Append_To (Decls, Make_Local_Deep_Finalize (Rec_Type, DF_Id));
 
index b545a58448d8ed996f571f2a17b0b05a23d03a39..72f0b539c2ebcee83f0c888a2e5813a58f908671 100644 (file)
@@ -1979,6 +1979,7 @@ package body Exp_Ch7 is
             Fin_Id :=
               Make_Defining_Identifier (Loc,
                 Chars => New_External_Name (Name_uFinalizer));
+            Set_Is_Finalizer (Fin_Id);
 
             --  The visibility semantics of At_End handlers force a strange
             --  separation of spec and body for stack-related finalizers:
index c5d3af7545e3245f8555c7a3575494900542f3a2..bd8bbb39d9c8e0af448c6ceea5679cb1fa0072d8 100644 (file)
@@ -14525,6 +14525,16 @@ package body Exp_Util is
       return Target;
    end Thunk_Target;
 
+   -----------------------
+   -- Try_Inline_Always --
+   -----------------------
+
+   function Try_Inline_Always (Subp : Entity_Id) return Boolean is
+     ((Is_Expression_Function (Subp) or else Is_Finalizer (Subp))
+       and then not Debug_Flag_Dot_8);
+   --  We want to inline expression functions and finalizers as much as
+   --  practical unless -gnatd.8.
+
    -------------------
    -- Type_Map_Hash --
    -------------------
index 7fbbe5fc9fd28c36b158b17dbc54185a290020b2..14d9e345b53729220e82bfda867d768bf9faf7f9 100644 (file)
@@ -1260,6 +1260,11 @@ package Exp_Util is
 
    --  WARNING: There is a matching C declaration of this subprogram in fe.h
 
+   function Try_Inline_Always (Subp : Entity_Id) return Boolean;
+   --  Determines if the backend should try hard to inline Subp. This is
+   --  similar to Subp having a pragma Inline_Always, but doesn't cause an
+   --  error if Subp can't actually be inlined.
+
    function Type_May_Have_Bit_Aligned_Components
      (Typ : Entity_Id) return Boolean;
    --  Determines if Typ is a composite type that has within it (looking down
index 9b85401eadc844e5529a484c8218457a980162c6..22fd1e372f6110a38b4986e3347fec490802ddc8 100644 (file)
@@ -708,6 +708,7 @@ package Gen_IL.Fields is
       Is_Exception_Handler,
       Is_Exported,
       Is_Finalized_Transient,
+      Is_Finalizer,
       Is_First_Subtype,
       Is_Fixed_Lower_Bound_Array_Subtype,
       Is_Fixed_Lower_Bound_Index_Subtype,
index 86701cf9e31ba02b065343ba2aa179c049cfece9..29b22c625872f156903f00b134fcd90c98729489 100644 (file)
@@ -146,6 +146,7 @@ begin -- Gen_IL.Gen.Gen_Entities
         Sm (Is_Entry_Formal, Flag),
         Sm (Is_Entry_Wrapper, Flag),
         Sm (Is_Exported, Flag),
+        Sm (Is_Finalizer, Flag),
         Sm (Is_First_Subtype, Flag),
         Sm (Is_Formal_Subprogram, Flag),
         Sm (Is_Frozen, Flag),
index a030d6b06f1fa9b816d845b4163ed459750690c7..0b5f87bd828245f1e59febb529afb3421fc1945f 100644 (file)
@@ -1778,11 +1778,6 @@ package body Sem_Elab is
       --  Determine whether arbitrary entity Id denotes internally generated
       --  routine Default_Initial_Condition.
 
-      function Is_Finalizer_Proc (Id : Entity_Id) return Boolean;
-      pragma Inline (Is_Finalizer_Proc);
-      --  Determine whether arbitrary entity Id denotes internally generated
-      --  routine _Finalizer.
-
       function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean;
       pragma Inline (Is_Initial_Condition_Proc);
       --  Determine whether arbitrary entity Id denotes internally generated
@@ -2438,7 +2433,7 @@ package body Sem_Elab is
          --  Calls to _Finalizer procedures must not appear in the output
          --  because this creates confusing noise.
 
-         elsif Is_Finalizer_Proc (Subp_Id) then
+         elsif Is_Finalizer (Subp_Id) then
             null;
 
          --  Initial_Condition
@@ -5338,7 +5333,7 @@ package body Sem_Elab is
 
             return
               (Is_Controlled_Procedure (Subp_Id, Name_Finalize)
-                 or else Is_Finalizer_Proc (Subp_Id)
+                 or else Is_Finalizer (Subp_Id)
                  or else Is_TSS (Subp_Id, TSS_Deep_Finalize))
                and then In_Initialization_Context (Call);
          end Is_Partial_Finalization_Proc;
@@ -6607,7 +6602,7 @@ package body Sem_Elab is
             --  Calls to _Finalizer procedures must not appear in the output
             --  because this creates confusing noise.
 
-            elsif Is_Finalizer_Proc (Subp_Id) then
+            elsif Is_Finalizer (Subp_Id) then
                null;
 
             --  Initial_Condition
@@ -13098,7 +13093,7 @@ package body Sem_Elab is
             --  Controlled finalization actions
 
             elsif Is_Controlled_Procedure (Targ_Id, Name_Finalize)
-              or else Is_Finalizer_Proc (Targ_Id)
+              or else Is_Finalizer (Targ_Id)
             then
                Extra := First_Formal_Type (Targ_Id);
                Kind  := Controlled_Finalization;
@@ -14467,7 +14462,7 @@ package body Sem_Elab is
       begin
          return
            Is_Accept_Alternative_Proc (Id)
-             or else Is_Finalizer_Proc (Id)
+             or else Is_Finalizer (Id)
              or else Is_Partial_Invariant_Proc (Id)
              or else Is_TSS (Id, TSS_Deep_Adjust)
              or else Is_TSS (Id, TSS_Deep_Finalize)
@@ -14488,17 +14483,6 @@ package body Sem_Elab is
          return Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id);
       end Is_Default_Initial_Condition_Proc;
 
-      -----------------------
-      -- Is_Finalizer_Proc --
-      -----------------------
-
-      function Is_Finalizer_Proc (Id : Entity_Id) return Boolean is
-      begin
-         --  To qualify, the entity must denote a _Finalizer procedure
-
-         return Ekind (Id) = E_Procedure and then Chars (Id) = Name_uFinalizer;
-      end Is_Finalizer_Proc;
-
       -------------------------------
       -- Is_Initial_Condition_Proc --
       -------------------------------