From 6c87c83bb2a8a65f6f73d23ebb863a5c67e4c6c2 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 19 Aug 2019 08:36:53 +0000 Subject: [Ada] Lift restriction on instantiations that are compilation units This change lifts the restriction that was still present in the new on-demand instantiation scheme for the body of generics instantiated in non-main units. The instantiations that are compilation units were still dealt with in the old-fashioned way, that is to say the decision of instantiating the body was still made up front during the analysis of the instance declaration, instead of being deferred until after a call to an inlined subprogram is encountered. This should save a few more cycles when full inlining across units is enabled, but there should otherwise be no functional changes. 2019-08-19 Eric Botcazou gcc/ada/ * inline.adb (Add_Inlined_Body): Do not special-case instances that are compilation units. (Add_Pending_Instantiation): Likewise. (Instantiate_Body): Skip instantiations that are compilation units and have already been performed. * sem_ch12.adb (Needs_Body_Instantiated): Do not special-case instances that are compilation units. (Load_Parent_Of_Generic): Be prepared for parent that is a compilation unit but whose instantiation node has not been replaced. gcc/testsuite/ * gnat.dg/generic_inst12.adb, gnat.dg/generic_inst12_pkg1.adb, gnat.dg/generic_inst12_pkg1.ads, gnat.dg/generic_inst12_pkg2.ads: New testcase. From-SVN: r274657 --- gcc/ada/inline.adb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'gcc/ada/inline.adb') diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index 22a50e2..46daa48 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -611,12 +611,11 @@ package body Inline is Inst_Decl := Unit_Declaration_Node (Inst); -- Do not inline the instance if the body already exists, - -- or if the instance is a compilation unit, or else if - -- the instance node is simply missing. + -- or the instance node is simply missing. if Present (Corresponding_Body (Inst_Decl)) - or else Nkind (Parent (Inst_Decl)) = N_Compilation_Unit - or else No (Next (Inst_Decl)) + or else (Nkind (Parent (Inst_Decl)) /= N_Compilation_Unit + and then No (Next (Inst_Decl))) then Set_Is_Called (Inst); else @@ -797,13 +796,11 @@ package body Inline is To_Pending_Instantiations.Set (Act_Decl, Index); - -- If an instantiation is either a compilation unit or is in the main - -- unit or subunit or is a nested subprogram, then its body is needed - -- as per the analysis already done in Analyze_Package_Instantiation - -- and Analyze_Subprogram_Instantiation. + -- If an instantiation is in the main unit or subunit, or is a nested + -- subprogram, then its body is needed as per the analysis done in + -- Analyze_Package_Instantiation & Analyze_Subprogram_Instantiation. - if Nkind (Parent (Inst)) = N_Compilation_Unit - or else In_Main_Unit_Or_Subunit (Act_Decl_Id) + if In_Main_Unit_Or_Subunit (Act_Decl_Id) or else (Is_Subprogram (Act_Decl_Id) and then Is_Nested (Act_Decl_Id)) then @@ -4460,6 +4457,13 @@ package body Inline is if No (Info.Inst_Node) then null; + -- If the instantiation node is a package body, this means that the + -- instance is a compilation unit and the instantiation has already + -- been performed by Build_Instance_Compilation_Unit_Nodes. + + elsif Nkind (Info.Inst_Node) = N_Package_Body then + null; + elsif Nkind (Info.Act_Decl) = N_Package_Declaration then Instantiate_Package_Body (Info); Add_Scope_To_Clean (Defining_Entity (Info.Act_Decl)); -- cgit v1.1