Implement TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS hook.
[official-gcc.git] / gcc / ipa-visibility.c
blob08f8bef4b0842f6618077c2e3a975d63d6d6b85a
1 /* IPA visibility pass
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file implements two related passes:
22 - pass_data_ipa_function_and_variable_visibility run just after
23 symbol table, references and callgraph are built
25 - pass_data_ipa_function_and_variable_visibility run as first
26 proper IPA pass (that is after early optimization, or, (with LTO)
27 as a first pass done at link-time.
29 Purpose of both passes is to set correctly visibility properties
30 of all symbols. This includes:
32 - Symbol privatization:
34 Some symbols that are declared public by frontend may be
35 turned local (either by -fwhole-program flag, by linker plugin feedback
36 or by other reasons)
38 - Discovery of local functions:
40 A local function is one whose calls can occur only in the current
41 compilation unit and all its calls are explicit, so we can change
42 its calling convention. We simply mark all static functions whose
43 address is not taken as local.
45 externally_visible flag is set for symbols that can not be privatized.
46 For privatized symbols we clear TREE_PUBLIC flag and dismantle comdat
47 group.
49 - Dismantling of comdat groups:
51 Comdat group represent a section that may be replaced by linker by
52 a different copy of the same section from other unit.
53 If we have resolution information (from linker plugin) and we know that
54 a given comdat gorup is prevailing, we can dismantle it and turn symbols
55 into normal symbols. If the resolution information says that the
56 section was previaled by copy from non-LTO code, we can also dismantle
57 it and turn all symbols into external.
59 - Local aliases:
61 Some symbols can be interposed by dynamic linker. Refering to these
62 symbols is expensive, since it needs to be overwritable by the dynamic
63 linker. In some cases we know that the interposition does not change
64 semantic and we can always refer to a local copy (as in the case of
65 inline function). In this case we produce a local alias and redirect
66 calls to it.
68 TODO: This should be done for references, too.
70 - Removal of static ocnstructors and destructors that have no side effects.
72 - Regularization of several oddities introduced by frontends that may
73 be impractical later in the optimization queue. */
75 #include "config.h"
76 #include "system.h"
77 #include "coretypes.h"
78 #include "tm.h"
79 #include "input.h"
80 #include "alias.h"
81 #include "symtab.h"
82 #include "tree.h"
83 #include "is-a.h"
84 #include "plugin-api.h"
85 #include "hard-reg-set.h"
86 #include "input.h"
87 #include "function.h"
88 #include "ipa-ref.h"
89 #include "cgraph.h"
90 #include "tree-pass.h"
91 #include "calls.h"
92 #include "gimple-expr.h"
93 #include "varasm.h"
95 /* Return true when NODE can not be local. Worker for cgraph_local_node_p. */
97 static bool
98 non_local_p (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
100 return !(node->only_called_directly_or_aliased_p ()
101 /* i386 would need update to output thunk with locak calling
102 ocnvetions. */
103 && !node->thunk.thunk_p
104 && node->definition
105 && !DECL_EXTERNAL (node->decl)
106 && !node->externally_visible
107 && !node->used_from_other_partition
108 && !node->in_other_partition);
111 /* Return true when function can be marked local. */
113 bool
114 cgraph_node::local_p (void)
116 cgraph_node *n = ultimate_alias_target ();
118 if (n->thunk.thunk_p)
119 return n->callees->callee->local_p ();
120 return !n->call_for_symbol_thunks_and_aliases (non_local_p,
121 NULL, true);
125 /* A helper for comdat_can_be_unshared_p. */
127 static bool
128 comdat_can_be_unshared_p_1 (symtab_node *node)
130 if (!node->externally_visible)
131 return true;
132 if (node->address_can_be_compared_p ())
134 struct ipa_ref *ref;
136 for (unsigned int i = 0; node->iterate_referring (i, ref); i++)
137 if (ref->address_matters_p ())
138 return false;
141 /* If the symbol is used in some weird way, better to not touch it. */
142 if (node->force_output)
143 return false;
145 /* Explicit instantiations needs to be output when possibly
146 used externally. */
147 if (node->forced_by_abi
148 && TREE_PUBLIC (node->decl)
149 && (node->resolution != LDPR_PREVAILING_DEF_IRONLY
150 && !flag_whole_program))
151 return false;
153 /* Non-readonly and volatile variables can not be duplicated. */
154 if (is_a <varpool_node *> (node)
155 && (!TREE_READONLY (node->decl)
156 || TREE_THIS_VOLATILE (node->decl)))
157 return false;
158 return true;
161 /* COMDAT functions must be shared only if they have address taken,
162 otherwise we can produce our own private implementation with
163 -fwhole-program.
164 Return true when turning COMDAT functoin static can not lead to wrong
165 code when the resulting object links with a library defining same COMDAT.
167 Virtual functions do have their addresses taken from the vtables,
168 but in C++ there is no way to compare their addresses for equality. */
170 static bool
171 comdat_can_be_unshared_p (symtab_node *node)
173 if (!comdat_can_be_unshared_p_1 (node))
174 return false;
175 if (node->same_comdat_group)
177 symtab_node *next;
179 /* If more than one function is in the same COMDAT group, it must
180 be shared even if just one function in the comdat group has
181 address taken. */
182 for (next = node->same_comdat_group;
183 next != node; next = next->same_comdat_group)
184 if (!comdat_can_be_unshared_p_1 (next))
185 return false;
187 return true;
190 /* Return true when function NODE should be considered externally visible. */
192 static bool
193 cgraph_externally_visible_p (struct cgraph_node *node,
194 bool whole_program)
196 if (!node->definition)
197 return false;
198 if (!TREE_PUBLIC (node->decl)
199 || DECL_EXTERNAL (node->decl))
200 return false;
202 /* Do not try to localize built-in functions yet. One of problems is that we
203 end up mangling their asm for WHOPR that makes it impossible to call them
204 using the implicit built-in declarations anymore. Similarly this enables
205 us to remove them as unreachable before actual calls may appear during
206 expansion or folding. */
207 if (DECL_BUILT_IN (node->decl))
208 return true;
210 /* If linker counts on us, we must preserve the function. */
211 if (node->used_from_object_file_p ())
212 return true;
213 if (DECL_PRESERVE_P (node->decl))
214 return true;
215 if (lookup_attribute ("externally_visible",
216 DECL_ATTRIBUTES (node->decl)))
217 return true;
218 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
219 && lookup_attribute ("dllexport",
220 DECL_ATTRIBUTES (node->decl)))
221 return true;
222 if (node->resolution == LDPR_PREVAILING_DEF_IRONLY)
223 return false;
224 /* When doing LTO or whole program, we can bring COMDAT functoins static.
225 This improves code quality and we know we will duplicate them at most twice
226 (in the case that we are not using plugin and link with object file
227 implementing same COMDAT) */
228 if ((in_lto_p || whole_program)
229 && DECL_COMDAT (node->decl)
230 && comdat_can_be_unshared_p (node))
231 return false;
233 /* When doing link time optimizations, hidden symbols become local. */
234 if (in_lto_p
235 && (DECL_VISIBILITY (node->decl) == VISIBILITY_HIDDEN
236 || DECL_VISIBILITY (node->decl) == VISIBILITY_INTERNAL)
237 /* Be sure that node is defined in IR file, not in other object
238 file. In that case we don't set used_from_other_object_file. */
239 && node->definition)
241 else if (!whole_program)
242 return true;
244 if (MAIN_NAME_P (DECL_NAME (node->decl)))
245 return true;
247 if (node->instrumentation_clone
248 && MAIN_NAME_P (DECL_NAME (node->orig_decl)))
249 return true;
251 return false;
254 /* Return true when variable should be considered externally visible. */
256 bool
257 varpool_node::externally_visible_p (void)
259 if (DECL_EXTERNAL (decl))
260 return true;
262 if (!TREE_PUBLIC (decl))
263 return false;
265 /* If linker counts on us, we must preserve the function. */
266 if (used_from_object_file_p ())
267 return true;
269 /* Bringing TLS variables local may cause dynamic linker failures
270 on limits of static TLS vars. */
271 if (DECL_THREAD_LOCAL_P (decl)
272 && (DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED
273 && DECL_TLS_MODEL (decl) != TLS_MODEL_INITIAL_EXEC))
274 return true;
276 if (DECL_HARD_REGISTER (decl))
277 return true;
278 if (DECL_PRESERVE_P (decl))
279 return true;
280 if (lookup_attribute ("externally_visible",
281 DECL_ATTRIBUTES (decl)))
282 return true;
283 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
284 && lookup_attribute ("dllexport",
285 DECL_ATTRIBUTES (decl)))
286 return true;
288 /* See if we have linker information about symbol not being used or
289 if we need to make guess based on the declaration.
291 Even if the linker clams the symbol is unused, never bring internal
292 symbols that are declared by user as used or externally visible.
293 This is needed for i.e. references from asm statements. */
294 if (used_from_object_file_p ())
295 return true;
296 if (resolution == LDPR_PREVAILING_DEF_IRONLY)
297 return false;
299 /* As a special case, the COMDAT virtual tables can be unshared.
300 In LTO mode turn vtables into static variables. The variable is readonly,
301 so this does not enable more optimization, but referring static var
302 is faster for dynamic linking. Also this match logic hidding vtables
303 from LTO symbol tables. */
304 if ((in_lto_p || flag_whole_program)
305 && DECL_COMDAT (decl)
306 && comdat_can_be_unshared_p (this))
307 return false;
309 /* When doing link time optimizations, hidden symbols become local. */
310 if (in_lto_p
311 && (DECL_VISIBILITY (decl) == VISIBILITY_HIDDEN
312 || DECL_VISIBILITY (decl) == VISIBILITY_INTERNAL)
313 /* Be sure that node is defined in IR file, not in other object
314 file. In that case we don't set used_from_other_object_file. */
315 && definition)
317 else if (!flag_whole_program)
318 return true;
320 /* Do not attempt to privatize COMDATS by default.
321 This would break linking with C++ libraries sharing
322 inline definitions.
324 FIXME: We can do so for readonly vars with no address taken and
325 possibly also for vtables since no direct pointer comparsion is done.
326 It might be interesting to do so to reduce linking overhead. */
327 if (DECL_COMDAT (decl) || DECL_WEAK (decl))
328 return true;
329 return false;
332 /* Return true if reference to NODE can be replaced by a local alias.
333 Local aliases save dynamic linking overhead and enable more optimizations.
336 bool
337 can_replace_by_local_alias (symtab_node *node)
339 return (node->get_availability () > AVAIL_INTERPOSABLE
340 && !decl_binds_to_current_def_p (node->decl)
341 && !node->can_be_discarded_p ());
344 /* Return true if we can replace refernece to NODE by local alias
345 within a virtual table. Generally we can replace function pointers
346 and virtual table pointers. */
348 bool
349 can_replace_by_local_alias_in_vtable (symtab_node *node)
351 if (is_a <varpool_node *> (node)
352 && !DECL_VIRTUAL_P (node->decl))
353 return false;
354 return can_replace_by_local_alias (node);
357 /* walk_tree callback that rewrites initializer references. */
359 static tree
360 update_vtable_references (tree *tp, int *walk_subtrees,
361 void *data ATTRIBUTE_UNUSED)
363 if (TREE_CODE (*tp) == VAR_DECL
364 || TREE_CODE (*tp) == FUNCTION_DECL)
366 if (can_replace_by_local_alias_in_vtable (symtab_node::get (*tp)))
367 *tp = symtab_node::get (*tp)->noninterposable_alias ()->decl;
368 *walk_subtrees = 0;
370 else if (IS_TYPE_OR_DECL_P (*tp))
371 *walk_subtrees = 0;
372 return NULL;
375 /* In LTO we can remove COMDAT groups and weak symbols.
376 Either turn them into normal symbols or external symbol depending on
377 resolution info. */
379 static void
380 update_visibility_by_resolution_info (symtab_node * node)
382 bool define;
384 if (!node->externally_visible
385 || (!DECL_WEAK (node->decl) && !DECL_ONE_ONLY (node->decl))
386 || node->resolution == LDPR_UNKNOWN)
387 return;
389 define = (node->resolution == LDPR_PREVAILING_DEF_IRONLY
390 || node->resolution == LDPR_PREVAILING_DEF
391 || node->resolution == LDPR_UNDEF
392 || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP);
394 /* The linker decisions ought to agree in the whole group. */
395 if (node->same_comdat_group)
396 for (symtab_node *next = node->same_comdat_group;
397 next != node; next = next->same_comdat_group)
399 if (!next->externally_visible)
400 continue;
402 bool same_def
403 = define == (next->resolution == LDPR_PREVAILING_DEF_IRONLY
404 || next->resolution == LDPR_PREVAILING_DEF
405 || next->resolution == LDPR_UNDEF
406 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP);
407 gcc_assert (in_lto_p || same_def);
408 if (!same_def)
409 return;
412 if (node->same_comdat_group)
413 for (symtab_node *next = node->same_comdat_group;
414 next != node; next = next->same_comdat_group)
416 next->set_comdat_group (NULL);
417 DECL_WEAK (next->decl) = false;
418 if (next->externally_visible
419 && !define)
420 DECL_EXTERNAL (next->decl) = true;
422 node->set_comdat_group (NULL);
423 DECL_WEAK (node->decl) = false;
424 if (!define)
425 DECL_EXTERNAL (node->decl) = true;
426 node->dissolve_same_comdat_group_list ();
429 /* Decide on visibility of all symbols. */
431 static unsigned int
432 function_and_variable_visibility (bool whole_program)
434 struct cgraph_node *node;
435 varpool_node *vnode;
437 /* All aliases should be procssed at this point. */
438 gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
440 FOR_EACH_FUNCTION (node)
442 int flags = flags_from_decl_or_type (node->decl);
444 /* Optimize away PURE and CONST constructors and destructors. */
445 if (optimize
446 && (flags & (ECF_CONST | ECF_PURE))
447 && !(flags & ECF_LOOPING_CONST_OR_PURE))
449 DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
450 DECL_STATIC_DESTRUCTOR (node->decl) = 0;
453 /* Frontends and alias code marks nodes as needed before parsing is finished.
454 We may end up marking as node external nodes where this flag is meaningless
455 strip it. */
456 if (DECL_EXTERNAL (node->decl) || !node->definition)
458 node->force_output = 0;
459 node->forced_by_abi = 0;
462 /* C++ FE on lack of COMDAT support create local COMDAT functions
463 (that ought to be shared but can not due to object format
464 limitations). It is necessary to keep the flag to make rest of C++ FE
465 happy. Clear the flag here to avoid confusion in middle-end. */
466 if (DECL_COMDAT (node->decl) && !TREE_PUBLIC (node->decl))
467 DECL_COMDAT (node->decl) = 0;
469 /* For external decls stop tracking same_comdat_group. It doesn't matter
470 what comdat group they are in when they won't be emitted in this TU. */
471 if (node->same_comdat_group && DECL_EXTERNAL (node->decl))
473 #ifdef ENABLE_CHECKING
474 symtab_node *n;
476 for (n = node->same_comdat_group;
477 n != node;
478 n = n->same_comdat_group)
479 /* If at least one of same comdat group functions is external,
480 all of them have to be, otherwise it is a front-end bug. */
481 gcc_assert (DECL_EXTERNAL (n->decl));
482 #endif
483 node->dissolve_same_comdat_group_list ();
485 gcc_assert ((!DECL_WEAK (node->decl)
486 && !DECL_COMDAT (node->decl))
487 || TREE_PUBLIC (node->decl)
488 || node->weakref
489 || DECL_EXTERNAL (node->decl));
490 if (cgraph_externally_visible_p (node, whole_program))
492 gcc_assert (!node->global.inlined_to);
493 node->externally_visible = true;
495 else
497 node->externally_visible = false;
498 node->forced_by_abi = false;
500 if (!node->externally_visible
501 && node->definition && !node->weakref
502 && !DECL_EXTERNAL (node->decl))
504 gcc_assert (whole_program || in_lto_p
505 || !TREE_PUBLIC (node->decl));
506 node->unique_name = ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
507 || node->unique_name
508 || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
509 && TREE_PUBLIC (node->decl));
510 node->resolution = LDPR_PREVAILING_DEF_IRONLY;
511 if (node->same_comdat_group && TREE_PUBLIC (node->decl))
513 symtab_node *next = node;
515 /* Set all members of comdat group local. */
516 if (node->same_comdat_group)
517 for (next = node->same_comdat_group;
518 next != node;
519 next = next->same_comdat_group)
521 next->set_comdat_group (NULL);
522 if (!next->alias)
523 next->set_section (NULL);
524 next->make_decl_local ();
525 next->unique_name = ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
526 || next->unique_name
527 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
528 && TREE_PUBLIC (next->decl));
530 /* cgraph_externally_visible_p has already checked all other nodes
531 in the group and they will all be made local. We need to
532 dissolve the group at once so that the predicate does not
533 segfault though. */
534 node->dissolve_same_comdat_group_list ();
536 if (TREE_PUBLIC (node->decl))
537 node->set_comdat_group (NULL);
538 if (DECL_COMDAT (node->decl) && !node->alias)
539 node->set_section (NULL);
540 node->make_decl_local ();
543 if (node->thunk.thunk_p
544 && !node->thunk.add_pointer_bounds_args
545 && TREE_PUBLIC (node->decl))
547 struct cgraph_node *decl_node = node;
549 decl_node = decl_node->callees->callee->function_symbol ();
551 /* Thunks have the same visibility as function they are attached to.
552 Make sure the C++ front end set this up properly. */
553 if (DECL_ONE_ONLY (decl_node->decl))
555 gcc_checking_assert (DECL_COMDAT (node->decl)
556 == DECL_COMDAT (decl_node->decl));
557 gcc_checking_assert (node->in_same_comdat_group_p (decl_node));
558 gcc_checking_assert (node->same_comdat_group);
560 node->forced_by_abi = decl_node->forced_by_abi;
561 if (DECL_EXTERNAL (decl_node->decl))
562 DECL_EXTERNAL (node->decl) = 1;
565 update_visibility_by_resolution_info (node);
567 FOR_EACH_DEFINED_FUNCTION (node)
569 if (!node->local.local)
570 node->local.local |= node->local_p ();
572 /* If we know that function can not be overwritten by a different semantics
573 and moreover its section can not be discarded, replace all direct calls
574 by calls to an noninterposable alias. This make dynamic linking
575 cheaper and enable more optimization.
577 TODO: We can also update virtual tables. */
578 if (node->callers
579 && can_replace_by_local_alias (node))
581 cgraph_node *alias = dyn_cast<cgraph_node *>
582 (node->noninterposable_alias ());
584 if (alias && alias != node)
586 while (node->callers)
588 struct cgraph_edge *e = node->callers;
590 e->redirect_callee (alias);
591 if (gimple_has_body_p (e->caller->decl))
593 push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
594 e->redirect_call_stmt_to_callee ();
595 pop_cfun ();
601 FOR_EACH_VARIABLE (vnode)
603 /* weak flag makes no sense on local variables. */
604 gcc_assert (!DECL_WEAK (vnode->decl)
605 || vnode->weakref
606 || TREE_PUBLIC (vnode->decl)
607 || DECL_EXTERNAL (vnode->decl));
608 /* In several cases declarations can not be common:
610 - when declaration has initializer
611 - when it is in weak
612 - when it has specific section
613 - when it resides in non-generic address space.
614 - if declaration is local, it will get into .local common section
615 so common flag is not needed. Frontends still produce these in
616 certain cases, such as for:
618 static int a __attribute__ ((common))
620 Canonicalize things here and clear the redundant flag. */
621 if (DECL_COMMON (vnode->decl)
622 && (!(TREE_PUBLIC (vnode->decl)
623 || DECL_EXTERNAL (vnode->decl))
624 || (DECL_INITIAL (vnode->decl)
625 && DECL_INITIAL (vnode->decl) != error_mark_node)
626 || DECL_WEAK (vnode->decl)
627 || DECL_SECTION_NAME (vnode->decl) != NULL
628 || ! (ADDR_SPACE_GENERIC_P
629 (TYPE_ADDR_SPACE (TREE_TYPE (vnode->decl))))))
630 DECL_COMMON (vnode->decl) = 0;
632 FOR_EACH_DEFINED_VARIABLE (vnode)
634 if (!vnode->definition)
635 continue;
636 if (vnode->externally_visible_p ())
637 vnode->externally_visible = true;
638 else
640 vnode->externally_visible = false;
641 vnode->forced_by_abi = false;
643 if (lookup_attribute ("no_reorder",
644 DECL_ATTRIBUTES (vnode->decl)))
645 vnode->no_reorder = 1;
646 if (!vnode->externally_visible
647 && !vnode->weakref)
649 gcc_assert (in_lto_p || whole_program || !TREE_PUBLIC (vnode->decl));
650 vnode->unique_name = ((vnode->resolution == LDPR_PREVAILING_DEF_IRONLY
651 || vnode->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
652 && TREE_PUBLIC (vnode->decl));
653 if (vnode->same_comdat_group && TREE_PUBLIC (vnode->decl))
655 symtab_node *next = vnode;
657 /* Set all members of comdat group local. */
658 if (vnode->same_comdat_group)
659 for (next = vnode->same_comdat_group;
660 next != vnode;
661 next = next->same_comdat_group)
663 next->set_comdat_group (NULL);
664 if (!next->alias)
665 next->set_section (NULL);
666 next->make_decl_local ();
667 next->unique_name = ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
668 || next->unique_name
669 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
670 && TREE_PUBLIC (next->decl));
672 vnode->dissolve_same_comdat_group_list ();
674 if (TREE_PUBLIC (vnode->decl))
675 vnode->set_comdat_group (NULL);
676 if (DECL_COMDAT (vnode->decl) && !vnode->alias)
677 vnode->set_section (NULL);
678 vnode->make_decl_local ();
679 vnode->resolution = LDPR_PREVAILING_DEF_IRONLY;
681 update_visibility_by_resolution_info (vnode);
683 /* Update virtual tables to point to local aliases where possible. */
684 if (DECL_VIRTUAL_P (vnode->decl)
685 && !DECL_EXTERNAL (vnode->decl))
687 int i;
688 struct ipa_ref *ref;
689 bool found = false;
691 /* See if there is something to update. */
692 for (i = 0; vnode->iterate_referring (i, ref); i++)
693 if (ref->use == IPA_REF_ADDR
694 && can_replace_by_local_alias_in_vtable (ref->referred))
696 found = true;
697 break;
699 if (found)
701 hash_set<tree> visited_nodes;
703 vnode->get_constructor ();
704 walk_tree (&DECL_INITIAL (vnode->decl),
705 update_vtable_references, NULL, &visited_nodes);
706 vnode->remove_all_references ();
707 record_references_in_initializer (vnode->decl, false);
712 if (dump_file)
714 fprintf (dump_file, "\nMarking local functions:");
715 FOR_EACH_DEFINED_FUNCTION (node)
716 if (node->local.local)
717 fprintf (dump_file, " %s", node->name ());
718 fprintf (dump_file, "\n\n");
719 fprintf (dump_file, "\nMarking externally visible functions:");
720 FOR_EACH_DEFINED_FUNCTION (node)
721 if (node->externally_visible)
722 fprintf (dump_file, " %s", node->name ());
723 fprintf (dump_file, "\n\n");
724 fprintf (dump_file, "\nMarking externally visible variables:");
725 FOR_EACH_DEFINED_VARIABLE (vnode)
726 if (vnode->externally_visible)
727 fprintf (dump_file, " %s", vnode->name ());
728 fprintf (dump_file, "\n\n");
730 symtab->function_flags_ready = true;
731 return 0;
734 /* Local function pass handling visibilities. This happens before LTO streaming
735 so in particular -fwhole-program should be ignored at this level. */
737 namespace {
739 const pass_data pass_data_ipa_function_and_variable_visibility =
741 SIMPLE_IPA_PASS, /* type */
742 "visibility", /* name */
743 OPTGROUP_NONE, /* optinfo_flags */
744 TV_CGRAPHOPT, /* tv_id */
745 0, /* properties_required */
746 0, /* properties_provided */
747 0, /* properties_destroyed */
748 0, /* todo_flags_start */
749 ( TODO_remove_functions | TODO_dump_symtab ), /* todo_flags_finish */
752 /* Bring functions local at LTO time with -fwhole-program. */
754 static unsigned int
755 whole_program_function_and_variable_visibility (void)
757 function_and_variable_visibility (flag_whole_program);
758 if (optimize)
759 ipa_discover_readonly_nonaddressable_vars ();
760 return 0;
763 } // anon namespace
765 namespace {
767 const pass_data pass_data_ipa_whole_program_visibility =
769 IPA_PASS, /* type */
770 "whole-program", /* name */
771 OPTGROUP_NONE, /* optinfo_flags */
772 TV_CGRAPHOPT, /* tv_id */
773 0, /* properties_required */
774 0, /* properties_provided */
775 0, /* properties_destroyed */
776 0, /* todo_flags_start */
777 ( TODO_remove_functions | TODO_dump_symtab ), /* todo_flags_finish */
780 class pass_ipa_whole_program_visibility : public ipa_opt_pass_d
782 public:
783 pass_ipa_whole_program_visibility (gcc::context *ctxt)
784 : ipa_opt_pass_d (pass_data_ipa_whole_program_visibility, ctxt,
785 NULL, /* generate_summary */
786 NULL, /* write_summary */
787 NULL, /* read_summary */
788 NULL, /* write_optimization_summary */
789 NULL, /* read_optimization_summary */
790 NULL, /* stmt_fixup */
791 0, /* function_transform_todo_flags_start */
792 NULL, /* function_transform */
793 NULL) /* variable_transform */
796 /* opt_pass methods: */
798 virtual bool gate (function *)
800 /* Do not re-run on ltrans stage. */
801 return !flag_ltrans;
803 virtual unsigned int execute (function *)
805 return whole_program_function_and_variable_visibility ();
808 }; // class pass_ipa_whole_program_visibility
810 } // anon namespace
812 ipa_opt_pass_d *
813 make_pass_ipa_whole_program_visibility (gcc::context *ctxt)
815 return new pass_ipa_whole_program_visibility (ctxt);
818 class pass_ipa_function_and_variable_visibility : public simple_ipa_opt_pass
820 public:
821 pass_ipa_function_and_variable_visibility (gcc::context *ctxt)
822 : simple_ipa_opt_pass (pass_data_ipa_function_and_variable_visibility,
823 ctxt)
826 /* opt_pass methods: */
827 virtual unsigned int execute (function *)
829 return function_and_variable_visibility (flag_whole_program && !flag_lto);
832 }; // class pass_ipa_function_and_variable_visibility
834 simple_ipa_opt_pass *
835 make_pass_ipa_function_and_variable_visibility (gcc::context *ctxt)
837 return new pass_ipa_function_and_variable_visibility (ctxt);