From: Eric Botcazou Date: Tue, 13 Aug 2019 08:08:11 +0000 (+0000) Subject: [Ada] Small cleanup and improvement in inlining machinery X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=49209838d35fbf7a130738be6eb0c281a40e8f20;p=gcc.git [Ada] Small cleanup and improvement in inlining machinery This is a small cleanup in the inlining machinery of the front-end dealing with back-end inlining. It should save a few cycles at -O0 by stopping it from doing useless work. No functional changes. 2019-08-13 Eric Botcazou gcc/ada/ * exp_ch6.adb: Remove with and use clauses for Sem_Ch12. (Expand_Call_Helper): Swap the back-end inlining case and the special front-end expansion case. In back-end inlining mode, do not invoke Add_Inlined_Body unless the call may be inlined. * inline.ads (Add_Pending_Instantiation): New function moved from... * inline.adb (Add_Inlined_Body): Simplify comment. Turn test on the enclosing unit into assertion. (Add_Pending_Instantiation): New function moved from... * sem_ch12.ads (Add_Pending_Instantiation): ...here. * sem_ch12.adb (Add_Pending_Instantiation): ...here. From-SVN: r274353 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index a34c4eec137..9a97482f521 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,17 @@ +2019-08-13 Eric Botcazou + + * exp_ch6.adb: Remove with and use clauses for Sem_Ch12. + (Expand_Call_Helper): Swap the back-end inlining case and the + special front-end expansion case. In back-end inlining mode, do + not invoke Add_Inlined_Body unless the call may be inlined. + * inline.ads (Add_Pending_Instantiation): New function moved + from... + * inline.adb (Add_Inlined_Body): Simplify comment. Turn test on + the enclosing unit into assertion. + (Add_Pending_Instantiation): New function moved from... + * sem_ch12.ads (Add_Pending_Instantiation): ...here. + * sem_ch12.adb (Add_Pending_Instantiation): ...here. + 2019-08-13 Eric Botcazou * sem.adb (Do_Analyze): Recompute Style_Check_Max_Line_Length diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 4fd38605e63..128fb9015df 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -60,7 +60,6 @@ with Sem; use Sem; with Sem_Aux; use Sem_Aux; 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_Dim; use Sem_Dim; with Sem_Disp; use Sem_Disp; @@ -4316,15 +4315,15 @@ package body Exp_Ch6 is if not Is_Inlined (Subp) then null; - -- Frontend inlining of expression functions (performed also when - -- backend inlining is enabled). + -- Front-end inlining of expression functions (performed also when + -- back-end inlining is enabled). elsif Is_Inlinable_Expression_Function (Subp) then Rewrite (N, New_Copy (Expression_Of_Expression_Function (Subp))); Analyze (N); return; - -- Handle frontend inlining + -- Handle front-end inlining elsif not Back_End_Inlining then Inlined_Subprogram : declare @@ -4420,27 +4419,36 @@ package body Exp_Ch6 is end if; end Inlined_Subprogram; - -- Back end inlining: let the back end handle it + -- Front-end expansion of simple functions returning unconstrained + -- types (see Check_And_Split_Unconstrained_Function). Note that the + -- case of a simple renaming (Body_To_Inline in N_Entity below, see + -- also Build_Renamed_Body) cannot be expanded here because this may + -- give rise to order-of-elaboration issues for the types of the + -- parameters of the subprogram, if any. + + elsif Present (Unit_Declaration_Node (Subp)) + and then Nkind (Unit_Declaration_Node (Subp)) = + N_Subprogram_Declaration + and then Present (Body_To_Inline (Unit_Declaration_Node (Subp))) + and then + Nkind (Body_To_Inline (Unit_Declaration_Node (Subp))) not in + N_Entity + then + Expand_Inlined_Call (Call_Node, Subp, Orig_Subp); + + -- Back-end inlining either if optimization is enabled or the call is + -- required to be inlined. - elsif No (Unit_Declaration_Node (Subp)) - or else Nkind (Unit_Declaration_Node (Subp)) /= - N_Subprogram_Declaration - or else No (Body_To_Inline (Unit_Declaration_Node (Subp))) - or else Nkind (Body_To_Inline (Unit_Declaration_Node (Subp))) in - N_Entity + elsif Optimization_Level > 0 + or else Has_Pragma_Inline_Always (Subp) then Add_Inlined_Body (Subp, Call_Node); - -- If the inlined call appears within an instantiation and either - -- is required to be inlined or optimization is enabled, ensure + -- If the inlined call appears within an instance, then ensure -- that the enclosing instance body is available so the back end -- can actually perform the inlining. - if In_Instance - and then Comes_From_Source (Subp) - and then (Has_Pragma_Inline_Always (Subp) - or else Optimization_Level > 0) - then + if In_Instance and then Comes_From_Source (Subp) then declare Decl : Node_Id; Inst : Entity_Id; @@ -4491,16 +4499,6 @@ package body Exp_Ch6 is end if; end; end if; - - -- Front end expansion of simple functions returning unconstrained - -- types (see Check_And_Split_Unconstrained_Function). Note that the - -- case of a simple renaming (Body_To_Inline in N_Entity above, see - -- also Build_Renamed_Body) cannot be expanded here because this may - -- give rise to order-of-elaboration issues for the types of the - -- parameters of the subprogram, if any. - - else - Expand_Inlined_Call (Call_Node, Subp, Orig_Subp); end if; end if; diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index 5b7fefc0c7e..3a3ec0cf8ed 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -485,9 +485,7 @@ package body Inline is -- is the case for an initialization procedure, which appears in the -- package declaration that contains the type. It is also the case if -- the body has already been analyzed. Finally, if the unit enclosing - -- E is an instance, the instance body will be analyzed in any case, - -- and there is no need to add the enclosing unit (whose body might not - -- be available). + -- E is an instance, the instance body will be analyzed in any case. -- Library-level functions must be handled specially, because there is -- no enclosing package to retrieve. In this case, it is the body of @@ -497,13 +495,14 @@ package body Inline is Pack : constant Entity_Id := Get_Code_Unit_Entity (E); begin + Set_Is_Called (E); + if Pack = E then - Set_Is_Called (E); Inlined_Bodies.Increment_Last; Inlined_Bodies.Table (Inlined_Bodies.Last) := E; - elsif Ekind (Pack) = E_Package then - Set_Is_Called (E); + else + pragma Assert (Ekind (Pack) = E_Package); if Is_Generic_Instance (Pack) then null; @@ -606,6 +605,26 @@ package body Inline is end if; end Add_Inlined_Subprogram; + -------------------------------- + -- Add_Pending_Instantiation -- + -------------------------------- + + procedure Add_Pending_Instantiation (Inst : Node_Id; Act_Decl : Node_Id) is + begin + -- Capture the body of the generic instantiation along with its context + -- for later processing by Instantiate_Bodies. + + Pending_Instantiations.Append + ((Act_Decl => Act_Decl, + Config_Switches => Save_Config_Switches, + Current_Sem_Unit => Current_Sem_Unit, + Expander_Status => Expander_Active, + Inst_Node => Inst, + Local_Suppress_Stack_Top => Local_Suppress_Stack_Top, + Scope_Suppress => Scope_Suppress, + Warnings => Save_Warnings)); + end Add_Pending_Instantiation; + ------------------------ -- Add_Scope_To_Clean -- ------------------------ diff --git a/gcc/ada/inline.ads b/gcc/ada/inline.ads index 0e5a47ea24b..e822ddceba2 100644 --- a/gcc/ada/inline.ads +++ b/gcc/ada/inline.ads @@ -143,6 +143,9 @@ package Inline is -- Add E's enclosing unit to Inlined_Bodies so that E can be subsequently -- retrieved and analyzed. N is the node giving rise to the call to E. + procedure Add_Pending_Instantiation (Inst : Node_Id; Act_Decl : Node_Id); + -- Add an entry in the table of generic bodies to be instantiated. + procedure Analyze_Inlined_Bodies; -- At end of compilation, analyze the bodies of all units that contain -- inlined subprograms that are actually called. diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index 8b031b529ae..9f174948253 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -1025,26 +1025,6 @@ package body Sem_Ch12 is raise Instantiation_Error; end Abandon_Instantiation; - -------------------------------- - -- Add_Pending_Instantiation -- - -------------------------------- - - procedure Add_Pending_Instantiation (Inst : Node_Id; Act_Decl : Node_Id) is - begin - -- Capture the body of the generic instantiation along with its context - -- for later processing by Instantiate_Bodies. - - Pending_Instantiations.Append - ((Act_Decl => Act_Decl, - Config_Switches => Save_Config_Switches, - Current_Sem_Unit => Current_Sem_Unit, - Expander_Status => Expander_Active, - Inst_Node => Inst, - Local_Suppress_Stack_Top => Local_Suppress_Stack_Top, - Scope_Suppress => Scope_Suppress, - Warnings => Save_Warnings)); - end Add_Pending_Instantiation; - ---------------------------------- -- Adjust_Inherited_Pragma_Sloc -- ---------------------------------- diff --git a/gcc/ada/sem_ch12.ads b/gcc/ada/sem_ch12.ads index 9c713681aec..f0b72f49dbd 100644 --- a/gcc/ada/sem_ch12.ads +++ b/gcc/ada/sem_ch12.ads @@ -37,10 +37,6 @@ package Sem_Ch12 is procedure Analyze_Formal_Subprogram_Declaration (N : Node_Id); procedure Analyze_Formal_Package_Declaration (N : Node_Id); - procedure Add_Pending_Instantiation (Inst : Node_Id; Act_Decl : Node_Id); - -- Add an entry in the table of instance bodies that must be analyzed - -- when inlining requires its body or the body of a nested instance. - function Build_Function_Wrapper (Formal_Subp : Entity_Id; Actual_Subp : Entity_Id) return Node_Id;