Fix cygwin performance loss on linpack.
[official-gcc.git] / gcc / ipa-visibility.c
blobd128ca85f1c684ce93a8033fe7d05eca87452091
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 "function.h"
80 #include "tree.h"
81 #include "gimple-expr.h"
82 #include "tree-pass.h"
83 #include "cgraph.h"
84 #include "calls.h"
85 #include "varasm.h"
87 /* Return true when NODE can not be local. Worker for cgraph_local_node_p. */
89 static bool
90 non_local_p (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
92 return !(node->only_called_directly_or_aliased_p ()
93 /* i386 would need update to output thunk with locak calling
94 ocnvetions. */
95 && !node->thunk.thunk_p
96 && node->definition
97 && !DECL_EXTERNAL (node->decl)
98 && !node->externally_visible
99 && !node->used_from_other_partition
100 && !node->in_other_partition);
103 /* Return true when function can be marked local. */
105 bool
106 cgraph_node::local_p (void)
108 cgraph_node *n = ultimate_alias_target ();
110 if (n->thunk.thunk_p)
111 return n->callees->callee->local_p ();
112 return !n->call_for_symbol_thunks_and_aliases (non_local_p,
113 NULL, true);
117 /* A helper for comdat_can_be_unshared_p. */
119 static bool
120 comdat_can_be_unshared_p_1 (symtab_node *node)
122 if (!node->externally_visible)
123 return true;
124 if (node->address_can_be_compared_p ())
126 struct ipa_ref *ref;
128 for (unsigned int i = 0; node->iterate_referring (i, ref); i++)
129 if (ref->address_matters_p ())
130 return false;
133 /* If the symbol is used in some weird way, better to not touch it. */
134 if (node->force_output)
135 return false;
137 /* Explicit instantiations needs to be output when possibly
138 used externally. */
139 if (node->forced_by_abi
140 && TREE_PUBLIC (node->decl)
141 && (node->resolution != LDPR_PREVAILING_DEF_IRONLY
142 && !flag_whole_program))
143 return false;
145 /* Non-readonly and volatile variables can not be duplicated. */
146 if (is_a <varpool_node *> (node)
147 && (!TREE_READONLY (node->decl)
148 || TREE_THIS_VOLATILE (node->decl)))
149 return false;
150 return true;
153 /* COMDAT functions must be shared only if they have address taken,
154 otherwise we can produce our own private implementation with
155 -fwhole-program.
156 Return true when turning COMDAT functoin static can not lead to wrong
157 code when the resulting object links with a library defining same COMDAT.
159 Virtual functions do have their addresses taken from the vtables,
160 but in C++ there is no way to compare their addresses for equality. */
162 static bool
163 comdat_can_be_unshared_p (symtab_node *node)
165 if (!comdat_can_be_unshared_p_1 (node))
166 return false;
167 if (node->same_comdat_group)
169 symtab_node *next;
171 /* If more than one function is in the same COMDAT group, it must
172 be shared even if just one function in the comdat group has
173 address taken. */
174 for (next = node->same_comdat_group;
175 next != node; next = next->same_comdat_group)
176 if (!comdat_can_be_unshared_p_1 (next))
177 return false;
179 return true;
182 /* Return true when function NODE should be considered externally visible. */
184 static bool
185 cgraph_externally_visible_p (struct cgraph_node *node,
186 bool whole_program)
188 if (!node->definition)
189 return false;
190 if (!TREE_PUBLIC (node->decl)
191 || DECL_EXTERNAL (node->decl))
192 return false;
194 /* Do not try to localize built-in functions yet. One of problems is that we
195 end up mangling their asm for WHOPR that makes it impossible to call them
196 using the implicit built-in declarations anymore. Similarly this enables
197 us to remove them as unreachable before actual calls may appear during
198 expansion or folding. */
199 if (DECL_BUILT_IN (node->decl))
200 return true;
202 /* If linker counts on us, we must preserve the function. */
203 if (node->used_from_object_file_p ())
204 return true;
205 if (DECL_PRESERVE_P (node->decl))
206 return true;
207 if (lookup_attribute ("externally_visible",
208 DECL_ATTRIBUTES (node->decl)))
209 return true;
210 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
211 && lookup_attribute ("dllexport",
212 DECL_ATTRIBUTES (node->decl)))
213 return true;
214 if (node->resolution == LDPR_PREVAILING_DEF_IRONLY)
215 return false;
216 /* When doing LTO or whole program, we can bring COMDAT functoins static.
217 This improves code quality and we know we will duplicate them at most twice
218 (in the case that we are not using plugin and link with object file
219 implementing same COMDAT) */
220 if ((in_lto_p || whole_program)
221 && DECL_COMDAT (node->decl)
222 && comdat_can_be_unshared_p (node))
223 return false;
225 /* When doing link time optimizations, hidden symbols become local. */
226 if (in_lto_p
227 && (DECL_VISIBILITY (node->decl) == VISIBILITY_HIDDEN
228 || DECL_VISIBILITY (node->decl) == VISIBILITY_INTERNAL)
229 /* Be sure that node is defined in IR file, not in other object
230 file. In that case we don't set used_from_other_object_file. */
231 && node->definition)
233 else if (!whole_program)
234 return true;
236 if (MAIN_NAME_P (DECL_NAME (node->decl)))
237 return true;
239 if (node->instrumentation_clone
240 && MAIN_NAME_P (DECL_NAME (node->orig_decl)))
241 return true;
243 return false;
246 /* Return true when variable should be considered externally visible. */
248 bool
249 varpool_node::externally_visible_p (void)
251 if (DECL_EXTERNAL (decl))
252 return true;
254 if (!TREE_PUBLIC (decl))
255 return false;
257 /* If linker counts on us, we must preserve the function. */
258 if (used_from_object_file_p ())
259 return true;
261 /* Bringing TLS variables local may cause dynamic linker failures
262 on limits of static TLS vars. */
263 if (DECL_THREAD_LOCAL_P (decl)
264 && (DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED
265 && DECL_TLS_MODEL (decl) != TLS_MODEL_INITIAL_EXEC))
266 return true;
268 if (DECL_HARD_REGISTER (decl))
269 return true;
270 if (DECL_PRESERVE_P (decl))
271 return true;
272 if (lookup_attribute ("externally_visible",
273 DECL_ATTRIBUTES (decl)))
274 return true;
275 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
276 && lookup_attribute ("dllexport",
277 DECL_ATTRIBUTES (decl)))
278 return true;
280 /* See if we have linker information about symbol not being used or
281 if we need to make guess based on the declaration.
283 Even if the linker clams the symbol is unused, never bring internal
284 symbols that are declared by user as used or externally visible.
285 This is needed for i.e. references from asm statements. */
286 if (used_from_object_file_p ())
287 return true;
288 if (resolution == LDPR_PREVAILING_DEF_IRONLY)
289 return false;
291 /* As a special case, the COMDAT virtual tables can be unshared.
292 In LTO mode turn vtables into static variables. The variable is readonly,
293 so this does not enable more optimization, but referring static var
294 is faster for dynamic linking. Also this match logic hidding vtables
295 from LTO symbol tables. */
296 if ((in_lto_p || flag_whole_program)
297 && DECL_COMDAT (decl)
298 && comdat_can_be_unshared_p (this))
299 return false;
301 /* When doing link time optimizations, hidden symbols become local. */
302 if (in_lto_p
303 && (DECL_VISIBILITY (decl) == VISIBILITY_HIDDEN
304 || DECL_VISIBILITY (decl) == VISIBILITY_INTERNAL)
305 /* Be sure that node is defined in IR file, not in other object
306 file. In that case we don't set used_from_other_object_file. */
307 && definition)
309 else if (!flag_whole_program)
310 return true;
312 /* Do not attempt to privatize COMDATS by default.
313 This would break linking with C++ libraries sharing
314 inline definitions.
316 FIXME: We can do so for readonly vars with no address taken and
317 possibly also for vtables since no direct pointer comparsion is done.
318 It might be interesting to do so to reduce linking overhead. */
319 if (DECL_COMDAT (decl) || DECL_WEAK (decl))
320 return true;
321 return false;
324 /* Return true if reference to NODE can be replaced by a local alias.
325 Local aliases save dynamic linking overhead and enable more optimizations.
328 bool
329 can_replace_by_local_alias (symtab_node *node)
331 return (node->get_availability () > AVAIL_INTERPOSABLE
332 && !decl_binds_to_current_def_p (node->decl)
333 && !node->can_be_discarded_p ());
336 /* Return true if we can replace refernece to NODE by local alias
337 within a virtual table. Generally we can replace function pointers
338 and virtual table pointers. */
340 bool
341 can_replace_by_local_alias_in_vtable (symtab_node *node)
343 if (is_a <varpool_node *> (node)
344 && !DECL_VIRTUAL_P (node->decl))
345 return false;
346 return can_replace_by_local_alias (node);
349 /* walk_tree callback that rewrites initializer references. */
351 static tree
352 update_vtable_references (tree *tp, int *walk_subtrees,
353 void *data ATTRIBUTE_UNUSED)
355 if (TREE_CODE (*tp) == VAR_DECL
356 || TREE_CODE (*tp) == FUNCTION_DECL)
358 if (can_replace_by_local_alias_in_vtable (symtab_node::get (*tp)))
359 *tp = symtab_node::get (*tp)->noninterposable_alias ()->decl;
360 *walk_subtrees = 0;
362 else if (IS_TYPE_OR_DECL_P (*tp))
363 *walk_subtrees = 0;
364 return NULL;
367 /* In LTO we can remove COMDAT groups and weak symbols.
368 Either turn them into normal symbols or external symbol depending on
369 resolution info. */
371 static void
372 update_visibility_by_resolution_info (symtab_node * node)
374 bool define;
376 if (!node->externally_visible
377 || (!DECL_WEAK (node->decl) && !DECL_ONE_ONLY (node->decl))
378 || node->resolution == LDPR_UNKNOWN)
379 return;
381 define = (node->resolution == LDPR_PREVAILING_DEF_IRONLY
382 || node->resolution == LDPR_PREVAILING_DEF
383 || node->resolution == LDPR_UNDEF
384 || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP);
386 /* The linker decisions ought to agree in the whole group. */
387 if (node->same_comdat_group)
388 for (symtab_node *next = node->same_comdat_group;
389 next != node; next = next->same_comdat_group)
391 if (!next->externally_visible)
392 continue;
394 bool same_def
395 = define == (next->resolution == LDPR_PREVAILING_DEF_IRONLY
396 || next->resolution == LDPR_PREVAILING_DEF
397 || next->resolution == LDPR_UNDEF
398 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP);
399 gcc_assert (in_lto_p || same_def);
400 if (!same_def)
401 return;
404 if (node->same_comdat_group)
405 for (symtab_node *next = node->same_comdat_group;
406 next != node; next = next->same_comdat_group)
408 next->set_comdat_group (NULL);
409 DECL_WEAK (next->decl) = false;
410 if (next->externally_visible
411 && !define)
412 DECL_EXTERNAL (next->decl) = true;
414 node->set_comdat_group (NULL);
415 DECL_WEAK (node->decl) = false;
416 if (!define)
417 DECL_EXTERNAL (node->decl) = true;
418 node->dissolve_same_comdat_group_list ();
421 /* Decide on visibility of all symbols. */
423 static unsigned int
424 function_and_variable_visibility (bool whole_program)
426 struct cgraph_node *node;
427 varpool_node *vnode;
429 /* All aliases should be procssed at this point. */
430 gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
432 FOR_EACH_FUNCTION (node)
434 int flags = flags_from_decl_or_type (node->decl);
436 /* Optimize away PURE and CONST constructors and destructors. */
437 if (optimize
438 && (flags & (ECF_CONST | ECF_PURE))
439 && !(flags & ECF_LOOPING_CONST_OR_PURE))
441 DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
442 DECL_STATIC_DESTRUCTOR (node->decl) = 0;
445 /* Frontends and alias code marks nodes as needed before parsing is finished.
446 We may end up marking as node external nodes where this flag is meaningless
447 strip it. */
448 if (DECL_EXTERNAL (node->decl) || !node->definition)
450 node->force_output = 0;
451 node->forced_by_abi = 0;
454 /* C++ FE on lack of COMDAT support create local COMDAT functions
455 (that ought to be shared but can not due to object format
456 limitations). It is necessary to keep the flag to make rest of C++ FE
457 happy. Clear the flag here to avoid confusion in middle-end. */
458 if (DECL_COMDAT (node->decl) && !TREE_PUBLIC (node->decl))
459 DECL_COMDAT (node->decl) = 0;
461 /* For external decls stop tracking same_comdat_group. It doesn't matter
462 what comdat group they are in when they won't be emitted in this TU. */
463 if (node->same_comdat_group && DECL_EXTERNAL (node->decl))
465 if (flag_checking)
467 for (symtab_node *n = node->same_comdat_group;
468 n != node;
469 n = n->same_comdat_group)
470 /* If at least one of same comdat group functions is external,
471 all of them have to be, otherwise it is a front-end bug. */
472 gcc_assert (DECL_EXTERNAL (n->decl));
474 node->dissolve_same_comdat_group_list ();
476 gcc_assert ((!DECL_WEAK (node->decl)
477 && !DECL_COMDAT (node->decl))
478 || TREE_PUBLIC (node->decl)
479 || node->weakref
480 || DECL_EXTERNAL (node->decl));
481 if (cgraph_externally_visible_p (node, whole_program))
483 gcc_assert (!node->global.inlined_to);
484 node->externally_visible = true;
486 else
488 node->externally_visible = false;
489 node->forced_by_abi = false;
491 if (!node->externally_visible
492 && node->definition && !node->weakref
493 && !DECL_EXTERNAL (node->decl))
495 gcc_assert (whole_program || in_lto_p
496 || !TREE_PUBLIC (node->decl));
497 node->unique_name = ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
498 || node->unique_name
499 || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
500 && TREE_PUBLIC (node->decl));
501 node->resolution = LDPR_PREVAILING_DEF_IRONLY;
502 if (node->same_comdat_group && TREE_PUBLIC (node->decl))
504 symtab_node *next = node;
506 /* Set all members of comdat group local. */
507 if (node->same_comdat_group)
508 for (next = node->same_comdat_group;
509 next != node;
510 next = next->same_comdat_group)
512 next->set_comdat_group (NULL);
513 if (!next->alias)
514 next->set_section (NULL);
515 next->make_decl_local ();
516 next->unique_name = ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
517 || next->unique_name
518 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
519 && TREE_PUBLIC (next->decl));
521 /* cgraph_externally_visible_p has already checked all other nodes
522 in the group and they will all be made local. We need to
523 dissolve the group at once so that the predicate does not
524 segfault though. */
525 node->dissolve_same_comdat_group_list ();
527 if (TREE_PUBLIC (node->decl))
528 node->set_comdat_group (NULL);
529 if (DECL_COMDAT (node->decl) && !node->alias)
530 node->set_section (NULL);
531 node->make_decl_local ();
534 if (node->thunk.thunk_p
535 && !node->thunk.add_pointer_bounds_args
536 && TREE_PUBLIC (node->decl))
538 struct cgraph_node *decl_node = node;
540 decl_node = decl_node->callees->callee->function_symbol ();
542 /* Thunks have the same visibility as function they are attached to.
543 Make sure the C++ front end set this up properly. */
544 if (DECL_ONE_ONLY (decl_node->decl))
546 gcc_checking_assert (DECL_COMDAT (node->decl)
547 == DECL_COMDAT (decl_node->decl));
548 gcc_checking_assert (node->in_same_comdat_group_p (decl_node));
549 gcc_checking_assert (node->same_comdat_group);
551 node->forced_by_abi = decl_node->forced_by_abi;
552 if (DECL_EXTERNAL (decl_node->decl))
553 DECL_EXTERNAL (node->decl) = 1;
556 update_visibility_by_resolution_info (node);
558 FOR_EACH_DEFINED_FUNCTION (node)
560 if (!node->local.local)
561 node->local.local |= node->local_p ();
563 /* If we know that function can not be overwritten by a different semantics
564 and moreover its section can not be discarded, replace all direct calls
565 by calls to an noninterposable alias. This make dynamic linking
566 cheaper and enable more optimization.
568 TODO: We can also update virtual tables. */
569 if (node->callers
570 && can_replace_by_local_alias (node))
572 cgraph_node *alias = dyn_cast<cgraph_node *>
573 (node->noninterposable_alias ());
575 if (alias && alias != node)
577 while (node->callers)
579 struct cgraph_edge *e = node->callers;
581 e->redirect_callee (alias);
582 if (gimple_has_body_p (e->caller->decl))
584 push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
585 e->redirect_call_stmt_to_callee ();
586 pop_cfun ();
592 FOR_EACH_VARIABLE (vnode)
594 /* weak flag makes no sense on local variables. */
595 gcc_assert (!DECL_WEAK (vnode->decl)
596 || vnode->weakref
597 || TREE_PUBLIC (vnode->decl)
598 || DECL_EXTERNAL (vnode->decl));
599 /* In several cases declarations can not be common:
601 - when declaration has initializer
602 - when it is in weak
603 - when it has specific section
604 - when it resides in non-generic address space.
605 - if declaration is local, it will get into .local common section
606 so common flag is not needed. Frontends still produce these in
607 certain cases, such as for:
609 static int a __attribute__ ((common))
611 Canonicalize things here and clear the redundant flag. */
612 if (DECL_COMMON (vnode->decl)
613 && (!(TREE_PUBLIC (vnode->decl)
614 || DECL_EXTERNAL (vnode->decl))
615 || (DECL_INITIAL (vnode->decl)
616 && DECL_INITIAL (vnode->decl) != error_mark_node)
617 || DECL_WEAK (vnode->decl)
618 || DECL_SECTION_NAME (vnode->decl) != NULL
619 || ! (ADDR_SPACE_GENERIC_P
620 (TYPE_ADDR_SPACE (TREE_TYPE (vnode->decl))))))
621 DECL_COMMON (vnode->decl) = 0;
623 FOR_EACH_DEFINED_VARIABLE (vnode)
625 if (!vnode->definition)
626 continue;
627 if (vnode->externally_visible_p ())
628 vnode->externally_visible = true;
629 else
631 vnode->externally_visible = false;
632 vnode->forced_by_abi = false;
634 if (lookup_attribute ("no_reorder",
635 DECL_ATTRIBUTES (vnode->decl)))
636 vnode->no_reorder = 1;
637 if (!vnode->externally_visible
638 && !vnode->weakref)
640 gcc_assert (in_lto_p || whole_program || !TREE_PUBLIC (vnode->decl));
641 vnode->unique_name = ((vnode->resolution == LDPR_PREVAILING_DEF_IRONLY
642 || vnode->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
643 && TREE_PUBLIC (vnode->decl));
644 if (vnode->same_comdat_group && TREE_PUBLIC (vnode->decl))
646 symtab_node *next = vnode;
648 /* Set all members of comdat group local. */
649 if (vnode->same_comdat_group)
650 for (next = vnode->same_comdat_group;
651 next != vnode;
652 next = next->same_comdat_group)
654 next->set_comdat_group (NULL);
655 if (!next->alias)
656 next->set_section (NULL);
657 next->make_decl_local ();
658 next->unique_name = ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
659 || next->unique_name
660 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
661 && TREE_PUBLIC (next->decl));
663 vnode->dissolve_same_comdat_group_list ();
665 if (TREE_PUBLIC (vnode->decl))
666 vnode->set_comdat_group (NULL);
667 if (DECL_COMDAT (vnode->decl) && !vnode->alias)
668 vnode->set_section (NULL);
669 vnode->make_decl_local ();
670 vnode->resolution = LDPR_PREVAILING_DEF_IRONLY;
672 update_visibility_by_resolution_info (vnode);
674 /* Update virtual tables to point to local aliases where possible. */
675 if (DECL_VIRTUAL_P (vnode->decl)
676 && !DECL_EXTERNAL (vnode->decl))
678 int i;
679 struct ipa_ref *ref;
680 bool found = false;
682 /* See if there is something to update. */
683 for (i = 0; vnode->iterate_referring (i, ref); i++)
684 if (ref->use == IPA_REF_ADDR
685 && can_replace_by_local_alias_in_vtable (ref->referred))
687 found = true;
688 break;
690 if (found)
692 hash_set<tree> visited_nodes;
694 vnode->get_constructor ();
695 walk_tree (&DECL_INITIAL (vnode->decl),
696 update_vtable_references, NULL, &visited_nodes);
697 vnode->remove_all_references ();
698 record_references_in_initializer (vnode->decl, false);
703 if (dump_file)
705 fprintf (dump_file, "\nMarking local functions:");
706 FOR_EACH_DEFINED_FUNCTION (node)
707 if (node->local.local)
708 fprintf (dump_file, " %s", node->name ());
709 fprintf (dump_file, "\n\n");
710 fprintf (dump_file, "\nMarking externally visible functions:");
711 FOR_EACH_DEFINED_FUNCTION (node)
712 if (node->externally_visible)
713 fprintf (dump_file, " %s", node->name ());
714 fprintf (dump_file, "\n\n");
715 fprintf (dump_file, "\nMarking externally visible variables:");
716 FOR_EACH_DEFINED_VARIABLE (vnode)
717 if (vnode->externally_visible)
718 fprintf (dump_file, " %s", vnode->name ());
719 fprintf (dump_file, "\n\n");
721 symtab->function_flags_ready = true;
722 return 0;
725 /* Local function pass handling visibilities. This happens before LTO streaming
726 so in particular -fwhole-program should be ignored at this level. */
728 namespace {
730 const pass_data pass_data_ipa_function_and_variable_visibility =
732 SIMPLE_IPA_PASS, /* type */
733 "visibility", /* name */
734 OPTGROUP_NONE, /* optinfo_flags */
735 TV_CGRAPHOPT, /* tv_id */
736 0, /* properties_required */
737 0, /* properties_provided */
738 0, /* properties_destroyed */
739 0, /* todo_flags_start */
740 ( TODO_remove_functions | TODO_dump_symtab ), /* todo_flags_finish */
743 /* Bring functions local at LTO time with -fwhole-program. */
745 static unsigned int
746 whole_program_function_and_variable_visibility (void)
748 function_and_variable_visibility (flag_whole_program);
749 if (optimize)
750 ipa_discover_readonly_nonaddressable_vars ();
751 return 0;
754 } // anon namespace
756 namespace {
758 const pass_data pass_data_ipa_whole_program_visibility =
760 IPA_PASS, /* type */
761 "whole-program", /* name */
762 OPTGROUP_NONE, /* optinfo_flags */
763 TV_CGRAPHOPT, /* tv_id */
764 0, /* properties_required */
765 0, /* properties_provided */
766 0, /* properties_destroyed */
767 0, /* todo_flags_start */
768 ( TODO_remove_functions | TODO_dump_symtab ), /* todo_flags_finish */
771 class pass_ipa_whole_program_visibility : public ipa_opt_pass_d
773 public:
774 pass_ipa_whole_program_visibility (gcc::context *ctxt)
775 : ipa_opt_pass_d (pass_data_ipa_whole_program_visibility, ctxt,
776 NULL, /* generate_summary */
777 NULL, /* write_summary */
778 NULL, /* read_summary */
779 NULL, /* write_optimization_summary */
780 NULL, /* read_optimization_summary */
781 NULL, /* stmt_fixup */
782 0, /* function_transform_todo_flags_start */
783 NULL, /* function_transform */
784 NULL) /* variable_transform */
787 /* opt_pass methods: */
789 virtual bool gate (function *)
791 /* Do not re-run on ltrans stage. */
792 return !flag_ltrans;
794 virtual unsigned int execute (function *)
796 return whole_program_function_and_variable_visibility ();
799 }; // class pass_ipa_whole_program_visibility
801 } // anon namespace
803 ipa_opt_pass_d *
804 make_pass_ipa_whole_program_visibility (gcc::context *ctxt)
806 return new pass_ipa_whole_program_visibility (ctxt);
809 class pass_ipa_function_and_variable_visibility : public simple_ipa_opt_pass
811 public:
812 pass_ipa_function_and_variable_visibility (gcc::context *ctxt)
813 : simple_ipa_opt_pass (pass_data_ipa_function_and_variable_visibility,
814 ctxt)
817 /* opt_pass methods: */
818 virtual unsigned int execute (function *)
820 return function_and_variable_visibility (flag_whole_program && !flag_lto);
823 }; // class pass_ipa_function_and_variable_visibility
825 simple_ipa_opt_pass *
826 make_pass_ipa_function_and_variable_visibility (gcc::context *ctxt)
828 return new pass_ipa_function_and_variable_visibility (ctxt);