annotate gcc/ada/inline.ads @ 118:fd00160c1b76

ifdef TARGET_64BIT
author mir3636
date Tue, 27 Feb 2018 15:01:35 +0900
parents 04ced10e8804
children 84e7813d76e9
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 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
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 Alloc;
kono
parents:
diff changeset
46 with Opt; use Opt;
kono
parents:
diff changeset
47 with Sem; use Sem;
kono
parents:
diff changeset
48 with Table;
kono
parents:
diff changeset
49 with Types; use Types;
kono
parents:
diff changeset
50 with Warnsw; use Warnsw;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 package Inline is
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 --------------------------------
kono
parents:
diff changeset
55 -- Generic Body Instantiation --
kono
parents:
diff changeset
56 --------------------------------
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 -- The bodies of generic instantiations are built after semantic analysis
kono
parents:
diff changeset
59 -- of the main unit is complete. Generic instantiations are saved in a
kono
parents:
diff changeset
60 -- global data structure, and the bodies constructed by means of a separate
kono
parents:
diff changeset
61 -- analysis and expansion step.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 -- See full description in body of Sem_Ch12 for more details
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 type Pending_Body_Info is record
kono
parents:
diff changeset
66 Inst_Node : Node_Id;
kono
parents:
diff changeset
67 -- Node for instantiation that requires the body
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 Act_Decl : Node_Id;
kono
parents:
diff changeset
70 -- Declaration for package or subprogram spec for instantiation
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 Expander_Status : Boolean;
kono
parents:
diff changeset
73 -- If the body is instantiated only for semantic checking, expansion
kono
parents:
diff changeset
74 -- must be inhibited.
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 Current_Sem_Unit : Unit_Number_Type;
kono
parents:
diff changeset
77 -- The semantic unit within which the instantiation is found. Must be
kono
parents:
diff changeset
78 -- restored when compiling the body, to insure that internal entities
kono
parents:
diff changeset
79 -- use the same counter and are unique over spec and body.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 Scope_Suppress : Suppress_Record;
kono
parents:
diff changeset
82 Local_Suppress_Stack_Top : Suppress_Stack_Entry_Ptr;
kono
parents:
diff changeset
83 -- Save suppress information at the point of instantiation. Used to
kono
parents:
diff changeset
84 -- properly inherit check status active at this point (see RM 11.5
kono
parents:
diff changeset
85 -- (7.2/2), AI95-00224-01):
kono
parents:
diff changeset
86 --
kono
parents:
diff changeset
87 -- "If a checking pragma applies to a generic instantiation, then the
kono
parents:
diff changeset
88 -- checking pragma also applies to the instance. If a checking pragma
kono
parents:
diff changeset
89 -- applies to a call to a subprogram that has a pragma Inline applied
kono
parents:
diff changeset
90 -- to it, then the checking pragma also applies to the inlined
kono
parents:
diff changeset
91 -- subprogram body".
kono
parents:
diff changeset
92 --
kono
parents:
diff changeset
93 -- This means we have to capture this information from the current scope
kono
parents:
diff changeset
94 -- at the point of instantiation.
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 Version : Ada_Version_Type;
kono
parents:
diff changeset
97 -- The body must be compiled with the same language version as the
kono
parents:
diff changeset
98 -- spec. The version may be set by a configuration pragma in a separate
kono
parents:
diff changeset
99 -- file or in the current file, and may differ from body to body.
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 Version_Pragma : Node_Id;
kono
parents:
diff changeset
102 -- This is linked with the Version value
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 Warnings : Warning_Record;
kono
parents:
diff changeset
105 -- Capture values of warning flags
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 SPARK_Mode : SPARK_Mode_Type;
kono
parents:
diff changeset
108 SPARK_Mode_Pragma : Node_Id;
kono
parents:
diff changeset
109 -- SPARK_Mode for an instance is the one applicable at the point of
kono
parents:
diff changeset
110 -- instantiation. SPARK_Mode_Pragma is the related active pragma.
kono
parents:
diff changeset
111 end record;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 package Pending_Instantiations is new Table.Table (
kono
parents:
diff changeset
114 Table_Component_Type => Pending_Body_Info,
kono
parents:
diff changeset
115 Table_Index_Type => Int,
kono
parents:
diff changeset
116 Table_Low_Bound => 0,
kono
parents:
diff changeset
117 Table_Initial => Alloc.Pending_Instantiations_Initial,
kono
parents:
diff changeset
118 Table_Increment => Alloc.Pending_Instantiations_Increment,
kono
parents:
diff changeset
119 Table_Name => "Pending_Instantiations");
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 -- The following table records subprograms and packages for which
kono
parents:
diff changeset
122 -- generation of subprogram descriptors must be delayed.
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 package Pending_Descriptor is new Table.Table (
kono
parents:
diff changeset
125 Table_Component_Type => Entity_Id,
kono
parents:
diff changeset
126 Table_Index_Type => Int,
kono
parents:
diff changeset
127 Table_Low_Bound => 0,
kono
parents:
diff changeset
128 Table_Initial => Alloc.Pending_Instantiations_Initial,
kono
parents:
diff changeset
129 Table_Increment => Alloc.Pending_Instantiations_Increment,
kono
parents:
diff changeset
130 Table_Name => "Pending_Descriptor");
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 -- The following should be initialized in an init call in Frontend, we
kono
parents:
diff changeset
133 -- have thoughts of making the frontend reusable in future ???
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 -----------------
kono
parents:
diff changeset
136 -- Subprograms --
kono
parents:
diff changeset
137 -----------------
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 procedure Initialize;
kono
parents:
diff changeset
140 -- Initialize internal tables
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 procedure Lock;
kono
parents:
diff changeset
143 -- Lock internal tables before calling backend
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 procedure Instantiate_Bodies;
kono
parents:
diff changeset
146 -- This procedure is called after semantic analysis is complete, to
kono
parents:
diff changeset
147 -- instantiate the bodies of generic instantiations that appear in the
kono
parents:
diff changeset
148 -- compilation unit.
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 procedure Add_Inlined_Body (E : Entity_Id; N : Node_Id);
kono
parents:
diff changeset
151 -- E is an inlined subprogram appearing in a call, either explicitly or in
kono
parents:
diff changeset
152 -- a discriminant check for which gigi builds a call or an at-end handler.
kono
parents:
diff changeset
153 -- Add E's enclosing unit to Inlined_Bodies so that E can be subsequently
kono
parents:
diff changeset
154 -- retrieved and analyzed. N is the node giving rise to the call to E.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 procedure Analyze_Inlined_Bodies;
kono
parents:
diff changeset
157 -- At end of compilation, analyze the bodies of all units that contain
kono
parents:
diff changeset
158 -- inlined subprograms that are actually called.
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 procedure Build_Body_To_Inline (N : Node_Id; Spec_Id : Entity_Id);
kono
parents:
diff changeset
161 -- If a subprogram has pragma Inline and inlining is active, use generic
kono
parents:
diff changeset
162 -- machinery to build an unexpanded body for the subprogram. This body is
kono
parents:
diff changeset
163 -- subsequently used for inline expansions at call sites. If subprogram can
kono
parents:
diff changeset
164 -- be inlined (depending on size and nature of local declarations) the
kono
parents:
diff changeset
165 -- template body is created. Otherwise subprogram body is treated normally
kono
parents:
diff changeset
166 -- and calls are not inlined in the frontend. If proper warnings are
kono
parents:
diff changeset
167 -- enabled and the subprogram contains a construct that cannot be inlined,
kono
parents:
diff changeset
168 -- the problematic construct is flagged accordingly.
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 function Call_Can_Be_Inlined_In_GNATprove_Mode
kono
parents:
diff changeset
171 (N : Node_Id;
kono
parents:
diff changeset
172 Subp : Entity_Id) return Boolean;
kono
parents:
diff changeset
173 -- Returns False if the call in node N to subprogram Subp cannot be inlined
kono
parents:
diff changeset
174 -- in GNATprove mode, because it may lead to missing a check on type
kono
parents:
diff changeset
175 -- conversion of input parameters otherwise. Returns True otherwise.
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 function Can_Be_Inlined_In_GNATprove_Mode
kono
parents:
diff changeset
178 (Spec_Id : Entity_Id;
kono
parents:
diff changeset
179 Body_Id : Entity_Id) return Boolean;
kono
parents:
diff changeset
180 -- Returns True if the subprogram identified by Spec_Id and Body_Id can
kono
parents:
diff changeset
181 -- be inlined in GNATprove mode. One but not both of Spec_Id and Body_Id
kono
parents:
diff changeset
182 -- can be Empty. Body_Id is Empty when doing a partial check on a call
kono
parents:
diff changeset
183 -- to a subprogram whose body has not been seen yet, to know whether this
kono
parents:
diff changeset
184 -- subprogram could possibly be inlined. GNATprove relies on this to adapt
kono
parents:
diff changeset
185 -- its treatment of the subprogram.
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 procedure Cannot_Inline
kono
parents:
diff changeset
188 (Msg : String;
kono
parents:
diff changeset
189 N : Node_Id;
kono
parents:
diff changeset
190 Subp : Entity_Id;
kono
parents:
diff changeset
191 Is_Serious : Boolean := False);
kono
parents:
diff changeset
192 -- This procedure is called if the node N, an instance of a call to
kono
parents:
diff changeset
193 -- subprogram Subp, cannot be inlined. Msg is the message to be issued,
kono
parents:
diff changeset
194 -- which ends with ? (it does not end with ?p?, this routine takes care of
kono
parents:
diff changeset
195 -- the need to change ? to ?p?). The behavior of this routine depends on
kono
parents:
diff changeset
196 -- the value of Back_End_Inlining:
kono
parents:
diff changeset
197 --
kono
parents:
diff changeset
198 -- * If Back_End_Inlining is not set (ie. legacy frontend inlining model)
kono
parents:
diff changeset
199 -- then if Subp has a pragma Always_Inlined, then an error message is
kono
parents:
diff changeset
200 -- issued (by removing the last character of Msg). If Subp is not
kono
parents:
diff changeset
201 -- Always_Inlined, then a warning is issued if the flag Ineffective_
kono
parents:
diff changeset
202 -- Inline_Warnings is set, adding ?p to the msg, and if not, the call
kono
parents:
diff changeset
203 -- has no effect.
kono
parents:
diff changeset
204 --
kono
parents:
diff changeset
205 -- * If Back_End_Inlining is set then:
kono
parents:
diff changeset
206 -- - If Is_Serious is true, then an error is reported (by removing the
kono
parents:
diff changeset
207 -- last character of Msg);
kono
parents:
diff changeset
208 --
kono
parents:
diff changeset
209 -- - otherwise:
kono
parents:
diff changeset
210 --
kono
parents:
diff changeset
211 -- * Compiling without optimizations if Subp has a pragma
kono
parents:
diff changeset
212 -- Always_Inlined, then an error message is issued; if Subp is
kono
parents:
diff changeset
213 -- not Always_Inlined, then a warning is issued if the flag
kono
parents:
diff changeset
214 -- Ineffective_Inline_Warnings is set (adding p?), and if not,
kono
parents:
diff changeset
215 -- the call has no effect.
kono
parents:
diff changeset
216 --
kono
parents:
diff changeset
217 -- * Compiling with optimizations then a warning is issued if the
kono
parents:
diff changeset
218 -- flag Ineffective_Inline_Warnings is set (adding p?); otherwise
kono
parents:
diff changeset
219 -- no effect since inlining may be performed by the backend.
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 procedure Check_And_Split_Unconstrained_Function
kono
parents:
diff changeset
222 (N : Node_Id;
kono
parents:
diff changeset
223 Spec_Id : Entity_Id;
kono
parents:
diff changeset
224 Body_Id : Entity_Id);
kono
parents:
diff changeset
225 -- Spec_Id and Body_Id are the entities of the specification and body of
kono
parents:
diff changeset
226 -- the subprogram body N. If N can be inlined by the frontend (supported
kono
parents:
diff changeset
227 -- cases documented in Check_Body_To_Inline) then build the body-to-inline
kono
parents:
diff changeset
228 -- associated with N and attach it to the declaration node of Spec_Id.
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 procedure Check_Package_Body_For_Inlining (N : Node_Id; P : Entity_Id);
kono
parents:
diff changeset
231 -- If front-end inlining is enabled and a package declaration contains
kono
parents:
diff changeset
232 -- inlined subprograms, load and compile the package body to collect the
kono
parents:
diff changeset
233 -- bodies of these subprograms, so they are available to inline calls.
kono
parents:
diff changeset
234 -- N is the compilation unit for the package.
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 procedure Expand_Inlined_Call
kono
parents:
diff changeset
237 (N : Node_Id;
kono
parents:
diff changeset
238 Subp : Entity_Id;
kono
parents:
diff changeset
239 Orig_Subp : Entity_Id);
kono
parents:
diff changeset
240 -- If called subprogram can be inlined by the front-end, retrieve the
kono
parents:
diff changeset
241 -- analyzed body, replace formals with actuals and expand call in place.
kono
parents:
diff changeset
242 -- Generate thunks for actuals that are expressions, and insert the
kono
parents:
diff changeset
243 -- corresponding constant declarations before the call. If the original
kono
parents:
diff changeset
244 -- call is to a derived operation, the return type is the one of the
kono
parents:
diff changeset
245 -- derived operation, but the body is that of the original, so return
kono
parents:
diff changeset
246 -- expressions in the body must be converted to the desired type (which
kono
parents:
diff changeset
247 -- is simply not noted in the tree without inline expansion).
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 function Has_Excluded_Declaration
kono
parents:
diff changeset
250 (Subp : Entity_Id;
kono
parents:
diff changeset
251 Decls : List_Id) return Boolean;
kono
parents:
diff changeset
252 -- Check a list of declarations, Decls, that make the inlining of Subp not
kono
parents:
diff changeset
253 -- worthwhile
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 function Has_Excluded_Statement
kono
parents:
diff changeset
256 (Subp : Entity_Id;
kono
parents:
diff changeset
257 Stats : List_Id) return Boolean;
kono
parents:
diff changeset
258 -- Check a list of statements, Stats, that make inlining of Subp not
kono
parents:
diff changeset
259 -- worthwhile, including any tasking statement, nested at any level.
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 procedure List_Inlining_Info;
kono
parents:
diff changeset
262 -- Generate listing of calls inlined by the frontend plus listing of
kono
parents:
diff changeset
263 -- calls to inline subprograms passed to the backend.
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 procedure Remove_Dead_Instance (N : Node_Id);
kono
parents:
diff changeset
266 -- If an instantiation appears in unreachable code, delete the pending
kono
parents:
diff changeset
267 -- body instance.
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 end Inline;