re PR tree-optimization/64454 (optimize (x%5)%5)
[official-gcc.git] / gcc / lto / lto-symtab.c
blob396d3e27f2320a47f0ac6941024a3eca3594726d
1 /* LTO symbol table.
2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, Inc.
5 This file is part of GCC.
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.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "diagnostic-core.h"
25 #include "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "options.h"
33 #include "wide-int.h"
34 #include "inchash.h"
35 #include "tree.h"
36 #include "fold-const.h"
37 #include "predict.h"
38 #include "tm.h"
39 #include "hard-reg-set.h"
40 #include "input.h"
41 #include "function.h"
42 #include "basic-block.h"
43 #include "tree-ssa-alias.h"
44 #include "internal-fn.h"
45 #include "gimple-expr.h"
46 #include "is-a.h"
47 #include "gimple.h"
48 #include "plugin-api.h"
49 #include "hash-map.h"
50 #include "ipa-ref.h"
51 #include "cgraph.h"
52 #include "lto-streamer.h"
53 #include "ipa-utils.h"
54 #include "alloc-pool.h"
55 #include "symbol-summary.h"
56 #include "ipa-prop.h"
57 #include "ipa-inline.h"
58 #include "builtins.h"
60 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
61 all edges and removing the old node. */
63 static void
64 lto_cgraph_replace_node (struct cgraph_node *node,
65 struct cgraph_node *prevailing_node)
67 struct cgraph_edge *e, *next;
68 bool compatible_p;
70 if (symtab->dump_file)
72 fprintf (symtab->dump_file, "Replacing cgraph node %s/%i by %s/%i"
73 " for symbol %s\n",
74 node->name (), node->order,
75 prevailing_node->name (),
76 prevailing_node->order,
77 IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name)
78 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)))));
81 /* Merge node flags. */
82 if (node->force_output)
83 prevailing_node->mark_force_output ();
84 if (node->forced_by_abi)
85 prevailing_node->forced_by_abi = true;
86 if (node->address_taken)
88 gcc_assert (!prevailing_node->global.inlined_to);
89 prevailing_node->mark_address_taken ();
91 if (node->definition && prevailing_node->definition)
92 prevailing_node->merged = true;
94 /* Redirect all incoming edges. */
95 compatible_p
96 = types_compatible_p (TREE_TYPE (TREE_TYPE (prevailing_node->decl)),
97 TREE_TYPE (TREE_TYPE (node->decl)));
98 for (e = node->callers; e; e = next)
100 next = e->next_caller;
101 e->redirect_callee (prevailing_node);
102 /* If there is a mismatch between the supposed callee return type and
103 the real one do not attempt to inline this function.
104 ??? We really need a way to match function signatures for ABI
105 compatibility and perform related promotions at inlining time. */
106 if (!compatible_p)
107 e->call_stmt_cannot_inline_p = 1;
109 /* Redirect incomming references. */
110 prevailing_node->clone_referring (node);
112 /* Fix instrumentation references. */
113 if (node->instrumented_version)
115 gcc_assert (node->instrumentation_clone
116 == prevailing_node->instrumentation_clone);
117 node->instrumented_version->instrumented_version = prevailing_node;
118 if (!prevailing_node->instrumented_version)
119 prevailing_node->instrumented_version = node->instrumented_version;
120 /* Need to reset node->instrumented_version to NULL,
121 otherwise node removal code would reset
122 node->instrumented_version->instrumented_version. */
123 node->instrumented_version = NULL;
126 ipa_merge_profiles (prevailing_node, node);
127 lto_free_function_in_decl_state_for_node (node);
129 if (node->decl != prevailing_node->decl)
130 node->release_body ();
132 /* Finally remove the replaced node. */
133 node->remove ();
136 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
137 all edges and removing the old node. */
139 static void
140 lto_varpool_replace_node (varpool_node *vnode,
141 varpool_node *prevailing_node)
143 gcc_assert (!vnode->definition || prevailing_node->definition);
144 gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
146 prevailing_node->clone_referring (vnode);
147 if (vnode->force_output)
148 prevailing_node->force_output = true;
149 if (vnode->forced_by_abi)
150 prevailing_node->forced_by_abi = true;
152 /* Be sure we can garbage collect the initializer. */
153 if (DECL_INITIAL (vnode->decl)
154 && vnode->decl != prevailing_node->decl)
155 DECL_INITIAL (vnode->decl) = error_mark_node;
157 /* Check and report ODR violations on virtual tables. */
158 if (DECL_VIRTUAL_P (vnode->decl) || DECL_VIRTUAL_P (prevailing_node->decl))
159 compare_virtual_tables (prevailing_node, vnode);
161 if (vnode->tls_model != prevailing_node->tls_model)
163 bool error = false;
165 /* Non-TLS and TLS never mix together. Also emulated model is not
166 compatible with anything else. */
167 if (prevailing_node->tls_model == TLS_MODEL_NONE
168 || prevailing_node->tls_model == TLS_MODEL_EMULATED
169 || vnode->tls_model == TLS_MODEL_NONE
170 || vnode->tls_model == TLS_MODEL_EMULATED)
171 error = true;
172 /* Linked is silently supporting transitions
173 GD -> IE, GD -> LE, LD -> LE, IE -> LE, LD -> IE.
174 Do the same transitions and error out on others. */
175 else if ((prevailing_node->tls_model == TLS_MODEL_REAL
176 || prevailing_node->tls_model == TLS_MODEL_LOCAL_DYNAMIC)
177 && (vnode->tls_model == TLS_MODEL_INITIAL_EXEC
178 || vnode->tls_model == TLS_MODEL_LOCAL_EXEC))
179 prevailing_node->tls_model = vnode->tls_model;
180 else if ((vnode->tls_model == TLS_MODEL_REAL
181 || vnode->tls_model == TLS_MODEL_LOCAL_DYNAMIC)
182 && (prevailing_node->tls_model == TLS_MODEL_INITIAL_EXEC
183 || prevailing_node->tls_model == TLS_MODEL_LOCAL_EXEC))
185 else if (prevailing_node->tls_model == TLS_MODEL_INITIAL_EXEC
186 && vnode->tls_model == TLS_MODEL_LOCAL_EXEC)
187 prevailing_node->tls_model = vnode->tls_model;
188 else if (vnode->tls_model == TLS_MODEL_INITIAL_EXEC
189 && prevailing_node->tls_model == TLS_MODEL_LOCAL_EXEC)
191 else
192 error = true;
193 if (error)
195 error_at (DECL_SOURCE_LOCATION (vnode->decl),
196 "%qD is defined with tls model %s", vnode->decl, tls_model_names [vnode->tls_model]);
197 inform (DECL_SOURCE_LOCATION (prevailing_node->decl),
198 "previously defined here as %s",
199 tls_model_names [prevailing_node->tls_model]);
202 /* Finally remove the replaced node. */
203 vnode->remove ();
206 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
207 Return false if the symbols are not fully compatible and a diagnostic
208 should be emitted. */
210 static bool
211 lto_symtab_merge (symtab_node *prevailing, symtab_node *entry)
213 tree prevailing_decl = prevailing->decl;
214 tree decl = entry->decl;
215 tree prevailing_type, type;
217 if (prevailing_decl == decl)
218 return true;
220 /* Merge decl state in both directions, we may still end up using
221 the new decl. */
222 TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
223 TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
225 /* The linker may ask us to combine two incompatible symbols.
226 Detect this case and notify the caller of required diagnostics. */
228 if (TREE_CODE (decl) == FUNCTION_DECL)
230 if (!types_compatible_p (TREE_TYPE (prevailing_decl),
231 TREE_TYPE (decl)))
232 /* If we don't have a merged type yet...sigh. The linker
233 wouldn't complain if the types were mismatched, so we
234 probably shouldn't either. Just use the type from
235 whichever decl appears to be associated with the
236 definition. If for some odd reason neither decl is, the
237 older one wins. */
238 (void) 0;
240 return true;
243 /* Now we exclusively deal with VAR_DECLs. */
245 /* Sharing a global symbol is a strong hint that two types are
246 compatible. We could use this information to complete
247 incomplete pointed-to types more aggressively here, ignoring
248 mismatches in both field and tag names. It's difficult though
249 to guarantee that this does not have side-effects on merging
250 more compatible types from other translation units though. */
252 /* We can tolerate differences in type qualification, the
253 qualification of the prevailing definition will prevail.
254 ??? In principle we might want to only warn for structurally
255 incompatible types here, but unless we have protective measures
256 for TBAA in place that would hide useful information. */
257 prevailing_type = TYPE_MAIN_VARIANT (TREE_TYPE (prevailing_decl));
258 type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
260 if (!types_compatible_p (prevailing_type, type))
262 if (COMPLETE_TYPE_P (type))
263 return false;
265 /* If type is incomplete then avoid warnings in the cases
266 that TBAA handles just fine. */
268 if (TREE_CODE (prevailing_type) != TREE_CODE (type))
269 return false;
271 if (TREE_CODE (prevailing_type) == ARRAY_TYPE)
273 tree tem1 = TREE_TYPE (prevailing_type);
274 tree tem2 = TREE_TYPE (type);
275 while (TREE_CODE (tem1) == ARRAY_TYPE
276 && TREE_CODE (tem2) == ARRAY_TYPE)
278 tem1 = TREE_TYPE (tem1);
279 tem2 = TREE_TYPE (tem2);
282 if (TREE_CODE (tem1) != TREE_CODE (tem2))
283 return false;
285 if (!types_compatible_p (tem1, tem2))
286 return false;
289 /* Fallthru. Compatible enough. */
292 /* ??? We might want to emit a warning here if type qualification
293 differences were spotted. Do not do this unconditionally though. */
295 /* There is no point in comparing too many details of the decls here.
296 The type compatibility checks or the completing of types has properly
297 dealt with most issues. */
299 /* The following should all not invoke fatal errors as in non-LTO
300 mode the linker wouldn't complain either. Just emit warnings. */
302 /* Report a warning if user-specified alignments do not match. */
303 if ((DECL_USER_ALIGN (prevailing_decl) && DECL_USER_ALIGN (decl))
304 && DECL_ALIGN (prevailing_decl) < DECL_ALIGN (decl))
305 return false;
307 return true;
310 /* Return true if the symtab entry E can be replaced by another symtab
311 entry. */
313 static bool
314 lto_symtab_resolve_replaceable_p (symtab_node *e)
316 if (DECL_EXTERNAL (e->decl)
317 || DECL_COMDAT (e->decl)
318 || DECL_ONE_ONLY (e->decl)
319 || DECL_WEAK (e->decl))
320 return true;
322 if (TREE_CODE (e->decl) == VAR_DECL)
323 return (DECL_COMMON (e->decl)
324 || (!flag_no_common && !DECL_INITIAL (e->decl)));
326 return false;
329 /* Return true, if the symbol E should be resolved by lto-symtab.
330 Those are all external symbols and all real symbols that are not static (we
331 handle renaming of static later in partitioning). */
333 static bool
334 lto_symtab_symbol_p (symtab_node *e)
336 if (!TREE_PUBLIC (e->decl) && !DECL_EXTERNAL (e->decl))
337 return false;
338 return e->real_symbol_p ();
341 /* Return true if the symtab entry E can be the prevailing one. */
343 static bool
344 lto_symtab_resolve_can_prevail_p (symtab_node *e)
346 if (!lto_symtab_symbol_p (e))
347 return false;
349 /* The C++ frontend ends up neither setting TREE_STATIC nor
350 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
351 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
352 if (DECL_EXTERNAL (e->decl))
353 return false;
355 return e->definition;
358 /* Resolve the symbol with the candidates in the chain *SLOT and store
359 their resolutions. */
361 static symtab_node *
362 lto_symtab_resolve_symbols (symtab_node *first)
364 symtab_node *e;
365 symtab_node *prevailing = NULL;
367 /* Always set e->node so that edges are updated to reflect decl merging. */
368 for (e = first; e; e = e->next_sharing_asm_name)
369 if (lto_symtab_symbol_p (e)
370 && (e->resolution == LDPR_PREVAILING_DEF_IRONLY
371 || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
372 || e->resolution == LDPR_PREVAILING_DEF))
374 prevailing = e;
375 break;
378 /* If the chain is already resolved there is nothing else to do. */
379 if (prevailing)
381 /* Assert it's the only one. */
382 for (e = prevailing->next_sharing_asm_name; e; e = e->next_sharing_asm_name)
383 if (lto_symtab_symbol_p (e)
384 && (e->resolution == LDPR_PREVAILING_DEF_IRONLY
385 || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
386 || e->resolution == LDPR_PREVAILING_DEF))
387 fatal_error (input_location, "multiple prevailing defs for %qE",
388 DECL_NAME (prevailing->decl));
389 return prevailing;
392 /* Find the single non-replaceable prevailing symbol and
393 diagnose ODR violations. */
394 for (e = first; e; e = e->next_sharing_asm_name)
396 if (!lto_symtab_resolve_can_prevail_p (e))
397 continue;
399 /* If we have a non-replaceable definition it prevails. */
400 if (!lto_symtab_resolve_replaceable_p (e))
402 if (prevailing)
404 error_at (DECL_SOURCE_LOCATION (e->decl),
405 "%qD has already been defined", e->decl);
406 inform (DECL_SOURCE_LOCATION (prevailing->decl),
407 "previously defined here");
409 prevailing = e;
412 if (prevailing)
413 return prevailing;
415 /* Do a second round choosing one from the replaceable prevailing decls. */
416 for (e = first; e; e = e->next_sharing_asm_name)
418 if (!lto_symtab_resolve_can_prevail_p (e))
419 continue;
421 /* Choose the first function that can prevail as prevailing. */
422 if (TREE_CODE (e->decl) == FUNCTION_DECL)
424 prevailing = e;
425 break;
428 /* From variables that can prevail choose the largest one. */
429 if (!prevailing
430 || tree_int_cst_lt (DECL_SIZE (prevailing->decl),
431 DECL_SIZE (e->decl))
432 /* When variables are equivalent try to chose one that has useful
433 DECL_INITIAL. This makes sense for keyed vtables that are
434 DECL_EXTERNAL but initialized. In units that do not need them
435 we replace the initializer by error_mark_node to conserve
436 memory.
438 We know that the vtable is keyed outside the LTO unit - otherwise
439 the keyed instance would prevail. We still can preserve useful
440 info in the initializer. */
441 || (DECL_SIZE (prevailing->decl) == DECL_SIZE (e->decl)
442 && (DECL_INITIAL (e->decl)
443 && DECL_INITIAL (e->decl) != error_mark_node)
444 && (!DECL_INITIAL (prevailing->decl)
445 || DECL_INITIAL (prevailing->decl) == error_mark_node)))
446 prevailing = e;
449 return prevailing;
452 /* Merge all decls in the symbol table chain to the prevailing decl and
453 issue diagnostics about type mismatches. If DIAGNOSED_P is true
454 do not issue further diagnostics.*/
456 static void
457 lto_symtab_merge_decls_2 (symtab_node *first, bool diagnosed_p)
459 symtab_node *prevailing;
460 symtab_node *e;
461 vec<tree> mismatches = vNULL;
462 unsigned i;
463 tree decl;
465 /* Nothing to do for a single entry. */
466 prevailing = first;
467 if (!prevailing->next_sharing_asm_name)
468 return;
470 /* Try to merge each entry with the prevailing one. */
471 for (e = prevailing->next_sharing_asm_name;
472 e; e = e->next_sharing_asm_name)
473 if (TREE_PUBLIC (e->decl))
475 if (!lto_symtab_merge (prevailing, e)
476 && !diagnosed_p
477 && !DECL_ARTIFICIAL (e->decl))
478 mismatches.safe_push (e->decl);
480 if (mismatches.is_empty ())
481 return;
483 /* Diagnose all mismatched re-declarations. */
484 FOR_EACH_VEC_ELT (mismatches, i, decl)
486 if (!types_compatible_p (TREE_TYPE (prevailing->decl),
487 TREE_TYPE (decl)))
488 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
489 "type of %qD does not match original "
490 "declaration", decl);
492 else if ((DECL_USER_ALIGN (prevailing->decl)
493 && DECL_USER_ALIGN (decl))
494 && DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
496 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
497 "alignment of %qD is bigger than "
498 "original declaration", decl);
501 if (diagnosed_p)
502 inform (DECL_SOURCE_LOCATION (prevailing->decl),
503 "previously declared here");
505 mismatches.release ();
508 /* Helper to process the decl chain for the symbol table entry *SLOT. */
510 static void
511 lto_symtab_merge_decls_1 (symtab_node *first)
513 symtab_node *e;
514 symtab_node *prevailing;
515 bool diagnosed_p = false;
517 if (symtab->dump_file)
519 fprintf (symtab->dump_file, "Merging nodes for %s. Candidates:\n",
520 first->asm_name ());
521 for (e = first; e; e = e->next_sharing_asm_name)
522 if (TREE_PUBLIC (e->decl))
523 e->dump (symtab->dump_file);
526 /* Compute the symbol resolutions. This is a no-op when using the
527 linker plugin and resolution was decided by the linker. */
528 prevailing = lto_symtab_resolve_symbols (first);
530 /* If there's not a prevailing symbol yet it's an external reference.
531 Happens a lot during ltrans. Choose the first symbol with a
532 cgraph or a varpool node. */
533 if (!prevailing)
535 for (prevailing = first;
536 prevailing; prevailing = prevailing->next_sharing_asm_name)
537 if (lto_symtab_symbol_p (prevailing))
538 break;
539 if (!prevailing)
540 return;
541 /* For variables chose with a priority variant with vnode
542 attached (i.e. from unit where external declaration of
543 variable is actually used).
544 When there are multiple variants, chose one with size.
545 This is needed for C++ typeinfos, for example in
546 lto/20081204-1 there are typeifos in both units, just
547 one of them do have size. */
548 if (TREE_CODE (prevailing->decl) == VAR_DECL)
550 for (e = prevailing->next_sharing_asm_name;
551 e; e = e->next_sharing_asm_name)
552 if (!COMPLETE_TYPE_P (TREE_TYPE (prevailing->decl))
553 && COMPLETE_TYPE_P (TREE_TYPE (e->decl))
554 && lto_symtab_symbol_p (e))
555 prevailing = e;
557 /* For variables prefer the non-builtin if one is available. */
558 else if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
560 for (e = first; e; e = e->next_sharing_asm_name)
561 if (TREE_CODE (e->decl) == FUNCTION_DECL
562 && !DECL_BUILT_IN (e->decl)
563 && lto_symtab_symbol_p (e))
565 prevailing = e;
566 break;
571 symtab->symtab_prevail_in_asm_name_hash (prevailing);
573 /* Diagnose mismatched objects. */
574 for (e = prevailing->next_sharing_asm_name;
575 e; e = e->next_sharing_asm_name)
577 if (TREE_CODE (prevailing->decl)
578 == TREE_CODE (e->decl))
579 continue;
580 if (!lto_symtab_symbol_p (e))
581 continue;
583 switch (TREE_CODE (prevailing->decl))
585 case VAR_DECL:
586 gcc_assert (TREE_CODE (e->decl) == FUNCTION_DECL);
587 error_at (DECL_SOURCE_LOCATION (e->decl),
588 "variable %qD redeclared as function",
589 prevailing->decl);
590 break;
592 case FUNCTION_DECL:
593 gcc_assert (TREE_CODE (e->decl) == VAR_DECL);
594 error_at (DECL_SOURCE_LOCATION (e->decl),
595 "function %qD redeclared as variable",
596 prevailing->decl);
597 break;
599 default:
600 gcc_unreachable ();
603 diagnosed_p = true;
605 if (diagnosed_p)
606 inform (DECL_SOURCE_LOCATION (prevailing->decl),
607 "previously declared here");
609 /* Merge the chain to the single prevailing decl and diagnose
610 mismatches. */
611 lto_symtab_merge_decls_2 (prevailing, diagnosed_p);
613 if (symtab->dump_file)
615 fprintf (symtab->dump_file, "After resolution:\n");
616 for (e = prevailing; e; e = e->next_sharing_asm_name)
617 e->dump (symtab->dump_file);
621 /* Resolve and merge all symbol table chains to a prevailing decl. */
623 void
624 lto_symtab_merge_decls (void)
626 symtab_node *node;
628 /* Populate assembler name hash. */
629 symtab->symtab_initialize_asm_name_hash ();
631 FOR_EACH_SYMBOL (node)
632 if (!node->previous_sharing_asm_name
633 && node->next_sharing_asm_name)
634 lto_symtab_merge_decls_1 (node);
637 /* Helper to process the decl chain for the symbol table entry *SLOT. */
639 static void
640 lto_symtab_merge_symbols_1 (symtab_node *prevailing)
642 symtab_node *e;
643 symtab_node *next;
645 /* Replace the cgraph node of each entry with the prevailing one. */
646 for (e = prevailing->next_sharing_asm_name; e;
647 e = next)
649 next = e->next_sharing_asm_name;
651 if (!lto_symtab_symbol_p (e))
652 continue;
653 cgraph_node *ce = dyn_cast <cgraph_node *> (e);
654 if (ce && !DECL_BUILT_IN (e->decl))
655 lto_cgraph_replace_node (ce, dyn_cast<cgraph_node *> (prevailing));
656 if (varpool_node *ve = dyn_cast <varpool_node *> (e))
657 lto_varpool_replace_node (ve, dyn_cast<varpool_node *> (prevailing));
660 return;
663 /* Merge cgraph nodes according to the symbol merging done by
664 lto_symtab_merge_decls. */
666 void
667 lto_symtab_merge_symbols (void)
669 symtab_node *node;
671 if (!flag_ltrans)
673 symtab->symtab_initialize_asm_name_hash ();
675 /* Do the actual merging.
676 At this point we invalidate hash translating decls into symtab nodes
677 because after removing one of duplicate decls the hash is not correcly
678 updated to the ohter dupliate. */
679 FOR_EACH_SYMBOL (node)
680 if (lto_symtab_symbol_p (node)
681 && node->next_sharing_asm_name
682 && !node->previous_sharing_asm_name)
683 lto_symtab_merge_symbols_1 (node);
685 /* Resolve weakref aliases whose target are now in the compilation unit.
686 also re-populate the hash translating decls into symtab nodes*/
687 FOR_EACH_SYMBOL (node)
689 cgraph_node *cnode, *cnode2;
690 varpool_node *vnode;
691 symtab_node *node2;
693 if (!node->analyzed && node->alias_target)
695 symtab_node *tgt = symtab_node::get_for_asmname (node->alias_target);
696 gcc_assert (node->weakref);
697 if (tgt)
698 node->resolve_alias (tgt);
700 node->aux = NULL;
702 if (!(cnode = dyn_cast <cgraph_node *> (node))
703 || !cnode->clone_of
704 || cnode->clone_of->decl != cnode->decl)
706 /* Builtins are not merged via decl merging. It is however
707 possible that tree merging unified the declaration. We
708 do not want duplicate entries in symbol table. */
709 if (cnode && DECL_BUILT_IN (node->decl)
710 && (cnode2 = cgraph_node::get (node->decl))
711 && cnode2 != cnode)
712 lto_cgraph_replace_node (cnode2, cnode);
714 /* The user defined assembler variables are also not unified by their
715 symbol name (since it is irrelevant), but we need to unify symbol
716 nodes if tree merging occured. */
717 if ((vnode = dyn_cast <varpool_node *> (node))
718 && DECL_HARD_REGISTER (vnode->decl)
719 && (node2 = symtab_node::get (vnode->decl))
720 && node2 != node)
721 lto_varpool_replace_node (dyn_cast <varpool_node *> (node2),
722 vnode);
725 /* Abstract functions may have duplicated cgraph nodes attached;
726 remove them. */
727 else if (cnode && DECL_ABSTRACT_P (cnode->decl)
728 && (cnode2 = cgraph_node::get (node->decl))
729 && cnode2 != cnode)
730 cnode2->remove ();
732 node->decl->decl_with_vis.symtab_node = node;
738 /* Given the decl DECL, return the prevailing decl with the same name. */
740 tree
741 lto_symtab_prevailing_decl (tree decl)
743 symtab_node *ret;
745 /* Builtins and local symbols are their own prevailing decl. */
746 if ((!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) || is_builtin_fn (decl))
747 return decl;
749 /* DECL_ABSTRACT_Ps are their own prevailing decl. */
750 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT_P (decl))
751 return decl;
753 /* Likewise builtins are their own prevailing decl. This preserves
754 non-builtin vs. builtin uses from compile-time. */
755 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
756 return decl;
758 /* Ensure DECL_ASSEMBLER_NAME will not set assembler name. */
759 gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
761 /* Walk through the list of candidates and return the one we merged to. */
762 ret = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (decl));
763 if (!ret)
764 return decl;
766 return ret->decl;