From 73efc7ff4c07b08d8c8ab5e5deeb00d5586878e3 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Tue, 9 Oct 2018 15:05:29 +0000 Subject: [PATCH] [Ada] Unnesting: avoid unnecessary loads of System 2018-10-09 Ed Schonberg gcc/ada/ * exp_unst.adb (Unnest_Subprogram): Do not load System to obtain the Address entity unless an activation record is being built. Removes useless with_clauses for System when nested subprograms do not have uplevel references, and therefore do not need activation records. From-SVN: r264967 --- gcc/ada/ChangeLog | 8 ++++++++ gcc/ada/exp_unst.adb | 25 +++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index e7ce7ee15df..aee5a62c0f4 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2018-10-09 Ed Schonberg + + * exp_unst.adb (Unnest_Subprogram): Do not load System to obtain + the Address entity unless an activation record is being built. + Removes useless with_clauses for System when nested subprograms + do not have uplevel references, and therefore do not need + activation records. + 2018-10-09 Ed Schonberg * sem_ch6.adb (Fully_Conformant_Expressions): Handle properly diff --git a/gcc/ada/exp_unst.adb b/gcc/ada/exp_unst.adb index de4ea1a26ce..0b63aa66fc5 100644 --- a/gcc/ada/exp_unst.adb +++ b/gcc/ada/exp_unst.adb @@ -746,6 +746,10 @@ package body Exp_Unst is procedure Register_Subprogram (E : Entity_Id; Bod : Node_Id) is L : constant Nat := Get_Level (Subp, E); + -- Subprograms declared in tasks and protected types cannot + -- be eliminated because calls to them may be in other units, + -- so they must be treated as reachable. + begin -- Subprograms declared in tasks and protected types cannot -- be eliminated because calls to them may be in other units, @@ -756,10 +760,6 @@ package body Exp_Unst is Bod => Bod, Lev => L, Reachable => In_Synchronized_Unit (E), - - -- Subprograms declared in tasks and protected types are - -- reachable and cannot be eliminated. - Uplevel_Ref => L, Declares_AREC => False, Uents => No_Elist, @@ -1148,7 +1148,7 @@ package body Exp_Unst is return Skip; end if; - -- Pragmas and component declarations can be ignored + -- Pragmas and component declarations can be ignored. -- Quantified expressions are expanded into explicit loops -- and the original epression must be ignored. @@ -1383,10 +1383,10 @@ package body Exp_Unst is -- If this entity was marked reachable because it is -- in a task or protected type, there may not appear - -- to be any calls to it, which would normally adjust - -- the levels of the parent subprograms. So we need to - -- be sure that the uplevel reference of that entity - -- takes into account possible calls. + -- to be any calls to it, which would normally + -- adjust the levels of the parent subprograms. + -- So we need to be sure that the uplevel reference + -- of that entity takes into account possible calls. if In_Synchronized_Unit (SUBF.Ent) and then SUBT.Lev < SUBI.Uplevel_Ref @@ -1627,7 +1627,7 @@ package body Exp_Unst is -- Loop through subprograms Subp_Loop : declare - Addr : constant Entity_Id := RTE (RE_Address); + Addr : Entity_Id := Empty; begin for J in Subps_First .. Subps.Last loop @@ -1745,9 +1745,14 @@ package body Exp_Unst is begin -- Build list of component declarations for ARECnT + -- and load System.Address. Clist := Empty_List; + if No (Addr) then + Addr := RTE (RE_Address); + end if; + -- If we are in a subprogram that has a static link that -- is passed in (as indicated by ARECnF being defined), -- then include ARECnU : ARECmPT where ARECmPT comes from -- 2.30.2