Line data Source code
1 : /* Callgraph clones
2 : Copyright (C) 2003-2026 Free Software Foundation, Inc.
3 : Contributed by Jan Hubicka
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : /* This module provide facilities for cloning functions. I.e. creating
22 : new functions based on existing functions with simple modifications,
23 : such as replacement of parameters.
24 :
25 : To allow whole program optimization without actual presence of function
26 : bodies, an additional infrastructure is provided for so-called virtual
27 : clones
28 :
29 : A virtual clone in the callgraph is a function that has no
30 : associated body, just a description of how to create its body based
31 : on a different function (which itself may be a virtual clone).
32 :
33 : The description of function modifications includes adjustments to
34 : the function's signature (which allows, for example, removing or
35 : adding function arguments), substitutions to perform on the
36 : function body, and, for inlined functions, a pointer to the
37 : function that it will be inlined into.
38 :
39 : It is also possible to redirect any edge of the callgraph from a
40 : function to its virtual clone. This implies updating of the call
41 : site to adjust for the new function signature.
42 :
43 : Most of the transformations performed by inter-procedural
44 : optimizations can be represented via virtual clones. For
45 : instance, a constant propagation pass can produce a virtual clone
46 : of the function which replaces one of its arguments by a
47 : constant. The inliner can represent its decisions by producing a
48 : clone of a function whose body will be later integrated into
49 : a given function.
50 :
51 : Using virtual clones, the program can be easily updated
52 : during the Execute stage, solving most of pass interactions
53 : problems that would otherwise occur during Transform.
54 :
55 : Virtual clones are later materialized in the LTRANS stage and
56 : turned into real functions. Passes executed after the virtual
57 : clone were introduced also perform their Transform stage
58 : on new functions, so for a pass there is no significant
59 : difference between operating on a real function or a virtual
60 : clone introduced before its Execute stage.
61 :
62 : Optimization passes then work on virtual clones introduced before
63 : their Execute stage as if they were real functions. The
64 : only difference is that clones are not visible during the
65 : Generate Summary stage. */
66 :
67 : #include "config.h"
68 : #include "system.h"
69 : #include "coretypes.h"
70 : #include "backend.h"
71 : #include "target.h"
72 : #include "rtl.h"
73 : #include "tree.h"
74 : #include "gimple.h"
75 : #include "stringpool.h"
76 : #include "cgraph.h"
77 : #include "lto-streamer.h"
78 : #include "tree-eh.h"
79 : #include "tree-cfg.h"
80 : #include "tree-inline.h"
81 : #include "debug.h"
82 : #include "attribs.h"
83 : #include "dumpfile.h"
84 : #include "gimple-pretty-print.h"
85 : #include "alloc-pool.h"
86 : #include "symbol-summary.h"
87 : #include "tree-vrp.h"
88 : #include "sreal.h"
89 : #include "ipa-cp.h"
90 : #include "ipa-prop.h"
91 : #include "ipa-fnsummary.h"
92 : #include "symtab-thunks.h"
93 : #include "symtab-clones.h"
94 :
95 : /* Create clone of edge in the node N represented by CALL_EXPR
96 : the callgraph. */
97 :
98 : cgraph_edge *
99 7817357 : cgraph_edge::clone (cgraph_node *n, gcall *call_stmt, unsigned stmt_uid,
100 : profile_count num, profile_count den,
101 : bool update_original)
102 : {
103 7817357 : cgraph_edge *new_edge;
104 7817357 : profile_count::adjust_for_ipa_scaling (&num, &den);
105 7817357 : profile_count prof_count = count.apply_scale (num, den);
106 :
107 7817357 : if (indirect_unknown_callee)
108 : {
109 200584 : tree decl;
110 :
111 199929 : if (call_stmt && (decl = gimple_call_fndecl (call_stmt))
112 : /* When the call is speculative, we need to resolve it
113 : via cgraph_resolve_speculation and not here. */
114 221152 : && !speculative)
115 : {
116 20568 : cgraph_node *callee = cgraph_node::get (decl);
117 20568 : gcc_checking_assert (callee);
118 20568 : new_edge = n->create_edge (callee, call_stmt, prof_count, true);
119 : }
120 : else
121 : {
122 360032 : new_edge = n->create_indirect_edge (call_stmt,
123 180016 : indirect_info->ecf_flags,
124 : prof_count, true);
125 :
126 180016 : if (indirect_info->kind == CIIK_POLYMORPHIC)
127 105058 : new_edge->indirect_info
128 105058 : = (new (ggc_alloc<cgraph_polymorphic_indirect_info> ())
129 : cgraph_polymorphic_indirect_info (
130 105058 : *(const cgraph_polymorphic_indirect_info *) indirect_info));
131 74958 : else if (indirect_info->kind == CIIK_SIMPLE)
132 74842 : new_edge->indirect_info
133 74842 : = (new (ggc_alloc<cgraph_simple_indirect_info> ())
134 : cgraph_simple_indirect_info (
135 74842 : *(const cgraph_simple_indirect_info *) indirect_info));
136 : else
137 116 : new_edge->indirect_info
138 116 : = (new (ggc_alloc<cgraph_indirect_call_info> ())
139 : cgraph_indirect_call_info(
140 116 : *(const cgraph_indirect_call_info *) indirect_info));
141 : }
142 : }
143 : else
144 : {
145 7616773 : new_edge = n->create_edge (callee, call_stmt, prof_count, true);
146 7616773 : if (indirect_info)
147 : {
148 0 : new_edge->indirect_info
149 0 : = ggc_cleared_alloc<cgraph_indirect_call_info> ();
150 0 : *new_edge->indirect_info = *indirect_info;
151 : }
152 : }
153 :
154 7817357 : new_edge->inline_failed = inline_failed;
155 7817357 : new_edge->indirect_inlining_edge = indirect_inlining_edge;
156 7817357 : if (!call_stmt)
157 237383 : new_edge->lto_stmt_uid = stmt_uid;
158 7817357 : new_edge->speculative_id = speculative_id;
159 : /* Clone flags that depend on call_stmt availability manually. */
160 7817357 : new_edge->can_throw_external = can_throw_external;
161 7817357 : new_edge->call_stmt_cannot_inline_p = call_stmt_cannot_inline_p;
162 7817357 : new_edge->speculative = speculative;
163 7817357 : new_edge->callback = callback;
164 7817357 : new_edge->has_callback = has_callback;
165 7817357 : new_edge->in_polymorphic_cdtor = in_polymorphic_cdtor;
166 :
167 : /* Update IPA profile. Local profiles need no updating in original. */
168 7817357 : if (update_original)
169 7064197 : count = count.combine_with_ipa_count_within (count.ipa ()
170 7064197 : - new_edge->count.ipa (),
171 7064197 : caller->count);
172 7817357 : symtab->call_edge_duplication_hooks (this, new_edge);
173 7817357 : return new_edge;
174 : }
175 :
176 : /* Set flags of NEW_NODE and its decl. NEW_NODE is a newly created private
177 : clone or its thunk. */
178 :
179 : void
180 143819 : set_new_clone_decl_and_node_flags (cgraph_node *new_node)
181 : {
182 143819 : DECL_EXTERNAL (new_node->decl) = 0;
183 143819 : TREE_PUBLIC (new_node->decl) = 0;
184 143819 : DECL_COMDAT (new_node->decl) = 0;
185 143819 : DECL_WEAK (new_node->decl) = 0;
186 143819 : DECL_VIRTUAL_P (new_node->decl) = 0;
187 143819 : DECL_STATIC_CONSTRUCTOR (new_node->decl) = 0;
188 143819 : DECL_STATIC_DESTRUCTOR (new_node->decl) = 0;
189 143819 : DECL_SET_IS_OPERATOR_NEW (new_node->decl, 0);
190 143819 : DECL_SET_IS_OPERATOR_DELETE (new_node->decl, 0);
191 143819 : DECL_IS_REPLACEABLE_OPERATOR (new_node->decl) = 0;
192 :
193 143819 : new_node->externally_visible = 0;
194 : /* Clones of callbacks might have their address taken, and thus cannot be
195 : local. */
196 143819 : new_node->local = !new_node->address_taken;
197 143819 : new_node->lowered = true;
198 143819 : new_node->semantic_interposition = 0;
199 143819 : }
200 :
201 : /* Duplicate thunk THUNK if necessary but make it to refer to NODE.
202 : ARGS_TO_SKIP, if non-NULL, determines which parameters should be omitted.
203 : Function can return NODE if no thunk is necessary, which can happen when
204 : thunk is this_adjusting but we are removing this parameter. */
205 :
206 : static cgraph_node *
207 30 : duplicate_thunk_for_node (cgraph_node *thunk, cgraph_node *node)
208 : {
209 30 : cgraph_node *new_thunk, *thunk_of;
210 30 : thunk_of = thunk->callees->callee->ultimate_alias_target ();
211 :
212 30 : if (thunk_of->thunk)
213 0 : node = duplicate_thunk_for_node (thunk_of, node);
214 :
215 30 : if (!DECL_ARGUMENTS (thunk->decl))
216 0 : thunk->get_untransformed_body ();
217 :
218 30 : thunk_info *i = thunk_info::get (thunk);
219 30 : cgraph_edge *cs;
220 30 : for (cs = node->callers; cs; cs = cs->next_caller)
221 12 : if (cs->caller->thunk)
222 : {
223 12 : thunk_info *i2 = thunk_info::get (cs->caller);
224 12 : if (*i2 == *i)
225 : return cs->caller;
226 : }
227 :
228 18 : tree new_decl;
229 18 : clone_info *info = clone_info::get (node);
230 18 : if (info && info->param_adjustments)
231 : {
232 : /* We do not need to duplicate this_adjusting thunks if we have removed
233 : this. */
234 15 : if (i->this_adjusting
235 15 : && !info->param_adjustments->first_param_intact_p ())
236 0 : return node;
237 :
238 15 : new_decl = copy_node (thunk->decl);
239 15 : ipa_param_body_adjustments body_adj (info->param_adjustments,
240 15 : new_decl);
241 15 : body_adj.modify_formal_parameters ();
242 15 : }
243 : else
244 : {
245 3 : new_decl = copy_node (thunk->decl);
246 3 : for (tree *arg = &DECL_ARGUMENTS (new_decl);
247 9 : *arg; arg = &DECL_CHAIN (*arg))
248 : {
249 6 : tree next = DECL_CHAIN (*arg);
250 6 : *arg = copy_node (*arg);
251 6 : DECL_CONTEXT (*arg) = new_decl;
252 6 : DECL_CHAIN (*arg) = next;
253 : }
254 : }
255 :
256 18 : gcc_checking_assert (!DECL_STRUCT_FUNCTION (new_decl));
257 18 : gcc_checking_assert (!DECL_INITIAL (new_decl));
258 18 : gcc_checking_assert (!DECL_RESULT (new_decl));
259 18 : gcc_checking_assert (!DECL_RTL_SET_P (new_decl));
260 :
261 18 : DECL_NAME (new_decl) = clone_function_name_numbered (thunk->decl,
262 : "artificial_thunk");
263 18 : SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
264 :
265 : /* We need to force DECL_IGNORED_P because the new thunk is created after
266 : early debug was run. */
267 18 : DECL_IGNORED_P (new_decl) = 1;
268 :
269 18 : new_thunk = cgraph_node::create (new_decl);
270 18 : set_new_clone_decl_and_node_flags (new_thunk);
271 18 : new_thunk->definition = true;
272 18 : new_thunk->can_change_signature = node->can_change_signature;
273 18 : new_thunk->thunk = thunk->thunk;
274 18 : new_thunk->unique_name = in_lto_p;
275 18 : new_thunk->former_clone_of = thunk->decl;
276 18 : if (info && info->param_adjustments)
277 15 : clone_info::get_create (new_thunk)->param_adjustments
278 15 : = info->param_adjustments;
279 18 : new_thunk->unit_id = thunk->unit_id;
280 18 : new_thunk->merged_comdat = thunk->merged_comdat;
281 18 : new_thunk->merged_extern_inline = thunk->merged_extern_inline;
282 :
283 18 : cgraph_edge *e = new_thunk->create_edge (node, NULL, new_thunk->count);
284 18 : symtab->call_edge_duplication_hooks (thunk->callees, e);
285 18 : symtab->call_cgraph_duplication_hooks (thunk, new_thunk);
286 18 : return new_thunk;
287 : }
288 :
289 : /* If E does not lead to a thunk, simply redirect it to N. Otherwise create
290 : one or more equivalent thunks for N and redirect E to the first in the
291 : chain. Note that it is then necessary to call
292 : n->expand_all_artificial_thunks once all callers are redirected. */
293 :
294 : void
295 431035 : cgraph_edge::redirect_callee_duplicating_thunks (cgraph_node *n)
296 : {
297 431035 : cgraph_node *orig_to = callee->ultimate_alias_target ();
298 431035 : if (orig_to->thunk)
299 30 : n = duplicate_thunk_for_node (orig_to, n);
300 :
301 431035 : redirect_callee (n);
302 431035 : }
303 :
304 : /* Call expand_thunk on all callers that are thunks and if analyze those nodes
305 : that were expanded. */
306 :
307 : void
308 3327097 : cgraph_node::expand_all_artificial_thunks ()
309 : {
310 3327097 : cgraph_edge *e;
311 3758518 : for (e = callers; e;)
312 431421 : if (e->caller->thunk)
313 : {
314 18 : cgraph_node *thunk = e->caller;
315 :
316 18 : e = e->next_caller;
317 18 : if (expand_thunk (thunk, false, false))
318 : {
319 0 : thunk->thunk = false;
320 0 : thunk->analyze ();
321 0 : ipa_analyze_node (thunk);
322 0 : inline_analyze_function (thunk);
323 : }
324 18 : thunk->expand_all_artificial_thunks ();
325 : }
326 : else
327 431403 : e = e->next_caller;
328 3327097 : }
329 :
330 : /* Dump information about creation of a call graph node clone to the dump file
331 : created by the -fdump-ipa-clones option. ORIGINAL is the function being
332 : cloned, CLONE is the new clone. SUFFIX is a string that helps identify the
333 : reason for cloning, often it is the suffix used by a particular IPA pass to
334 : create unique function names. SUFFIX can be NULL and in that case the
335 : dumping will not take place, which must be the case only for helper clones
336 : which will never be emitted to the output. */
337 :
338 : void
339 4888108 : dump_callgraph_transformation (const cgraph_node *original,
340 : const cgraph_node *clone,
341 : const char *suffix)
342 : {
343 4888108 : if (suffix && symtab->ipa_clones_dump_file)
344 : {
345 52 : fprintf (symtab->ipa_clones_dump_file,
346 : "Callgraph clone;%s;%d;%s;%d;%d;%s;%d;%s;%d;%d;%s\n",
347 : original->asm_name (), original->get_uid (),
348 26 : DECL_SOURCE_FILE (original->decl),
349 26 : DECL_SOURCE_LINE (original->decl),
350 26 : DECL_SOURCE_COLUMN (original->decl), clone->asm_name (),
351 26 : clone->get_uid (), DECL_SOURCE_FILE (clone->decl),
352 26 : DECL_SOURCE_LINE (clone->decl), DECL_SOURCE_COLUMN (clone->decl),
353 : suffix);
354 :
355 26 : symtab->cloned_nodes.add (original);
356 26 : symtab->cloned_nodes.add (clone);
357 : }
358 4888108 : }
359 :
360 : /* Turn profile of N to local profile. */
361 :
362 : static void
363 0 : localize_profile (cgraph_node *n)
364 : {
365 0 : n->count = n->count.guessed_local ();
366 0 : for (cgraph_edge *e = n->callees; e; e=e->next_callee)
367 : {
368 0 : e->count = e->count.guessed_local ();
369 0 : if (!e->inline_failed)
370 0 : localize_profile (e->callee);
371 : }
372 0 : for (cgraph_edge *e = n->indirect_calls; e; e=e->next_callee)
373 0 : e->count = e->count.guessed_local ();
374 0 : }
375 :
376 : /* Create node representing clone of N executed COUNT times. Decrease
377 : the execution counts from original node too.
378 : The new clone will have decl set to DECL that may or may not be the same
379 : as decl of N.
380 :
381 : When UPDATE_ORIGINAL is true, the counts are subtracted from the original
382 : function's profile to reflect the fact that part of execution is handled
383 : by node.
384 : When CALL_DUPLICATION_HOOK is true, the ipa passes are acknowledged about
385 : the new clone. Otherwise the caller is responsible for doing so later.
386 :
387 : If the new node is being inlined into another one, NEW_INLINED_TO should be
388 : the outline function the new one is (even indirectly) inlined to. All hooks
389 : will see this in node's inlined_to, when invoked. Should be NULL if the
390 : node is not inlined.
391 :
392 : SUFFIX is string that is appended to the original name, it should only be
393 : NULL if NEW_INLINED_TO is not NULL or if the clone being created is
394 : temporary and a record about it should not be added into the ipa-clones dump
395 : file.
396 :
397 : If PARAM_ADJUSTMENTS is non-NULL, the parameter manipulation information
398 : will be overwritten by the new structure. Otherwise the new node will
399 : share parameter manipulation information with the original node. */
400 :
401 : cgraph_node *
402 3326917 : cgraph_node::create_clone (tree new_decl, profile_count prof_count,
403 : bool update_original,
404 : vec<cgraph_edge *> redirect_callers,
405 : bool call_duplication_hook,
406 : cgraph_node *new_inlined_to,
407 : ipa_param_adjustments *param_adjustments,
408 : const char *suffix)
409 : {
410 3326917 : cgraph_node *new_node = symtab->create_empty ();
411 3326917 : cgraph_edge *e;
412 3326917 : unsigned i;
413 3326917 : profile_count old_count = count;
414 3326917 : bool nonzero = count.ipa ().nonzero_p ();
415 :
416 3326917 : if (new_inlined_to)
417 3158024 : dump_callgraph_transformation (this, new_inlined_to, "inlining to");
418 :
419 : /* When inlining we scale precisely to prof_count, when cloning we can
420 : preserve local profile. */
421 3158024 : if (!new_inlined_to)
422 168893 : prof_count = count.combine_with_ipa_count (prof_count);
423 3326917 : new_node->count = prof_count;
424 3326917 : new_node->has_omp_variant_constructs = this->has_omp_variant_constructs;
425 :
426 : /* Update IPA profile. Local profiles need no updating in original. */
427 3326917 : if (update_original)
428 : {
429 3135832 : if (inlined_to)
430 475013 : count = count.combine_with_ipa_count_within (count.ipa ()
431 950026 : - prof_count.ipa (),
432 : inlined_to->count);
433 : else
434 2660819 : count = count.combine_with_ipa_count (count.ipa () - prof_count.ipa ());
435 : }
436 3326917 : new_node->decl = new_decl;
437 3326917 : new_node->order = order;
438 3326917 : new_node->register_symbol ();
439 3326917 : new_node->lto_file_data = lto_file_data;
440 3326917 : new_node->analyzed = analyzed;
441 3326917 : new_node->definition = definition;
442 3326917 : new_node->versionable = versionable;
443 3326917 : new_node->can_change_signature = can_change_signature;
444 3326917 : new_node->redefined_extern_inline = redefined_extern_inline;
445 3326917 : new_node->semantic_interposition = semantic_interposition;
446 3326917 : new_node->tm_may_enter_irr = tm_may_enter_irr;
447 3326917 : new_node->externally_visible = false;
448 3326917 : new_node->no_reorder = no_reorder;
449 3326917 : new_node->local = true;
450 3326917 : new_node->inlined_to = new_inlined_to;
451 3326917 : new_node->rtl = rtl;
452 3326917 : new_node->frequency = frequency;
453 3326917 : new_node->tp_first_run = tp_first_run;
454 3326917 : new_node->tm_clone = tm_clone;
455 3326917 : new_node->icf_merged = icf_merged;
456 3326917 : new_node->assume_function = assume_function;
457 3326917 : new_node->thunk = thunk;
458 3326917 : new_node->unit_id = unit_id;
459 3326917 : new_node->merged_comdat = merged_comdat;
460 3326917 : new_node->merged_extern_inline = merged_extern_inline;
461 3326917 : new_node->must_remain_in_tu_body = must_remain_in_tu_body;
462 3326917 : clone_info *info = clone_info::get (this);
463 :
464 3326917 : if (param_adjustments)
465 137459 : clone_info::get_create (new_node)->param_adjustments = param_adjustments;
466 3189458 : else if (info && info->param_adjustments)
467 325926 : clone_info::get_create (new_node)->param_adjustments
468 325926 : = info->param_adjustments;
469 3326917 : new_node->split_part = split_part;
470 :
471 3757781 : FOR_EACH_VEC_ELT (redirect_callers, i, e)
472 : {
473 : /* Redirect calls to the old version node to point to its new
474 : version. The only exception is when the edge was proved to
475 : be unreachable during the cloning procedure. */
476 430864 : if (!e->callee
477 430864 : || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
478 : BUILT_IN_UNREACHABLE_TRAP))
479 430864 : e->redirect_callee_duplicating_thunks (new_node);
480 : }
481 3326917 : new_node->expand_all_artificial_thunks ();
482 :
483 6654720 : for (e = callees;e; e=e->next_callee)
484 3327803 : e->clone (new_node, e->call_stmt, e->lto_stmt_uid, new_node->count, old_count,
485 : update_original);
486 :
487 3417886 : for (e = indirect_calls; e; e = e->next_callee)
488 90969 : e->clone (new_node, e->call_stmt, e->lto_stmt_uid,
489 : new_node->count, old_count, update_original);
490 3326917 : new_node->clone_references (this);
491 :
492 3326917 : new_node->next_sibling_clone = clones;
493 3326917 : if (clones)
494 1621226 : clones->prev_sibling_clone = new_node;
495 3326917 : clones = new_node;
496 3326917 : new_node->clone_of = this;
497 :
498 3326917 : if (call_duplication_hook)
499 3159686 : symtab->call_cgraph_duplication_hooks (this, new_node);
500 : /* With partial train run we do not want to assume that original's
501 : count is zero whenever we redurect all executed edges to clone.
502 : Simply drop profile to local one in this case. */
503 3326917 : if (update_original
504 3135832 : && opt_for_fn (decl, flag_profile_partial_training)
505 0 : && nonzero
506 0 : && count.ipa_p ()
507 3326917 : && !count.ipa ().nonzero_p ()
508 3326917 : && !inlined_to)
509 0 : localize_profile (this);
510 :
511 3326917 : if (!new_inlined_to)
512 168893 : dump_callgraph_transformation (this, new_node, suffix);
513 :
514 3326917 : return new_node;
515 : }
516 :
517 : static GTY(()) hash_map<const char *, unsigned> *clone_fn_ids;
518 :
519 : /* Return a new assembler name for a clone of decl named NAME. Apart
520 : from the string SUFFIX, the new name will end with a unique (for
521 : each NAME) unspecified number. If clone numbering is not needed
522 : then the two argument clone_function_name should be used instead.
523 : Should not be called directly except for by
524 : lto-partition.cc:privatize_symbol_name_1. */
525 :
526 : tree
527 114240 : clone_function_name_numbered (const char *name, const char *suffix)
528 : {
529 : /* Initialize the function->counter mapping the first time it's
530 : needed. */
531 114240 : if (!clone_fn_ids)
532 21304 : clone_fn_ids = hash_map<const char *, unsigned int>::create_ggc (64);
533 342720 : unsigned int &suffix_counter = clone_fn_ids->get_or_insert (
534 114240 : IDENTIFIER_POINTER (get_identifier (name)));
535 114240 : return clone_function_name (name, suffix, suffix_counter++);
536 : }
537 :
538 : /* Return a new assembler name for a clone of DECL. Apart from string
539 : SUFFIX, the new name will end with a unique (for each DECL
540 : assembler name) unspecified number. If clone numbering is not
541 : needed then the two argument clone_function_name should be used
542 : instead. */
543 :
544 : tree
545 114240 : clone_function_name_numbered (tree decl, const char *suffix)
546 : {
547 114240 : tree name = DECL_ASSEMBLER_NAME (decl);
548 114240 : return clone_function_name_numbered (IDENTIFIER_POINTER (name),
549 114240 : suffix);
550 : }
551 :
552 : /* Return a new assembler name for a clone of decl named NAME. Apart
553 : from the string SUFFIX, the new name will end with the specified
554 : NUMBER. If clone numbering is not needed then the two argument
555 : clone_function_name should be used instead. */
556 :
557 : tree
558 258385 : clone_function_name (const char *name, const char *suffix,
559 : unsigned long number)
560 : {
561 258385 : size_t len = strlen (name);
562 258385 : char *tmp_name, *prefix;
563 :
564 258385 : prefix = XALLOCAVEC (char, len + strlen (suffix) + 2);
565 258385 : memcpy (prefix, name, len);
566 258385 : strcpy (prefix + len + 1, suffix);
567 258385 : prefix[len] = symbol_table::symbol_suffix_separator ();
568 258385 : ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, number);
569 258385 : return get_identifier (tmp_name);
570 : }
571 :
572 : /* Return a new assembler name for a clone of DECL. Apart from the
573 : string SUFFIX, the new name will end with the specified NUMBER. If
574 : clone numbering is not needed then the two argument
575 : clone_function_name should be used instead. */
576 :
577 : tree
578 143801 : clone_function_name (tree decl, const char *suffix,
579 : unsigned long number)
580 : {
581 287602 : return clone_function_name (
582 143801 : IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), suffix, number);
583 : }
584 :
585 : /* Return a new assembler name ending with the string SUFFIX for a
586 : clone of DECL. */
587 :
588 : tree
589 66912 : clone_function_name (tree decl, const char *suffix)
590 : {
591 66912 : tree identifier = DECL_ASSEMBLER_NAME (decl);
592 : /* For consistency this needs to behave the same way as
593 : ASM_FORMAT_PRIVATE_NAME does, but without the final number
594 : suffix. */
595 66912 : return clone_identifier (identifier, suffix);
596 : }
597 :
598 : /* Return true if symbol is valid in assembler name. */
599 :
600 : static bool
601 9978 : is_valid_asm_symbol (char c)
602 : {
603 9978 : if ('a' <= c && c <= 'z')
604 : return true;
605 1885 : if ('A' <= c && c <= 'Z')
606 : return true;
607 1885 : if ('0' <= c && c <= '9')
608 : return true;
609 823 : if (c == '_')
610 707 : return true;
611 : return false;
612 : }
613 :
614 : /* Return a new clone of ID ending with the string SUFFIX.
615 : If FILTER_SUFFIX is true, any illegal asm characters in the SUFFIX are
616 : replaced with _. */
617 :
618 : tree
619 68390 : clone_identifier (tree id, const char *suffix, bool filter_suffix)
620 : {
621 68390 : char *separator = XALLOCAVEC (char, 2);
622 68390 : separator[0] = symbol_table::symbol_suffix_separator ();
623 68390 : separator[1] = 0;
624 : #if defined (NO_DOT_IN_LABEL) && defined (NO_DOLLAR_IN_LABEL)
625 : const char *prefix = "__";
626 : #else
627 68390 : const char *prefix = "";
628 : #endif
629 68390 : if (!suffix)
630 174 : suffix = "";
631 :
632 68390 : if (!filter_suffix)
633 : {
634 67243 : char *result = ACONCAT (
635 : (prefix, IDENTIFIER_POINTER (id), separator, suffix, (char *) 0));
636 67243 : return get_identifier (result);
637 : }
638 : else
639 : {
640 : /* Replace any illegal chars with _. */
641 1147 : int suffix_len = strlen (suffix);
642 1147 : char *converted_suffix = XALLOCAVEC (char, suffix_len + 1);
643 11125 : for (int i = 0; i < suffix_len; i++)
644 9978 : if (!is_valid_asm_symbol (suffix[i]))
645 116 : converted_suffix[i] = '_';
646 : else
647 9862 : converted_suffix[i] = suffix[i];
648 1147 : converted_suffix[suffix_len] = '\0';
649 :
650 1147 : char *result = ACONCAT ((prefix, IDENTIFIER_POINTER (id), separator,
651 : converted_suffix, (char *) 0));
652 1147 : return get_identifier (result);
653 : }
654 : }
655 :
656 : /* Create callgraph node clone with new declaration. The actual body will be
657 : copied later at compilation stage. The name of the new clone will be
658 : constructed from the name of the original node, SUFFIX and NUM_SUFFIX.
659 :
660 : TODO: after merging in ipa-sra use function call notes instead of args_to_skip
661 : bitmap interface.
662 : */
663 : cgraph_node *
664 143801 : cgraph_node::create_virtual_clone (const vec<cgraph_edge *> &redirect_callers,
665 : vec<ipa_replace_map *, va_gc> *tree_map,
666 : ipa_param_adjustments *param_adjustments,
667 : const char * suffix, unsigned num_suffix)
668 : {
669 143801 : tree old_decl = decl;
670 143801 : cgraph_node *new_node = NULL;
671 143801 : tree new_decl;
672 143801 : size_t len, i;
673 143801 : ipa_replace_map *map;
674 143801 : char *name;
675 :
676 143801 : gcc_checking_assert (versionable);
677 : /* TODO: It would be nice if we could recognize that param_adjustments do not
678 : actually perform any changes, but at the moment let's require it simply
679 : does not exist. */
680 143801 : gcc_assert (can_change_signature || !param_adjustments);
681 :
682 : /* Make a new FUNCTION_DECL tree node */
683 142234 : if (!param_adjustments)
684 6342 : new_decl = copy_node (old_decl);
685 : else
686 137459 : new_decl = param_adjustments->adjust_decl (old_decl);
687 :
688 : /* These pointers represent function body and will be populated only when clone
689 : is materialized. */
690 143801 : gcc_assert (new_decl != old_decl);
691 143801 : copy_debug_abstract_origin (new_decl, old_decl);
692 143801 : DECL_STRUCT_FUNCTION (new_decl) = NULL;
693 143801 : DECL_ARGUMENTS (new_decl) = NULL;
694 143801 : DECL_INITIAL (new_decl) = NULL;
695 143801 : DECL_RESULT (new_decl) = NULL;
696 : /* We cannot do DECL_RESULT (new_decl) = NULL; here because of LTO partitioning
697 : sometimes storing only clone decl instead of original. */
698 :
699 : /* Generate a new name for the new version. */
700 143801 : len = IDENTIFIER_LENGTH (DECL_NAME (old_decl));
701 143801 : name = XALLOCAVEC (char, len + strlen (suffix) + 2);
702 143801 : memcpy (name, IDENTIFIER_POINTER (DECL_NAME (old_decl)), len);
703 143801 : strcpy (name + len + 1, suffix);
704 143801 : name[len] = '.';
705 143801 : DECL_NAME (new_decl) = get_identifier (name);
706 143801 : SET_DECL_ASSEMBLER_NAME (new_decl,
707 : clone_function_name (old_decl, suffix, num_suffix));
708 143801 : SET_DECL_RTL (new_decl, NULL);
709 :
710 143801 : new_node = create_clone (new_decl, count, false,
711 : redirect_callers, false, NULL, param_adjustments,
712 : suffix);
713 :
714 : /* Update the properties.
715 : Make clone visible only within this translation unit. Make sure
716 : that is not weak also.
717 : ??? We cannot use COMDAT linkage because there is no
718 : ABI support for this. */
719 143801 : set_new_clone_decl_and_node_flags (new_node);
720 143801 : new_node->ipcp_clone = ipcp_clone;
721 143801 : if (tree_map)
722 15162 : clone_info::get_create (new_node)->tree_map = tree_map;
723 143801 : if (!implicit_section)
724 143789 : new_node->set_section (*this);
725 :
726 : /* Clones of global symbols or symbols with unique names are unique. */
727 143801 : if ((TREE_PUBLIC (old_decl)
728 107609 : && !DECL_EXTERNAL (old_decl)
729 94120 : && !DECL_WEAK (old_decl)
730 2271 : && !DECL_COMDAT (old_decl))
731 249139 : || in_lto_p)
732 7686 : new_node->unique_name = true;
733 170032 : FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
734 : {
735 26231 : tree repl = map->new_tree;
736 26231 : if (map->force_load_ref)
737 : {
738 435 : gcc_assert (TREE_CODE (repl) == ADDR_EXPR);
739 435 : repl = get_base_address (TREE_OPERAND (repl, 0));
740 : }
741 26231 : new_node->maybe_create_reference (repl, NULL);
742 : }
743 :
744 143801 : if (ipa_transforms_to_apply.exists ())
745 123522 : new_node->ipa_transforms_to_apply
746 123522 : = ipa_transforms_to_apply.copy ();
747 :
748 143801 : symtab->call_cgraph_duplication_hooks (this, new_node);
749 :
750 143801 : return new_node;
751 : }
752 :
753 : /* callgraph node being removed from symbol table; see if its entry can be
754 : replaced by other inline clone.
755 : INFO is clone info to attach to the new root. */
756 : cgraph_node *
757 106349330 : cgraph_node::find_replacement (clone_info *info)
758 : {
759 106349330 : cgraph_node *next_inline_clone, *replacement;
760 :
761 106349330 : for (next_inline_clone = clones;
762 : next_inline_clone
763 106349330 : && next_inline_clone->decl != decl;
764 0 : next_inline_clone = next_inline_clone->next_sibling_clone)
765 : ;
766 :
767 : /* If there is inline clone of the node being removed, we need
768 : to put it into the position of removed node and reorganize all
769 : other clones to be based on it. */
770 106349330 : if (next_inline_clone)
771 : {
772 414368 : cgraph_node *n;
773 414368 : cgraph_node *new_clones;
774 :
775 414368 : replacement = next_inline_clone;
776 :
777 : /* Unlink inline clone from the list of clones of removed node. */
778 414368 : if (next_inline_clone->next_sibling_clone)
779 248254 : next_inline_clone->next_sibling_clone->prev_sibling_clone
780 248254 : = next_inline_clone->prev_sibling_clone;
781 414368 : if (next_inline_clone->prev_sibling_clone)
782 : {
783 0 : gcc_assert (clones != next_inline_clone);
784 0 : next_inline_clone->prev_sibling_clone->next_sibling_clone
785 0 : = next_inline_clone->next_sibling_clone;
786 : }
787 : else
788 : {
789 414368 : gcc_assert (clones == next_inline_clone);
790 414368 : clones = next_inline_clone->next_sibling_clone;
791 : }
792 :
793 414368 : new_clones = clones;
794 414368 : clones = NULL;
795 :
796 : /* Copy clone info. */
797 414368 : if (info)
798 65869 : *clone_info::get_create (next_inline_clone) = *info;
799 :
800 : /* Now place it into clone tree at same level at NODE. */
801 414368 : next_inline_clone->clone_of = clone_of;
802 414368 : next_inline_clone->prev_sibling_clone = NULL;
803 414368 : next_inline_clone->next_sibling_clone = NULL;
804 414368 : if (clone_of)
805 : {
806 3033 : if (clone_of->clones)
807 3033 : clone_of->clones->prev_sibling_clone = next_inline_clone;
808 3033 : next_inline_clone->next_sibling_clone = clone_of->clones;
809 3033 : clone_of->clones = next_inline_clone;
810 : }
811 :
812 : /* Merge the clone list. */
813 414368 : if (new_clones)
814 : {
815 248254 : if (!next_inline_clone->clones)
816 244824 : next_inline_clone->clones = new_clones;
817 : else
818 : {
819 : n = next_inline_clone->clones;
820 11016 : while (n->next_sibling_clone)
821 : n = n->next_sibling_clone;
822 3430 : n->next_sibling_clone = new_clones;
823 3430 : new_clones->prev_sibling_clone = n;
824 : }
825 : }
826 :
827 : /* Update clone_of pointers. */
828 414368 : n = new_clones;
829 2755421 : while (n)
830 : {
831 2341053 : n->clone_of = next_inline_clone;
832 2341053 : n = n->next_sibling_clone;
833 : }
834 :
835 : /* Update order in order to be able to find a LTO section
836 : with function body. */
837 414368 : replacement->order = order;
838 :
839 414368 : return replacement;
840 : }
841 : else
842 : return NULL;
843 : }
844 :
845 : /* Like cgraph_set_call_stmt but walk the clone tree and update all
846 : clones sharing the same function body.
847 : When WHOLE_SPECULATIVE_EDGES is true, all three components of
848 : speculative edge gets updated. Otherwise we update only direct
849 : call. */
850 :
851 : void
852 1924746 : cgraph_node::set_call_stmt_including_clones (gimple *old_stmt,
853 : gcall *new_stmt,
854 : bool update_speculative)
855 : {
856 1924746 : cgraph_node *node;
857 1924746 : cgraph_edge *master_edge = get_edge (old_stmt);
858 :
859 1924746 : if (master_edge)
860 1812071 : cgraph_edge::set_call_stmt (master_edge, new_stmt, update_speculative);
861 :
862 1924746 : node = clones;
863 1924746 : if (node)
864 1315881 : while (node != this)
865 : {
866 1053354 : cgraph_edge *edge = node->get_edge (old_stmt);
867 1053354 : if (edge)
868 : {
869 1046697 : edge = cgraph_edge::set_call_stmt (edge, new_stmt,
870 : update_speculative);
871 : /* If UPDATE_SPECULATIVE is false, it means that we are turning
872 : speculative call into a real code sequence. Update the
873 : callgraph edges. */
874 1046697 : if (edge->speculative && !update_speculative)
875 : {
876 0 : cgraph_edge *indirect = edge->speculative_call_indirect_edge ();
877 :
878 0 : for (cgraph_edge *next, *direct
879 0 : = edge->first_speculative_call_target ();
880 0 : direct;
881 0 : direct = next)
882 : {
883 0 : next = direct->next_speculative_call_target ();
884 0 : direct->speculative_call_target_ref ()->speculative = false;
885 0 : direct->speculative = false;
886 : }
887 0 : indirect->speculative = false;
888 : }
889 : }
890 1053354 : if (node->clones)
891 : node = node->clones;
892 1008376 : else if (node->next_sibling_clone)
893 : node = node->next_sibling_clone;
894 : else
895 : {
896 592553 : while (node != this && !node->next_sibling_clone)
897 307505 : node = node->clone_of;
898 285048 : if (node != this)
899 22521 : node = node->next_sibling_clone;
900 : }
901 : }
902 1924746 : }
903 :
904 : /* Like cgraph_create_edge walk the clone tree and update all clones sharing
905 : same function body. If clones already have edge for OLD_STMT; only
906 : update the edge same way as cgraph_set_call_stmt_including_clones does.
907 :
908 : TODO: COUNT and LOOP_DEPTH should be properly distributed based on relative
909 : frequencies of the clones. */
910 :
911 : void
912 0 : cgraph_node::create_edge_including_clones (cgraph_node *callee,
913 : gimple *old_stmt, gcall *stmt,
914 : profile_count count,
915 : cgraph_inline_failed_t reason)
916 : {
917 0 : cgraph_node *node;
918 :
919 0 : if (!get_edge (stmt))
920 : {
921 0 : cgraph_edge *edge = create_edge (callee, stmt, count);
922 0 : edge->inline_failed = reason;
923 : }
924 :
925 0 : node = clones;
926 0 : if (node)
927 0 : while (node != this)
928 : /* Thunk clones do not get updated while copying inline function body. */
929 0 : if (!node->thunk)
930 : {
931 0 : cgraph_edge *edge = node->get_edge (old_stmt);
932 :
933 : /* It is possible that clones already contain the edge while
934 : master didn't. Either we promoted indirect call into direct
935 : call in the clone or we are processing clones of unreachable
936 : master where edges has been removed. */
937 0 : if (edge)
938 0 : edge = cgraph_edge::set_call_stmt (edge, stmt);
939 0 : else if (! node->get_edge (stmt))
940 : {
941 0 : edge = node->create_edge (callee, stmt, count);
942 0 : edge->inline_failed = reason;
943 : }
944 :
945 0 : if (node->clones)
946 : node = node->clones;
947 0 : else if (node->next_sibling_clone)
948 : node = node->next_sibling_clone;
949 : else
950 : {
951 0 : while (node != this && !node->next_sibling_clone)
952 0 : node = node->clone_of;
953 0 : if (node != this)
954 0 : node = node->next_sibling_clone;
955 : }
956 : }
957 0 : }
958 :
959 : /* Remove the node from cgraph and all inline clones inlined into it.
960 : Skip however removal of FORBIDDEN_NODE and return true if it needs to be
961 : removed. This allows to call the function from outer loop walking clone
962 : tree. */
963 :
964 : bool
965 535 : cgraph_node::remove_symbol_and_inline_clones (cgraph_node *forbidden_node)
966 : {
967 535 : cgraph_edge *e, *next;
968 535 : bool found = false;
969 :
970 535 : if (this == forbidden_node)
971 : {
972 0 : cgraph_edge::remove (callers);
973 0 : return true;
974 : }
975 666 : for (e = callees; e; e = next)
976 : {
977 131 : next = e->next_callee;
978 131 : if (!e->inline_failed)
979 19 : found |= e->callee->remove_symbol_and_inline_clones (forbidden_node);
980 : }
981 535 : remove ();
982 535 : return found;
983 : }
984 :
985 : /* The edges representing the callers of the NEW_VERSION node were
986 : fixed by cgraph_function_versioning (), now the call_expr in their
987 : respective tree code should be updated to call the NEW_VERSION. */
988 :
989 : static void
990 57452 : update_call_expr (cgraph_node *new_version)
991 : {
992 57452 : cgraph_edge *e;
993 :
994 57452 : gcc_assert (new_version);
995 :
996 : /* Update the call expr on the edges to call the new version. */
997 57452 : for (e = new_version->callers; e; e = e->next_caller)
998 : {
999 0 : function *inner_function = DECL_STRUCT_FUNCTION (e->caller->decl);
1000 0 : gimple_call_set_fndecl (e->call_stmt, new_version->decl);
1001 0 : maybe_clean_eh_stmt_fn (inner_function, e->call_stmt);
1002 : }
1003 57452 : }
1004 :
1005 :
1006 : /* Create a new cgraph node which is the new version of
1007 : callgraph node. REDIRECT_CALLERS holds the callers
1008 : edges which should be redirected to point to
1009 : NEW_VERSION. ALL the callees edges of the node
1010 : are cloned to the new version node. Return the new
1011 : version node.
1012 :
1013 : If non-NULL BLOCK_TO_COPY determine what basic blocks
1014 : was copied to prevent duplications of calls that are dead
1015 : in the clone. */
1016 :
1017 : cgraph_node *
1018 60734 : cgraph_node::create_version_clone (tree new_decl,
1019 : vec<cgraph_edge *> redirect_callers,
1020 : bitmap bbs_to_copy,
1021 : const char *suffix)
1022 : {
1023 60734 : cgraph_node *new_version;
1024 60734 : cgraph_edge *e;
1025 60734 : unsigned i;
1026 :
1027 60734 : new_version = cgraph_node::create (new_decl);
1028 :
1029 60734 : new_version->analyzed = analyzed;
1030 60734 : new_version->definition = definition;
1031 60734 : new_version->local = local;
1032 60734 : new_version->externally_visible = false;
1033 60734 : new_version->no_reorder = no_reorder;
1034 60734 : new_version->local = new_version->definition;
1035 60734 : new_version->inlined_to = inlined_to;
1036 60734 : new_version->rtl = rtl;
1037 60734 : new_version->count = count;
1038 60734 : new_version->unit_id = unit_id;
1039 60734 : new_version->merged_comdat = merged_comdat;
1040 60734 : new_version->merged_extern_inline = merged_extern_inline;
1041 :
1042 310597 : for (e = callees; e; e=e->next_callee)
1043 249863 : if (!bbs_to_copy
1044 249863 : || bitmap_bit_p (bbs_to_copy, gimple_bb (e->call_stmt)->index))
1045 191394 : e->clone (new_version, e->call_stmt,
1046 : e->lto_stmt_uid, count, count,
1047 : true);
1048 68292 : for (e = indirect_calls; e; e=e->next_callee)
1049 7558 : if (!bbs_to_copy
1050 7558 : || bitmap_bit_p (bbs_to_copy, gimple_bb (e->call_stmt)->index))
1051 5026 : e->clone (new_version, e->call_stmt,
1052 : e->lto_stmt_uid, count, count,
1053 : true);
1054 60734 : FOR_EACH_VEC_ELT (redirect_callers, i, e)
1055 : {
1056 : /* Redirect calls to the old version node to point to its new
1057 : version. */
1058 0 : e->redirect_callee (new_version);
1059 : }
1060 60734 : new_version->calls_comdat_local = new_version->check_calls_comdat_local_p ();
1061 :
1062 60734 : dump_callgraph_transformation (this, new_version, suffix);
1063 :
1064 60734 : return new_version;
1065 : }
1066 :
1067 : /* Perform function versioning.
1068 : Function versioning includes copying of the tree and
1069 : a callgraph update (creating a new cgraph node and updating
1070 : its callees and callers).
1071 :
1072 : REDIRECT_CALLERS varray includes the edges to be redirected
1073 : to the new version.
1074 :
1075 : TREE_MAP is a mapping of tree nodes we want to replace with
1076 : new ones (according to results of prior analysis).
1077 :
1078 : If non-NULL PARAM_ADJUSTMENTS determine how function formal parameters
1079 : should be modified in the new version and if it should return void.
1080 : If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
1081 : If non_NULL NEW_ENTRY determine new entry BB of the clone.
1082 : SUFFIX is a string that will be used to create a new name for the new
1083 : function.
1084 :
1085 : If TARGET_ATTRIBUTES is non-null, when creating a new declaration,
1086 : add the attributes to DECL_ATTRIBUTES. And call valid_attribute_p
1087 : that will promote value of the attribute DECL_FUNCTION_SPECIFIC_TARGET
1088 : of the declaration.
1089 :
1090 : If VERSION_DECL is set true, use clone_function_name_numbered for the
1091 : function clone. Otherwise, use clone_function_name.
1092 :
1093 : Return the new version's cgraph node. */
1094 :
1095 : cgraph_node *
1096 57453 : cgraph_node::create_version_clone_with_body
1097 : (vec<cgraph_edge *> redirect_callers,
1098 : vec<ipa_replace_map *, va_gc> *tree_map,
1099 : ipa_param_adjustments *param_adjustments,
1100 : bitmap bbs_to_copy, basic_block new_entry_block, const char *suffix,
1101 : tree target_attributes, bool version_decl)
1102 : {
1103 57453 : tree old_decl = decl;
1104 57453 : cgraph_node *new_version_node = NULL;
1105 57453 : tree new_decl;
1106 :
1107 57453 : if (!tree_versionable_function_p (old_decl))
1108 : return NULL;
1109 :
1110 : /* TODO: Restore an assert that we do not change signature if
1111 : can_change_signature is false. We cannot just check that
1112 : param_adjustments is NULL because unfortunately ipa-split removes return
1113 : values from such functions. */
1114 :
1115 : /* Make a new FUNCTION_DECL tree node for the new version. */
1116 57453 : if (param_adjustments)
1117 29494 : new_decl = param_adjustments->adjust_decl (old_decl);
1118 : else
1119 27959 : new_decl = copy_node (old_decl);
1120 :
1121 : /* Generate a new name for the new version. */
1122 57453 : tree fnname = (version_decl ? clone_function_name_numbered (old_decl, suffix)
1123 139 : : clone_function_name (old_decl, suffix));
1124 57453 : DECL_NAME (new_decl) = fnname;
1125 57453 : SET_DECL_ASSEMBLER_NAME (new_decl, fnname);
1126 57453 : SET_DECL_RTL (new_decl, NULL);
1127 :
1128 57453 : DECL_VIRTUAL_P (new_decl) = 0;
1129 :
1130 57453 : if (target_attributes)
1131 : {
1132 139 : DECL_ATTRIBUTES (new_decl) = target_attributes;
1133 :
1134 139 : location_t saved_loc = input_location;
1135 139 : tree v = TREE_VALUE (target_attributes);
1136 139 : input_location = DECL_SOURCE_LOCATION (new_decl);
1137 139 : bool r;
1138 139 : tree name_id = get_attribute_name (target_attributes);
1139 139 : const char *name_str = IDENTIFIER_POINTER (name_id);
1140 139 : if (strcmp (name_str, "target") == 0)
1141 139 : r = targetm.target_option.valid_attribute_p (new_decl, name_id, v, 1);
1142 0 : else if (strcmp (name_str, "target_version") == 0)
1143 0 : r = targetm.target_option.valid_version_attribute_p (new_decl, name_id,
1144 : v, 1);
1145 : else
1146 0 : gcc_unreachable();
1147 :
1148 139 : input_location = saved_loc;
1149 139 : if (!r)
1150 : return NULL;
1151 : }
1152 :
1153 : /* When the old decl was a con-/destructor make sure the clone isn't. */
1154 57452 : DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
1155 57452 : DECL_STATIC_DESTRUCTOR (new_decl) = 0;
1156 57452 : DECL_SET_IS_OPERATOR_NEW (new_decl, 0);
1157 57452 : DECL_SET_IS_OPERATOR_DELETE (new_decl, 0);
1158 57452 : DECL_IS_REPLACEABLE_OPERATOR (new_decl) = 0;
1159 :
1160 : /* Create the new version's call-graph node.
1161 : and update the edges of the new node. */
1162 57452 : new_version_node = create_version_clone (new_decl, redirect_callers,
1163 : bbs_to_copy, suffix);
1164 :
1165 57452 : if (ipa_transforms_to_apply.exists ())
1166 0 : new_version_node->ipa_transforms_to_apply
1167 0 : = ipa_transforms_to_apply.copy ();
1168 : /* Copy the OLD_VERSION_NODE function tree to the new version. */
1169 57452 : tree_function_versioning (old_decl, new_decl, tree_map, param_adjustments,
1170 : false, bbs_to_copy, new_entry_block);
1171 :
1172 : /* Update the new version's properties.
1173 : Make The new version visible only within this translation unit. Make sure
1174 : that is not weak also.
1175 : ??? We cannot use COMDAT linkage because there is no
1176 : ABI support for this. */
1177 57452 : new_version_node->make_decl_local ();
1178 57452 : DECL_VIRTUAL_P (new_version_node->decl) = 0;
1179 57452 : new_version_node->externally_visible = 0;
1180 57452 : new_version_node->local = 1;
1181 57452 : new_version_node->lowered = true;
1182 57452 : if (!implicit_section)
1183 57436 : new_version_node->set_section (*this);
1184 : /* Clones of global symbols or symbols with unique names are unique. */
1185 57452 : if ((TREE_PUBLIC (old_decl)
1186 53735 : && !DECL_EXTERNAL (old_decl)
1187 44118 : && !DECL_WEAK (old_decl)
1188 13309 : && !DECL_COMDAT (old_decl))
1189 97878 : || in_lto_p)
1190 13350 : new_version_node->unique_name = true;
1191 :
1192 : /* Update the call_expr on the edges to call the new version node. */
1193 57452 : update_call_expr (new_version_node);
1194 :
1195 57452 : symtab->call_cgraph_insertion_hooks (new_version_node);
1196 57452 : return new_version_node;
1197 : }
1198 :
1199 : /* Remove the node from the tree of virtual and inline clones and make it a
1200 : standalone node - not a clone any more. */
1201 :
1202 143218 : void cgraph_node::remove_from_clone_tree ()
1203 : {
1204 143218 : if (next_sibling_clone)
1205 1101 : next_sibling_clone->prev_sibling_clone = prev_sibling_clone;
1206 143218 : if (prev_sibling_clone)
1207 1743 : prev_sibling_clone->next_sibling_clone = next_sibling_clone;
1208 : else
1209 141475 : clone_of->clones = next_sibling_clone;
1210 143218 : next_sibling_clone = NULL;
1211 143218 : prev_sibling_clone = NULL;
1212 143218 : clone_of = NULL;
1213 143218 : }
1214 :
1215 : /* Given virtual clone, turn it into actual clone. */
1216 :
1217 : void
1218 143218 : cgraph_node::materialize_clone ()
1219 : {
1220 143218 : clone_info *info = clone_info::get (this);
1221 143218 : clone_of->get_untransformed_body ();
1222 143218 : former_clone_of = clone_of->decl;
1223 143218 : if (clone_of->former_clone_of)
1224 4610 : former_clone_of = clone_of->former_clone_of;
1225 143218 : if (symtab->dump_file)
1226 : {
1227 0 : fprintf (symtab->dump_file, "cloning %s to %s\n",
1228 0 : clone_of->dump_name (),
1229 : dump_name ());
1230 0 : if (info && info->tree_map)
1231 : {
1232 0 : fprintf (symtab->dump_file, " replace map:");
1233 0 : for (unsigned int i = 0;
1234 0 : i < vec_safe_length (info->tree_map);
1235 : i++)
1236 : {
1237 0 : ipa_replace_map *replace_info;
1238 0 : replace_info = (*info->tree_map)[i];
1239 0 : fprintf (symtab->dump_file, "%s %i -> ",
1240 : i ? "," : "", replace_info->parm_num);
1241 0 : print_generic_expr (symtab->dump_file,
1242 : replace_info->new_tree);
1243 : }
1244 0 : fprintf (symtab->dump_file, "\n");
1245 : }
1246 0 : if (info && info->param_adjustments)
1247 0 : info->param_adjustments->dump (symtab->dump_file);
1248 : }
1249 143218 : clear_stmts_in_references ();
1250 : /* Copy the OLD_VERSION_NODE function tree to the new version. */
1251 143218 : tree_function_versioning (clone_of->decl, decl,
1252 : info ? info->tree_map : NULL,
1253 : info ? info->param_adjustments : NULL,
1254 : true, NULL, NULL);
1255 143218 : if (symtab->dump_file)
1256 : {
1257 0 : dump_function_to_file (clone_of->decl, symtab->dump_file,
1258 : dump_flags);
1259 0 : dump_function_to_file (decl, symtab->dump_file, dump_flags);
1260 : }
1261 :
1262 143218 : cgraph_node *this_clone_of = clone_of;
1263 : /* Function is no longer clone. */
1264 143218 : remove_from_clone_tree ();
1265 143218 : if (!this_clone_of->analyzed && !this_clone_of->clones)
1266 139004 : this_clone_of->release_body ();
1267 143218 : }
1268 :
1269 : #include "gt-cgraphclones.h"
|