===================================================================
@@ -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;