diff mbox

[Ada] Inter-unit inlining of expression functions with -gnatn1

Message ID 20141120142437.GA6455@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Nov. 20, 2014, 2:24 p.m. UTC
This enables inter-unit inlining of expression functions with -gnatn1, or more
simply with -O1/-O2 -gnatn.  These functions are automatically candidates for
inlining, but there were actually inlined across units only with -gnatn2, or
more simply -O3 -gnatn.

The following program must compile without warnings with -O -gnatn -Winline:

with Q; use Q;

procedure P (I : Integer) is
begin
  if Process (I) /= 2 * I then
    raise Program_Error;
  end if;
end;
package Q is

  function Process (I : Integer) return Integer;
  pragma Inline (Process);

end Q;
with R; use R;

package body Q is

  function Process (I : Integer) return Integer is
  begin
    return Process2 (I) + Process3 (I);
  end;

end Q;
package R is

  function Process2 (I : Integer) return Integer;

  function Process3 (I : Integer) return Integer is (I);

private

  function Process2 (I : Integer) return Integer is (I);

end R;

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

2014-11-20  Eric Botcazou  <ebotcazou@adacore.com>

	* inline.adb (Add_Inlined_Subprogram): Insert all programs
	generated as a body or whose declaration was provided along with
	the body.
diff mbox

Patch

Index: inline.adb
===================================================================
--- inline.adb	(revision 217842)
+++ inline.adb	(working copy)
@@ -454,6 +454,7 @@ 
 
    procedure Add_Inlined_Subprogram (Index : Subp_Index) is
       E    : constant Entity_Id := Inlined.Table (Index).Name;
+      Decl : constant Node_Id   := Parent (Declaration_Node (E));
       Pack : constant Entity_Id := Get_Code_Unit_Entity (E);
 
       procedure Register_Backend_Inlined_Subprogram (Subp : Entity_Id);
@@ -486,14 +487,17 @@ 
    begin
       --  If the subprogram is to be inlined, and if its unit is known to be
       --  inlined or is an instance whose body will be analyzed anyway or the
-      --  subprogram has been generated by the compiler, and if it is declared
+      --  subprogram was generated as a body by the compiler (for example an
+      --  initialization procedure) or its declaration was provided along with
+      --  the body (for example an expression function), and if it is declared
       --  at the library level not in the main unit, and if it can be inlined
       --  by the back-end, then insert it in the list of inlined subprograms.
 
       if Is_Inlined (E)
         and then (Is_Inlined (Pack)
                    or else Is_Generic_Instance (Pack)
-                   or else Is_Internal (E))
+                   or else Nkind (Decl) = N_Subprogram_Body
+                   or else Present (Corresponding_Body (Decl)))
         and then not In_Main_Unit_Or_Subunit (E)
         and then not Is_Nested (E)
         and then not Has_Initialized_Type (E)