sem_ch12.ads (Need_Subprogram_Instance_Body): new function...
authorArnaud Charlet <charlet@gcc.gnu.org>
Fri, 1 Aug 2008 08:19:04 +0000 (10:19 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Fri, 1 Aug 2008 08:19:04 +0000 (10:19 +0200)
2008-08-01  Ed Schonberg  <schonberg@adacore.com>

* sem_ch12.ads (Need_Subprogram_Instance_Body): new function, to create
a pending instantiation for the body of a subprogram that is to be
inlined.

* sem_ch12.adb:
(Analyze_Subprogram_Instantiation): use Need_Subprogram_Instance_Body.

* sem_prag.adb (Make_Inline): If the pragma applies to an instance,
create a pending instance for its body, so that calls to the subprogram
can be inlined by the back-end.

From-SVN: r138480

gcc/ada/ChangeLog
gcc/ada/sem_ch12.adb
gcc/ada/sem_ch12.ads
gcc/ada/sem_prag.adb

index 630f30f6c671117549e2396d028954d157c90497..3eb081d0278a1822d74331a704f6587f5fdbee0a 100644 (file)
@@ -1,3 +1,21 @@
+2008-08-01  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_ch12.ads (Need_Subprogram_Instance_Body): new function, to create
+       a pending instantiation for the body of a subprogram that is to be
+       inlined.
+
+       * sem_ch12.adb:
+       (Analyze_Subprogram_Instantiation): use Need_Subprogram_Instance_Body.
+
+       * sem_prag.adb (Make_Inline): If the pragma applies to an instance,
+       create a pending instance for its body, so that calls to the subprogram
+       can be inlined by the back-end.
+
+2008-08-01  Jose Ruiz  <ruiz@adacore.com>
+
+       * gnat_ugn.texi: Document the RTX run times (rts-rtx-rtss and
+       rts-rtx-w32).
+
 2008-08-01  Robert Dewar  <dewar@adacore.com>
 
        * scng.adb (Error_Illegal_Wide_Character): Bump scan pointer
index b2e7d85248777027a96fa13065e9e5f60f383774..48011e71ade79b4c32af25d6e9f34b339d6a70cd 100644 (file)
@@ -3753,6 +3753,38 @@ package body Sem_Ch12 is
       Analyze_Subprogram_Instantiation (N, E_Procedure);
    end Analyze_Procedure_Instantiation;
 
+   -----------------------------------
+   -- Need_Subprogram_Instance_Body --
+   -----------------------------------
+
+   function Need_Subprogram_Instance_Body
+     (N    : Node_Id;
+      Subp : Entity_Id) return Boolean
+   is
+   begin
+      if (Is_In_Main_Unit (N)
+            or else Is_Inlined (Subp)
+            or else Is_Inlined (Alias (Subp)))
+        and then (Operating_Mode = Generate_Code
+                    or else (Operating_Mode = Check_Semantics
+                               and then ASIS_Mode))
+        and then (Expander_Active or else ASIS_Mode)
+        and then not ABE_Is_Certain (N)
+        and then not Is_Eliminated (Subp)
+      then
+         Pending_Instantiations.Append
+           ((Inst_Node                => N,
+             Act_Decl                 => Unit_Declaration_Node (Subp),
+             Expander_Status          => Expander_Active,
+             Current_Sem_Unit         => Current_Sem_Unit,
+             Scope_Suppress           => Scope_Suppress,
+             Local_Suppress_Stack_Top => Local_Suppress_Stack_Top));
+         return True;
+      else
+         return False;
+      end if;
+   end Need_Subprogram_Instance_Body;
+
    --------------------------------------
    -- Analyze_Subprogram_Instantiation --
    --------------------------------------
@@ -4144,22 +4176,7 @@ package body Sem_Ch12 is
             --  If the context requires a full instantiation, mark node for
             --  subsequent construction of the body.
 
-            if (Is_In_Main_Unit (N)
-                  or else Is_Inlined (Act_Decl_Id))
-              and then (Operating_Mode = Generate_Code
-                          or else (Operating_Mode = Check_Semantics
-                                     and then ASIS_Mode))
-              and then (Expander_Active or else ASIS_Mode)
-              and then not ABE_Is_Certain (N)
-              and then not Is_Eliminated (Act_Decl_Id)
-            then
-               Pending_Instantiations.Append
-                 ((Inst_Node                => N,
-                   Act_Decl                 => Act_Decl,
-                   Expander_Status          => Expander_Active,
-                   Current_Sem_Unit         => Current_Sem_Unit,
-                   Scope_Suppress           => Scope_Suppress,
-                   Local_Suppress_Stack_Top => Local_Suppress_Stack_Top));
+            if Need_Subprogram_Instance_Body (N, Act_Decl_Id) then
 
                Check_Forward_Instantiation (Gen_Decl);
 
@@ -8699,6 +8716,13 @@ package body Sem_Ch12 is
    begin
       Gen_Body_Id := Corresponding_Body (Gen_Decl);
 
+      --  Subprogram body may have been created already because of
+      --  an inline pragma.
+
+      if Present (Corresponding_Body (Act_Decl)) then
+         return;
+      end if;
+
       Expander_Mode_Save_And_Set (Body_Info.Expander_Status);
 
       --  Re-establish the state of information on which checks are suppressed.
index 7ebb2e88342ed1d03b760f047c83f8b87d81afa7..c3b34173e18ef245ba18f51528ed0c5f6602c1c3 100644 (file)
@@ -106,6 +106,16 @@ package Sem_Ch12 is
    --  function and procedure instances. The flag Body_Optional has the
    --  same purpose as described for Instantiate_Package_Body.
 
+   function Need_Subprogram_Instance_Body
+     (N    : Node_Id;
+      Subp : Entity_Id) return Boolean;
+
+   --  If a subprogram instance is inlined, indicate that the body of it
+   --  must be created, to be used in inlined calls by the back-end. The
+   --  subprogram may be inlined because the generic itself carries the
+   --  pragma, or because a pragma appears for the instance in the scope.
+   --  of the instance.
+
    procedure Save_Global_References (N : Node_Id);
    --  Traverse the original generic unit, and capture all references to
    --  entities that are defined outside of the generic in the analyzed
index 803f054ce4f19a2307a08ba91033a0dcd4207d38..b54cda616cf67b06f63bf4de7525e717499b038d 100644 (file)
@@ -53,6 +53,7 @@ with Sem_Aux;  use Sem_Aux;
 with Sem_Ch3;  use Sem_Ch3;
 with Sem_Ch6;  use Sem_Ch6;
 with Sem_Ch8;  use Sem_Ch8;
+with Sem_Ch12; use Sem_Ch12;
 with Sem_Ch13; use Sem_Ch13;
 with Sem_Dist; use Sem_Dist;
 with Sem_Elim; use Sem_Elim;
@@ -3752,6 +3753,22 @@ package body Sem_Prag is
                     and then Present (Corresponding_Body (Decl))
                   then
                      Set_Inline_Flags (Corresponding_Body (Decl));
+
+                  elsif Is_Generic_Instance (Subp) then
+
+                     --  Indicate that the body needs to be created for
+                     --  inlining subsequent calls. The instantiation
+                     --  node follows the declaration of the wrapper
+                     --  package created for it.
+
+                     if Scope (Subp) /= Standard_Standard
+                       and then
+                         Need_Subprogram_Instance_Body
+                          (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
+                              Subp)
+                     then
+                        null;
+                     end if;
                   end if;
                end if;