annotate gcc/ada/inline.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- I N L I N E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This module handles four kinds of inlining activity:
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 -- a) Instantiation of generic bodies. This is done unconditionally, after
kono
parents:
diff changeset
29 -- analysis and expansion of the main unit.
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 -- b) Compilation of unit bodies that contain the bodies of inlined sub-
kono
parents:
diff changeset
32 -- programs. This is done only if inlining is enabled (-gnatn). Full inlining
kono
parents:
diff changeset
33 -- requires that a) and b) be mutually recursive, because each step may
kono
parents:
diff changeset
34 -- generate another generic expansion and further inlined calls.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- c) Front-end inlining for Inline_Always subprograms. This is primarily an
kono
parents:
diff changeset
37 -- expansion activity that is performed for performance reasons, and when the
kono
parents:
diff changeset
38 -- target does not use the GCC back end.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- d) Front-end inlining for GNATprove, to perform source transformations
kono
parents:
diff changeset
41 -- to simplify formal verification. The machinery used is the same as for
kono
parents:
diff changeset
42 -- Inline_Always subprograms, but there are fewer restrictions on the source
kono
parents:
diff changeset
43 -- of subprograms.
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 with Opt; use Opt;
kono
parents:
diff changeset
46 with Sem; use Sem;
kono
parents:
diff changeset
47 with Types; use Types;
kono
parents:
diff changeset
48 with Warnsw; use Warnsw;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 package Inline is
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 --------------------------------
kono
parents:
diff changeset
53 -- Generic Body Instantiation --
kono
parents:
diff changeset
54 --------------------------------
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 -- The bodies of generic instantiations are built after semantic analysis
kono
parents:
diff changeset
57 -- of the main unit is complete. Generic instantiations are saved in a
kono
parents:
diff changeset
58 -- global data structure, and the bodies constructed by means of a separate
kono
parents:
diff changeset
59 -- analysis and expansion step.
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- See full description in body of Sem_Ch12 for more details
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 type Pending_Body_Info is record
kono
parents:
diff changeset
64 Act_Decl : Node_Id;
kono
parents:
diff changeset
65 -- Declaration for package or subprogram spec for instantiation
kono
parents:
diff changeset
66
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
67 Config_Switches : Config_Switches_Type;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
68 -- Capture the values of configuration switches
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
70 Current_Sem_Unit : Unit_Number_Type;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
71 -- The semantic unit within which the instantiation is found. Must be
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
72 -- restored when compiling the body, to insure that internal entities
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
73 -- use the same counter and are unique over spec and body.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
74
111
kono
parents:
diff changeset
75 Expander_Status : Boolean;
kono
parents:
diff changeset
76 -- If the body is instantiated only for semantic checking, expansion
kono
parents:
diff changeset
77 -- must be inhibited.
kono
parents:
diff changeset
78
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
79 Inst_Node : Node_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
80 -- Node for instantiation that requires the body
111
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 Scope_Suppress : Suppress_Record;
kono
parents:
diff changeset
83 Local_Suppress_Stack_Top : Suppress_Stack_Entry_Ptr;
kono
parents:
diff changeset
84 -- Save suppress information at the point of instantiation. Used to
kono
parents:
diff changeset
85 -- properly inherit check status active at this point (see RM 11.5
kono
parents:
diff changeset
86 -- (7.2/2), AI95-00224-01):
kono
parents:
diff changeset
87 --
kono
parents:
diff changeset
88 -- "If a checking pragma applies to a generic instantiation, then the
kono
parents:
diff changeset
89 -- checking pragma also applies to the instance. If a checking pragma
kono
parents:
diff changeset
90 -- applies to a call to a subprogram that has a pragma Inline applied
kono
parents:
diff changeset
91 -- to it, then the checking pragma also applies to the inlined
kono
parents:
diff changeset
92 -- subprogram body".
kono
parents:
diff changeset
93 --
kono
parents:
diff changeset
94 -- This means we have to capture this information from the current scope
kono
parents:
diff changeset
95 -- at the point of instantiation.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 Warnings : Warning_Record;
kono
parents:
diff changeset
98 -- Capture values of warning flags
kono
parents:
diff changeset
99 end record;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 -----------------
kono
parents:
diff changeset
102 -- Subprograms --
kono
parents:
diff changeset
103 -----------------
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 procedure Initialize;
kono
parents:
diff changeset
106 -- Initialize internal tables
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 procedure Lock;
kono
parents:
diff changeset
109 -- Lock internal tables before calling backend
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 procedure Instantiate_Bodies;
kono
parents:
diff changeset
112 -- This procedure is called after semantic analysis is complete, to
kono
parents:
diff changeset
113 -- instantiate the bodies of generic instantiations that appear in the
kono
parents:
diff changeset
114 -- compilation unit.
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 procedure Add_Inlined_Body (E : Entity_Id; N : Node_Id);
kono
parents:
diff changeset
117 -- E is an inlined subprogram appearing in a call, either explicitly or in
kono
parents:
diff changeset
118 -- a discriminant check for which gigi builds a call or an at-end handler.
kono
parents:
diff changeset
119 -- Add E's enclosing unit to Inlined_Bodies so that E can be subsequently
kono
parents:
diff changeset
120 -- retrieved and analyzed. N is the node giving rise to the call to E.
kono
parents:
diff changeset
121
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
122 procedure Add_Pending_Instantiation (Inst : Node_Id; Act_Decl : Node_Id);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
123 -- Add an entry in the table of generic bodies to be instantiated.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
124
111
kono
parents:
diff changeset
125 procedure Analyze_Inlined_Bodies;
kono
parents:
diff changeset
126 -- At end of compilation, analyze the bodies of all units that contain
kono
parents:
diff changeset
127 -- inlined subprograms that are actually called.
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 procedure Build_Body_To_Inline (N : Node_Id; Spec_Id : Entity_Id);
kono
parents:
diff changeset
130 -- If a subprogram has pragma Inline and inlining is active, use generic
kono
parents:
diff changeset
131 -- machinery to build an unexpanded body for the subprogram. This body is
kono
parents:
diff changeset
132 -- subsequently used for inline expansions at call sites. If subprogram can
kono
parents:
diff changeset
133 -- be inlined (depending on size and nature of local declarations) the
kono
parents:
diff changeset
134 -- template body is created. Otherwise subprogram body is treated normally
kono
parents:
diff changeset
135 -- and calls are not inlined in the frontend. If proper warnings are
kono
parents:
diff changeset
136 -- enabled and the subprogram contains a construct that cannot be inlined,
kono
parents:
diff changeset
137 -- the problematic construct is flagged accordingly.
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 function Call_Can_Be_Inlined_In_GNATprove_Mode
kono
parents:
diff changeset
140 (N : Node_Id;
kono
parents:
diff changeset
141 Subp : Entity_Id) return Boolean;
kono
parents:
diff changeset
142 -- Returns False if the call in node N to subprogram Subp cannot be inlined
kono
parents:
diff changeset
143 -- in GNATprove mode, because it may lead to missing a check on type
kono
parents:
diff changeset
144 -- conversion of input parameters otherwise. Returns True otherwise.
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 function Can_Be_Inlined_In_GNATprove_Mode
kono
parents:
diff changeset
147 (Spec_Id : Entity_Id;
kono
parents:
diff changeset
148 Body_Id : Entity_Id) return Boolean;
kono
parents:
diff changeset
149 -- Returns True if the subprogram identified by Spec_Id and Body_Id can
kono
parents:
diff changeset
150 -- be inlined in GNATprove mode. One but not both of Spec_Id and Body_Id
kono
parents:
diff changeset
151 -- can be Empty. Body_Id is Empty when doing a partial check on a call
kono
parents:
diff changeset
152 -- to a subprogram whose body has not been seen yet, to know whether this
kono
parents:
diff changeset
153 -- subprogram could possibly be inlined. GNATprove relies on this to adapt
kono
parents:
diff changeset
154 -- its treatment of the subprogram.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 procedure Cannot_Inline
kono
parents:
diff changeset
157 (Msg : String;
kono
parents:
diff changeset
158 N : Node_Id;
kono
parents:
diff changeset
159 Subp : Entity_Id;
kono
parents:
diff changeset
160 Is_Serious : Boolean := False);
kono
parents:
diff changeset
161 -- This procedure is called if the node N, an instance of a call to
kono
parents:
diff changeset
162 -- subprogram Subp, cannot be inlined. Msg is the message to be issued,
kono
parents:
diff changeset
163 -- which ends with ? (it does not end with ?p?, this routine takes care of
kono
parents:
diff changeset
164 -- the need to change ? to ?p?). The behavior of this routine depends on
kono
parents:
diff changeset
165 -- the value of Back_End_Inlining:
kono
parents:
diff changeset
166 --
kono
parents:
diff changeset
167 -- * If Back_End_Inlining is not set (ie. legacy frontend inlining model)
kono
parents:
diff changeset
168 -- then if Subp has a pragma Always_Inlined, then an error message is
kono
parents:
diff changeset
169 -- issued (by removing the last character of Msg). If Subp is not
kono
parents:
diff changeset
170 -- Always_Inlined, then a warning is issued if the flag Ineffective_
kono
parents:
diff changeset
171 -- Inline_Warnings is set, adding ?p to the msg, and if not, the call
kono
parents:
diff changeset
172 -- has no effect.
kono
parents:
diff changeset
173 --
kono
parents:
diff changeset
174 -- * If Back_End_Inlining is set then:
kono
parents:
diff changeset
175 -- - If Is_Serious is true, then an error is reported (by removing the
kono
parents:
diff changeset
176 -- last character of Msg);
kono
parents:
diff changeset
177 --
kono
parents:
diff changeset
178 -- - otherwise:
kono
parents:
diff changeset
179 --
kono
parents:
diff changeset
180 -- * Compiling without optimizations if Subp has a pragma
kono
parents:
diff changeset
181 -- Always_Inlined, then an error message is issued; if Subp is
kono
parents:
diff changeset
182 -- not Always_Inlined, then a warning is issued if the flag
kono
parents:
diff changeset
183 -- Ineffective_Inline_Warnings is set (adding p?), and if not,
kono
parents:
diff changeset
184 -- the call has no effect.
kono
parents:
diff changeset
185 --
kono
parents:
diff changeset
186 -- * Compiling with optimizations then a warning is issued if the
kono
parents:
diff changeset
187 -- flag Ineffective_Inline_Warnings is set (adding p?); otherwise
kono
parents:
diff changeset
188 -- no effect since inlining may be performed by the backend.
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 procedure Check_And_Split_Unconstrained_Function
kono
parents:
diff changeset
191 (N : Node_Id;
kono
parents:
diff changeset
192 Spec_Id : Entity_Id;
kono
parents:
diff changeset
193 Body_Id : Entity_Id);
kono
parents:
diff changeset
194 -- Spec_Id and Body_Id are the entities of the specification and body of
kono
parents:
diff changeset
195 -- the subprogram body N. If N can be inlined by the frontend (supported
kono
parents:
diff changeset
196 -- cases documented in Check_Body_To_Inline) then build the body-to-inline
kono
parents:
diff changeset
197 -- associated with N and attach it to the declaration node of Spec_Id.
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 procedure Check_Package_Body_For_Inlining (N : Node_Id; P : Entity_Id);
kono
parents:
diff changeset
200 -- If front-end inlining is enabled and a package declaration contains
kono
parents:
diff changeset
201 -- inlined subprograms, load and compile the package body to collect the
kono
parents:
diff changeset
202 -- bodies of these subprograms, so they are available to inline calls.
kono
parents:
diff changeset
203 -- N is the compilation unit for the package.
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 procedure Expand_Inlined_Call
kono
parents:
diff changeset
206 (N : Node_Id;
kono
parents:
diff changeset
207 Subp : Entity_Id;
kono
parents:
diff changeset
208 Orig_Subp : Entity_Id);
kono
parents:
diff changeset
209 -- If called subprogram can be inlined by the front-end, retrieve the
kono
parents:
diff changeset
210 -- analyzed body, replace formals with actuals and expand call in place.
kono
parents:
diff changeset
211 -- Generate thunks for actuals that are expressions, and insert the
kono
parents:
diff changeset
212 -- corresponding constant declarations before the call. If the original
kono
parents:
diff changeset
213 -- call is to a derived operation, the return type is the one of the
kono
parents:
diff changeset
214 -- derived operation, but the body is that of the original, so return
kono
parents:
diff changeset
215 -- expressions in the body must be converted to the desired type (which
kono
parents:
diff changeset
216 -- is simply not noted in the tree without inline expansion).
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 function Has_Excluded_Declaration
kono
parents:
diff changeset
219 (Subp : Entity_Id;
kono
parents:
diff changeset
220 Decls : List_Id) return Boolean;
kono
parents:
diff changeset
221 -- Check a list of declarations, Decls, that make the inlining of Subp not
kono
parents:
diff changeset
222 -- worthwhile
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 function Has_Excluded_Statement
kono
parents:
diff changeset
225 (Subp : Entity_Id;
kono
parents:
diff changeset
226 Stats : List_Id) return Boolean;
kono
parents:
diff changeset
227 -- Check a list of statements, Stats, that make inlining of Subp not
kono
parents:
diff changeset
228 -- worthwhile, including any tasking statement, nested at any level.
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 procedure List_Inlining_Info;
kono
parents:
diff changeset
231 -- Generate listing of calls inlined by the frontend plus listing of
kono
parents:
diff changeset
232 -- calls to inline subprograms passed to the backend.
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 procedure Remove_Dead_Instance (N : Node_Id);
kono
parents:
diff changeset
235 -- If an instantiation appears in unreachable code, delete the pending
kono
parents:
diff changeset
236 -- body instance.
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 end Inline;