+2019-08-13 Eric Botcazou <ebotcazou@adacore.com>
+
+ * 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 <ebotcazou@adacore.com>
* sem.adb (Do_Analyze): Recompute Style_Check_Max_Line_Length
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;
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
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;
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;
-- 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
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;
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 --
------------------------
-- 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.
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 --
----------------------------------
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;