diff options
author | Arnaud Charlet <charlet@gcc.gnu.org> | 2012-06-12 14:11:50 +0200 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2012-06-12 14:11:50 +0200 |
commit | 4c7be3105294ae11d15bcb9265a1199a34666e1b (patch) | |
tree | 8b357df419b643a99514ae1be0743478c65946d4 /gcc/ada/inline.adb | |
parent | 33738c606df5ea714dd9260ba65e7643e3216dea (diff) | |
download | gcc-4c7be3105294ae11d15bcb9265a1199a34666e1b.zip gcc-4c7be3105294ae11d15bcb9265a1199a34666e1b.tar.gz gcc-4c7be3105294ae11d15bcb9265a1199a34666e1b.tar.bz2 |
[multiple changes]
2012-06-12 Robert Dewar <dewar@adacore.com>
* sem_ch12.adb: Minor reformatting.
2012-06-12 Eric Botcazou <ebotcazou@adacore.com>
* opt.ads (Inline_Level): New variable.
* gnat1drv.adb (Adjust_Global_Switches): Set it based on optimization
level if it has not been set by the user.
* switch-c.adb (Scan_Front_End_Switches): Accept -gnatn1 and -gnatn2
and set Inline_Level accordingly.
* inline.adb (Add_Inlined_Body): Declate new Inline_Level_Type type.
(Must_Inline): Return Inline_Level_T instead of Boolean to indicate
whether the package of the inlined subprogram must be compiled.
If Inline_Level is set to 1, only compile packages of subprograms
directly called from the main unit.
* usage.adb (Usage): Adjust line for -gnatn switch.
* gnat_ugn.texi (Switches for gcc): Document -gnatn1 and -gnatn2.
From-SVN: r188451
Diffstat (limited to 'gcc/ada/inline.adb')
-rw-r--r-- | gcc/ada/inline.adb | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index 2fa6054..01f8ff1 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -229,7 +229,13 @@ package body Inline is procedure Add_Inlined_Body (E : Entity_Id) is - function Must_Inline return Boolean; + type Inline_Level_Type is (Dont_Inline, Inline_Call, Inline_Package); + -- Level of inlining for the call: Dont_Inline means no inlining, + -- Inline_Call means that only the call is considered for inlining, + -- Inline_Package means that the call is considered for inlining and + -- its package compiled and scanned for more inlining opportunities. + + function Must_Inline return Inline_Level_Type; -- Inlining is only done if the call statement N is in the main unit, -- or within the body of another inlined subprogram. @@ -237,7 +243,7 @@ package body Inline is -- Must_Inline -- ----------------- - function Must_Inline return Boolean is + function Must_Inline return Inline_Level_Type is Scop : Entity_Id; Comp : Node_Id; @@ -251,7 +257,7 @@ package body Inline is -- trouble to try to inline at this level. if Scop = Standard_Standard then - return False; + return Dont_Inline; end if; -- Otherwise lookup scope stack to outer scope @@ -267,14 +273,19 @@ package body Inline is Comp := Parent (Comp); end loop; + -- If the call is in the main unit, inline the call and compile the + -- package of the subprogram to find more calls to be inlined. + if Comp = Cunit (Main_Unit) or else Comp = Library_Unit (Cunit (Main_Unit)) then Add_Call (E); - return True; + return Inline_Package; end if; - -- Call is not in main unit. See if it's in some inlined subprogram + -- 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. Scop := Current_Scope; while Scope (Scop) /= Standard_Standard @@ -284,15 +295,21 @@ package body Inline is and then Is_Inlined (Scop) then Add_Call (E, Scop); - return True; + if Inline_Level = 1 then + return Inline_Call; + else + return Inline_Package; + end if; end if; Scop := Scope (Scop); end loop; - return False; + return Dont_Inline; end Must_Inline; + Level : Inline_Level_Type; + -- Start of processing for Add_Inlined_Body begin @@ -309,11 +326,15 @@ package body Inline is -- no enclosing package to retrieve. In this case, it is the body of -- the function that will have to be loaded. - if not Is_Abstract_Subprogram (E) - and then not Is_Nested (E) - and then Convention (E) /= Convention_Protected - and then Must_Inline + 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 declare Pack : constant Entity_Id := Get_Code_Unit_Entity (E); @@ -339,7 +360,8 @@ package body Inline is -- declares the type, and that body is visible to the back end. -- Do not inline it either if it is in the main unit. - elsif not Is_Inlined (Pack) + elsif Level = Inline_Package + and then not Is_Inlined (Pack) and then Comes_From_Source (E) and then not In_Main_Unit_Or_Subunit (Pack) then |