diff mbox

[Ada] Cleanups in inter-unit inlining engine

Message ID 20151016124122.GA57457@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 16, 2015, 12:41 p.m. UTC
This removes a component in the record attached to every subprogram considered
for inter-unit inlining, which doesn't serve any useful purpose.

In addition, this fixes a small inconsistency in the code driving inter-unit
inlining from the front-end.  The code was at the same time discarding the
subprograms that cannot be inlined outside their unit, typically nested
subprograms, and taking them into account to build the edges of the callgraph.

This could later fool the algorithm computing the transitive closure of the
calls inlined from the main unit because vertices of the callgraph were not
present in the table of inlined subprograms.

No simple testcase.

Tested on x86_64-pc-linux-gnu, committed on trunk

2015-10-16  Eric Botcazou  <ebotcazou@adacore.com>

	* inline.adb (Subp_Info): Remove Listed component.
	(Add_Inlined_Subprogram): Take an entity instead of an index.
	Do not set Listed component to True.
	(New_Entry): Do not initialize Listed component to False.
	(Analyze_Inlined_Bodies): Do not test Listed component
	(Must_Inline): Add calls not in the main unit only
	if they are in a subprogram that can be inlined outside its unit.
	(Add_Inlined_Body): Move test around and add comment.
diff mbox

Patch

Index: inline.adb
===================================================================
--- inline.adb	(revision 228866)
+++ inline.adb	(working copy)
@@ -158,7 +158,6 @@ 
       Name        : Entity_Id  := Empty;
       Next        : Subp_Index := No_Subp;
       First_Succ  : Succ_Index := No_Succ;
-      Listed      : Boolean    := False;
       Main_Call   : Boolean    := False;
       Processed   : Boolean    := False;
    end record;
@@ -180,8 +179,8 @@ 
    --  called, and for the inlined subprogram that contains the call. If
    --  the call is in the main compilation unit, Caller is Empty.
 
-   procedure Add_Inlined_Subprogram (Index : Subp_Index);
-   --  Add the subprogram to the list of inlined subprogram for the unit
+   procedure Add_Inlined_Subprogram (E : Entity_Id);
+   --  Add subprogram E to the list of inlined subprogram for the unit
 
    function Add_Subp (E : Entity_Id) return Subp_Index;
    --  Make entry in Inlined table for subprogram E, or return table index
@@ -347,15 +346,19 @@ 
             return Inline_Package;
          end if;
 
-         --  The call is not in the main unit. See if it is in some inlined
-         --  subprogram. If so, inline the call and, if the inlining level is
-         --  set to 1, stop there; otherwise also compile the package as above.
+         --  The call is not in the main unit. See if it is in some subprogram
+         --  that can be inlined outside its unit. If so, inline the call and,
+         --  if the inlining level is set to 1, stop there; otherwise also
+         --  compile the package as above.
 
          Scop := Current_Scope;
          while Scope (Scop) /= Standard_Standard
            and then not Is_Child_Unit (Scop)
          loop
-            if Is_Overloadable (Scop) and then Is_Inlined (Scop) then
+            if Is_Overloadable (Scop)
+              and then Is_Inlined (Scop)
+              and then not Is_Nested (Scop)
+            then
                Add_Call (E, Scop);
 
                if Inline_Level = 1 then
@@ -378,6 +381,15 @@ 
    begin
       Append_New_Elmt (N, To => Backend_Calls);
 
+      --  Skip subprograms that cannot be inlined outside their unit
+
+      if Is_Abstract_Subprogram (E)
+        or else Convention (E) = Convention_Protected
+        or else Is_Nested (E)
+      then
+         return;
+      end if;
+
       --  Find unit containing E, and add to list of inlined bodies if needed.
       --  If the body is already present, no need to load any other unit. This
       --  is the case for an initialization procedure, which appears in the
@@ -391,13 +403,6 @@ 
       --  no enclosing package to retrieve. In this case, it is the body of
       --  the function that will have to be loaded.
 
-      if Is_Abstract_Subprogram (E)
-        or else Is_Nested (E)
-        or else Convention (E) = Convention_Protected
-      then
-         return;
-      end if;
-
       Level := Must_Inline;
 
       if Level /= Dont_Inline then
@@ -475,8 +480,7 @@ 
    -- Add_Inlined_Subprogram --
    ----------------------------
 
-   procedure Add_Inlined_Subprogram (Index : Subp_Index) is
-      E    : constant Entity_Id := Inlined.Table (Index).Name;
+   procedure Add_Inlined_Subprogram (E : Entity_Id) is
       Decl : constant Node_Id   := Parent (Declaration_Node (E));
       Pack : constant Entity_Id := Get_Code_Unit_Entity (E);
 
@@ -538,8 +542,6 @@ 
       else
          Register_Backend_Not_Inlined_Subprogram (E);
       end if;
-
-      Inlined.Table (Index).Listed := True;
    end Add_Inlined_Subprogram;
 
    ------------------------
@@ -606,7 +608,6 @@ 
          Inlined.Table (Inlined.Last).Name        := E;
          Inlined.Table (Inlined.Last).Next        := No_Subp;
          Inlined.Table (Inlined.Last).First_Succ  := No_Succ;
-         Inlined.Table (Inlined.Last).Listed      := False;
          Inlined.Table (Inlined.Last).Main_Call   := False;
          Inlined.Table (Inlined.Last).Processed   := False;
       end New_Entry;
@@ -832,7 +833,7 @@ 
          --  as part of an inlined package, but are not themselves called. An
          --  accurate computation of just those subprograms that are needed
          --  requires that we perform a transitive closure over the call graph,
-         --  starting from calls in the main program.
+         --  starting from calls in the main compilation unit.
 
          for Index in Inlined.First .. Inlined.Last loop
             if not Is_Called (Inlined.Table (Index).Name) then
@@ -879,10 +880,8 @@ 
          --  subprograms for the unit.
 
          for Index in Inlined.First .. Inlined.Last loop
-            if Is_Called (Inlined.Table (Index).Name)
-              and then not Inlined.Table (Index).Listed
-            then
-               Add_Inlined_Subprogram (Index);
+            if Is_Called (Inlined.Table (Index).Name) then
+               Add_Inlined_Subprogram (Inlined.Table (Index).Name);
             end if;
          end loop;