annotate gcc/cgraphunit.c @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents: 67
diff changeset
1 /* Driver of optimization process
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Jan Hubicka
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
111
kono
parents: 67
diff changeset
21 /* This module implements main driver of compilation process.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 The main scope of this file is to act as an interface in between
111
kono
parents: 67
diff changeset
24 tree based frontends and the backend.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 The front-end is supposed to use following functionality:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
111
kono
parents: 67
diff changeset
28 - finalize_function
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 This function is called once front-end has parsed whole body of function
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 and it is certain that the function body nor the declaration will change.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 (There is one exception needed for implementing GCC extern inline
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 function.)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
111
kono
parents: 67
diff changeset
36 - varpool_finalize_decl
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 This function has same behavior as the above but is used for static
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 variables.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
111
kono
parents: 67
diff changeset
41 - add_asm_node
kono
parents: 67
diff changeset
42
kono
parents: 67
diff changeset
43 Insert new toplevel ASM statement
kono
parents: 67
diff changeset
44
kono
parents: 67
diff changeset
45 - finalize_compilation_unit
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 This function is called once (source level) compilation unit is finalized
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 and it will no longer change.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
111
kono
parents: 67
diff changeset
50 The symbol table is constructed starting from the trivially needed
kono
parents: 67
diff changeset
51 symbols finalized by the frontend. Functions are lowered into
kono
parents: 67
diff changeset
52 GIMPLE representation and callgraph/reference lists are constructed.
kono
parents: 67
diff changeset
53 Those are used to discover other necessary functions and variables.
kono
parents: 67
diff changeset
54
kono
parents: 67
diff changeset
55 At the end the bodies of unreachable functions are removed.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 The function can be called multiple times when multiple source level
111
kono
parents: 67
diff changeset
58 compilation units are combined.
kono
parents: 67
diff changeset
59
kono
parents: 67
diff changeset
60 - compile
kono
parents: 67
diff changeset
61
kono
parents: 67
diff changeset
62 This passes control to the back-end. Optimizations are performed and
kono
parents: 67
diff changeset
63 final assembler is generated. This is done in the following way. Note
kono
parents: 67
diff changeset
64 that with link time optimization the process is split into three
kono
parents: 67
diff changeset
65 stages (compile time, linktime analysis and parallel linktime as
kono
parents: 67
diff changeset
66 indicated bellow).
kono
parents: 67
diff changeset
67
kono
parents: 67
diff changeset
68 Compile time:
kono
parents: 67
diff changeset
69
kono
parents: 67
diff changeset
70 1) Inter-procedural optimization.
kono
parents: 67
diff changeset
71 (ipa_passes)
kono
parents: 67
diff changeset
72
kono
parents: 67
diff changeset
73 This part is further split into:
kono
parents: 67
diff changeset
74
kono
parents: 67
diff changeset
75 a) early optimizations. These are local passes executed in
kono
parents: 67
diff changeset
76 the topological order on the callgraph.
kono
parents: 67
diff changeset
77
kono
parents: 67
diff changeset
78 The purpose of early optimiations is to optimize away simple
kono
parents: 67
diff changeset
79 things that may otherwise confuse IP analysis. Very simple
kono
parents: 67
diff changeset
80 propagation across the callgraph is done i.e. to discover
kono
parents: 67
diff changeset
81 functions without side effects and simple inlining is performed.
kono
parents: 67
diff changeset
82
kono
parents: 67
diff changeset
83 b) early small interprocedural passes.
kono
parents: 67
diff changeset
84
kono
parents: 67
diff changeset
85 Those are interprocedural passes executed only at compilation
kono
parents: 67
diff changeset
86 time. These include, for example, transational memory lowering,
kono
parents: 67
diff changeset
87 unreachable code removal and other simple transformations.
kono
parents: 67
diff changeset
88
kono
parents: 67
diff changeset
89 c) IP analysis stage. All interprocedural passes do their
kono
parents: 67
diff changeset
90 analysis.
kono
parents: 67
diff changeset
91
kono
parents: 67
diff changeset
92 Interprocedural passes differ from small interprocedural
kono
parents: 67
diff changeset
93 passes by their ability to operate across whole program
kono
parents: 67
diff changeset
94 at linktime. Their analysis stage is performed early to
kono
parents: 67
diff changeset
95 both reduce linking times and linktime memory usage by
kono
parents: 67
diff changeset
96 not having to represent whole program in memory.
kono
parents: 67
diff changeset
97
kono
parents: 67
diff changeset
98 d) LTO sreaming. When doing LTO, everything important gets
kono
parents: 67
diff changeset
99 streamed into the object file.
kono
parents: 67
diff changeset
100
kono
parents: 67
diff changeset
101 Compile time and or linktime analysis stage (WPA):
kono
parents: 67
diff changeset
102
kono
parents: 67
diff changeset
103 At linktime units gets streamed back and symbol table is
kono
parents: 67
diff changeset
104 merged. Function bodies are not streamed in and not
kono
parents: 67
diff changeset
105 available.
kono
parents: 67
diff changeset
106 e) IP propagation stage. All IP passes execute their
kono
parents: 67
diff changeset
107 IP propagation. This is done based on the earlier analysis
kono
parents: 67
diff changeset
108 without having function bodies at hand.
kono
parents: 67
diff changeset
109 f) Ltrans streaming. When doing WHOPR LTO, the program
kono
parents: 67
diff changeset
110 is partitioned and streamed into multple object files.
kono
parents: 67
diff changeset
111
kono
parents: 67
diff changeset
112 Compile time and/or parallel linktime stage (ltrans)
kono
parents: 67
diff changeset
113
kono
parents: 67
diff changeset
114 Each of the object files is streamed back and compiled
kono
parents: 67
diff changeset
115 separately. Now the function bodies becomes available
kono
parents: 67
diff changeset
116 again.
kono
parents: 67
diff changeset
117
kono
parents: 67
diff changeset
118 2) Virtual clone materialization
kono
parents: 67
diff changeset
119 (cgraph_materialize_clone)
kono
parents: 67
diff changeset
120
kono
parents: 67
diff changeset
121 IP passes can produce copies of existing functoins (such
kono
parents: 67
diff changeset
122 as versioned clones or inline clones) without actually
kono
parents: 67
diff changeset
123 manipulating their bodies by creating virtual clones in
kono
parents: 67
diff changeset
124 the callgraph. At this time the virtual clones are
kono
parents: 67
diff changeset
125 turned into real functions
kono
parents: 67
diff changeset
126 3) IP transformation
kono
parents: 67
diff changeset
127
kono
parents: 67
diff changeset
128 All IP passes transform function bodies based on earlier
kono
parents: 67
diff changeset
129 decision of the IP propagation.
kono
parents: 67
diff changeset
130
kono
parents: 67
diff changeset
131 4) late small IP passes
kono
parents: 67
diff changeset
132
kono
parents: 67
diff changeset
133 Simple IP passes working within single program partition.
kono
parents: 67
diff changeset
134
kono
parents: 67
diff changeset
135 5) Expansion
kono
parents: 67
diff changeset
136 (expand_all_functions)
kono
parents: 67
diff changeset
137
kono
parents: 67
diff changeset
138 At this stage functions that needs to be output into
kono
parents: 67
diff changeset
139 assembler are identified and compiled in topological order
kono
parents: 67
diff changeset
140 6) Output of variables and aliases
kono
parents: 67
diff changeset
141 Now it is known what variable references was not optimized
kono
parents: 67
diff changeset
142 out and thus all variables are output to the file.
kono
parents: 67
diff changeset
143
kono
parents: 67
diff changeset
144 Note that with -fno-toplevel-reorder passes 5 and 6
kono
parents: 67
diff changeset
145 are combined together in cgraph_output_in_order.
kono
parents: 67
diff changeset
146
kono
parents: 67
diff changeset
147 Finally there are functions to manipulate the callgraph from
kono
parents: 67
diff changeset
148 backend.
kono
parents: 67
diff changeset
149 - cgraph_add_new_function is used to add backend produced
kono
parents: 67
diff changeset
150 functions introduced after the unit is finalized.
kono
parents: 67
diff changeset
151 The functions are enqueue for later processing and inserted
kono
parents: 67
diff changeset
152 into callgraph with cgraph_process_new_functions.
kono
parents: 67
diff changeset
153
kono
parents: 67
diff changeset
154 - cgraph_function_versioning
kono
parents: 67
diff changeset
155
kono
parents: 67
diff changeset
156 produces a copy of function into new one (a version)
kono
parents: 67
diff changeset
157 and apply simple transformations
kono
parents: 67
diff changeset
158 */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 #include "coretypes.h"
111
kono
parents: 67
diff changeset
163 #include "backend.h"
kono
parents: 67
diff changeset
164 #include "target.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 #include "rtl.h"
111
kono
parents: 67
diff changeset
166 #include "tree.h"
kono
parents: 67
diff changeset
167 #include "gimple.h"
kono
parents: 67
diff changeset
168 #include "cfghooks.h"
kono
parents: 67
diff changeset
169 #include "regset.h" /* FIXME: For reg_obstack. */
kono
parents: 67
diff changeset
170 #include "alloc-pool.h"
kono
parents: 67
diff changeset
171 #include "tree-pass.h"
kono
parents: 67
diff changeset
172 #include "stringpool.h"
kono
parents: 67
diff changeset
173 #include "gimple-ssa.h"
kono
parents: 67
diff changeset
174 #include "cgraph.h"
kono
parents: 67
diff changeset
175 #include "coverage.h"
kono
parents: 67
diff changeset
176 #include "lto-streamer.h"
kono
parents: 67
diff changeset
177 #include "fold-const.h"
kono
parents: 67
diff changeset
178 #include "varasm.h"
kono
parents: 67
diff changeset
179 #include "stor-layout.h"
kono
parents: 67
diff changeset
180 #include "output.h"
kono
parents: 67
diff changeset
181 #include "cfgcleanup.h"
kono
parents: 67
diff changeset
182 #include "gimple-fold.h"
kono
parents: 67
diff changeset
183 #include "gimplify.h"
kono
parents: 67
diff changeset
184 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
185 #include "gimplify-me.h"
kono
parents: 67
diff changeset
186 #include "tree-cfg.h"
kono
parents: 67
diff changeset
187 #include "tree-into-ssa.h"
kono
parents: 67
diff changeset
188 #include "tree-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 #include "langhooks.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 #include "toplev.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 #include "debug.h"
111
kono
parents: 67
diff changeset
192 #include "symbol-summary.h"
kono
parents: 67
diff changeset
193 #include "tree-vrp.h"
kono
parents: 67
diff changeset
194 #include "ipa-prop.h"
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
195 #include "gimple-pretty-print.h"
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
196 #include "plugin.h"
111
kono
parents: 67
diff changeset
197 #include "ipa-fnsummary.h"
kono
parents: 67
diff changeset
198 #include "ipa-utils.h"
kono
parents: 67
diff changeset
199 #include "except.h"
kono
parents: 67
diff changeset
200 #include "cfgloop.h"
kono
parents: 67
diff changeset
201 #include "context.h"
kono
parents: 67
diff changeset
202 #include "pass_manager.h"
kono
parents: 67
diff changeset
203 #include "tree-nested.h"
kono
parents: 67
diff changeset
204 #include "dbgcnt.h"
kono
parents: 67
diff changeset
205 #include "lto-section-names.h"
kono
parents: 67
diff changeset
206 #include "stringpool.h"
kono
parents: 67
diff changeset
207 #include "attribs.h"
kono
parents: 67
diff changeset
208
kono
parents: 67
diff changeset
209 /* Queue of cgraph nodes scheduled to be added into cgraph. This is a
kono
parents: 67
diff changeset
210 secondary queue used during optimization to accommodate passes that
kono
parents: 67
diff changeset
211 may generate new functions that need to be optimized and expanded. */
kono
parents: 67
diff changeset
212 vec<cgraph_node *> cgraph_new_nodes;
kono
parents: 67
diff changeset
213
kono
parents: 67
diff changeset
214 static void expand_all_functions (void);
kono
parents: 67
diff changeset
215 static void mark_functions_to_output (void);
kono
parents: 67
diff changeset
216 static void handle_alias_pairs (void);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
218 /* Used for vtable lookup in thunk adjusting. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
219 static GTY (()) tree vtable_entry_type;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
220
111
kono
parents: 67
diff changeset
221 /* Return true if this symbol is a function from the C frontend specified
kono
parents: 67
diff changeset
222 directly in RTL form (with "__RTL"). */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
224 bool
111
kono
parents: 67
diff changeset
225 symtab_node::native_rtl_p () const
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 {
111
kono
parents: 67
diff changeset
227 if (TREE_CODE (decl) != FUNCTION_DECL)
kono
parents: 67
diff changeset
228 return false;
kono
parents: 67
diff changeset
229 if (!DECL_STRUCT_FUNCTION (decl))
kono
parents: 67
diff changeset
230 return false;
kono
parents: 67
diff changeset
231 return DECL_STRUCT_FUNCTION (decl)->curr_properties & PROP_rtl;
kono
parents: 67
diff changeset
232 }
kono
parents: 67
diff changeset
233
kono
parents: 67
diff changeset
234 /* Determine if symbol declaration is needed. That is, visible to something
kono
parents: 67
diff changeset
235 either outside this translation unit, something magic in the system
kono
parents: 67
diff changeset
236 configury */
kono
parents: 67
diff changeset
237 bool
kono
parents: 67
diff changeset
238 symtab_node::needed_p (void)
kono
parents: 67
diff changeset
239 {
kono
parents: 67
diff changeset
240 /* Double check that no one output the function into assembly file
kono
parents: 67
diff changeset
241 early. */
kono
parents: 67
diff changeset
242 if (!native_rtl_p ())
kono
parents: 67
diff changeset
243 gcc_checking_assert
kono
parents: 67
diff changeset
244 (!DECL_ASSEMBLER_NAME_SET_P (decl)
kono
parents: 67
diff changeset
245 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)));
kono
parents: 67
diff changeset
246
kono
parents: 67
diff changeset
247 if (!definition)
kono
parents: 67
diff changeset
248 return false;
kono
parents: 67
diff changeset
249
kono
parents: 67
diff changeset
250 if (DECL_EXTERNAL (decl))
kono
parents: 67
diff changeset
251 return false;
kono
parents: 67
diff changeset
252
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 /* If the user told us it is used, then it must be so. */
111
kono
parents: 67
diff changeset
254 if (force_output)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256
111
kono
parents: 67
diff changeset
257 /* ABI forced symbols are needed when they are external. */
kono
parents: 67
diff changeset
258 if (forced_by_abi && TREE_PUBLIC (decl))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
111
kono
parents: 67
diff changeset
261 /* Keep constructors, destructors and virtual functions. */
kono
parents: 67
diff changeset
262 if (TREE_CODE (decl) == FUNCTION_DECL
kono
parents: 67
diff changeset
263 && (DECL_STATIC_CONSTRUCTOR (decl) || DECL_STATIC_DESTRUCTOR (decl)))
kono
parents: 67
diff changeset
264 return true;
kono
parents: 67
diff changeset
265
kono
parents: 67
diff changeset
266 /* Externally visible variables must be output. The exception is
kono
parents: 67
diff changeset
267 COMDAT variables that must be output only when they are needed. */
kono
parents: 67
diff changeset
268 if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273
111
kono
parents: 67
diff changeset
274 /* Head and terminator of the queue of nodes to be processed while building
kono
parents: 67
diff changeset
275 callgraph. */
kono
parents: 67
diff changeset
276
kono
parents: 67
diff changeset
277 static symtab_node symtab_terminator;
kono
parents: 67
diff changeset
278 static symtab_node *queued_nodes = &symtab_terminator;
kono
parents: 67
diff changeset
279
kono
parents: 67
diff changeset
280 /* Add NODE to queue starting at QUEUED_NODES.
kono
parents: 67
diff changeset
281 The queue is linked via AUX pointers and terminated by pointer to 1. */
kono
parents: 67
diff changeset
282
kono
parents: 67
diff changeset
283 static void
kono
parents: 67
diff changeset
284 enqueue_node (symtab_node *node)
kono
parents: 67
diff changeset
285 {
kono
parents: 67
diff changeset
286 if (node->aux)
kono
parents: 67
diff changeset
287 return;
kono
parents: 67
diff changeset
288 gcc_checking_assert (queued_nodes);
kono
parents: 67
diff changeset
289 node->aux = queued_nodes;
kono
parents: 67
diff changeset
290 queued_nodes = node;
kono
parents: 67
diff changeset
291 }
kono
parents: 67
diff changeset
292
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 functions into callgraph in a way so they look like ordinary reachable
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 functions inserted into callgraph already at construction time. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296
111
kono
parents: 67
diff changeset
297 void
kono
parents: 67
diff changeset
298 symbol_table::process_new_functions (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 tree fndecl;
111
kono
parents: 67
diff changeset
301
kono
parents: 67
diff changeset
302 if (!cgraph_new_nodes.exists ())
kono
parents: 67
diff changeset
303 return;
kono
parents: 67
diff changeset
304
kono
parents: 67
diff changeset
305 handle_alias_pairs ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 /* Note that this queue may grow as its being processed, as the new
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 functions may generate new ones. */
111
kono
parents: 67
diff changeset
308 for (unsigned i = 0; i < cgraph_new_nodes.length (); i++)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 {
111
kono
parents: 67
diff changeset
310 cgraph_node *node = cgraph_new_nodes[i];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 fndecl = node->decl;
111
kono
parents: 67
diff changeset
312 switch (state)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 {
111
kono
parents: 67
diff changeset
314 case CONSTRUCTION:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 /* At construction time we just need to finalize function and move
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 it into reachable functions list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
111
kono
parents: 67
diff changeset
318 cgraph_node::finalize_function (fndecl, false);
kono
parents: 67
diff changeset
319 call_cgraph_insertion_hooks (node);
kono
parents: 67
diff changeset
320 enqueue_node (node);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322
111
kono
parents: 67
diff changeset
323 case IPA:
kono
parents: 67
diff changeset
324 case IPA_SSA:
kono
parents: 67
diff changeset
325 case IPA_SSA_AFTER_INLINING:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 /* When IPA optimization already started, do all essential
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 transformations that has been already performed on the whole
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 cgraph but not on this function. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 gimple_register_cfg_hooks ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 if (!node->analyzed)
111
kono
parents: 67
diff changeset
332 node->analyze ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 push_cfun (DECL_STRUCT_FUNCTION (fndecl));
111
kono
parents: 67
diff changeset
334 if ((state == IPA_SSA || state == IPA_SSA_AFTER_INLINING)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 && !gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl)))
111
kono
parents: 67
diff changeset
336 {
kono
parents: 67
diff changeset
337 bool summaried_computed = ipa_fn_summaries != NULL;
kono
parents: 67
diff changeset
338 g->get_passes ()->execute_early_local_passes ();
kono
parents: 67
diff changeset
339 /* Early passes compure inline parameters to do inlining
kono
parents: 67
diff changeset
340 and splitting. This is redundant for functions added late.
kono
parents: 67
diff changeset
341 Just throw away whatever it did. */
kono
parents: 67
diff changeset
342 if (!summaried_computed)
kono
parents: 67
diff changeset
343 ipa_free_fn_summary ();
kono
parents: 67
diff changeset
344 }
kono
parents: 67
diff changeset
345 else if (ipa_fn_summaries != NULL)
kono
parents: 67
diff changeset
346 compute_fn_summary (node, true);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 free_dominance_info (CDI_POST_DOMINATORS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 free_dominance_info (CDI_DOMINATORS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 pop_cfun ();
111
kono
parents: 67
diff changeset
350 call_cgraph_insertion_hooks (node);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
111
kono
parents: 67
diff changeset
353 case EXPANSION:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 /* Functions created during expansion shall be compiled
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 directly. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
356 node->process = 0;
111
kono
parents: 67
diff changeset
357 call_cgraph_insertion_hooks (node);
kono
parents: 67
diff changeset
358 node->expand ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 }
111
kono
parents: 67
diff changeset
366
kono
parents: 67
diff changeset
367 cgraph_new_nodes.release ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 /* As an GCC extension we allow redefinition of the function. The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 semantics when both copies of bodies differ is not well defined.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 We replace the old body with new body so in unit at a time mode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 we always use new body, while in normal mode we may end up with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 old body inlined into some functions and new body expanded and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 inlined in others.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 ??? It may make more sense to use one body for inlining and other
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 body for expanding the function but this is difficult to do. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379
111
kono
parents: 67
diff changeset
380 void
kono
parents: 67
diff changeset
381 cgraph_node::reset (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 {
111
kono
parents: 67
diff changeset
383 /* If process is set, then we have already begun whole-unit analysis.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 This is *not* testing for whether we've already emitted the function.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 That case can be sort-of legitimately seen with real function redefinition
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 errors. I would argue that the front end should never present us with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 such a case, but don't enforce that for now. */
111
kono
parents: 67
diff changeset
388 gcc_assert (!process);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 /* Reset our data structures so we can analyze the function again. */
111
kono
parents: 67
diff changeset
391 memset (&local, 0, sizeof (local));
kono
parents: 67
diff changeset
392 memset (&global, 0, sizeof (global));
kono
parents: 67
diff changeset
393 memset (&rtl, 0, sizeof (rtl));
kono
parents: 67
diff changeset
394 analyzed = false;
kono
parents: 67
diff changeset
395 definition = false;
kono
parents: 67
diff changeset
396 alias = false;
kono
parents: 67
diff changeset
397 transparent_alias = false;
kono
parents: 67
diff changeset
398 weakref = false;
kono
parents: 67
diff changeset
399 cpp_implicit_alias = false;
kono
parents: 67
diff changeset
400
kono
parents: 67
diff changeset
401 remove_callees ();
kono
parents: 67
diff changeset
402 remove_all_references ();
kono
parents: 67
diff changeset
403 }
kono
parents: 67
diff changeset
404
kono
parents: 67
diff changeset
405 /* Return true when there are references to the node. INCLUDE_SELF is
kono
parents: 67
diff changeset
406 true if a self reference counts as a reference. */
kono
parents: 67
diff changeset
407
kono
parents: 67
diff changeset
408 bool
kono
parents: 67
diff changeset
409 symtab_node::referred_to_p (bool include_self)
kono
parents: 67
diff changeset
410 {
kono
parents: 67
diff changeset
411 ipa_ref *ref = NULL;
kono
parents: 67
diff changeset
412
kono
parents: 67
diff changeset
413 /* See if there are any references at all. */
kono
parents: 67
diff changeset
414 if (iterate_referring (0, ref))
kono
parents: 67
diff changeset
415 return true;
kono
parents: 67
diff changeset
416 /* For functions check also calls. */
kono
parents: 67
diff changeset
417 cgraph_node *cn = dyn_cast <cgraph_node *> (this);
kono
parents: 67
diff changeset
418 if (cn && cn->callers)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 {
111
kono
parents: 67
diff changeset
420 if (include_self)
kono
parents: 67
diff changeset
421 return true;
kono
parents: 67
diff changeset
422 for (cgraph_edge *e = cn->callers; e; e = e->next_caller)
kono
parents: 67
diff changeset
423 if (e->caller != this)
kono
parents: 67
diff changeset
424 return true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 }
111
kono
parents: 67
diff changeset
426 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 /* DECL has been parsed. Take it, queue it, compile it at the whim of the
111
kono
parents: 67
diff changeset
430 logic in effect. If NO_COLLECT is true, then our caller cannot stand to have
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 the garbage collector run at the moment. We would need to either create
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 a new GC context, or just not compile right now. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 void
111
kono
parents: 67
diff changeset
435 cgraph_node::finalize_function (tree decl, bool no_collect)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 {
111
kono
parents: 67
diff changeset
437 cgraph_node *node = cgraph_node::get_create (decl);
kono
parents: 67
diff changeset
438
kono
parents: 67
diff changeset
439 if (node->definition)
kono
parents: 67
diff changeset
440 {
kono
parents: 67
diff changeset
441 /* Nested functions should only be defined once. */
kono
parents: 67
diff changeset
442 gcc_assert (!DECL_CONTEXT (decl)
kono
parents: 67
diff changeset
443 || TREE_CODE (DECL_CONTEXT (decl)) != FUNCTION_DECL);
kono
parents: 67
diff changeset
444 node->reset ();
kono
parents: 67
diff changeset
445 node->local.redefined_extern_inline = true;
kono
parents: 67
diff changeset
446 }
kono
parents: 67
diff changeset
447
kono
parents: 67
diff changeset
448 /* Set definition first before calling notice_global_symbol so that
kono
parents: 67
diff changeset
449 it is available to notice_global_symbol. */
kono
parents: 67
diff changeset
450 node->definition = true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 notice_global_symbol (decl);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL;
111
kono
parents: 67
diff changeset
453 if (!flag_toplevel_reorder)
kono
parents: 67
diff changeset
454 node->no_reorder = true;
kono
parents: 67
diff changeset
455
kono
parents: 67
diff changeset
456 /* With -fkeep-inline-functions we are keeping all inline functions except
kono
parents: 67
diff changeset
457 for extern inline ones. */
kono
parents: 67
diff changeset
458 if (flag_keep_inline_functions
kono
parents: 67
diff changeset
459 && DECL_DECLARED_INLINE_P (decl)
kono
parents: 67
diff changeset
460 && !DECL_EXTERNAL (decl)
kono
parents: 67
diff changeset
461 && !DECL_DISREGARD_INLINE_LIMITS (decl))
kono
parents: 67
diff changeset
462 node->force_output = 1;
kono
parents: 67
diff changeset
463
kono
parents: 67
diff changeset
464 /* __RTL functions were already output as soon as they were parsed (due
kono
parents: 67
diff changeset
465 to the large amount of global state in the backend).
kono
parents: 67
diff changeset
466 Mark such functions as "force_output" to reflect the fact that they
kono
parents: 67
diff changeset
467 will be in the asm file when considering the symbols they reference.
kono
parents: 67
diff changeset
468 The attempt to output them later on will bail out immediately. */
kono
parents: 67
diff changeset
469 if (node->native_rtl_p ())
kono
parents: 67
diff changeset
470 node->force_output = 1;
kono
parents: 67
diff changeset
471
kono
parents: 67
diff changeset
472 /* When not optimizing, also output the static functions. (see
kono
parents: 67
diff changeset
473 PR24561), but don't do so for always_inline functions, functions
kono
parents: 67
diff changeset
474 declared inline and nested functions. These were optimized out
kono
parents: 67
diff changeset
475 in the original implementation and it is unclear whether we want
kono
parents: 67
diff changeset
476 to change the behavior here. */
kono
parents: 67
diff changeset
477 if (((!opt_for_fn (decl, optimize) || flag_keep_static_functions
kono
parents: 67
diff changeset
478 || node->no_reorder)
kono
parents: 67
diff changeset
479 && !node->cpp_implicit_alias
kono
parents: 67
diff changeset
480 && !DECL_DISREGARD_INLINE_LIMITS (decl)
kono
parents: 67
diff changeset
481 && !DECL_DECLARED_INLINE_P (decl)
kono
parents: 67
diff changeset
482 && !(DECL_CONTEXT (decl)
kono
parents: 67
diff changeset
483 && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL))
kono
parents: 67
diff changeset
484 && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
kono
parents: 67
diff changeset
485 node->force_output = 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 /* If we've not yet emitted decl, tell the debug info about it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 if (!TREE_ASM_WRITTEN (decl))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 (*debug_hooks->deferred_inline_function) (decl);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490
111
kono
parents: 67
diff changeset
491 if (!no_collect)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 ggc_collect ();
111
kono
parents: 67
diff changeset
493
kono
parents: 67
diff changeset
494 if (symtab->state == CONSTRUCTION
kono
parents: 67
diff changeset
495 && (node->needed_p () || node->referred_to_p ()))
kono
parents: 67
diff changeset
496 enqueue_node (node);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498
111
kono
parents: 67
diff changeset
499 /* Add the function FNDECL to the call graph.
kono
parents: 67
diff changeset
500 Unlike finalize_function, this function is intended to be used
kono
parents: 67
diff changeset
501 by middle end and allows insertion of new function at arbitrary point
kono
parents: 67
diff changeset
502 of compilation. The function can be either in high, low or SSA form
kono
parents: 67
diff changeset
503 GIMPLE.
kono
parents: 67
diff changeset
504
kono
parents: 67
diff changeset
505 The function is assumed to be reachable and have address taken (so no
kono
parents: 67
diff changeset
506 API breaking optimizations are performed on it).
kono
parents: 67
diff changeset
507
kono
parents: 67
diff changeset
508 Main work done by this function is to enqueue the function for later
kono
parents: 67
diff changeset
509 processing to avoid need the passes to be re-entrant. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 void
111
kono
parents: 67
diff changeset
512 cgraph_node::add_new_function (tree fndecl, bool lowered)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
513 {
111
kono
parents: 67
diff changeset
514 gcc::pass_manager *passes = g->get_passes ();
kono
parents: 67
diff changeset
515 cgraph_node *node;
kono
parents: 67
diff changeset
516
kono
parents: 67
diff changeset
517 if (dump_file)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
518 {
111
kono
parents: 67
diff changeset
519 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
kono
parents: 67
diff changeset
520 const char *function_type = ((gimple_has_body_p (fndecl))
kono
parents: 67
diff changeset
521 ? (lowered
kono
parents: 67
diff changeset
522 ? (gimple_in_ssa_p (fn)
kono
parents: 67
diff changeset
523 ? "ssa gimple"
kono
parents: 67
diff changeset
524 : "low gimple")
kono
parents: 67
diff changeset
525 : "high gimple")
kono
parents: 67
diff changeset
526 : "to-be-gimplified");
kono
parents: 67
diff changeset
527 fprintf (dump_file,
kono
parents: 67
diff changeset
528 "Added new %s function %s to callgraph\n",
kono
parents: 67
diff changeset
529 function_type,
kono
parents: 67
diff changeset
530 fndecl_name (fndecl));
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
531 }
111
kono
parents: 67
diff changeset
532
kono
parents: 67
diff changeset
533 switch (symtab->state)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
534 {
111
kono
parents: 67
diff changeset
535 case PARSING:
kono
parents: 67
diff changeset
536 cgraph_node::finalize_function (fndecl, false);
kono
parents: 67
diff changeset
537 break;
kono
parents: 67
diff changeset
538 case CONSTRUCTION:
kono
parents: 67
diff changeset
539 /* Just enqueue function to be processed at nearest occurrence. */
kono
parents: 67
diff changeset
540 node = cgraph_node::get_create (fndecl);
kono
parents: 67
diff changeset
541 if (lowered)
kono
parents: 67
diff changeset
542 node->lowered = true;
kono
parents: 67
diff changeset
543 cgraph_new_nodes.safe_push (node);
kono
parents: 67
diff changeset
544 break;
kono
parents: 67
diff changeset
545
kono
parents: 67
diff changeset
546 case IPA:
kono
parents: 67
diff changeset
547 case IPA_SSA:
kono
parents: 67
diff changeset
548 case IPA_SSA_AFTER_INLINING:
kono
parents: 67
diff changeset
549 case EXPANSION:
kono
parents: 67
diff changeset
550 /* Bring the function into finalized state and enqueue for later
kono
parents: 67
diff changeset
551 analyzing and compilation. */
kono
parents: 67
diff changeset
552 node = cgraph_node::get_create (fndecl);
kono
parents: 67
diff changeset
553 node->local.local = false;
kono
parents: 67
diff changeset
554 node->definition = true;
kono
parents: 67
diff changeset
555 node->force_output = true;
kono
parents: 67
diff changeset
556 if (TREE_PUBLIC (fndecl))
kono
parents: 67
diff changeset
557 node->externally_visible = true;
kono
parents: 67
diff changeset
558 if (!lowered && symtab->state == EXPANSION)
kono
parents: 67
diff changeset
559 {
kono
parents: 67
diff changeset
560 push_cfun (DECL_STRUCT_FUNCTION (fndecl));
kono
parents: 67
diff changeset
561 gimple_register_cfg_hooks ();
kono
parents: 67
diff changeset
562 bitmap_obstack_initialize (NULL);
kono
parents: 67
diff changeset
563 execute_pass_list (cfun, passes->all_lowering_passes);
kono
parents: 67
diff changeset
564 passes->execute_early_local_passes ();
kono
parents: 67
diff changeset
565 bitmap_obstack_release (NULL);
kono
parents: 67
diff changeset
566 pop_cfun ();
kono
parents: 67
diff changeset
567
kono
parents: 67
diff changeset
568 lowered = true;
kono
parents: 67
diff changeset
569 }
kono
parents: 67
diff changeset
570 if (lowered)
kono
parents: 67
diff changeset
571 node->lowered = true;
kono
parents: 67
diff changeset
572 cgraph_new_nodes.safe_push (node);
kono
parents: 67
diff changeset
573 break;
kono
parents: 67
diff changeset
574
kono
parents: 67
diff changeset
575 case FINISHED:
kono
parents: 67
diff changeset
576 /* At the very end of compilation we have to do all the work up
kono
parents: 67
diff changeset
577 to expansion. */
kono
parents: 67
diff changeset
578 node = cgraph_node::create (fndecl);
kono
parents: 67
diff changeset
579 if (lowered)
kono
parents: 67
diff changeset
580 node->lowered = true;
kono
parents: 67
diff changeset
581 node->definition = true;
kono
parents: 67
diff changeset
582 node->analyze ();
kono
parents: 67
diff changeset
583 push_cfun (DECL_STRUCT_FUNCTION (fndecl));
kono
parents: 67
diff changeset
584 gimple_register_cfg_hooks ();
kono
parents: 67
diff changeset
585 bitmap_obstack_initialize (NULL);
kono
parents: 67
diff changeset
586 if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl)))
kono
parents: 67
diff changeset
587 g->get_passes ()->execute_early_local_passes ();
kono
parents: 67
diff changeset
588 bitmap_obstack_release (NULL);
kono
parents: 67
diff changeset
589 pop_cfun ();
kono
parents: 67
diff changeset
590 node->expand ();
kono
parents: 67
diff changeset
591 break;
kono
parents: 67
diff changeset
592
kono
parents: 67
diff changeset
593 default:
kono
parents: 67
diff changeset
594 gcc_unreachable ();
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
595 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
596
111
kono
parents: 67
diff changeset
597 /* Set a personality if required and we already passed EH lowering. */
kono
parents: 67
diff changeset
598 if (lowered
kono
parents: 67
diff changeset
599 && (function_needs_eh_personality (DECL_STRUCT_FUNCTION (fndecl))
kono
parents: 67
diff changeset
600 == eh_personality_lang))
kono
parents: 67
diff changeset
601 DECL_FUNCTION_PERSONALITY (fndecl) = lang_hooks.eh_personality ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 /* Analyze the function scheduled to be output. */
111
kono
parents: 67
diff changeset
605 void
kono
parents: 67
diff changeset
606 cgraph_node::analyze (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 {
111
kono
parents: 67
diff changeset
608 if (native_rtl_p ())
kono
parents: 67
diff changeset
609 {
kono
parents: 67
diff changeset
610 analyzed = true;
kono
parents: 67
diff changeset
611 return;
kono
parents: 67
diff changeset
612 }
kono
parents: 67
diff changeset
613
kono
parents: 67
diff changeset
614 tree decl = this->decl;
kono
parents: 67
diff changeset
615 location_t saved_loc = input_location;
kono
parents: 67
diff changeset
616 input_location = DECL_SOURCE_LOCATION (decl);
kono
parents: 67
diff changeset
617
kono
parents: 67
diff changeset
618 if (thunk.thunk_p)
kono
parents: 67
diff changeset
619 {
kono
parents: 67
diff changeset
620 cgraph_node *t = cgraph_node::get (thunk.alias);
kono
parents: 67
diff changeset
621
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
622 create_edge (t, NULL, t->count);
111
kono
parents: 67
diff changeset
623 callees->can_throw_external = !TREE_NOTHROW (t->decl);
kono
parents: 67
diff changeset
624 /* Target code in expand_thunk may need the thunk's target
kono
parents: 67
diff changeset
625 to be analyzed, so recurse here. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
626 if (!t->analyzed && t->definition)
111
kono
parents: 67
diff changeset
627 t->analyze ();
kono
parents: 67
diff changeset
628 if (t->alias)
kono
parents: 67
diff changeset
629 {
kono
parents: 67
diff changeset
630 t = t->get_alias_target ();
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
631 if (!t->analyzed && t->definition)
111
kono
parents: 67
diff changeset
632 t->analyze ();
kono
parents: 67
diff changeset
633 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
634 bool ret = expand_thunk (false, false);
111
kono
parents: 67
diff changeset
635 thunk.alias = NULL;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
636 if (!ret)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
637 return;
111
kono
parents: 67
diff changeset
638 }
kono
parents: 67
diff changeset
639 if (alias)
kono
parents: 67
diff changeset
640 resolve_alias (cgraph_node::get (alias_target), transparent_alias);
kono
parents: 67
diff changeset
641 else if (dispatcher_function)
kono
parents: 67
diff changeset
642 {
kono
parents: 67
diff changeset
643 /* Generate the dispatcher body of multi-versioned functions. */
kono
parents: 67
diff changeset
644 cgraph_function_version_info *dispatcher_version_info
kono
parents: 67
diff changeset
645 = function_version ();
kono
parents: 67
diff changeset
646 if (dispatcher_version_info != NULL
kono
parents: 67
diff changeset
647 && (dispatcher_version_info->dispatcher_resolver
kono
parents: 67
diff changeset
648 == NULL_TREE))
kono
parents: 67
diff changeset
649 {
kono
parents: 67
diff changeset
650 tree resolver = NULL_TREE;
kono
parents: 67
diff changeset
651 gcc_assert (targetm.generate_version_dispatcher_body);
kono
parents: 67
diff changeset
652 resolver = targetm.generate_version_dispatcher_body (this);
kono
parents: 67
diff changeset
653 gcc_assert (resolver != NULL_TREE);
kono
parents: 67
diff changeset
654 }
kono
parents: 67
diff changeset
655 }
kono
parents: 67
diff changeset
656 else
kono
parents: 67
diff changeset
657 {
kono
parents: 67
diff changeset
658 push_cfun (DECL_STRUCT_FUNCTION (decl));
kono
parents: 67
diff changeset
659
kono
parents: 67
diff changeset
660 assign_assembler_name_if_needed (decl);
kono
parents: 67
diff changeset
661
kono
parents: 67
diff changeset
662 /* Make sure to gimplify bodies only once. During analyzing a
kono
parents: 67
diff changeset
663 function we lower it, which will require gimplified nested
kono
parents: 67
diff changeset
664 functions, so we can end up here with an already gimplified
kono
parents: 67
diff changeset
665 body. */
kono
parents: 67
diff changeset
666 if (!gimple_has_body_p (decl))
kono
parents: 67
diff changeset
667 gimplify_function_tree (decl);
kono
parents: 67
diff changeset
668
kono
parents: 67
diff changeset
669 /* Lower the function. */
kono
parents: 67
diff changeset
670 if (!lowered)
kono
parents: 67
diff changeset
671 {
kono
parents: 67
diff changeset
672 if (nested)
kono
parents: 67
diff changeset
673 lower_nested_functions (decl);
kono
parents: 67
diff changeset
674 gcc_assert (!nested);
kono
parents: 67
diff changeset
675
kono
parents: 67
diff changeset
676 gimple_register_cfg_hooks ();
kono
parents: 67
diff changeset
677 bitmap_obstack_initialize (NULL);
kono
parents: 67
diff changeset
678 execute_pass_list (cfun, g->get_passes ()->all_lowering_passes);
kono
parents: 67
diff changeset
679 free_dominance_info (CDI_POST_DOMINATORS);
kono
parents: 67
diff changeset
680 free_dominance_info (CDI_DOMINATORS);
kono
parents: 67
diff changeset
681 compact_blocks ();
kono
parents: 67
diff changeset
682 bitmap_obstack_release (NULL);
kono
parents: 67
diff changeset
683 lowered = true;
kono
parents: 67
diff changeset
684 }
kono
parents: 67
diff changeset
685
kono
parents: 67
diff changeset
686 pop_cfun ();
kono
parents: 67
diff changeset
687 }
kono
parents: 67
diff changeset
688 analyzed = true;
kono
parents: 67
diff changeset
689
kono
parents: 67
diff changeset
690 input_location = saved_loc;
kono
parents: 67
diff changeset
691 }
kono
parents: 67
diff changeset
692
kono
parents: 67
diff changeset
693 /* C++ frontend produce same body aliases all over the place, even before PCH
kono
parents: 67
diff changeset
694 gets streamed out. It relies on us linking the aliases with their function
kono
parents: 67
diff changeset
695 in order to do the fixups, but ipa-ref is not PCH safe. Consequentely we
kono
parents: 67
diff changeset
696 first produce aliases without links, but once C++ FE is sure he won't sream
kono
parents: 67
diff changeset
697 PCH we build the links via this function. */
kono
parents: 67
diff changeset
698
kono
parents: 67
diff changeset
699 void
kono
parents: 67
diff changeset
700 symbol_table::process_same_body_aliases (void)
kono
parents: 67
diff changeset
701 {
kono
parents: 67
diff changeset
702 symtab_node *node;
kono
parents: 67
diff changeset
703 FOR_EACH_SYMBOL (node)
kono
parents: 67
diff changeset
704 if (node->cpp_implicit_alias && !node->analyzed)
kono
parents: 67
diff changeset
705 node->resolve_alias
kono
parents: 67
diff changeset
706 (VAR_P (node->alias_target)
kono
parents: 67
diff changeset
707 ? (symtab_node *)varpool_node::get_create (node->alias_target)
kono
parents: 67
diff changeset
708 : (symtab_node *)cgraph_node::get_create (node->alias_target));
kono
parents: 67
diff changeset
709 cpp_implicit_aliases_done = true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
712 /* Process attributes common for vars and functions. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
713
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
714 static void
111
kono
parents: 67
diff changeset
715 process_common_attributes (symtab_node *node, tree decl)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
716 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
717 tree weakref = lookup_attribute ("weakref", DECL_ATTRIBUTES (decl));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
718
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
719 if (weakref && !lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
720 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
721 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
722 "%<weakref%> attribute should be accompanied with"
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
723 " an %<alias%> attribute");
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
724 DECL_WEAK (decl) = 0;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
725 DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
726 DECL_ATTRIBUTES (decl));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
727 }
111
kono
parents: 67
diff changeset
728
kono
parents: 67
diff changeset
729 if (lookup_attribute ("no_reorder", DECL_ATTRIBUTES (decl)))
kono
parents: 67
diff changeset
730 node->no_reorder = 1;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
731 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
732
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 /* Look for externally_visible and used attributes and mark cgraph nodes
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 accordingly.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 We cannot mark the nodes at the point the attributes are processed (in
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 handle_*_attribute) because the copy of the declarations available at that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 point may not be canonical. For example, in:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 void f();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 void f() __attribute__((used));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 the declaration we see in handle_used_attribute will be the second
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 declaration -- but the front end will subsequently merge that declaration
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 with the original declaration and discard the second declaration.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746
111
kono
parents: 67
diff changeset
747 Furthermore, we can't mark these nodes in finalize_function because:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 void f() {}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 void f() __attribute__((externally_visible));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 is valid.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 So, we walk the nodes at the end of the translation unit, applying the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 attributes at that point. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 static void
111
kono
parents: 67
diff changeset
758 process_function_and_variable_attributes (cgraph_node *first,
kono
parents: 67
diff changeset
759 varpool_node *first_var)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 {
111
kono
parents: 67
diff changeset
761 cgraph_node *node;
kono
parents: 67
diff changeset
762 varpool_node *vnode;
kono
parents: 67
diff changeset
763
kono
parents: 67
diff changeset
764 for (node = symtab->first_function (); node != first;
kono
parents: 67
diff changeset
765 node = symtab->next_function (node))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 tree decl = node->decl;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
768 if (DECL_PRESERVE_P (decl))
111
kono
parents: 67
diff changeset
769 node->mark_force_output ();
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
770 else if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 if (! TREE_PUBLIC (node->decl))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
773 warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
774 "%<externally_visible%>"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
775 " attribute have effect only on public objects");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
777 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
111
kono
parents: 67
diff changeset
778 && (node->definition && !node->alias))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
779 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
780 warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
781 "%<weakref%> attribute ignored"
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
782 " because function is defined");
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
783 DECL_WEAK (decl) = 0;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
784 DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
785 DECL_ATTRIBUTES (decl));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
786 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
787 else if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
788 && node->definition
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
789 && !node->alias)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
790 warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
791 "%<alias%> attribute ignored"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
792 " because function is defined");
111
kono
parents: 67
diff changeset
793
kono
parents: 67
diff changeset
794 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl))
kono
parents: 67
diff changeset
795 && !DECL_DECLARED_INLINE_P (decl)
kono
parents: 67
diff changeset
796 /* redefining extern inline function makes it DECL_UNINLINABLE. */
kono
parents: 67
diff changeset
797 && !DECL_UNINLINABLE (decl))
kono
parents: 67
diff changeset
798 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
kono
parents: 67
diff changeset
799 "always_inline function might not be inlinable");
kono
parents: 67
diff changeset
800
kono
parents: 67
diff changeset
801 process_common_attributes (node, decl);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802 }
111
kono
parents: 67
diff changeset
803 for (vnode = symtab->first_variable (); vnode != first_var;
kono
parents: 67
diff changeset
804 vnode = symtab->next_variable (vnode))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 tree decl = vnode->decl;
111
kono
parents: 67
diff changeset
807 if (DECL_EXTERNAL (decl)
kono
parents: 67
diff changeset
808 && DECL_INITIAL (decl))
kono
parents: 67
diff changeset
809 varpool_node::finalize_decl (decl);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
810 if (DECL_PRESERVE_P (decl))
111
kono
parents: 67
diff changeset
811 vnode->force_output = true;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
812 else if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 if (! TREE_PUBLIC (vnode->decl))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
815 warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
816 "%<externally_visible%>"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
817 " attribute have effect only on public objects");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
819 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
111
kono
parents: 67
diff changeset
820 && vnode->definition
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
821 && DECL_INITIAL (decl))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
822 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
823 warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
824 "%<weakref%> attribute ignored"
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
825 " because variable is initialized");
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
826 DECL_WEAK (decl) = 0;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
827 DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
828 DECL_ATTRIBUTES (decl));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
829 }
111
kono
parents: 67
diff changeset
830 process_common_attributes (vnode, decl);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833
111
kono
parents: 67
diff changeset
834 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct the
kono
parents: 67
diff changeset
835 middle end to output the variable to asm file, if needed or externally
kono
parents: 67
diff changeset
836 visible. */
kono
parents: 67
diff changeset
837
kono
parents: 67
diff changeset
838 void
kono
parents: 67
diff changeset
839 varpool_node::finalize_decl (tree decl)
kono
parents: 67
diff changeset
840 {
kono
parents: 67
diff changeset
841 varpool_node *node = varpool_node::get_create (decl);
kono
parents: 67
diff changeset
842
kono
parents: 67
diff changeset
843 gcc_assert (TREE_STATIC (decl) || DECL_EXTERNAL (decl));
kono
parents: 67
diff changeset
844
kono
parents: 67
diff changeset
845 if (node->definition)
kono
parents: 67
diff changeset
846 return;
kono
parents: 67
diff changeset
847 /* Set definition first before calling notice_global_symbol so that
kono
parents: 67
diff changeset
848 it is available to notice_global_symbol. */
kono
parents: 67
diff changeset
849 node->definition = true;
kono
parents: 67
diff changeset
850 notice_global_symbol (decl);
kono
parents: 67
diff changeset
851 if (!flag_toplevel_reorder)
kono
parents: 67
diff changeset
852 node->no_reorder = true;
kono
parents: 67
diff changeset
853 if (TREE_THIS_VOLATILE (decl) || DECL_PRESERVE_P (decl)
kono
parents: 67
diff changeset
854 /* Traditionally we do not eliminate static variables when not
kono
parents: 67
diff changeset
855 optimizing and when not doing toplevel reoder. */
kono
parents: 67
diff changeset
856 || (node->no_reorder && !DECL_COMDAT (node->decl)
kono
parents: 67
diff changeset
857 && !DECL_ARTIFICIAL (node->decl)))
kono
parents: 67
diff changeset
858 node->force_output = true;
kono
parents: 67
diff changeset
859
kono
parents: 67
diff changeset
860 if (symtab->state == CONSTRUCTION
kono
parents: 67
diff changeset
861 && (node->needed_p () || node->referred_to_p ()))
kono
parents: 67
diff changeset
862 enqueue_node (node);
kono
parents: 67
diff changeset
863 if (symtab->state >= IPA_SSA)
kono
parents: 67
diff changeset
864 node->analyze ();
kono
parents: 67
diff changeset
865 /* Some frontends produce various interface variables after compilation
kono
parents: 67
diff changeset
866 finished. */
kono
parents: 67
diff changeset
867 if (symtab->state == FINISHED
kono
parents: 67
diff changeset
868 || (node->no_reorder
kono
parents: 67
diff changeset
869 && symtab->state == EXPANSION))
kono
parents: 67
diff changeset
870 node->assemble_decl ();
kono
parents: 67
diff changeset
871 }
kono
parents: 67
diff changeset
872
kono
parents: 67
diff changeset
873 /* EDGE is an polymorphic call. Mark all possible targets as reachable
kono
parents: 67
diff changeset
874 and if there is only one target, perform trivial devirtualization.
kono
parents: 67
diff changeset
875 REACHABLE_CALL_TARGETS collects target lists we already walked to
kono
parents: 67
diff changeset
876 avoid udplicate work. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 static void
111
kono
parents: 67
diff changeset
879 walk_polymorphic_call_targets (hash_set<void *> *reachable_call_targets,
kono
parents: 67
diff changeset
880 cgraph_edge *edge)
kono
parents: 67
diff changeset
881 {
kono
parents: 67
diff changeset
882 unsigned int i;
kono
parents: 67
diff changeset
883 void *cache_token;
kono
parents: 67
diff changeset
884 bool final;
kono
parents: 67
diff changeset
885 vec <cgraph_node *>targets
kono
parents: 67
diff changeset
886 = possible_polymorphic_call_targets
kono
parents: 67
diff changeset
887 (edge, &final, &cache_token);
kono
parents: 67
diff changeset
888
kono
parents: 67
diff changeset
889 if (!reachable_call_targets->add (cache_token))
kono
parents: 67
diff changeset
890 {
kono
parents: 67
diff changeset
891 if (symtab->dump_file)
kono
parents: 67
diff changeset
892 dump_possible_polymorphic_call_targets
kono
parents: 67
diff changeset
893 (symtab->dump_file, edge);
kono
parents: 67
diff changeset
894
kono
parents: 67
diff changeset
895 for (i = 0; i < targets.length (); i++)
kono
parents: 67
diff changeset
896 {
kono
parents: 67
diff changeset
897 /* Do not bother to mark virtual methods in anonymous namespace;
kono
parents: 67
diff changeset
898 either we will find use of virtual table defining it, or it is
kono
parents: 67
diff changeset
899 unused. */
kono
parents: 67
diff changeset
900 if (targets[i]->definition
kono
parents: 67
diff changeset
901 && TREE_CODE
kono
parents: 67
diff changeset
902 (TREE_TYPE (targets[i]->decl))
kono
parents: 67
diff changeset
903 == METHOD_TYPE
kono
parents: 67
diff changeset
904 && !type_in_anonymous_namespace_p
kono
parents: 67
diff changeset
905 (TYPE_METHOD_BASETYPE (TREE_TYPE (targets[i]->decl))))
kono
parents: 67
diff changeset
906 enqueue_node (targets[i]);
kono
parents: 67
diff changeset
907 }
kono
parents: 67
diff changeset
908 }
kono
parents: 67
diff changeset
909
kono
parents: 67
diff changeset
910 /* Very trivial devirtualization; when the type is
kono
parents: 67
diff changeset
911 final or anonymous (so we know all its derivation)
kono
parents: 67
diff changeset
912 and there is only one possible virtual call target,
kono
parents: 67
diff changeset
913 make the edge direct. */
kono
parents: 67
diff changeset
914 if (final)
kono
parents: 67
diff changeset
915 {
kono
parents: 67
diff changeset
916 if (targets.length () <= 1 && dbg_cnt (devirt))
kono
parents: 67
diff changeset
917 {
kono
parents: 67
diff changeset
918 cgraph_node *target;
kono
parents: 67
diff changeset
919 if (targets.length () == 1)
kono
parents: 67
diff changeset
920 target = targets[0];
kono
parents: 67
diff changeset
921 else
kono
parents: 67
diff changeset
922 target = cgraph_node::create
kono
parents: 67
diff changeset
923 (builtin_decl_implicit (BUILT_IN_UNREACHABLE));
kono
parents: 67
diff changeset
924
kono
parents: 67
diff changeset
925 if (symtab->dump_file)
kono
parents: 67
diff changeset
926 {
kono
parents: 67
diff changeset
927 fprintf (symtab->dump_file,
kono
parents: 67
diff changeset
928 "Devirtualizing call: ");
kono
parents: 67
diff changeset
929 print_gimple_stmt (symtab->dump_file,
kono
parents: 67
diff changeset
930 edge->call_stmt, 0,
kono
parents: 67
diff changeset
931 TDF_SLIM);
kono
parents: 67
diff changeset
932 }
kono
parents: 67
diff changeset
933 if (dump_enabled_p ())
kono
parents: 67
diff changeset
934 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
935 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, edge->call_stmt,
111
kono
parents: 67
diff changeset
936 "devirtualizing call in %s to %s\n",
kono
parents: 67
diff changeset
937 edge->caller->name (), target->name ());
kono
parents: 67
diff changeset
938 }
kono
parents: 67
diff changeset
939
kono
parents: 67
diff changeset
940 edge->make_direct (target);
kono
parents: 67
diff changeset
941 edge->redirect_call_stmt_to_callee ();
kono
parents: 67
diff changeset
942
kono
parents: 67
diff changeset
943 if (symtab->dump_file)
kono
parents: 67
diff changeset
944 {
kono
parents: 67
diff changeset
945 fprintf (symtab->dump_file,
kono
parents: 67
diff changeset
946 "Devirtualized as: ");
kono
parents: 67
diff changeset
947 print_gimple_stmt (symtab->dump_file,
kono
parents: 67
diff changeset
948 edge->call_stmt, 0,
kono
parents: 67
diff changeset
949 TDF_SLIM);
kono
parents: 67
diff changeset
950 }
kono
parents: 67
diff changeset
951 }
kono
parents: 67
diff changeset
952 }
kono
parents: 67
diff changeset
953 }
kono
parents: 67
diff changeset
954
kono
parents: 67
diff changeset
955 /* Issue appropriate warnings for the global declaration DECL. */
kono
parents: 67
diff changeset
956
kono
parents: 67
diff changeset
957 static void
kono
parents: 67
diff changeset
958 check_global_declaration (symtab_node *snode)
kono
parents: 67
diff changeset
959 {
kono
parents: 67
diff changeset
960 const char *decl_file;
kono
parents: 67
diff changeset
961 tree decl = snode->decl;
kono
parents: 67
diff changeset
962
kono
parents: 67
diff changeset
963 /* Warn about any function declared static but not defined. We don't
kono
parents: 67
diff changeset
964 warn about variables, because many programs have static variables
kono
parents: 67
diff changeset
965 that exist only to get some text into the object file. */
kono
parents: 67
diff changeset
966 if (TREE_CODE (decl) == FUNCTION_DECL
kono
parents: 67
diff changeset
967 && DECL_INITIAL (decl) == 0
kono
parents: 67
diff changeset
968 && DECL_EXTERNAL (decl)
kono
parents: 67
diff changeset
969 && ! DECL_ARTIFICIAL (decl)
kono
parents: 67
diff changeset
970 && ! TREE_NO_WARNING (decl)
kono
parents: 67
diff changeset
971 && ! TREE_PUBLIC (decl)
kono
parents: 67
diff changeset
972 && (warn_unused_function
kono
parents: 67
diff changeset
973 || snode->referred_to_p (/*include_self=*/false)))
kono
parents: 67
diff changeset
974 {
kono
parents: 67
diff changeset
975 if (snode->referred_to_p (/*include_self=*/false))
kono
parents: 67
diff changeset
976 pedwarn (input_location, 0, "%q+F used but never defined", decl);
kono
parents: 67
diff changeset
977 else
kono
parents: 67
diff changeset
978 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
kono
parents: 67
diff changeset
979 /* This symbol is effectively an "extern" declaration now. */
kono
parents: 67
diff changeset
980 TREE_PUBLIC (decl) = 1;
kono
parents: 67
diff changeset
981 }
kono
parents: 67
diff changeset
982
kono
parents: 67
diff changeset
983 /* Warn about static fns or vars defined but not used. */
kono
parents: 67
diff changeset
984 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
kono
parents: 67
diff changeset
985 || (((warn_unused_variable && ! TREE_READONLY (decl))
kono
parents: 67
diff changeset
986 || (warn_unused_const_variable > 0 && TREE_READONLY (decl)
kono
parents: 67
diff changeset
987 && (warn_unused_const_variable == 2
kono
parents: 67
diff changeset
988 || (main_input_filename != NULL
kono
parents: 67
diff changeset
989 && (decl_file = DECL_SOURCE_FILE (decl)) != NULL
kono
parents: 67
diff changeset
990 && filename_cmp (main_input_filename,
kono
parents: 67
diff changeset
991 decl_file) == 0))))
kono
parents: 67
diff changeset
992 && VAR_P (decl)))
kono
parents: 67
diff changeset
993 && ! DECL_IN_SYSTEM_HEADER (decl)
kono
parents: 67
diff changeset
994 && ! snode->referred_to_p (/*include_self=*/false)
kono
parents: 67
diff changeset
995 /* This TREE_USED check is needed in addition to referred_to_p
kono
parents: 67
diff changeset
996 above, because the `__unused__' attribute is not being
kono
parents: 67
diff changeset
997 considered for referred_to_p. */
kono
parents: 67
diff changeset
998 && ! TREE_USED (decl)
kono
parents: 67
diff changeset
999 /* The TREE_USED bit for file-scope decls is kept in the identifier,
kono
parents: 67
diff changeset
1000 to handle multiple external decls in different scopes. */
kono
parents: 67
diff changeset
1001 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
kono
parents: 67
diff changeset
1002 && ! DECL_EXTERNAL (decl)
kono
parents: 67
diff changeset
1003 && ! DECL_ARTIFICIAL (decl)
kono
parents: 67
diff changeset
1004 && ! DECL_ABSTRACT_ORIGIN (decl)
kono
parents: 67
diff changeset
1005 && ! TREE_PUBLIC (decl)
kono
parents: 67
diff changeset
1006 /* A volatile variable might be used in some non-obvious way. */
kono
parents: 67
diff changeset
1007 && (! VAR_P (decl) || ! TREE_THIS_VOLATILE (decl))
kono
parents: 67
diff changeset
1008 /* Global register variables must be declared to reserve them. */
kono
parents: 67
diff changeset
1009 && ! (VAR_P (decl) && DECL_REGISTER (decl))
kono
parents: 67
diff changeset
1010 /* Global ctors and dtors are called by the runtime. */
kono
parents: 67
diff changeset
1011 && (TREE_CODE (decl) != FUNCTION_DECL
kono
parents: 67
diff changeset
1012 || (!DECL_STATIC_CONSTRUCTOR (decl)
kono
parents: 67
diff changeset
1013 && !DECL_STATIC_DESTRUCTOR (decl)))
kono
parents: 67
diff changeset
1014 /* Otherwise, ask the language. */
kono
parents: 67
diff changeset
1015 && lang_hooks.decls.warn_unused_global (decl))
kono
parents: 67
diff changeset
1016 warning_at (DECL_SOURCE_LOCATION (decl),
kono
parents: 67
diff changeset
1017 (TREE_CODE (decl) == FUNCTION_DECL)
kono
parents: 67
diff changeset
1018 ? OPT_Wunused_function
kono
parents: 67
diff changeset
1019 : (TREE_READONLY (decl)
kono
parents: 67
diff changeset
1020 ? OPT_Wunused_const_variable_
kono
parents: 67
diff changeset
1021 : OPT_Wunused_variable),
kono
parents: 67
diff changeset
1022 "%qD defined but not used", decl);
kono
parents: 67
diff changeset
1023 }
kono
parents: 67
diff changeset
1024
kono
parents: 67
diff changeset
1025 /* Discover all functions and variables that are trivially needed, analyze
kono
parents: 67
diff changeset
1026 them as well as all functions and variables referred by them */
kono
parents: 67
diff changeset
1027 static cgraph_node *first_analyzed;
kono
parents: 67
diff changeset
1028 static varpool_node *first_analyzed_var;
kono
parents: 67
diff changeset
1029
kono
parents: 67
diff changeset
1030 /* FIRST_TIME is set to TRUE for the first time we are called for a
kono
parents: 67
diff changeset
1031 translation unit from finalize_compilation_unit() or false
kono
parents: 67
diff changeset
1032 otherwise. */
kono
parents: 67
diff changeset
1033
kono
parents: 67
diff changeset
1034 static void
kono
parents: 67
diff changeset
1035 analyze_functions (bool first_time)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 /* Keep track of already processed nodes when called multiple times for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 intermodule optimization. */
111
kono
parents: 67
diff changeset
1039 cgraph_node *first_handled = first_analyzed;
kono
parents: 67
diff changeset
1040 varpool_node *first_handled_var = first_analyzed_var;
kono
parents: 67
diff changeset
1041 hash_set<void *> reachable_call_targets;
kono
parents: 67
diff changeset
1042
kono
parents: 67
diff changeset
1043 symtab_node *node;
kono
parents: 67
diff changeset
1044 symtab_node *next;
kono
parents: 67
diff changeset
1045 int i;
kono
parents: 67
diff changeset
1046 ipa_ref *ref;
kono
parents: 67
diff changeset
1047 bool changed = true;
kono
parents: 67
diff changeset
1048 location_t saved_loc = input_location;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1050 bitmap_obstack_initialize (NULL);
111
kono
parents: 67
diff changeset
1051 symtab->state = CONSTRUCTION;
kono
parents: 67
diff changeset
1052 input_location = UNKNOWN_LOCATION;
kono
parents: 67
diff changeset
1053
kono
parents: 67
diff changeset
1054 /* Ugly, but the fixup can not happen at a time same body alias is created;
kono
parents: 67
diff changeset
1055 C++ FE is confused about the COMDAT groups being right. */
kono
parents: 67
diff changeset
1056 if (symtab->cpp_implicit_aliases_done)
kono
parents: 67
diff changeset
1057 FOR_EACH_SYMBOL (node)
kono
parents: 67
diff changeset
1058 if (node->cpp_implicit_alias)
kono
parents: 67
diff changeset
1059 node->fixup_same_cpp_alias_visibility (node->get_alias_target ());
kono
parents: 67
diff changeset
1060 build_type_inheritance_graph ();
kono
parents: 67
diff changeset
1061
kono
parents: 67
diff changeset
1062 /* Analysis adds static variables that in turn adds references to new functions.
kono
parents: 67
diff changeset
1063 So we need to iterate the process until it stabilize. */
kono
parents: 67
diff changeset
1064 while (changed)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 {
111
kono
parents: 67
diff changeset
1066 changed = false;
kono
parents: 67
diff changeset
1067 process_function_and_variable_attributes (first_analyzed,
kono
parents: 67
diff changeset
1068 first_analyzed_var);
kono
parents: 67
diff changeset
1069
kono
parents: 67
diff changeset
1070 /* First identify the trivially needed symbols. */
kono
parents: 67
diff changeset
1071 for (node = symtab->first_symbol ();
kono
parents: 67
diff changeset
1072 node != first_analyzed
kono
parents: 67
diff changeset
1073 && node != first_analyzed_var; node = node->next)
kono
parents: 67
diff changeset
1074 {
kono
parents: 67
diff changeset
1075 /* Convert COMDAT group designators to IDENTIFIER_NODEs. */
kono
parents: 67
diff changeset
1076 node->get_comdat_group_id ();
kono
parents: 67
diff changeset
1077 if (node->needed_p ())
kono
parents: 67
diff changeset
1078 {
kono
parents: 67
diff changeset
1079 enqueue_node (node);
kono
parents: 67
diff changeset
1080 if (!changed && symtab->dump_file)
kono
parents: 67
diff changeset
1081 fprintf (symtab->dump_file, "Trivially needed symbols:");
kono
parents: 67
diff changeset
1082 changed = true;
kono
parents: 67
diff changeset
1083 if (symtab->dump_file)
kono
parents: 67
diff changeset
1084 fprintf (symtab->dump_file, " %s", node->asm_name ());
kono
parents: 67
diff changeset
1085 if (!changed && symtab->dump_file)
kono
parents: 67
diff changeset
1086 fprintf (symtab->dump_file, "\n");
kono
parents: 67
diff changeset
1087 }
kono
parents: 67
diff changeset
1088 if (node == first_analyzed
kono
parents: 67
diff changeset
1089 || node == first_analyzed_var)
kono
parents: 67
diff changeset
1090 break;
kono
parents: 67
diff changeset
1091 }
kono
parents: 67
diff changeset
1092 symtab->process_new_functions ();
kono
parents: 67
diff changeset
1093 first_analyzed_var = symtab->first_variable ();
kono
parents: 67
diff changeset
1094 first_analyzed = symtab->first_function ();
kono
parents: 67
diff changeset
1095
kono
parents: 67
diff changeset
1096 if (changed && symtab->dump_file)
kono
parents: 67
diff changeset
1097 fprintf (symtab->dump_file, "\n");
kono
parents: 67
diff changeset
1098
kono
parents: 67
diff changeset
1099 /* Lower representation, build callgraph edges and references for all trivially
kono
parents: 67
diff changeset
1100 needed symbols and all symbols referred by them. */
kono
parents: 67
diff changeset
1101 while (queued_nodes != &symtab_terminator)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 {
111
kono
parents: 67
diff changeset
1103 changed = true;
kono
parents: 67
diff changeset
1104 node = queued_nodes;
kono
parents: 67
diff changeset
1105 queued_nodes = (symtab_node *)queued_nodes->aux;
kono
parents: 67
diff changeset
1106 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
kono
parents: 67
diff changeset
1107 if (cnode && cnode->definition)
kono
parents: 67
diff changeset
1108 {
kono
parents: 67
diff changeset
1109 cgraph_edge *edge;
kono
parents: 67
diff changeset
1110 tree decl = cnode->decl;
kono
parents: 67
diff changeset
1111
kono
parents: 67
diff changeset
1112 /* ??? It is possible to create extern inline function
kono
parents: 67
diff changeset
1113 and later using weak alias attribute to kill its body.
kono
parents: 67
diff changeset
1114 See gcc.c-torture/compile/20011119-1.c */
kono
parents: 67
diff changeset
1115 if (!DECL_STRUCT_FUNCTION (decl)
kono
parents: 67
diff changeset
1116 && !cnode->alias
kono
parents: 67
diff changeset
1117 && !cnode->thunk.thunk_p
kono
parents: 67
diff changeset
1118 && !cnode->dispatcher_function)
kono
parents: 67
diff changeset
1119 {
kono
parents: 67
diff changeset
1120 cnode->reset ();
kono
parents: 67
diff changeset
1121 cnode->local.redefined_extern_inline = true;
kono
parents: 67
diff changeset
1122 continue;
kono
parents: 67
diff changeset
1123 }
kono
parents: 67
diff changeset
1124
kono
parents: 67
diff changeset
1125 if (!cnode->analyzed)
kono
parents: 67
diff changeset
1126 cnode->analyze ();
kono
parents: 67
diff changeset
1127
kono
parents: 67
diff changeset
1128 for (edge = cnode->callees; edge; edge = edge->next_callee)
kono
parents: 67
diff changeset
1129 if (edge->callee->definition
kono
parents: 67
diff changeset
1130 && (!DECL_EXTERNAL (edge->callee->decl)
kono
parents: 67
diff changeset
1131 /* When not optimizing, do not try to analyze extern
kono
parents: 67
diff changeset
1132 inline functions. Doing so is pointless. */
kono
parents: 67
diff changeset
1133 || opt_for_fn (edge->callee->decl, optimize)
kono
parents: 67
diff changeset
1134 /* Weakrefs needs to be preserved. */
kono
parents: 67
diff changeset
1135 || edge->callee->alias
kono
parents: 67
diff changeset
1136 /* always_inline functions are inlined aven at -O0. */
kono
parents: 67
diff changeset
1137 || lookup_attribute
kono
parents: 67
diff changeset
1138 ("always_inline",
kono
parents: 67
diff changeset
1139 DECL_ATTRIBUTES (edge->callee->decl))
kono
parents: 67
diff changeset
1140 /* Multiversioned functions needs the dispatcher to
kono
parents: 67
diff changeset
1141 be produced locally even for extern functions. */
kono
parents: 67
diff changeset
1142 || edge->callee->function_version ()))
kono
parents: 67
diff changeset
1143 enqueue_node (edge->callee);
kono
parents: 67
diff changeset
1144 if (opt_for_fn (cnode->decl, optimize)
kono
parents: 67
diff changeset
1145 && opt_for_fn (cnode->decl, flag_devirtualize))
kono
parents: 67
diff changeset
1146 {
kono
parents: 67
diff changeset
1147 cgraph_edge *next;
kono
parents: 67
diff changeset
1148
kono
parents: 67
diff changeset
1149 for (edge = cnode->indirect_calls; edge; edge = next)
kono
parents: 67
diff changeset
1150 {
kono
parents: 67
diff changeset
1151 next = edge->next_callee;
kono
parents: 67
diff changeset
1152 if (edge->indirect_info->polymorphic)
kono
parents: 67
diff changeset
1153 walk_polymorphic_call_targets (&reachable_call_targets,
kono
parents: 67
diff changeset
1154 edge);
kono
parents: 67
diff changeset
1155 }
kono
parents: 67
diff changeset
1156 }
kono
parents: 67
diff changeset
1157
kono
parents: 67
diff changeset
1158 /* If decl is a clone of an abstract function,
kono
parents: 67
diff changeset
1159 mark that abstract function so that we don't release its body.
kono
parents: 67
diff changeset
1160 The DECL_INITIAL() of that abstract function declaration
kono
parents: 67
diff changeset
1161 will be later needed to output debug info. */
kono
parents: 67
diff changeset
1162 if (DECL_ABSTRACT_ORIGIN (decl))
kono
parents: 67
diff changeset
1163 {
kono
parents: 67
diff changeset
1164 cgraph_node *origin_node
kono
parents: 67
diff changeset
1165 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (decl));
kono
parents: 67
diff changeset
1166 origin_node->used_as_abstract_origin = true;
kono
parents: 67
diff changeset
1167 }
kono
parents: 67
diff changeset
1168 /* Preserve a functions function context node. It will
kono
parents: 67
diff changeset
1169 later be needed to output debug info. */
kono
parents: 67
diff changeset
1170 if (tree fn = decl_function_context (decl))
kono
parents: 67
diff changeset
1171 {
kono
parents: 67
diff changeset
1172 cgraph_node *origin_node = cgraph_node::get_create (fn);
kono
parents: 67
diff changeset
1173 enqueue_node (origin_node);
kono
parents: 67
diff changeset
1174 }
kono
parents: 67
diff changeset
1175 }
kono
parents: 67
diff changeset
1176 else
kono
parents: 67
diff changeset
1177 {
kono
parents: 67
diff changeset
1178 varpool_node *vnode = dyn_cast <varpool_node *> (node);
kono
parents: 67
diff changeset
1179 if (vnode && vnode->definition && !vnode->analyzed)
kono
parents: 67
diff changeset
1180 vnode->analyze ();
kono
parents: 67
diff changeset
1181 }
kono
parents: 67
diff changeset
1182
kono
parents: 67
diff changeset
1183 if (node->same_comdat_group)
kono
parents: 67
diff changeset
1184 {
kono
parents: 67
diff changeset
1185 symtab_node *next;
kono
parents: 67
diff changeset
1186 for (next = node->same_comdat_group;
kono
parents: 67
diff changeset
1187 next != node;
kono
parents: 67
diff changeset
1188 next = next->same_comdat_group)
kono
parents: 67
diff changeset
1189 if (!next->comdat_local_p ())
kono
parents: 67
diff changeset
1190 enqueue_node (next);
kono
parents: 67
diff changeset
1191 }
kono
parents: 67
diff changeset
1192 for (i = 0; node->iterate_reference (i, ref); i++)
kono
parents: 67
diff changeset
1193 if (ref->referred->definition
kono
parents: 67
diff changeset
1194 && (!DECL_EXTERNAL (ref->referred->decl)
kono
parents: 67
diff changeset
1195 || ((TREE_CODE (ref->referred->decl) != FUNCTION_DECL
kono
parents: 67
diff changeset
1196 && optimize)
kono
parents: 67
diff changeset
1197 || (TREE_CODE (ref->referred->decl) == FUNCTION_DECL
kono
parents: 67
diff changeset
1198 && opt_for_fn (ref->referred->decl, optimize))
kono
parents: 67
diff changeset
1199 || node->alias
kono
parents: 67
diff changeset
1200 || ref->referred->alias)))
kono
parents: 67
diff changeset
1201 enqueue_node (ref->referred);
kono
parents: 67
diff changeset
1202 symtab->process_new_functions ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1203 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 }
111
kono
parents: 67
diff changeset
1205 update_type_inheritance_graph ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207 /* Collect entry points to the unit. */
111
kono
parents: 67
diff changeset
1208 if (symtab->dump_file)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 {
111
kono
parents: 67
diff changeset
1210 fprintf (symtab->dump_file, "\n\nInitial ");
kono
parents: 67
diff changeset
1211 symtab->dump (symtab->dump_file);
kono
parents: 67
diff changeset
1212 }
kono
parents: 67
diff changeset
1213
kono
parents: 67
diff changeset
1214 if (first_time)
kono
parents: 67
diff changeset
1215 {
kono
parents: 67
diff changeset
1216 symtab_node *snode;
kono
parents: 67
diff changeset
1217 FOR_EACH_SYMBOL (snode)
kono
parents: 67
diff changeset
1218 check_global_declaration (snode);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220
111
kono
parents: 67
diff changeset
1221 if (symtab->dump_file)
kono
parents: 67
diff changeset
1222 fprintf (symtab->dump_file, "\nRemoving unused symbols:");
kono
parents: 67
diff changeset
1223
kono
parents: 67
diff changeset
1224 for (node = symtab->first_symbol ();
kono
parents: 67
diff changeset
1225 node != first_handled
kono
parents: 67
diff changeset
1226 && node != first_handled_var; node = next)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 next = node->next;
111
kono
parents: 67
diff changeset
1229 if (!node->aux && !node->referred_to_p ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1230 {
111
kono
parents: 67
diff changeset
1231 if (symtab->dump_file)
kono
parents: 67
diff changeset
1232 fprintf (symtab->dump_file, " %s", node->name ());
kono
parents: 67
diff changeset
1233
kono
parents: 67
diff changeset
1234 /* See if the debugger can use anything before the DECL
kono
parents: 67
diff changeset
1235 passes away. Perhaps it can notice a DECL that is now a
kono
parents: 67
diff changeset
1236 constant and can tag the early DIE with an appropriate
kono
parents: 67
diff changeset
1237 attribute.
kono
parents: 67
diff changeset
1238
kono
parents: 67
diff changeset
1239 Otherwise, this is the last chance the debug_hooks have
kono
parents: 67
diff changeset
1240 at looking at optimized away DECLs, since
kono
parents: 67
diff changeset
1241 late_global_decl will subsequently be called from the
kono
parents: 67
diff changeset
1242 contents of the now pruned symbol table. */
kono
parents: 67
diff changeset
1243 if (VAR_P (node->decl)
kono
parents: 67
diff changeset
1244 && !decl_function_context (node->decl))
kono
parents: 67
diff changeset
1245 {
kono
parents: 67
diff changeset
1246 /* We are reclaiming totally unreachable code and variables
kono
parents: 67
diff changeset
1247 so they effectively appear as readonly. Show that to
kono
parents: 67
diff changeset
1248 the debug machinery. */
kono
parents: 67
diff changeset
1249 TREE_READONLY (node->decl) = 1;
kono
parents: 67
diff changeset
1250 node->definition = false;
kono
parents: 67
diff changeset
1251 (*debug_hooks->late_global_decl) (node->decl);
kono
parents: 67
diff changeset
1252 }
kono
parents: 67
diff changeset
1253
kono
parents: 67
diff changeset
1254 node->remove ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1255 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1256 }
111
kono
parents: 67
diff changeset
1257 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
kono
parents: 67
diff changeset
1258 {
kono
parents: 67
diff changeset
1259 tree decl = node->decl;
kono
parents: 67
diff changeset
1260
kono
parents: 67
diff changeset
1261 if (cnode->definition && !gimple_has_body_p (decl)
kono
parents: 67
diff changeset
1262 && !cnode->alias
kono
parents: 67
diff changeset
1263 && !cnode->thunk.thunk_p)
kono
parents: 67
diff changeset
1264 cnode->reset ();
kono
parents: 67
diff changeset
1265
kono
parents: 67
diff changeset
1266 gcc_assert (!cnode->definition || cnode->thunk.thunk_p
kono
parents: 67
diff changeset
1267 || cnode->alias
kono
parents: 67
diff changeset
1268 || gimple_has_body_p (decl)
kono
parents: 67
diff changeset
1269 || cnode->native_rtl_p ());
kono
parents: 67
diff changeset
1270 gcc_assert (cnode->analyzed == cnode->definition);
kono
parents: 67
diff changeset
1271 }
kono
parents: 67
diff changeset
1272 node->aux = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273 }
111
kono
parents: 67
diff changeset
1274 for (;node; node = node->next)
kono
parents: 67
diff changeset
1275 node->aux = NULL;
kono
parents: 67
diff changeset
1276 first_analyzed = symtab->first_function ();
kono
parents: 67
diff changeset
1277 first_analyzed_var = symtab->first_variable ();
kono
parents: 67
diff changeset
1278 if (symtab->dump_file)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 {
111
kono
parents: 67
diff changeset
1280 fprintf (symtab->dump_file, "\n\nReclaimed ");
kono
parents: 67
diff changeset
1281 symtab->dump (symtab->dump_file);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1283 bitmap_obstack_release (NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284 ggc_collect ();
111
kono
parents: 67
diff changeset
1285 /* Initialize assembler name hash, in particular we want to trigger C++
kono
parents: 67
diff changeset
1286 mangling and same body alias creation before we free DECL_ARGUMENTS
kono
parents: 67
diff changeset
1287 used by it. */
kono
parents: 67
diff changeset
1288 if (!seen_error ())
kono
parents: 67
diff changeset
1289 symtab->symtab_initialize_asm_name_hash ();
kono
parents: 67
diff changeset
1290
kono
parents: 67
diff changeset
1291 input_location = saved_loc;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1292 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293
111
kono
parents: 67
diff changeset
1294 /* Check declaration of the type of ALIAS for compatibility with its TARGET
kono
parents: 67
diff changeset
1295 (which may be an ifunc resolver) and issue a diagnostic when they are
kono
parents: 67
diff changeset
1296 not compatible according to language rules (plus a C++ extension for
kono
parents: 67
diff changeset
1297 non-static member functions). */
kono
parents: 67
diff changeset
1298
kono
parents: 67
diff changeset
1299 static void
kono
parents: 67
diff changeset
1300 maybe_diag_incompatible_alias (tree alias, tree target)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1301 {
111
kono
parents: 67
diff changeset
1302 tree altype = TREE_TYPE (alias);
kono
parents: 67
diff changeset
1303 tree targtype = TREE_TYPE (target);
kono
parents: 67
diff changeset
1304
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1305 bool ifunc = cgraph_node::get (alias)->ifunc_resolver;
111
kono
parents: 67
diff changeset
1306 tree funcptr = altype;
kono
parents: 67
diff changeset
1307
kono
parents: 67
diff changeset
1308 if (ifunc)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 {
111
kono
parents: 67
diff changeset
1310 /* Handle attribute ifunc first. */
kono
parents: 67
diff changeset
1311 if (TREE_CODE (altype) == METHOD_TYPE)
kono
parents: 67
diff changeset
1312 {
kono
parents: 67
diff changeset
1313 /* Set FUNCPTR to the type of the alias target. If the type
kono
parents: 67
diff changeset
1314 is a non-static member function of class C, construct a type
kono
parents: 67
diff changeset
1315 of an ordinary function taking C* as the first argument,
kono
parents: 67
diff changeset
1316 followed by the member function argument list, and use it
kono
parents: 67
diff changeset
1317 instead to check for incompatibility. This conversion is
kono
parents: 67
diff changeset
1318 not defined by the language but an extension provided by
kono
parents: 67
diff changeset
1319 G++. */
kono
parents: 67
diff changeset
1320
kono
parents: 67
diff changeset
1321 tree rettype = TREE_TYPE (altype);
kono
parents: 67
diff changeset
1322 tree args = TYPE_ARG_TYPES (altype);
kono
parents: 67
diff changeset
1323 altype = build_function_type (rettype, args);
kono
parents: 67
diff changeset
1324 funcptr = altype;
kono
parents: 67
diff changeset
1325 }
kono
parents: 67
diff changeset
1326
kono
parents: 67
diff changeset
1327 targtype = TREE_TYPE (targtype);
kono
parents: 67
diff changeset
1328
kono
parents: 67
diff changeset
1329 if (POINTER_TYPE_P (targtype))
kono
parents: 67
diff changeset
1330 {
kono
parents: 67
diff changeset
1331 targtype = TREE_TYPE (targtype);
kono
parents: 67
diff changeset
1332
kono
parents: 67
diff changeset
1333 /* Only issue Wattribute-alias for conversions to void* with
kono
parents: 67
diff changeset
1334 -Wextra. */
kono
parents: 67
diff changeset
1335 if (VOID_TYPE_P (targtype) && !extra_warnings)
kono
parents: 67
diff changeset
1336 return;
kono
parents: 67
diff changeset
1337
kono
parents: 67
diff changeset
1338 /* Proceed to handle incompatible ifunc resolvers below. */
kono
parents: 67
diff changeset
1339 }
kono
parents: 67
diff changeset
1340 else
kono
parents: 67
diff changeset
1341 {
kono
parents: 67
diff changeset
1342 funcptr = build_pointer_type (funcptr);
kono
parents: 67
diff changeset
1343
kono
parents: 67
diff changeset
1344 error_at (DECL_SOURCE_LOCATION (target),
kono
parents: 67
diff changeset
1345 "%<ifunc%> resolver for %qD must return %qT",
kono
parents: 67
diff changeset
1346 alias, funcptr);
kono
parents: 67
diff changeset
1347 inform (DECL_SOURCE_LOCATION (alias),
kono
parents: 67
diff changeset
1348 "resolver indirect function declared here");
kono
parents: 67
diff changeset
1349 return;
kono
parents: 67
diff changeset
1350 }
kono
parents: 67
diff changeset
1351 }
kono
parents: 67
diff changeset
1352
kono
parents: 67
diff changeset
1353 if ((!FUNC_OR_METHOD_TYPE_P (targtype)
kono
parents: 67
diff changeset
1354 || (prototype_p (altype)
kono
parents: 67
diff changeset
1355 && prototype_p (targtype)
kono
parents: 67
diff changeset
1356 && !types_compatible_p (altype, targtype))))
kono
parents: 67
diff changeset
1357 {
kono
parents: 67
diff changeset
1358 /* Warn for incompatibilities. Avoid warning for functions
kono
parents: 67
diff changeset
1359 without a prototype to make it possible to declare aliases
kono
parents: 67
diff changeset
1360 without knowing the exact type, as libstdc++ does. */
kono
parents: 67
diff changeset
1361 if (ifunc)
kono
parents: 67
diff changeset
1362 {
kono
parents: 67
diff changeset
1363 funcptr = build_pointer_type (funcptr);
kono
parents: 67
diff changeset
1364
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1365 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1366 if (warning_at (DECL_SOURCE_LOCATION (target),
kono
parents: 67
diff changeset
1367 OPT_Wattribute_alias,
kono
parents: 67
diff changeset
1368 "%<ifunc%> resolver for %qD should return %qT",
kono
parents: 67
diff changeset
1369 alias, funcptr))
kono
parents: 67
diff changeset
1370 inform (DECL_SOURCE_LOCATION (alias),
kono
parents: 67
diff changeset
1371 "resolver indirect function declared here");
kono
parents: 67
diff changeset
1372 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1373 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1374 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1375 auto_diagnostic_group d;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1376 if (warning_at (DECL_SOURCE_LOCATION (alias),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1377 OPT_Wattribute_alias,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1378 "%qD alias between functions of incompatible "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1379 "types %qT and %qT", alias, altype, targtype))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1380 inform (DECL_SOURCE_LOCATION (target),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1381 "aliased declaration here");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1382 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1383 }
111
kono
parents: 67
diff changeset
1384 }
kono
parents: 67
diff changeset
1385
kono
parents: 67
diff changeset
1386 /* Translate the ugly representation of aliases as alias pairs into nice
kono
parents: 67
diff changeset
1387 representation in callgraph. We don't handle all cases yet,
kono
parents: 67
diff changeset
1388 unfortunately. */
kono
parents: 67
diff changeset
1389
kono
parents: 67
diff changeset
1390 static void
kono
parents: 67
diff changeset
1391 handle_alias_pairs (void)
kono
parents: 67
diff changeset
1392 {
kono
parents: 67
diff changeset
1393 alias_pair *p;
kono
parents: 67
diff changeset
1394 unsigned i;
kono
parents: 67
diff changeset
1395
kono
parents: 67
diff changeset
1396 for (i = 0; alias_pairs && alias_pairs->iterate (i, &p);)
kono
parents: 67
diff changeset
1397 {
kono
parents: 67
diff changeset
1398 symtab_node *target_node = symtab_node::get_for_asmname (p->target);
kono
parents: 67
diff changeset
1399
kono
parents: 67
diff changeset
1400 /* Weakrefs with target not defined in current unit are easy to handle:
kono
parents: 67
diff changeset
1401 they behave just as external variables except we need to note the
kono
parents: 67
diff changeset
1402 alias flag to later output the weakref pseudo op into asm file. */
kono
parents: 67
diff changeset
1403 if (!target_node
kono
parents: 67
diff changeset
1404 && lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)) != NULL)
kono
parents: 67
diff changeset
1405 {
kono
parents: 67
diff changeset
1406 symtab_node *node = symtab_node::get (p->decl);
kono
parents: 67
diff changeset
1407 if (node)
kono
parents: 67
diff changeset
1408 {
kono
parents: 67
diff changeset
1409 node->alias_target = p->target;
kono
parents: 67
diff changeset
1410 node->weakref = true;
kono
parents: 67
diff changeset
1411 node->alias = true;
kono
parents: 67
diff changeset
1412 node->transparent_alias = true;
kono
parents: 67
diff changeset
1413 }
kono
parents: 67
diff changeset
1414 alias_pairs->unordered_remove (i);
kono
parents: 67
diff changeset
1415 continue;
kono
parents: 67
diff changeset
1416 }
kono
parents: 67
diff changeset
1417 else if (!target_node)
kono
parents: 67
diff changeset
1418 {
kono
parents: 67
diff changeset
1419 error ("%q+D aliased to undefined symbol %qE", p->decl, p->target);
kono
parents: 67
diff changeset
1420 symtab_node *node = symtab_node::get (p->decl);
kono
parents: 67
diff changeset
1421 if (node)
kono
parents: 67
diff changeset
1422 node->alias = false;
kono
parents: 67
diff changeset
1423 alias_pairs->unordered_remove (i);
kono
parents: 67
diff changeset
1424 continue;
kono
parents: 67
diff changeset
1425 }
kono
parents: 67
diff changeset
1426
kono
parents: 67
diff changeset
1427 if (DECL_EXTERNAL (target_node->decl)
kono
parents: 67
diff changeset
1428 /* We use local aliases for C++ thunks to force the tailcall
kono
parents: 67
diff changeset
1429 to bind locally. This is a hack - to keep it working do
kono
parents: 67
diff changeset
1430 the following (which is not strictly correct). */
kono
parents: 67
diff changeset
1431 && (TREE_CODE (target_node->decl) != FUNCTION_DECL
kono
parents: 67
diff changeset
1432 || ! DECL_VIRTUAL_P (target_node->decl))
kono
parents: 67
diff changeset
1433 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
kono
parents: 67
diff changeset
1434 {
kono
parents: 67
diff changeset
1435 error ("%q+D aliased to external symbol %qE",
kono
parents: 67
diff changeset
1436 p->decl, p->target);
kono
parents: 67
diff changeset
1437 }
kono
parents: 67
diff changeset
1438
kono
parents: 67
diff changeset
1439 if (TREE_CODE (p->decl) == FUNCTION_DECL
kono
parents: 67
diff changeset
1440 && target_node && is_a <cgraph_node *> (target_node))
kono
parents: 67
diff changeset
1441 {
kono
parents: 67
diff changeset
1442 maybe_diag_incompatible_alias (p->decl, target_node->decl);
kono
parents: 67
diff changeset
1443
kono
parents: 67
diff changeset
1444 cgraph_node *src_node = cgraph_node::get (p->decl);
kono
parents: 67
diff changeset
1445 if (src_node && src_node->definition)
kono
parents: 67
diff changeset
1446 src_node->reset ();
kono
parents: 67
diff changeset
1447 cgraph_node::create_alias (p->decl, target_node->decl);
kono
parents: 67
diff changeset
1448 alias_pairs->unordered_remove (i);
kono
parents: 67
diff changeset
1449 }
kono
parents: 67
diff changeset
1450 else if (VAR_P (p->decl)
kono
parents: 67
diff changeset
1451 && target_node && is_a <varpool_node *> (target_node))
kono
parents: 67
diff changeset
1452 {
kono
parents: 67
diff changeset
1453 varpool_node::create_alias (p->decl, target_node->decl);
kono
parents: 67
diff changeset
1454 alias_pairs->unordered_remove (i);
kono
parents: 67
diff changeset
1455 }
kono
parents: 67
diff changeset
1456 else
kono
parents: 67
diff changeset
1457 {
kono
parents: 67
diff changeset
1458 error ("%q+D alias between function and variable is not supported",
kono
parents: 67
diff changeset
1459 p->decl);
kono
parents: 67
diff changeset
1460 inform (DECL_SOURCE_LOCATION (target_node->decl),
kono
parents: 67
diff changeset
1461 "aliased declaration here");
kono
parents: 67
diff changeset
1462
kono
parents: 67
diff changeset
1463 alias_pairs->unordered_remove (i);
kono
parents: 67
diff changeset
1464 }
kono
parents: 67
diff changeset
1465 }
kono
parents: 67
diff changeset
1466 vec_free (alias_pairs);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1467 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1468
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1469
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1470 /* Figure out what functions we want to assemble. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1471
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1472 static void
111
kono
parents: 67
diff changeset
1473 mark_functions_to_output (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1474 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1475 bool check_same_comdat_groups = false;
111
kono
parents: 67
diff changeset
1476 cgraph_node *node;
kono
parents: 67
diff changeset
1477
kono
parents: 67
diff changeset
1478 if (flag_checking)
kono
parents: 67
diff changeset
1479 FOR_EACH_FUNCTION (node)
kono
parents: 67
diff changeset
1480 gcc_assert (!node->process);
kono
parents: 67
diff changeset
1481
kono
parents: 67
diff changeset
1482 FOR_EACH_FUNCTION (node)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1483 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1484 tree decl = node->decl;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1485
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1486 gcc_assert (!node->process || node->same_comdat_group);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1487 if (node->process)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1488 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1489
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1490 /* We need to output all local functions that are used and not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1491 always inlined, as well as those that are reachable from
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1492 outside the current compilation unit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1493 if (node->analyzed
111
kono
parents: 67
diff changeset
1494 && !node->thunk.thunk_p
kono
parents: 67
diff changeset
1495 && !node->alias
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1496 && !node->global.inlined_to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1497 && !TREE_ASM_WRITTEN (decl)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1498 && !DECL_EXTERNAL (decl))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1499 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1500 node->process = 1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1501 if (node->same_comdat_group)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1502 {
111
kono
parents: 67
diff changeset
1503 cgraph_node *next;
kono
parents: 67
diff changeset
1504 for (next = dyn_cast<cgraph_node *> (node->same_comdat_group);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1505 next != node;
111
kono
parents: 67
diff changeset
1506 next = dyn_cast<cgraph_node *> (next->same_comdat_group))
kono
parents: 67
diff changeset
1507 if (!next->thunk.thunk_p && !next->alias
kono
parents: 67
diff changeset
1508 && !next->comdat_local_p ())
kono
parents: 67
diff changeset
1509 next->process = 1;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1510 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1511 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1512 else if (node->same_comdat_group)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1513 {
111
kono
parents: 67
diff changeset
1514 if (flag_checking)
kono
parents: 67
diff changeset
1515 check_same_comdat_groups = true;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1516 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1517 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1518 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1519 /* We should've reclaimed all functions that are not needed. */
111
kono
parents: 67
diff changeset
1520 if (flag_checking
kono
parents: 67
diff changeset
1521 && !node->global.inlined_to
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1522 && gimple_has_body_p (decl)
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1523 /* FIXME: in ltrans unit when offline copy is outside partition but inline copies
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1524 are inside partition, we can end up not removing the body since we no longer
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1525 have analyzed node pointing to it. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1526 && !node->in_other_partition
111
kono
parents: 67
diff changeset
1527 && !node->alias
kono
parents: 67
diff changeset
1528 && !node->clones
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1529 && !DECL_EXTERNAL (decl))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1530 {
111
kono
parents: 67
diff changeset
1531 node->debug ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1532 internal_error ("failed to reclaim unneeded function");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1533 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1534 gcc_assert (node->global.inlined_to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1535 || !gimple_has_body_p (decl)
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1536 || node->in_other_partition
111
kono
parents: 67
diff changeset
1537 || node->clones
kono
parents: 67
diff changeset
1538 || DECL_ARTIFICIAL (decl)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1539 || DECL_EXTERNAL (decl));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1540
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1541 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1542
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1543 }
111
kono
parents: 67
diff changeset
1544 if (flag_checking && check_same_comdat_groups)
kono
parents: 67
diff changeset
1545 FOR_EACH_FUNCTION (node)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1546 if (node->same_comdat_group && !node->process)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1547 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1548 tree decl = node->decl;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1549 if (!node->global.inlined_to
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1550 && gimple_has_body_p (decl)
111
kono
parents: 67
diff changeset
1551 /* FIXME: in an ltrans unit when the offline copy is outside a
kono
parents: 67
diff changeset
1552 partition but inline copies are inside a partition, we can
kono
parents: 67
diff changeset
1553 end up not removing the body since we no longer have an
kono
parents: 67
diff changeset
1554 analyzed node pointing to it. */
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1555 && !node->in_other_partition
111
kono
parents: 67
diff changeset
1556 && !node->clones
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1557 && !DECL_EXTERNAL (decl))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1558 {
111
kono
parents: 67
diff changeset
1559 node->debug ();
kono
parents: 67
diff changeset
1560 internal_error ("failed to reclaim unneeded function in same "
kono
parents: 67
diff changeset
1561 "comdat group");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1562 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1563 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1564 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1565
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1566 /* DECL is FUNCTION_DECL. Initialize datastructures so DECL is a function
111
kono
parents: 67
diff changeset
1567 in lowered gimple form. IN_SSA is true if the gimple is in SSA.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1568
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1569 Set current_function_decl and cfun to newly constructed empty function body.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1570 return basic block in the function body. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1571
111
kono
parents: 67
diff changeset
1572 basic_block
kono
parents: 67
diff changeset
1573 init_lowered_empty_function (tree decl, bool in_ssa, profile_count count)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1574 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1575 basic_block bb;
111
kono
parents: 67
diff changeset
1576 edge e;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1577
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1578 current_function_decl = decl;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1579 allocate_struct_function (decl, false);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1580 gimple_register_cfg_hooks ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1581 init_empty_tree_cfg ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1582 init_tree_ssa (cfun);
111
kono
parents: 67
diff changeset
1583
kono
parents: 67
diff changeset
1584 if (in_ssa)
kono
parents: 67
diff changeset
1585 {
kono
parents: 67
diff changeset
1586 init_ssa_operands (cfun);
kono
parents: 67
diff changeset
1587 cfun->gimple_df->in_ssa_p = true;
kono
parents: 67
diff changeset
1588 cfun->curr_properties |= PROP_ssa;
kono
parents: 67
diff changeset
1589 }
kono
parents: 67
diff changeset
1590
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1591 DECL_INITIAL (decl) = make_node (BLOCK);
111
kono
parents: 67
diff changeset
1592 BLOCK_SUPERCONTEXT (DECL_INITIAL (decl)) = decl;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1593
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1594 DECL_SAVED_TREE (decl) = error_mark_node;
111
kono
parents: 67
diff changeset
1595 cfun->curr_properties |= (PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_any
kono
parents: 67
diff changeset
1596 | PROP_cfg | PROP_loops);
kono
parents: 67
diff changeset
1597
kono
parents: 67
diff changeset
1598 set_loops_for_fn (cfun, ggc_cleared_alloc<loops> ());
kono
parents: 67
diff changeset
1599 init_loops_structure (cfun, loops_for_fn (cfun), 1);
kono
parents: 67
diff changeset
1600 loops_for_fn (cfun)->state |= LOOPS_MAY_HAVE_MULTIPLE_LATCHES;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1601
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1602 /* Create BB for body of the function and connect it properly. */
111
kono
parents: 67
diff changeset
1603 ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = count;
kono
parents: 67
diff changeset
1604 EXIT_BLOCK_PTR_FOR_FN (cfun)->count = count;
kono
parents: 67
diff changeset
1605 bb = create_basic_block (NULL, ENTRY_BLOCK_PTR_FOR_FN (cfun));
kono
parents: 67
diff changeset
1606 bb->count = count;
kono
parents: 67
diff changeset
1607 e = make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), bb, EDGE_FALLTHRU);
kono
parents: 67
diff changeset
1608 e->probability = profile_probability::always ();
kono
parents: 67
diff changeset
1609 e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
kono
parents: 67
diff changeset
1610 e->probability = profile_probability::always ();
kono
parents: 67
diff changeset
1611 add_bb_to_loop (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1612
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1613 return bb;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1614 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1615
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1616 /* Adjust PTR by the constant FIXED_OFFSET, by the vtable offset indicated by
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1617 VIRTUAL_OFFSET, and by the indirect offset indicated by INDIRECT_OFFSET, if
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1618 it is non-null. THIS_ADJUSTING is nonzero for a this adjusting thunk and zero
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1619 for a result adjusting thunk. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1620
111
kono
parents: 67
diff changeset
1621 tree
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1622 thunk_adjust (gimple_stmt_iterator * bsi,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1623 tree ptr, bool this_adjusting,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1624 HOST_WIDE_INT fixed_offset, tree virtual_offset,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1625 HOST_WIDE_INT indirect_offset)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1626 {
111
kono
parents: 67
diff changeset
1627 gassign *stmt;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1628 tree ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1629
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1630 if (this_adjusting
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1631 && fixed_offset != 0)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1632 {
111
kono
parents: 67
diff changeset
1633 stmt = gimple_build_assign
kono
parents: 67
diff changeset
1634 (ptr, fold_build_pointer_plus_hwi_loc (input_location,
kono
parents: 67
diff changeset
1635 ptr,
kono
parents: 67
diff changeset
1636 fixed_offset));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1637 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1638 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1639
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1640 if (!vtable_entry_type && (virtual_offset || indirect_offset != 0))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1641 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1642 tree vfunc_type = make_node (FUNCTION_TYPE);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1643 TREE_TYPE (vfunc_type) = integer_type_node;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1644 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1645 layout_type (vfunc_type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1646
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1647 vtable_entry_type = build_pointer_type (vfunc_type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1648 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1649
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1650 /* If there's a virtual offset, look up that value in the vtable and
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1651 adjust the pointer again. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1652 if (virtual_offset)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1653 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1654 tree vtabletmp;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1655 tree vtabletmp2;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1656 tree vtabletmp3;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1657
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1658 vtabletmp =
111
kono
parents: 67
diff changeset
1659 create_tmp_reg (build_pointer_type
kono
parents: 67
diff changeset
1660 (build_pointer_type (vtable_entry_type)), "vptr");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1661
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1662 /* The vptr is always at offset zero in the object. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1663 stmt = gimple_build_assign (vtabletmp,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1664 build1 (NOP_EXPR, TREE_TYPE (vtabletmp),
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1665 ptr));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1666 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1667
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1668 /* Form the vtable address. */
111
kono
parents: 67
diff changeset
1669 vtabletmp2 = create_tmp_reg (TREE_TYPE (TREE_TYPE (vtabletmp)),
kono
parents: 67
diff changeset
1670 "vtableaddr");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1671 stmt = gimple_build_assign (vtabletmp2,
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1672 build_simple_mem_ref (vtabletmp));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1673 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1674
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1675 /* Find the entry with the vcall offset. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1676 stmt = gimple_build_assign (vtabletmp2,
111
kono
parents: 67
diff changeset
1677 fold_build_pointer_plus_loc (input_location,
kono
parents: 67
diff changeset
1678 vtabletmp2,
kono
parents: 67
diff changeset
1679 virtual_offset));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1680 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1681
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1682 /* Get the offset itself. */
111
kono
parents: 67
diff changeset
1683 vtabletmp3 = create_tmp_reg (TREE_TYPE (TREE_TYPE (vtabletmp2)),
kono
parents: 67
diff changeset
1684 "vcalloffset");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1685 stmt = gimple_build_assign (vtabletmp3,
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1686 build_simple_mem_ref (vtabletmp2));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1687 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1688
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1689 /* Adjust the `this' pointer. */
111
kono
parents: 67
diff changeset
1690 ptr = fold_build_pointer_plus_loc (input_location, ptr, vtabletmp3);
kono
parents: 67
diff changeset
1691 ptr = force_gimple_operand_gsi (bsi, ptr, true, NULL_TREE, false,
kono
parents: 67
diff changeset
1692 GSI_CONTINUE_LINKING);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1693 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1694
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1695 /* Likewise for an offset that is stored in the object that contains the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1696 vtable. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1697 if (indirect_offset != 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1698 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1699 tree offset_ptr, offset_tree;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1700
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1701 /* Get the address of the offset. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1702 offset_ptr
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1703 = create_tmp_reg (build_pointer_type
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1704 (build_pointer_type (vtable_entry_type)),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1705 "offset_ptr");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1706 stmt = gimple_build_assign (offset_ptr,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1707 build1 (NOP_EXPR, TREE_TYPE (offset_ptr),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1708 ptr));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1709 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1710
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1711 stmt = gimple_build_assign
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1712 (offset_ptr,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1713 fold_build_pointer_plus_hwi_loc (input_location, offset_ptr,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1714 indirect_offset));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1715 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1716
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1717 /* Get the offset itself. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1718 offset_tree = create_tmp_reg (TREE_TYPE (TREE_TYPE (offset_ptr)),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1719 "offset");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1720 stmt = gimple_build_assign (offset_tree,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1721 build_simple_mem_ref (offset_ptr));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1722 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1723
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1724 /* Adjust the `this' pointer. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1725 ptr = fold_build_pointer_plus_loc (input_location, ptr, offset_tree);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1726 ptr = force_gimple_operand_gsi (bsi, ptr, true, NULL_TREE, false,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1727 GSI_CONTINUE_LINKING);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1728 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1729
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1730 if (!this_adjusting
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1731 && fixed_offset != 0)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1732 /* Adjust the pointer by the constant. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1733 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1734 tree ptrtmp;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1735
111
kono
parents: 67
diff changeset
1736 if (VAR_P (ptr))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1737 ptrtmp = ptr;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1738 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1739 {
111
kono
parents: 67
diff changeset
1740 ptrtmp = create_tmp_reg (TREE_TYPE (ptr), "ptr");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1741 stmt = gimple_build_assign (ptrtmp, ptr);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1742 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1743 }
111
kono
parents: 67
diff changeset
1744 ptr = fold_build_pointer_plus_hwi_loc (input_location,
kono
parents: 67
diff changeset
1745 ptrtmp, fixed_offset);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1746 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1747
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1748 /* Emit the statement and gimplify the adjustment expression. */
111
kono
parents: 67
diff changeset
1749 ret = create_tmp_reg (TREE_TYPE (ptr), "adjusted_this");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1750 stmt = gimple_build_assign (ret, ptr);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1751 gsi_insert_after (bsi, stmt, GSI_NEW_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1752
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1753 return ret;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1754 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1755
111
kono
parents: 67
diff changeset
1756 /* Expand thunk NODE to gimple if possible.
kono
parents: 67
diff changeset
1757 When FORCE_GIMPLE_THUNK is true, gimple thunk is created and
kono
parents: 67
diff changeset
1758 no assembler is produced.
kono
parents: 67
diff changeset
1759 When OUTPUT_ASM_THUNK is true, also produce assembler for
kono
parents: 67
diff changeset
1760 thunks that are not lowered. */
kono
parents: 67
diff changeset
1761
kono
parents: 67
diff changeset
1762 bool
kono
parents: 67
diff changeset
1763 cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1764 {
111
kono
parents: 67
diff changeset
1765 bool this_adjusting = thunk.this_adjusting;
kono
parents: 67
diff changeset
1766 HOST_WIDE_INT fixed_offset = thunk.fixed_offset;
kono
parents: 67
diff changeset
1767 HOST_WIDE_INT virtual_value = thunk.virtual_value;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1768 HOST_WIDE_INT indirect_offset = thunk.indirect_offset;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1769 tree virtual_offset = NULL;
111
kono
parents: 67
diff changeset
1770 tree alias = callees->callee->decl;
kono
parents: 67
diff changeset
1771 tree thunk_fndecl = decl;
kono
parents: 67
diff changeset
1772 tree a;
kono
parents: 67
diff changeset
1773
kono
parents: 67
diff changeset
1774 /* Instrumentation thunk is the same function with
kono
parents: 67
diff changeset
1775 a different signature. Never need to expand it. */
kono
parents: 67
diff changeset
1776 if (thunk.add_pointer_bounds_args)
kono
parents: 67
diff changeset
1777 return false;
kono
parents: 67
diff changeset
1778
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1779 if (!force_gimple_thunk
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1780 && this_adjusting
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1781 && indirect_offset == 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1782 && !DECL_EXTERNAL (alias)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1783 && !DECL_STATIC_CHAIN (alias)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1784 && targetm.asm_out.can_output_mi_thunk (thunk_fndecl, fixed_offset,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1785 virtual_value, alias))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1786 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1787 const char *fnname;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1788 tree fn_block;
111
kono
parents: 67
diff changeset
1789 tree restype = TREE_TYPE (TREE_TYPE (thunk_fndecl));
kono
parents: 67
diff changeset
1790
kono
parents: 67
diff changeset
1791 if (!output_asm_thunks)
kono
parents: 67
diff changeset
1792 {
kono
parents: 67
diff changeset
1793 analyzed = true;
kono
parents: 67
diff changeset
1794 return false;
kono
parents: 67
diff changeset
1795 }
kono
parents: 67
diff changeset
1796
kono
parents: 67
diff changeset
1797 if (in_lto_p)
kono
parents: 67
diff changeset
1798 get_untransformed_body ();
kono
parents: 67
diff changeset
1799 a = DECL_ARGUMENTS (thunk_fndecl);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1800
111
kono
parents: 67
diff changeset
1801 current_function_decl = thunk_fndecl;
kono
parents: 67
diff changeset
1802
kono
parents: 67
diff changeset
1803 /* Ensure thunks are emitted in their correct sections. */
kono
parents: 67
diff changeset
1804 resolve_unique_section (thunk_fndecl, 0,
kono
parents: 67
diff changeset
1805 flag_function_sections);
kono
parents: 67
diff changeset
1806
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1807 DECL_RESULT (thunk_fndecl)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1808 = build_decl (DECL_SOURCE_LOCATION (thunk_fndecl),
111
kono
parents: 67
diff changeset
1809 RESULT_DECL, 0, restype);
kono
parents: 67
diff changeset
1810 DECL_CONTEXT (DECL_RESULT (thunk_fndecl)) = thunk_fndecl;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1811 fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1812
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1813 /* The back end expects DECL_INITIAL to contain a BLOCK, so we
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1814 create one. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1815 fn_block = make_node (BLOCK);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1816 BLOCK_VARS (fn_block) = a;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1817 DECL_INITIAL (thunk_fndecl) = fn_block;
111
kono
parents: 67
diff changeset
1818 BLOCK_SUPERCONTEXT (fn_block) = thunk_fndecl;
kono
parents: 67
diff changeset
1819 allocate_struct_function (thunk_fndecl, false);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1820 init_function_start (thunk_fndecl);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1821 cfun->is_thunk = 1;
111
kono
parents: 67
diff changeset
1822 insn_locations_init ();
kono
parents: 67
diff changeset
1823 set_curr_insn_location (DECL_SOURCE_LOCATION (thunk_fndecl));
kono
parents: 67
diff changeset
1824 prologue_location = curr_insn_location ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1825 assemble_start_function (thunk_fndecl, fnname);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1826
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1827 targetm.asm_out.output_mi_thunk (asm_out_file, thunk_fndecl,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1828 fixed_offset, virtual_value, alias);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1829
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1830 assemble_end_function (thunk_fndecl, fnname);
111
kono
parents: 67
diff changeset
1831 insn_locations_finalize ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1832 init_insn_lengths ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1833 free_after_compilation (cfun);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1834 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
111
kono
parents: 67
diff changeset
1835 thunk.thunk_p = false;
kono
parents: 67
diff changeset
1836 analyzed = false;
kono
parents: 67
diff changeset
1837 }
kono
parents: 67
diff changeset
1838 else if (stdarg_p (TREE_TYPE (thunk_fndecl)))
kono
parents: 67
diff changeset
1839 {
kono
parents: 67
diff changeset
1840 error ("generic thunk code fails for method %qD which uses %<...%>",
kono
parents: 67
diff changeset
1841 thunk_fndecl);
kono
parents: 67
diff changeset
1842 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
kono
parents: 67
diff changeset
1843 analyzed = true;
kono
parents: 67
diff changeset
1844 return false;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1845 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1846 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1847 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1848 tree restype;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1849 basic_block bb, then_bb, else_bb, return_bb;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1850 gimple_stmt_iterator bsi;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1851 int nargs = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1852 tree arg;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1853 int i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1854 tree resdecl;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1855 tree restmp = NULL;
111
kono
parents: 67
diff changeset
1856
kono
parents: 67
diff changeset
1857 gcall *call;
kono
parents: 67
diff changeset
1858 greturn *ret;
kono
parents: 67
diff changeset
1859 bool alias_is_noreturn = TREE_THIS_VOLATILE (alias);
kono
parents: 67
diff changeset
1860
kono
parents: 67
diff changeset
1861 /* We may be called from expand_thunk that releses body except for
kono
parents: 67
diff changeset
1862 DECL_ARGUMENTS. In this case force_gimple_thunk is true. */
kono
parents: 67
diff changeset
1863 if (in_lto_p && !force_gimple_thunk)
kono
parents: 67
diff changeset
1864 get_untransformed_body ();
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1865
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1866 /* We need to force DECL_IGNORED_P when the thunk is created
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1867 after early debug was run. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1868 if (force_gimple_thunk)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1869 DECL_IGNORED_P (thunk_fndecl) = 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1870
111
kono
parents: 67
diff changeset
1871 a = DECL_ARGUMENTS (thunk_fndecl);
kono
parents: 67
diff changeset
1872
kono
parents: 67
diff changeset
1873 current_function_decl = thunk_fndecl;
kono
parents: 67
diff changeset
1874
kono
parents: 67
diff changeset
1875 /* Ensure thunks are emitted in their correct sections. */
kono
parents: 67
diff changeset
1876 resolve_unique_section (thunk_fndecl, 0,
kono
parents: 67
diff changeset
1877 flag_function_sections);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1878
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1879 bitmap_obstack_initialize (NULL);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1880
111
kono
parents: 67
diff changeset
1881 if (thunk.virtual_offset_p)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1882 virtual_offset = size_int (virtual_value);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1883
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1884 /* Build the return declaration for the function. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1885 restype = TREE_TYPE (TREE_TYPE (thunk_fndecl));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1886 if (DECL_RESULT (thunk_fndecl) == NULL_TREE)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1887 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1888 resdecl = build_decl (input_location, RESULT_DECL, 0, restype);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1889 DECL_ARTIFICIAL (resdecl) = 1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1890 DECL_IGNORED_P (resdecl) = 1;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1891 DECL_CONTEXT (resdecl) = thunk_fndecl;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1892 DECL_RESULT (thunk_fndecl) = resdecl;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1893 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1894 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1895 resdecl = DECL_RESULT (thunk_fndecl);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1896
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1897 profile_count cfg_count = count;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1898 if (!cfg_count.initialized_p ())
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1899 cfg_count = profile_count::from_gcov_type (BB_FREQ_MAX).guessed_local ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1900
111
kono
parents: 67
diff changeset
1901 bb = then_bb = else_bb = return_bb
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1902 = init_lowered_empty_function (thunk_fndecl, true, cfg_count);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1903
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1904 bsi = gsi_start_bb (bb);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1905
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1906 /* Build call to the function being thunked. */
111
kono
parents: 67
diff changeset
1907 if (!VOID_TYPE_P (restype)
kono
parents: 67
diff changeset
1908 && (!alias_is_noreturn
kono
parents: 67
diff changeset
1909 || TREE_ADDRESSABLE (restype)
kono
parents: 67
diff changeset
1910 || TREE_CODE (TYPE_SIZE_UNIT (restype)) != INTEGER_CST))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1911 {
111
kono
parents: 67
diff changeset
1912 if (DECL_BY_REFERENCE (resdecl))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1913 {
111
kono
parents: 67
diff changeset
1914 restmp = gimple_fold_indirect_ref (resdecl);
kono
parents: 67
diff changeset
1915 if (!restmp)
kono
parents: 67
diff changeset
1916 restmp = build2 (MEM_REF,
kono
parents: 67
diff changeset
1917 TREE_TYPE (TREE_TYPE (DECL_RESULT (alias))),
kono
parents: 67
diff changeset
1918 resdecl,
kono
parents: 67
diff changeset
1919 build_int_cst (TREE_TYPE
kono
parents: 67
diff changeset
1920 (DECL_RESULT (alias)), 0));
kono
parents: 67
diff changeset
1921 }
kono
parents: 67
diff changeset
1922 else if (!is_gimple_reg_type (restype))
kono
parents: 67
diff changeset
1923 {
kono
parents: 67
diff changeset
1924 if (aggregate_value_p (resdecl, TREE_TYPE (thunk_fndecl)))
kono
parents: 67
diff changeset
1925 {
kono
parents: 67
diff changeset
1926 restmp = resdecl;
kono
parents: 67
diff changeset
1927
kono
parents: 67
diff changeset
1928 if (VAR_P (restmp))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1929 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1930 add_local_decl (cfun, restmp);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1931 BLOCK_VARS (DECL_INITIAL (current_function_decl))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1932 = restmp;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1933 }
111
kono
parents: 67
diff changeset
1934 }
kono
parents: 67
diff changeset
1935 else
kono
parents: 67
diff changeset
1936 restmp = create_tmp_var (restype, "retval");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1937 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1938 else
111
kono
parents: 67
diff changeset
1939 restmp = create_tmp_reg (restype, "retval");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1940 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1941
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1942 for (arg = a; arg; arg = DECL_CHAIN (arg))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1943 nargs++;
111
kono
parents: 67
diff changeset
1944 auto_vec<tree> vargs (nargs);
kono
parents: 67
diff changeset
1945 i = 0;
kono
parents: 67
diff changeset
1946 arg = a;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1947 if (this_adjusting)
111
kono
parents: 67
diff changeset
1948 {
kono
parents: 67
diff changeset
1949 vargs.quick_push (thunk_adjust (&bsi, a, 1, fixed_offset,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1950 virtual_offset, indirect_offset));
111
kono
parents: 67
diff changeset
1951 arg = DECL_CHAIN (a);
kono
parents: 67
diff changeset
1952 i = 1;
kono
parents: 67
diff changeset
1953 }
kono
parents: 67
diff changeset
1954
kono
parents: 67
diff changeset
1955 if (nargs)
kono
parents: 67
diff changeset
1956 for (; i < nargs; i++, arg = DECL_CHAIN (arg))
kono
parents: 67
diff changeset
1957 {
kono
parents: 67
diff changeset
1958 tree tmp = arg;
kono
parents: 67
diff changeset
1959 if (VECTOR_TYPE_P (TREE_TYPE (arg))
kono
parents: 67
diff changeset
1960 || TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
kono
parents: 67
diff changeset
1961 DECL_GIMPLE_REG_P (arg) = 1;
kono
parents: 67
diff changeset
1962
kono
parents: 67
diff changeset
1963 if (!is_gimple_val (arg))
kono
parents: 67
diff changeset
1964 {
kono
parents: 67
diff changeset
1965 tmp = create_tmp_reg (TYPE_MAIN_VARIANT
kono
parents: 67
diff changeset
1966 (TREE_TYPE (arg)), "arg");
kono
parents: 67
diff changeset
1967 gimple *stmt = gimple_build_assign (tmp, arg);
kono
parents: 67
diff changeset
1968 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
kono
parents: 67
diff changeset
1969 }
kono
parents: 67
diff changeset
1970 vargs.quick_push (tmp);
kono
parents: 67
diff changeset
1971 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1972 call = gimple_build_call_vec (build_fold_addr_expr_loc (0, alias), vargs);
111
kono
parents: 67
diff changeset
1973 callees->call_stmt = call;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
1974 gimple_call_set_from_thunk (call, true);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1975 if (DECL_STATIC_CHAIN (alias))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1976 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1977 tree p = DECL_STRUCT_FUNCTION (alias)->static_chain_decl;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1978 tree type = TREE_TYPE (p);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1979 tree decl = build_decl (DECL_SOURCE_LOCATION (thunk_fndecl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1980 PARM_DECL, create_tmp_var_name ("CHAIN"),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1981 type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1982 DECL_ARTIFICIAL (decl) = 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1983 DECL_IGNORED_P (decl) = 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1984 TREE_USED (decl) = 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1985 DECL_CONTEXT (decl) = thunk_fndecl;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1986 DECL_ARG_TYPE (decl) = type;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1987 TREE_READONLY (decl) = 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1988
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1989 struct function *sf = DECL_STRUCT_FUNCTION (thunk_fndecl);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1990 sf->static_chain_decl = decl;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1991
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1992 gimple_call_set_chain (call, decl);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1993 }
111
kono
parents: 67
diff changeset
1994
kono
parents: 67
diff changeset
1995 /* Return slot optimization is always possible and in fact requred to
kono
parents: 67
diff changeset
1996 return values with DECL_BY_REFERENCE. */
kono
parents: 67
diff changeset
1997 if (aggregate_value_p (resdecl, TREE_TYPE (thunk_fndecl))
kono
parents: 67
diff changeset
1998 && (!is_gimple_reg_type (TREE_TYPE (resdecl))
kono
parents: 67
diff changeset
1999 || DECL_BY_REFERENCE (resdecl)))
kono
parents: 67
diff changeset
2000 gimple_call_set_return_slot_opt (call, true);
kono
parents: 67
diff changeset
2001
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2002 if (restmp)
111
kono
parents: 67
diff changeset
2003 {
kono
parents: 67
diff changeset
2004 gimple_call_set_lhs (call, restmp);
kono
parents: 67
diff changeset
2005 gcc_assert (useless_type_conversion_p (TREE_TYPE (restmp),
kono
parents: 67
diff changeset
2006 TREE_TYPE (TREE_TYPE (alias))));
kono
parents: 67
diff changeset
2007 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2008 gsi_insert_after (&bsi, call, GSI_NEW_STMT);
111
kono
parents: 67
diff changeset
2009 if (!alias_is_noreturn)
kono
parents: 67
diff changeset
2010 {
kono
parents: 67
diff changeset
2011 if (restmp && !this_adjusting
kono
parents: 67
diff changeset
2012 && (fixed_offset || virtual_offset))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2013 {
111
kono
parents: 67
diff changeset
2014 tree true_label = NULL_TREE;
kono
parents: 67
diff changeset
2015
kono
parents: 67
diff changeset
2016 if (TREE_CODE (TREE_TYPE (restmp)) == POINTER_TYPE)
kono
parents: 67
diff changeset
2017 {
kono
parents: 67
diff changeset
2018 gimple *stmt;
kono
parents: 67
diff changeset
2019 edge e;
kono
parents: 67
diff changeset
2020 /* If the return type is a pointer, we need to
kono
parents: 67
diff changeset
2021 protect against NULL. We know there will be an
kono
parents: 67
diff changeset
2022 adjustment, because that's why we're emitting a
kono
parents: 67
diff changeset
2023 thunk. */
kono
parents: 67
diff changeset
2024 then_bb = create_basic_block (NULL, bb);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2025 then_bb->count = cfg_count - cfg_count.apply_scale (1, 16);
111
kono
parents: 67
diff changeset
2026 return_bb = create_basic_block (NULL, then_bb);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2027 return_bb->count = cfg_count;
111
kono
parents: 67
diff changeset
2028 else_bb = create_basic_block (NULL, else_bb);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2029 else_bb->count = cfg_count.apply_scale (1, 16);
111
kono
parents: 67
diff changeset
2030 add_bb_to_loop (then_bb, bb->loop_father);
kono
parents: 67
diff changeset
2031 add_bb_to_loop (return_bb, bb->loop_father);
kono
parents: 67
diff changeset
2032 add_bb_to_loop (else_bb, bb->loop_father);
kono
parents: 67
diff changeset
2033 remove_edge (single_succ_edge (bb));
kono
parents: 67
diff changeset
2034 true_label = gimple_block_label (then_bb);
kono
parents: 67
diff changeset
2035 stmt = gimple_build_cond (NE_EXPR, restmp,
kono
parents: 67
diff changeset
2036 build_zero_cst (TREE_TYPE (restmp)),
kono
parents: 67
diff changeset
2037 NULL_TREE, NULL_TREE);
kono
parents: 67
diff changeset
2038 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
kono
parents: 67
diff changeset
2039 e = make_edge (bb, then_bb, EDGE_TRUE_VALUE);
kono
parents: 67
diff changeset
2040 e->probability = profile_probability::guessed_always ()
kono
parents: 67
diff changeset
2041 .apply_scale (1, 16);
kono
parents: 67
diff changeset
2042 e = make_edge (bb, else_bb, EDGE_FALSE_VALUE);
kono
parents: 67
diff changeset
2043 e->probability = profile_probability::guessed_always ()
kono
parents: 67
diff changeset
2044 .apply_scale (1, 16);
kono
parents: 67
diff changeset
2045 make_single_succ_edge (return_bb,
kono
parents: 67
diff changeset
2046 EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
kono
parents: 67
diff changeset
2047 make_single_succ_edge (then_bb, return_bb, EDGE_FALLTHRU);
kono
parents: 67
diff changeset
2048 e = make_edge (else_bb, return_bb, EDGE_FALLTHRU);
kono
parents: 67
diff changeset
2049 e->probability = profile_probability::always ();
kono
parents: 67
diff changeset
2050 bsi = gsi_last_bb (then_bb);
kono
parents: 67
diff changeset
2051 }
kono
parents: 67
diff changeset
2052
kono
parents: 67
diff changeset
2053 restmp = thunk_adjust (&bsi, restmp, /*this_adjusting=*/0,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2054 fixed_offset, virtual_offset,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2055 indirect_offset);
111
kono
parents: 67
diff changeset
2056 if (true_label)
kono
parents: 67
diff changeset
2057 {
kono
parents: 67
diff changeset
2058 gimple *stmt;
kono
parents: 67
diff changeset
2059 bsi = gsi_last_bb (else_bb);
kono
parents: 67
diff changeset
2060 stmt = gimple_build_assign (restmp,
kono
parents: 67
diff changeset
2061 build_zero_cst (TREE_TYPE (restmp)));
kono
parents: 67
diff changeset
2062 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
kono
parents: 67
diff changeset
2063 bsi = gsi_last_bb (return_bb);
kono
parents: 67
diff changeset
2064 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2065 }
111
kono
parents: 67
diff changeset
2066 else
kono
parents: 67
diff changeset
2067 gimple_call_set_tail (call, true);
kono
parents: 67
diff changeset
2068
kono
parents: 67
diff changeset
2069 /* Build return value. */
kono
parents: 67
diff changeset
2070 if (!DECL_BY_REFERENCE (resdecl))
kono
parents: 67
diff changeset
2071 ret = gimple_build_return (restmp);
kono
parents: 67
diff changeset
2072 else
kono
parents: 67
diff changeset
2073 ret = gimple_build_return (resdecl);
kono
parents: 67
diff changeset
2074
kono
parents: 67
diff changeset
2075 gsi_insert_after (&bsi, ret, GSI_NEW_STMT);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2076 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2077 else
111
kono
parents: 67
diff changeset
2078 {
kono
parents: 67
diff changeset
2079 gimple_call_set_tail (call, true);
kono
parents: 67
diff changeset
2080 remove_edge (single_succ_edge (bb));
kono
parents: 67
diff changeset
2081 }
kono
parents: 67
diff changeset
2082
kono
parents: 67
diff changeset
2083 cfun->gimple_df->in_ssa_p = true;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2084 update_max_bb_count ();
111
kono
parents: 67
diff changeset
2085 profile_status_for_fn (cfun)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2086 = cfg_count.initialized_p () && cfg_count.ipa_p ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2087 ? PROFILE_READ : PROFILE_GUESSED;
111
kono
parents: 67
diff changeset
2088 /* FIXME: C++ FE should stop setting TREE_ASM_WRITTEN on thunks. */
kono
parents: 67
diff changeset
2089 TREE_ASM_WRITTEN (thunk_fndecl) = false;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2090 delete_unreachable_blocks ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2091 update_ssa (TODO_update_ssa);
111
kono
parents: 67
diff changeset
2092 checking_verify_flow_info ();
kono
parents: 67
diff changeset
2093 free_dominance_info (CDI_DOMINATORS);
kono
parents: 67
diff changeset
2094
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2095 /* Since we want to emit the thunk, we explicitly mark its name as
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2096 referenced. */
111
kono
parents: 67
diff changeset
2097 thunk.thunk_p = false;
kono
parents: 67
diff changeset
2098 lowered = true;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2099 bitmap_obstack_release (NULL);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2100 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2101 current_function_decl = NULL;
111
kono
parents: 67
diff changeset
2102 set_cfun (NULL);
kono
parents: 67
diff changeset
2103 return true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2104 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2105
111
kono
parents: 67
diff changeset
2106 /* Assemble thunks and aliases associated to node. */
kono
parents: 67
diff changeset
2107
kono
parents: 67
diff changeset
2108 void
kono
parents: 67
diff changeset
2109 cgraph_node::assemble_thunks_and_aliases (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2110 {
111
kono
parents: 67
diff changeset
2111 cgraph_edge *e;
kono
parents: 67
diff changeset
2112 ipa_ref *ref;
kono
parents: 67
diff changeset
2113
kono
parents: 67
diff changeset
2114 for (e = callers; e;)
kono
parents: 67
diff changeset
2115 if (e->caller->thunk.thunk_p
kono
parents: 67
diff changeset
2116 && !e->caller->global.inlined_to
kono
parents: 67
diff changeset
2117 && !e->caller->thunk.add_pointer_bounds_args)
kono
parents: 67
diff changeset
2118 {
kono
parents: 67
diff changeset
2119 cgraph_node *thunk = e->caller;
kono
parents: 67
diff changeset
2120
kono
parents: 67
diff changeset
2121 e = e->next_caller;
kono
parents: 67
diff changeset
2122 thunk->expand_thunk (true, false);
kono
parents: 67
diff changeset
2123 thunk->assemble_thunks_and_aliases ();
kono
parents: 67
diff changeset
2124 }
kono
parents: 67
diff changeset
2125 else
kono
parents: 67
diff changeset
2126 e = e->next_caller;
kono
parents: 67
diff changeset
2127
kono
parents: 67
diff changeset
2128 FOR_EACH_ALIAS (this, ref)
kono
parents: 67
diff changeset
2129 {
kono
parents: 67
diff changeset
2130 cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
kono
parents: 67
diff changeset
2131 if (!alias->transparent_alias)
kono
parents: 67
diff changeset
2132 {
kono
parents: 67
diff changeset
2133 bool saved_written = TREE_ASM_WRITTEN (decl);
kono
parents: 67
diff changeset
2134
kono
parents: 67
diff changeset
2135 /* Force assemble_alias to really output the alias this time instead
kono
parents: 67
diff changeset
2136 of buffering it in same alias pairs. */
kono
parents: 67
diff changeset
2137 TREE_ASM_WRITTEN (decl) = 1;
kono
parents: 67
diff changeset
2138 do_assemble_alias (alias->decl,
kono
parents: 67
diff changeset
2139 DECL_ASSEMBLER_NAME (decl));
kono
parents: 67
diff changeset
2140 alias->assemble_thunks_and_aliases ();
kono
parents: 67
diff changeset
2141 TREE_ASM_WRITTEN (decl) = saved_written;
kono
parents: 67
diff changeset
2142 }
kono
parents: 67
diff changeset
2143 }
kono
parents: 67
diff changeset
2144 }
kono
parents: 67
diff changeset
2145
kono
parents: 67
diff changeset
2146 /* Expand function specified by node. */
kono
parents: 67
diff changeset
2147
kono
parents: 67
diff changeset
2148 void
kono
parents: 67
diff changeset
2149 cgraph_node::expand (void)
kono
parents: 67
diff changeset
2150 {
kono
parents: 67
diff changeset
2151 location_t saved_loc;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2152
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2153 /* We ought to not compile any inline clones. */
111
kono
parents: 67
diff changeset
2154 gcc_assert (!global.inlined_to);
kono
parents: 67
diff changeset
2155
kono
parents: 67
diff changeset
2156 /* __RTL functions are compiled as soon as they are parsed, so don't
kono
parents: 67
diff changeset
2157 do it again. */
kono
parents: 67
diff changeset
2158 if (native_rtl_p ())
kono
parents: 67
diff changeset
2159 return;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2160
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2161 announce_function (decl);
111
kono
parents: 67
diff changeset
2162 process = 0;
kono
parents: 67
diff changeset
2163 gcc_assert (lowered);
kono
parents: 67
diff changeset
2164 get_untransformed_body ();
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2165
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2166 /* Generate RTL for the body of DECL. */
111
kono
parents: 67
diff changeset
2167
kono
parents: 67
diff changeset
2168 timevar_push (TV_REST_OF_COMPILATION);
kono
parents: 67
diff changeset
2169
kono
parents: 67
diff changeset
2170 gcc_assert (symtab->global_info_ready);
kono
parents: 67
diff changeset
2171
kono
parents: 67
diff changeset
2172 /* Initialize the default bitmap obstack. */
kono
parents: 67
diff changeset
2173 bitmap_obstack_initialize (NULL);
kono
parents: 67
diff changeset
2174
kono
parents: 67
diff changeset
2175 /* Initialize the RTL code for the function. */
kono
parents: 67
diff changeset
2176 saved_loc = input_location;
kono
parents: 67
diff changeset
2177 input_location = DECL_SOURCE_LOCATION (decl);
kono
parents: 67
diff changeset
2178
kono
parents: 67
diff changeset
2179 gcc_assert (DECL_STRUCT_FUNCTION (decl));
kono
parents: 67
diff changeset
2180 push_cfun (DECL_STRUCT_FUNCTION (decl));
kono
parents: 67
diff changeset
2181 init_function_start (decl);
kono
parents: 67
diff changeset
2182
kono
parents: 67
diff changeset
2183 gimple_register_cfg_hooks ();
kono
parents: 67
diff changeset
2184
kono
parents: 67
diff changeset
2185 bitmap_obstack_initialize (&reg_obstack); /* FIXME, only at RTL generation*/
kono
parents: 67
diff changeset
2186
kono
parents: 67
diff changeset
2187 execute_all_ipa_transforms ();
kono
parents: 67
diff changeset
2188
kono
parents: 67
diff changeset
2189 /* Perform all tree transforms and optimizations. */
kono
parents: 67
diff changeset
2190
kono
parents: 67
diff changeset
2191 /* Signal the start of passes. */
kono
parents: 67
diff changeset
2192 invoke_plugin_callbacks (PLUGIN_ALL_PASSES_START, NULL);
kono
parents: 67
diff changeset
2193
kono
parents: 67
diff changeset
2194 execute_pass_list (cfun, g->get_passes ()->all_passes);
kono
parents: 67
diff changeset
2195
kono
parents: 67
diff changeset
2196 /* Signal the end of passes. */
kono
parents: 67
diff changeset
2197 invoke_plugin_callbacks (PLUGIN_ALL_PASSES_END, NULL);
kono
parents: 67
diff changeset
2198
kono
parents: 67
diff changeset
2199 bitmap_obstack_release (&reg_obstack);
kono
parents: 67
diff changeset
2200
kono
parents: 67
diff changeset
2201 /* Release the default bitmap obstack. */
kono
parents: 67
diff changeset
2202 bitmap_obstack_release (NULL);
kono
parents: 67
diff changeset
2203
kono
parents: 67
diff changeset
2204 /* If requested, warn about function definitions where the function will
kono
parents: 67
diff changeset
2205 return a value (usually of some struct or union type) which itself will
kono
parents: 67
diff changeset
2206 take up a lot of stack space. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2207 if (!DECL_EXTERNAL (decl) && TREE_TYPE (decl))
111
kono
parents: 67
diff changeset
2208 {
kono
parents: 67
diff changeset
2209 tree ret_type = TREE_TYPE (TREE_TYPE (decl));
kono
parents: 67
diff changeset
2210
kono
parents: 67
diff changeset
2211 if (ret_type && TYPE_SIZE_UNIT (ret_type)
kono
parents: 67
diff changeset
2212 && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2213 && compare_tree_int (TYPE_SIZE_UNIT (ret_type),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2214 warn_larger_than_size) > 0)
111
kono
parents: 67
diff changeset
2215 {
kono
parents: 67
diff changeset
2216 unsigned int size_as_int
kono
parents: 67
diff changeset
2217 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
kono
parents: 67
diff changeset
2218
kono
parents: 67
diff changeset
2219 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2220 warning (OPT_Wlarger_than_,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2221 "size of return value of %q+D is %u bytes",
111
kono
parents: 67
diff changeset
2222 decl, size_as_int);
kono
parents: 67
diff changeset
2223 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2224 warning (OPT_Wlarger_than_,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2225 "size of return value of %q+D is larger than %wu bytes",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2226 decl, warn_larger_than_size);
111
kono
parents: 67
diff changeset
2227 }
kono
parents: 67
diff changeset
2228 }
kono
parents: 67
diff changeset
2229
kono
parents: 67
diff changeset
2230 gimple_set_body (decl, NULL);
kono
parents: 67
diff changeset
2231 if (DECL_STRUCT_FUNCTION (decl) == 0
kono
parents: 67
diff changeset
2232 && !cgraph_node::get (decl)->origin)
kono
parents: 67
diff changeset
2233 {
kono
parents: 67
diff changeset
2234 /* Stop pointing to the local nodes about to be freed.
kono
parents: 67
diff changeset
2235 But DECL_INITIAL must remain nonzero so we know this
kono
parents: 67
diff changeset
2236 was an actual function definition.
kono
parents: 67
diff changeset
2237 For a nested function, this is done in c_pop_function_context.
kono
parents: 67
diff changeset
2238 If rest_of_compilation set this to 0, leave it 0. */
kono
parents: 67
diff changeset
2239 if (DECL_INITIAL (decl) != 0)
kono
parents: 67
diff changeset
2240 DECL_INITIAL (decl) = error_mark_node;
kono
parents: 67
diff changeset
2241 }
kono
parents: 67
diff changeset
2242
kono
parents: 67
diff changeset
2243 input_location = saved_loc;
kono
parents: 67
diff changeset
2244
kono
parents: 67
diff changeset
2245 ggc_collect ();
kono
parents: 67
diff changeset
2246 timevar_pop (TV_REST_OF_COMPILATION);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2247
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2248 /* Make sure that BE didn't give up on compiling. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2249 gcc_assert (TREE_ASM_WRITTEN (decl));
111
kono
parents: 67
diff changeset
2250 if (cfun)
kono
parents: 67
diff changeset
2251 pop_cfun ();
kono
parents: 67
diff changeset
2252
kono
parents: 67
diff changeset
2253 /* It would make a lot more sense to output thunks before function body to get more
kono
parents: 67
diff changeset
2254 forward and lest backwarding jumps. This however would need solving problem
kono
parents: 67
diff changeset
2255 with comdats. See PR48668. Also aliases must come after function itself to
kono
parents: 67
diff changeset
2256 make one pass assemblers, like one on AIX, happy. See PR 50689.
kono
parents: 67
diff changeset
2257 FIXME: Perhaps thunks should be move before function IFF they are not in comdat
kono
parents: 67
diff changeset
2258 groups. */
kono
parents: 67
diff changeset
2259 assemble_thunks_and_aliases ();
kono
parents: 67
diff changeset
2260 release_body ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2261 /* Eliminate all call edges. This is important so the GIMPLE_CALL no longer
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2262 points to the dead function body. */
111
kono
parents: 67
diff changeset
2263 remove_callees ();
kono
parents: 67
diff changeset
2264 remove_all_references ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2265 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2266
111
kono
parents: 67
diff changeset
2267 /* Node comparer that is responsible for the order that corresponds
kono
parents: 67
diff changeset
2268 to time when a function was launched for the first time. */
kono
parents: 67
diff changeset
2269
kono
parents: 67
diff changeset
2270 static int
kono
parents: 67
diff changeset
2271 node_cmp (const void *pa, const void *pb)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2272 {
111
kono
parents: 67
diff changeset
2273 const cgraph_node *a = *(const cgraph_node * const *) pa;
kono
parents: 67
diff changeset
2274 const cgraph_node *b = *(const cgraph_node * const *) pb;
kono
parents: 67
diff changeset
2275
kono
parents: 67
diff changeset
2276 /* Functions with time profile must be before these without profile. */
kono
parents: 67
diff changeset
2277 if (!a->tp_first_run || !b->tp_first_run)
kono
parents: 67
diff changeset
2278 return a->tp_first_run - b->tp_first_run;
kono
parents: 67
diff changeset
2279
kono
parents: 67
diff changeset
2280 return a->tp_first_run != b->tp_first_run
kono
parents: 67
diff changeset
2281 ? b->tp_first_run - a->tp_first_run
kono
parents: 67
diff changeset
2282 : b->order - a->order;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2283 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2284
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2285 /* Expand all functions that must be output.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2286
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2287 Attempt to topologically sort the nodes so function is output when
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2288 all called functions are already assembled to allow data to be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2289 propagated across the callgraph. Use a stack to get smaller distance
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2290 between a function and its callees (later we may choose to use a more
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2291 sophisticated algorithm for function reordering; we will likely want
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2292 to use subsections to make the output functions appear in top-down
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2293 order). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2294
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2295 static void
111
kono
parents: 67
diff changeset
2296 expand_all_functions (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2297 {
111
kono
parents: 67
diff changeset
2298 cgraph_node *node;
kono
parents: 67
diff changeset
2299 cgraph_node **order = XCNEWVEC (cgraph_node *,
kono
parents: 67
diff changeset
2300 symtab->cgraph_count);
kono
parents: 67
diff changeset
2301 unsigned int expanded_func_count = 0, profiled_func_count = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2302 int order_pos, new_order_pos = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2303 int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2304
111
kono
parents: 67
diff changeset
2305 order_pos = ipa_reverse_postorder (order);
kono
parents: 67
diff changeset
2306 gcc_assert (order_pos == symtab->cgraph_count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2307
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2308 /* Garbage collector may remove inline clones we eliminate during
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2309 optimization. So we must be sure to not reference them. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2310 for (i = 0; i < order_pos; i++)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2311 if (order[i]->process)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2312 order[new_order_pos++] = order[i];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2313
111
kono
parents: 67
diff changeset
2314 if (flag_profile_reorder_functions)
kono
parents: 67
diff changeset
2315 qsort (order, new_order_pos, sizeof (cgraph_node *), node_cmp);
kono
parents: 67
diff changeset
2316
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2317 for (i = new_order_pos - 1; i >= 0; i--)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2318 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2319 node = order[i];
111
kono
parents: 67
diff changeset
2320
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2321 if (node->process)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2322 {
111
kono
parents: 67
diff changeset
2323 expanded_func_count++;
kono
parents: 67
diff changeset
2324 if(node->tp_first_run)
kono
parents: 67
diff changeset
2325 profiled_func_count++;
kono
parents: 67
diff changeset
2326
kono
parents: 67
diff changeset
2327 if (symtab->dump_file)
kono
parents: 67
diff changeset
2328 fprintf (symtab->dump_file,
kono
parents: 67
diff changeset
2329 "Time profile order in expand_all_functions:%s:%d\n",
kono
parents: 67
diff changeset
2330 node->asm_name (), node->tp_first_run);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2331 node->process = 0;
111
kono
parents: 67
diff changeset
2332 node->expand ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2333 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2334 }
111
kono
parents: 67
diff changeset
2335
kono
parents: 67
diff changeset
2336 if (dump_file)
kono
parents: 67
diff changeset
2337 fprintf (dump_file, "Expanded functions with time profile (%s):%u/%u\n",
kono
parents: 67
diff changeset
2338 main_input_filename, profiled_func_count, expanded_func_count);
kono
parents: 67
diff changeset
2339
kono
parents: 67
diff changeset
2340 if (symtab->dump_file && flag_profile_reorder_functions)
kono
parents: 67
diff changeset
2341 fprintf (symtab->dump_file, "Expanded functions with time profile:%u/%u\n",
kono
parents: 67
diff changeset
2342 profiled_func_count, expanded_func_count);
kono
parents: 67
diff changeset
2343
kono
parents: 67
diff changeset
2344 symtab->process_new_functions ();
kono
parents: 67
diff changeset
2345 free_gimplify_stack ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2346
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2347 free (order);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2348 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2349
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2350 /* This is used to sort the node types by the cgraph order number. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2351
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2352 enum cgraph_order_sort_kind
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2353 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2354 ORDER_UNDEFINED = 0,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2355 ORDER_FUNCTION,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2356 ORDER_VAR,
111
kono
parents: 67
diff changeset
2357 ORDER_VAR_UNDEF,
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2358 ORDER_ASM
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2359 };
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2360
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2361 struct cgraph_order_sort
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2362 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2363 enum cgraph_order_sort_kind kind;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2364 union
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2365 {
111
kono
parents: 67
diff changeset
2366 cgraph_node *f;
kono
parents: 67
diff changeset
2367 varpool_node *v;
kono
parents: 67
diff changeset
2368 asm_node *a;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2369 } u;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2370 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2371
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2372 /* Output all functions, variables, and asm statements in the order
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2373 according to their order fields, which is the order in which they
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2374 appeared in the file. This implements -fno-toplevel-reorder. In
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2375 this mode we may output functions and variables which don't really
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2376 need to be output. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2377
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2378 static void
111
kono
parents: 67
diff changeset
2379 output_in_order (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2380 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2381 int max;
111
kono
parents: 67
diff changeset
2382 cgraph_order_sort *nodes;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2383 int i;
111
kono
parents: 67
diff changeset
2384 cgraph_node *pf;
kono
parents: 67
diff changeset
2385 varpool_node *pv;
kono
parents: 67
diff changeset
2386 asm_node *pa;
kono
parents: 67
diff changeset
2387 max = symtab->order;
kono
parents: 67
diff changeset
2388 nodes = XCNEWVEC (cgraph_order_sort, max);
kono
parents: 67
diff changeset
2389
kono
parents: 67
diff changeset
2390 FOR_EACH_DEFINED_FUNCTION (pf)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2391 {
111
kono
parents: 67
diff changeset
2392 if (pf->process && !pf->thunk.thunk_p && !pf->alias)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2393 {
111
kono
parents: 67
diff changeset
2394 if (!pf->no_reorder)
kono
parents: 67
diff changeset
2395 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2396 i = pf->order;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2397 gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2398 nodes[i].kind = ORDER_FUNCTION;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2399 nodes[i].u.f = pf;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2400 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2401 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2402
111
kono
parents: 67
diff changeset
2403 /* There is a similar loop in symbol_table::output_variables.
kono
parents: 67
diff changeset
2404 Please keep them in sync. */
kono
parents: 67
diff changeset
2405 FOR_EACH_VARIABLE (pv)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2406 {
111
kono
parents: 67
diff changeset
2407 if (!pv->no_reorder)
kono
parents: 67
diff changeset
2408 continue;
kono
parents: 67
diff changeset
2409 if (DECL_HARD_REGISTER (pv->decl)
kono
parents: 67
diff changeset
2410 || DECL_HAS_VALUE_EXPR_P (pv->decl))
kono
parents: 67
diff changeset
2411 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2412 i = pv->order;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2413 gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
111
kono
parents: 67
diff changeset
2414 nodes[i].kind = pv->definition ? ORDER_VAR : ORDER_VAR_UNDEF;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2415 nodes[i].u.v = pv;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2416 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2417
111
kono
parents: 67
diff changeset
2418 for (pa = symtab->first_asm_symbol (); pa; pa = pa->next)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2419 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2420 i = pa->order;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2421 gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2422 nodes[i].kind = ORDER_ASM;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2423 nodes[i].u.a = pa;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2424 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2425
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2426 /* In toplevel reorder mode we output all statics; mark them as needed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2427
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2428 for (i = 0; i < max; ++i)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2429 if (nodes[i].kind == ORDER_VAR)
111
kono
parents: 67
diff changeset
2430 nodes[i].u.v->finalize_named_section_flags ();
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2431
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2432 for (i = 0; i < max; ++i)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2433 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2434 switch (nodes[i].kind)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2435 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2436 case ORDER_FUNCTION:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2437 nodes[i].u.f->process = 0;
111
kono
parents: 67
diff changeset
2438 nodes[i].u.f->expand ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2439 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2440
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2441 case ORDER_VAR:
111
kono
parents: 67
diff changeset
2442 nodes[i].u.v->assemble_decl ();
kono
parents: 67
diff changeset
2443 break;
kono
parents: 67
diff changeset
2444
kono
parents: 67
diff changeset
2445 case ORDER_VAR_UNDEF:
kono
parents: 67
diff changeset
2446 assemble_undefined_decl (nodes[i].u.v->decl);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2447 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2448
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2449 case ORDER_ASM:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2450 assemble_asm (nodes[i].u.a->asm_str);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2451 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2452
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2453 case ORDER_UNDEFINED:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2454 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2455
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2456 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2457 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2458 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2459 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2460
111
kono
parents: 67
diff changeset
2461 symtab->clear_asm_symbols ();
kono
parents: 67
diff changeset
2462
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2463 free (nodes);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2464 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2465
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2466 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2467 ipa_passes (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2468 {
111
kono
parents: 67
diff changeset
2469 gcc::pass_manager *passes = g->get_passes ();
kono
parents: 67
diff changeset
2470
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2471 set_cfun (NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2472 current_function_decl = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2473 gimple_register_cfg_hooks ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2474 bitmap_obstack_initialize (NULL);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2475
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2476 invoke_plugin_callbacks (PLUGIN_ALL_IPA_PASSES_START, NULL);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2477
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2478 if (!in_lto_p)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2479 {
111
kono
parents: 67
diff changeset
2480 execute_ipa_pass_list (passes->all_small_ipa_passes);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2481 if (seen_error ())
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2482 return;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2483 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2484
111
kono
parents: 67
diff changeset
2485 /* This extra symtab_remove_unreachable_nodes pass tends to catch some
kono
parents: 67
diff changeset
2486 devirtualization and other changes where removal iterate. */
kono
parents: 67
diff changeset
2487 symtab->remove_unreachable_nodes (symtab->dump_file);
kono
parents: 67
diff changeset
2488
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2489 /* If pass_all_early_optimizations was not scheduled, the state of
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2490 the cgraph will not be properly updated. Update it now. */
111
kono
parents: 67
diff changeset
2491 if (symtab->state < IPA_SSA)
kono
parents: 67
diff changeset
2492 symtab->state = IPA_SSA;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2493
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2494 if (!in_lto_p)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2495 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2496 /* Generate coverage variables and constructors. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2497 coverage_finish ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2498
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2499 /* Process new functions added. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2500 set_cfun (NULL);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2501 current_function_decl = NULL;
111
kono
parents: 67
diff changeset
2502 symtab->process_new_functions ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2503
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2504 execute_ipa_summary_passes
111
kono
parents: 67
diff changeset
2505 ((ipa_opt_pass_d *) passes->all_regular_ipa_passes);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2506 }
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2507
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2508 /* Some targets need to handle LTO assembler output specially. */
111
kono
parents: 67
diff changeset
2509 if (flag_generate_lto || flag_generate_offload)
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2510 targetm.asm_out.lto_start ();
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2511
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2512 if (!in_lto_p
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2513 || flag_incremental_link == INCREMENTAL_LINK_LTO)
111
kono
parents: 67
diff changeset
2514 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2515 if (!quiet_flag)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2516 fprintf (stderr, "Streaming LTO\n");
111
kono
parents: 67
diff changeset
2517 if (g->have_offload)
kono
parents: 67
diff changeset
2518 {
kono
parents: 67
diff changeset
2519 section_name_prefix = OFFLOAD_SECTION_NAME_PREFIX;
kono
parents: 67
diff changeset
2520 lto_stream_offload_p = true;
kono
parents: 67
diff changeset
2521 ipa_write_summaries ();
kono
parents: 67
diff changeset
2522 lto_stream_offload_p = false;
kono
parents: 67
diff changeset
2523 }
kono
parents: 67
diff changeset
2524 if (flag_lto)
kono
parents: 67
diff changeset
2525 {
kono
parents: 67
diff changeset
2526 section_name_prefix = LTO_SECTION_NAME_PREFIX;
kono
parents: 67
diff changeset
2527 lto_stream_offload_p = false;
kono
parents: 67
diff changeset
2528 ipa_write_summaries ();
kono
parents: 67
diff changeset
2529 }
kono
parents: 67
diff changeset
2530 }
kono
parents: 67
diff changeset
2531
kono
parents: 67
diff changeset
2532 if (flag_generate_lto || flag_generate_offload)
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2533 targetm.asm_out.lto_end ();
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2534
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2535 if (!flag_ltrans
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2536 && ((in_lto_p && flag_incremental_link != INCREMENTAL_LINK_LTO)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2537 || !flag_lto || flag_fat_lto_objects))
111
kono
parents: 67
diff changeset
2538 execute_ipa_pass_list (passes->all_regular_ipa_passes);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2539 invoke_plugin_callbacks (PLUGIN_ALL_IPA_PASSES_END, NULL);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2540
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2541 bitmap_obstack_release (NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2542 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2543
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2544
111
kono
parents: 67
diff changeset
2545 /* Return string alias is alias of. */
kono
parents: 67
diff changeset
2546
kono
parents: 67
diff changeset
2547 static tree
kono
parents: 67
diff changeset
2548 get_alias_symbol (tree decl)
kono
parents: 67
diff changeset
2549 {
kono
parents: 67
diff changeset
2550 tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
kono
parents: 67
diff changeset
2551 return get_identifier (TREE_STRING_POINTER
kono
parents: 67
diff changeset
2552 (TREE_VALUE (TREE_VALUE (alias))));
kono
parents: 67
diff changeset
2553 }
kono
parents: 67
diff changeset
2554
kono
parents: 67
diff changeset
2555
kono
parents: 67
diff changeset
2556 /* Weakrefs may be associated to external decls and thus not output
kono
parents: 67
diff changeset
2557 at expansion time. Emit all necessary aliases. */
kono
parents: 67
diff changeset
2558
kono
parents: 67
diff changeset
2559 void
kono
parents: 67
diff changeset
2560 symbol_table::output_weakrefs (void)
kono
parents: 67
diff changeset
2561 {
kono
parents: 67
diff changeset
2562 symtab_node *node;
kono
parents: 67
diff changeset
2563 FOR_EACH_SYMBOL (node)
kono
parents: 67
diff changeset
2564 if (node->alias
kono
parents: 67
diff changeset
2565 && !TREE_ASM_WRITTEN (node->decl)
kono
parents: 67
diff changeset
2566 && node->weakref)
kono
parents: 67
diff changeset
2567 {
kono
parents: 67
diff changeset
2568 tree target;
kono
parents: 67
diff changeset
2569
kono
parents: 67
diff changeset
2570 /* Weakrefs are special by not requiring target definition in current
kono
parents: 67
diff changeset
2571 compilation unit. It is thus bit hard to work out what we want to
kono
parents: 67
diff changeset
2572 alias.
kono
parents: 67
diff changeset
2573 When alias target is defined, we need to fetch it from symtab reference,
kono
parents: 67
diff changeset
2574 otherwise it is pointed to by alias_target. */
kono
parents: 67
diff changeset
2575 if (node->alias_target)
kono
parents: 67
diff changeset
2576 target = (DECL_P (node->alias_target)
kono
parents: 67
diff changeset
2577 ? DECL_ASSEMBLER_NAME (node->alias_target)
kono
parents: 67
diff changeset
2578 : node->alias_target);
kono
parents: 67
diff changeset
2579 else if (node->analyzed)
kono
parents: 67
diff changeset
2580 target = DECL_ASSEMBLER_NAME (node->get_alias_target ()->decl);
kono
parents: 67
diff changeset
2581 else
kono
parents: 67
diff changeset
2582 {
kono
parents: 67
diff changeset
2583 gcc_unreachable ();
kono
parents: 67
diff changeset
2584 target = get_alias_symbol (node->decl);
kono
parents: 67
diff changeset
2585 }
kono
parents: 67
diff changeset
2586 do_assemble_alias (node->decl, target);
kono
parents: 67
diff changeset
2587 }
kono
parents: 67
diff changeset
2588 }
kono
parents: 67
diff changeset
2589
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2590 /* Perform simple optimizations based on callgraph. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2591
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2592 void
111
kono
parents: 67
diff changeset
2593 symbol_table::compile (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2594 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2595 if (seen_error ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2596 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2597
111
kono
parents: 67
diff changeset
2598 symtab_node::checking_verify_symtab_nodes ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2599
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2600 timevar_push (TV_CGRAPHOPT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2601 if (pre_ipa_mem_report)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2602 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2603 fprintf (stderr, "Memory consumption before IPA\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2604 dump_memory_report (false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2605 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2606 if (!quiet_flag)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2607 fprintf (stderr, "Performing interprocedural optimizations\n");
111
kono
parents: 67
diff changeset
2608 state = IPA;
kono
parents: 67
diff changeset
2609
kono
parents: 67
diff changeset
2610 /* If LTO is enabled, initialize the streamer hooks needed by GIMPLE. */
kono
parents: 67
diff changeset
2611 if (flag_generate_lto || flag_generate_offload)
kono
parents: 67
diff changeset
2612 lto_streamer_hooks_init ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2613
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2614 /* Don't run the IPA passes if there was any error or sorry messages. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2615 if (!seen_error ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2616 ipa_passes ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2617
111
kono
parents: 67
diff changeset
2618 /* Do nothing else if any IPA pass found errors or if we are just streaming LTO. */
kono
parents: 67
diff changeset
2619 if (seen_error ()
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2620 || ((!in_lto_p || flag_incremental_link == INCREMENTAL_LINK_LTO)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2621 && flag_lto && !flag_fat_lto_objects))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2622 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2623 timevar_pop (TV_CGRAPHOPT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2624 return;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2625 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2626
111
kono
parents: 67
diff changeset
2627 global_info_ready = true;
kono
parents: 67
diff changeset
2628 if (dump_file)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2629 {
111
kono
parents: 67
diff changeset
2630 fprintf (dump_file, "Optimized ");
kono
parents: 67
diff changeset
2631 symtab->dump (dump_file);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2632 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2633 if (post_ipa_mem_report)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2634 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2635 fprintf (stderr, "Memory consumption after IPA\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2636 dump_memory_report (false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2637 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2638 timevar_pop (TV_CGRAPHOPT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2639
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2640 /* Output everything. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2641 switch_to_section (text_section);
36
855418dad1a3 gcc-4.4-20091020
e075725
parents: 0
diff changeset
2642 (*debug_hooks->assembly_start) ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2643 if (!quiet_flag)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2644 fprintf (stderr, "Assembling functions:\n");
111
kono
parents: 67
diff changeset
2645 symtab_node::checking_verify_symtab_nodes ();
kono
parents: 67
diff changeset
2646
kono
parents: 67
diff changeset
2647 bitmap_obstack_initialize (NULL);
kono
parents: 67
diff changeset
2648 execute_ipa_pass_list (g->get_passes ()->all_late_ipa_passes);
kono
parents: 67
diff changeset
2649 bitmap_obstack_release (NULL);
kono
parents: 67
diff changeset
2650 mark_functions_to_output ();
kono
parents: 67
diff changeset
2651
kono
parents: 67
diff changeset
2652 /* When weakref support is missing, we automatically translate all
kono
parents: 67
diff changeset
2653 references to NODE to references to its ultimate alias target.
kono
parents: 67
diff changeset
2654 The renaming mechanizm uses flag IDENTIFIER_TRANSPARENT_ALIAS and
kono
parents: 67
diff changeset
2655 TREE_CHAIN.
kono
parents: 67
diff changeset
2656
kono
parents: 67
diff changeset
2657 Set up this mapping before we output any assembler but once we are sure
kono
parents: 67
diff changeset
2658 that all symbol renaming is done.
kono
parents: 67
diff changeset
2659
kono
parents: 67
diff changeset
2660 FIXME: All this uglyness can go away if we just do renaming at gimple
kono
parents: 67
diff changeset
2661 level by physically rewritting the IL. At the moment we can only redirect
kono
parents: 67
diff changeset
2662 calls, so we need infrastructure for renaming references as well. */
kono
parents: 67
diff changeset
2663 #ifndef ASM_OUTPUT_WEAKREF
kono
parents: 67
diff changeset
2664 symtab_node *node;
kono
parents: 67
diff changeset
2665
kono
parents: 67
diff changeset
2666 FOR_EACH_SYMBOL (node)
kono
parents: 67
diff changeset
2667 if (node->alias
kono
parents: 67
diff changeset
2668 && lookup_attribute ("weakref", DECL_ATTRIBUTES (node->decl)))
kono
parents: 67
diff changeset
2669 {
kono
parents: 67
diff changeset
2670 IDENTIFIER_TRANSPARENT_ALIAS
kono
parents: 67
diff changeset
2671 (DECL_ASSEMBLER_NAME (node->decl)) = 1;
kono
parents: 67
diff changeset
2672 TREE_CHAIN (DECL_ASSEMBLER_NAME (node->decl))
kono
parents: 67
diff changeset
2673 = (node->alias_target ? node->alias_target
kono
parents: 67
diff changeset
2674 : DECL_ASSEMBLER_NAME (node->get_alias_target ()->decl));
kono
parents: 67
diff changeset
2675 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2676 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2677
111
kono
parents: 67
diff changeset
2678 state = EXPANSION;
kono
parents: 67
diff changeset
2679
kono
parents: 67
diff changeset
2680 /* Output first asm statements and anything ordered. The process
kono
parents: 67
diff changeset
2681 flag is cleared for these nodes, so we skip them later. */
kono
parents: 67
diff changeset
2682 output_in_order ();
kono
parents: 67
diff changeset
2683 expand_all_functions ();
kono
parents: 67
diff changeset
2684 output_variables ();
kono
parents: 67
diff changeset
2685
kono
parents: 67
diff changeset
2686 process_new_functions ();
kono
parents: 67
diff changeset
2687 state = FINISHED;
kono
parents: 67
diff changeset
2688 output_weakrefs ();
kono
parents: 67
diff changeset
2689
kono
parents: 67
diff changeset
2690 if (dump_file)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2691 {
111
kono
parents: 67
diff changeset
2692 fprintf (dump_file, "\nFinal ");
kono
parents: 67
diff changeset
2693 symtab->dump (dump_file);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2694 }
111
kono
parents: 67
diff changeset
2695 if (!flag_checking)
kono
parents: 67
diff changeset
2696 return;
kono
parents: 67
diff changeset
2697 symtab_node::verify_symtab_nodes ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2698 /* Double check that all inline clones are gone and that all
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2699 function bodies have been released from memory. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2700 if (!seen_error ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2701 {
111
kono
parents: 67
diff changeset
2702 cgraph_node *node;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2703 bool error_found = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2704
111
kono
parents: 67
diff changeset
2705 FOR_EACH_DEFINED_FUNCTION (node)
kono
parents: 67
diff changeset
2706 if (node->global.inlined_to
kono
parents: 67
diff changeset
2707 || gimple_has_body_p (node->decl))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2708 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2709 error_found = true;
111
kono
parents: 67
diff changeset
2710 node->debug ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2711 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2712 if (error_found)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2713 internal_error ("nodes with unreleased memory found");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2714 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2715 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2716
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2717 /* Earlydebug dump file, flags, and number. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2718
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2719 static int debuginfo_early_dump_nr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2720 static FILE *debuginfo_early_dump_file;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2721 static dump_flags_t debuginfo_early_dump_flags;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2722
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2723 /* Debug dump file, flags, and number. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2724
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2725 static int debuginfo_dump_nr;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2726 static FILE *debuginfo_dump_file;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2727 static dump_flags_t debuginfo_dump_flags;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2728
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2729 /* Register the debug and earlydebug dump files. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2730
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2731 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2732 debuginfo_early_init (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2733 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2734 gcc::dump_manager *dumps = g->get_dumps ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2735 debuginfo_early_dump_nr = dumps->dump_register (".earlydebug", "earlydebug",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2736 "earlydebug", DK_tree,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2737 OPTGROUP_NONE,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2738 false);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2739 debuginfo_dump_nr = dumps->dump_register (".debug", "debug",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2740 "debug", DK_tree,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2741 OPTGROUP_NONE,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2742 false);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2743 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2744
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2745 /* Initialize the debug and earlydebug dump files. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2746
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2747 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2748 debuginfo_init (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2749 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2750 gcc::dump_manager *dumps = g->get_dumps ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2751 debuginfo_dump_file = dump_begin (debuginfo_dump_nr, NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2752 debuginfo_dump_flags = dumps->get_dump_file_info (debuginfo_dump_nr)->pflags;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2753 debuginfo_early_dump_file = dump_begin (debuginfo_early_dump_nr, NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2754 debuginfo_early_dump_flags
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2755 = dumps->get_dump_file_info (debuginfo_early_dump_nr)->pflags;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2756 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2757
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2758 /* Finalize the debug and earlydebug dump files. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2759
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2760 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2761 debuginfo_fini (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2762 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2763 if (debuginfo_dump_file)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2764 dump_end (debuginfo_dump_nr, debuginfo_dump_file);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2765 if (debuginfo_early_dump_file)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2766 dump_end (debuginfo_early_dump_nr, debuginfo_early_dump_file);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2767 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2768
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2769 /* Set dump_file to the debug dump file. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2770
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2771 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2772 debuginfo_start (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2773 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2774 set_dump_file (debuginfo_dump_file);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2775 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2776
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2777 /* Undo setting dump_file to the debug dump file. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2778
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2779 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2780 debuginfo_stop (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2781 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2782 set_dump_file (NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2783 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2784
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2785 /* Set dump_file to the earlydebug dump file. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2786
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2787 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2788 debuginfo_early_start (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2789 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2790 set_dump_file (debuginfo_early_dump_file);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2791 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2792
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2793 /* Undo setting dump_file to the earlydebug dump file. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2794
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2795 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2796 debuginfo_early_stop (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2797 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2798 set_dump_file (NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2799 }
111
kono
parents: 67
diff changeset
2800
kono
parents: 67
diff changeset
2801 /* Analyze the whole compilation unit once it is parsed completely. */
kono
parents: 67
diff changeset
2802
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2803 void
111
kono
parents: 67
diff changeset
2804 symbol_table::finalize_compilation_unit (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2805 {
111
kono
parents: 67
diff changeset
2806 timevar_push (TV_CGRAPH);
kono
parents: 67
diff changeset
2807
kono
parents: 67
diff changeset
2808 /* If we're here there's no current function anymore. Some frontends
kono
parents: 67
diff changeset
2809 are lazy in clearing these. */
kono
parents: 67
diff changeset
2810 current_function_decl = NULL;
kono
parents: 67
diff changeset
2811 set_cfun (NULL);
kono
parents: 67
diff changeset
2812
kono
parents: 67
diff changeset
2813 /* Do not skip analyzing the functions if there were errors, we
kono
parents: 67
diff changeset
2814 miss diagnostics for following functions otherwise. */
kono
parents: 67
diff changeset
2815
kono
parents: 67
diff changeset
2816 /* Emit size functions we didn't inline. */
kono
parents: 67
diff changeset
2817 finalize_size_functions ();
kono
parents: 67
diff changeset
2818
kono
parents: 67
diff changeset
2819 /* Mark alias targets necessary and emit diagnostics. */
kono
parents: 67
diff changeset
2820 handle_alias_pairs ();
kono
parents: 67
diff changeset
2821
kono
parents: 67
diff changeset
2822 if (!quiet_flag)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2823 {
111
kono
parents: 67
diff changeset
2824 fprintf (stderr, "\nAnalyzing compilation unit\n");
kono
parents: 67
diff changeset
2825 fflush (stderr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2826 }
111
kono
parents: 67
diff changeset
2827
kono
parents: 67
diff changeset
2828 if (flag_dump_passes)
kono
parents: 67
diff changeset
2829 dump_passes ();
kono
parents: 67
diff changeset
2830
kono
parents: 67
diff changeset
2831 /* Gimplify and lower all functions, compute reachability and
kono
parents: 67
diff changeset
2832 remove unreachable nodes. */
kono
parents: 67
diff changeset
2833 analyze_functions (/*first_time=*/true);
kono
parents: 67
diff changeset
2834
kono
parents: 67
diff changeset
2835 /* Mark alias targets necessary and emit diagnostics. */
kono
parents: 67
diff changeset
2836 handle_alias_pairs ();
kono
parents: 67
diff changeset
2837
kono
parents: 67
diff changeset
2838 /* Gimplify and lower thunks. */
kono
parents: 67
diff changeset
2839 analyze_functions (/*first_time=*/false);
kono
parents: 67
diff changeset
2840
kono
parents: 67
diff changeset
2841 /* Offloading requires LTO infrastructure. */
kono
parents: 67
diff changeset
2842 if (!in_lto_p && g->have_offload)
kono
parents: 67
diff changeset
2843 flag_generate_offload = 1;
kono
parents: 67
diff changeset
2844
kono
parents: 67
diff changeset
2845 if (!seen_error ())
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2846 {
111
kono
parents: 67
diff changeset
2847 /* Emit early debug for reachable functions, and by consequence,
kono
parents: 67
diff changeset
2848 locally scoped symbols. */
kono
parents: 67
diff changeset
2849 struct cgraph_node *cnode;
kono
parents: 67
diff changeset
2850 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
kono
parents: 67
diff changeset
2851 (*debug_hooks->early_global_decl) (cnode->decl);
kono
parents: 67
diff changeset
2852
kono
parents: 67
diff changeset
2853 /* Clean up anything that needs cleaning up after initial debug
kono
parents: 67
diff changeset
2854 generation. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2855 debuginfo_early_start ();
111
kono
parents: 67
diff changeset
2856 (*debug_hooks->early_finish) (main_input_filename);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2857 debuginfo_early_stop ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2858 }
111
kono
parents: 67
diff changeset
2859
kono
parents: 67
diff changeset
2860 /* Finally drive the pass manager. */
kono
parents: 67
diff changeset
2861 compile ();
kono
parents: 67
diff changeset
2862
kono
parents: 67
diff changeset
2863 timevar_pop (TV_CGRAPH);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2864 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2865
111
kono
parents: 67
diff changeset
2866 /* Reset all state within cgraphunit.c so that we can rerun the compiler
kono
parents: 67
diff changeset
2867 within the same process. For use by toplev::finalize. */
kono
parents: 67
diff changeset
2868
kono
parents: 67
diff changeset
2869 void
kono
parents: 67
diff changeset
2870 cgraphunit_c_finalize (void)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2871 {
111
kono
parents: 67
diff changeset
2872 gcc_assert (cgraph_new_nodes.length () == 0);
kono
parents: 67
diff changeset
2873 cgraph_new_nodes.truncate (0);
kono
parents: 67
diff changeset
2874
kono
parents: 67
diff changeset
2875 vtable_entry_type = NULL;
kono
parents: 67
diff changeset
2876 queued_nodes = &symtab_terminator;
kono
parents: 67
diff changeset
2877
kono
parents: 67
diff changeset
2878 first_analyzed = NULL;
kono
parents: 67
diff changeset
2879 first_analyzed_var = NULL;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2880 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2881
111
kono
parents: 67
diff changeset
2882 /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
kono
parents: 67
diff changeset
2883 kind of wrapper method. */
kono
parents: 67
diff changeset
2884
kono
parents: 67
diff changeset
2885 void
kono
parents: 67
diff changeset
2886 cgraph_node::create_wrapper (cgraph_node *target)
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2887 {
111
kono
parents: 67
diff changeset
2888 /* Preserve DECL_RESULT so we get right by reference flag. */
kono
parents: 67
diff changeset
2889 tree decl_result = DECL_RESULT (decl);
kono
parents: 67
diff changeset
2890
kono
parents: 67
diff changeset
2891 /* Remove the function's body but keep arguments to be reused
kono
parents: 67
diff changeset
2892 for thunk. */
kono
parents: 67
diff changeset
2893 release_body (true);
kono
parents: 67
diff changeset
2894 reset ();
kono
parents: 67
diff changeset
2895
kono
parents: 67
diff changeset
2896 DECL_UNINLINABLE (decl) = false;
kono
parents: 67
diff changeset
2897 DECL_RESULT (decl) = decl_result;
kono
parents: 67
diff changeset
2898 DECL_INITIAL (decl) = NULL;
kono
parents: 67
diff changeset
2899 allocate_struct_function (decl, false);
kono
parents: 67
diff changeset
2900 set_cfun (NULL);
kono
parents: 67
diff changeset
2901
kono
parents: 67
diff changeset
2902 /* Turn alias into thunk and expand it into GIMPLE representation. */
kono
parents: 67
diff changeset
2903 definition = true;
kono
parents: 67
diff changeset
2904
kono
parents: 67
diff changeset
2905 memset (&thunk, 0, sizeof (cgraph_thunk_info));
kono
parents: 67
diff changeset
2906 thunk.thunk_p = true;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2907 create_edge (target, NULL, count);
111
kono
parents: 67
diff changeset
2908 callees->can_throw_external = !TREE_NOTHROW (target->decl);
kono
parents: 67
diff changeset
2909
kono
parents: 67
diff changeset
2910 tree arguments = DECL_ARGUMENTS (decl);
kono
parents: 67
diff changeset
2911
kono
parents: 67
diff changeset
2912 while (arguments)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
2913 {
111
kono
parents: 67
diff changeset
2914 TREE_ADDRESSABLE (arguments) = false;
kono
parents: 67
diff changeset
2915 arguments = TREE_CHAIN (arguments);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2916 }
111
kono
parents: 67
diff changeset
2917
kono
parents: 67
diff changeset
2918 expand_thunk (false, true);
kono
parents: 67
diff changeset
2919
kono
parents: 67
diff changeset
2920 /* Inline summary set-up. */
kono
parents: 67
diff changeset
2921 analyze ();
kono
parents: 67
diff changeset
2922 inline_analyze_function (this);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2923 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 36
diff changeset
2924
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2925 #include "gt-cgraphunit.h"