2 Copyright (C) 2003-2014 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
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
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
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
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.
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
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. */
77 #include "coretypes.h"
82 #include "plugin-api.h"
87 #include "hard-reg-set.h"
92 #include "tree-pass.h"
94 #include "gimple-expr.h"
97 /* Return true when NODE can not be local. Worker for cgraph_local_node_p. */
100 cgraph_node::non_local_p (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
102 /* FIXME: Aliases can be local, but i386 gets thunks wrong then. */
103 return !(node
->only_called_directly_or_aliased_p ()
104 && !node
->has_aliases_p ()
106 && !DECL_EXTERNAL (node
->decl
)
107 && !node
->externally_visible
108 && !node
->used_from_other_partition
109 && !node
->in_other_partition
);
112 /* Return true when function can be marked local. */
115 cgraph_node::local_p (void)
117 cgraph_node
*n
= ultimate_alias_target ();
119 /* FIXME: thunks can be considered local, but we need prevent i386
120 from attempting to change calling convention of them. */
121 if (n
->thunk
.thunk_p
)
123 return !n
->call_for_symbol_thunks_and_aliases (cgraph_node::non_local_p
,
128 /* Return true when there is a reference to node and it is not vtable. */
131 symtab_node::address_taken_from_non_vtable_p (void)
134 struct ipa_ref
*ref
= NULL
;
136 for (i
= 0; iterate_referring (i
, ref
); i
++)
137 if (ref
->use
== IPA_REF_ADDR
)
140 if (is_a
<cgraph_node
*> (ref
->referring
))
142 node
= dyn_cast
<varpool_node
*> (ref
->referring
);
143 if (!DECL_VIRTUAL_P (node
->decl
))
149 /* A helper for comdat_can_be_unshared_p. */
152 comdat_can_be_unshared_p_1 (symtab_node
*node
)
154 if (!node
->externally_visible
)
156 /* When address is taken, we don't know if equality comparison won't
157 break eventually. Exception are virutal functions, C++
158 constructors/destructors and vtables, where this is not possible by
159 language standard. */
160 if (!DECL_VIRTUAL_P (node
->decl
)
161 && (TREE_CODE (node
->decl
) != FUNCTION_DECL
162 || (!DECL_CXX_CONSTRUCTOR_P (node
->decl
)
163 && !DECL_CXX_DESTRUCTOR_P (node
->decl
)))
164 && node
->address_taken_from_non_vtable_p ())
167 /* If the symbol is used in some weird way, better to not touch it. */
168 if (node
->force_output
)
171 /* Explicit instantiations needs to be output when possibly
173 if (node
->forced_by_abi
174 && TREE_PUBLIC (node
->decl
)
175 && (node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY
176 && !flag_whole_program
))
179 /* Non-readonly and volatile variables can not be duplicated. */
180 if (is_a
<varpool_node
*> (node
)
181 && (!TREE_READONLY (node
->decl
)
182 || TREE_THIS_VOLATILE (node
->decl
)))
187 /* COMDAT functions must be shared only if they have address taken,
188 otherwise we can produce our own private implementation with
190 Return true when turning COMDAT functoin static can not lead to wrong
191 code when the resulting object links with a library defining same COMDAT.
193 Virtual functions do have their addresses taken from the vtables,
194 but in C++ there is no way to compare their addresses for equality. */
197 comdat_can_be_unshared_p (symtab_node
*node
)
199 if (!comdat_can_be_unshared_p_1 (node
))
201 if (node
->same_comdat_group
)
205 /* If more than one function is in the same COMDAT group, it must
206 be shared even if just one function in the comdat group has
208 for (next
= node
->same_comdat_group
;
209 next
!= node
; next
= next
->same_comdat_group
)
210 if (!comdat_can_be_unshared_p_1 (next
))
216 /* Return true when function NODE should be considered externally visible. */
219 cgraph_externally_visible_p (struct cgraph_node
*node
,
222 if (!node
->definition
)
224 if (!TREE_PUBLIC (node
->decl
)
225 || DECL_EXTERNAL (node
->decl
))
228 /* Do not try to localize built-in functions yet. One of problems is that we
229 end up mangling their asm for WHOPR that makes it impossible to call them
230 using the implicit built-in declarations anymore. Similarly this enables
231 us to remove them as unreachable before actual calls may appear during
232 expansion or folding. */
233 if (DECL_BUILT_IN (node
->decl
))
236 /* If linker counts on us, we must preserve the function. */
237 if (node
->used_from_object_file_p ())
239 if (DECL_PRESERVE_P (node
->decl
))
241 if (lookup_attribute ("externally_visible",
242 DECL_ATTRIBUTES (node
->decl
)))
244 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
245 && lookup_attribute ("dllexport",
246 DECL_ATTRIBUTES (node
->decl
)))
248 if (node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
)
250 /* When doing LTO or whole program, we can bring COMDAT functoins static.
251 This improves code quality and we know we will duplicate them at most twice
252 (in the case that we are not using plugin and link with object file
253 implementing same COMDAT) */
254 if ((in_lto_p
|| whole_program
)
255 && DECL_COMDAT (node
->decl
)
256 && comdat_can_be_unshared_p (node
))
259 /* When doing link time optimizations, hidden symbols become local. */
261 && (DECL_VISIBILITY (node
->decl
) == VISIBILITY_HIDDEN
262 || DECL_VISIBILITY (node
->decl
) == VISIBILITY_INTERNAL
)
263 /* Be sure that node is defined in IR file, not in other object
264 file. In that case we don't set used_from_other_object_file. */
267 else if (!whole_program
)
270 if (MAIN_NAME_P (DECL_NAME (node
->decl
)))
273 if (node
->instrumentation_clone
274 && MAIN_NAME_P (DECL_NAME (node
->orig_decl
)))
280 /* Return true when variable should be considered externally visible. */
283 varpool_node::externally_visible_p (void)
285 if (DECL_EXTERNAL (decl
))
288 if (!TREE_PUBLIC (decl
))
291 /* If linker counts on us, we must preserve the function. */
292 if (used_from_object_file_p ())
295 /* Bringing TLS variables local may cause dynamic linker failures
296 on limits of static TLS vars. */
297 if (DECL_THREAD_LOCAL_P (decl
)
298 && (DECL_TLS_MODEL (decl
) != TLS_MODEL_EMULATED
299 && DECL_TLS_MODEL (decl
) != TLS_MODEL_INITIAL_EXEC
))
302 if (DECL_HARD_REGISTER (decl
))
304 if (DECL_PRESERVE_P (decl
))
306 if (lookup_attribute ("externally_visible",
307 DECL_ATTRIBUTES (decl
)))
309 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
310 && lookup_attribute ("dllexport",
311 DECL_ATTRIBUTES (decl
)))
314 /* See if we have linker information about symbol not being used or
315 if we need to make guess based on the declaration.
317 Even if the linker clams the symbol is unused, never bring internal
318 symbols that are declared by user as used or externally visible.
319 This is needed for i.e. references from asm statements. */
320 if (used_from_object_file_p ())
322 if (resolution
== LDPR_PREVAILING_DEF_IRONLY
)
325 /* As a special case, the COMDAT virtual tables can be unshared.
326 In LTO mode turn vtables into static variables. The variable is readonly,
327 so this does not enable more optimization, but referring static var
328 is faster for dynamic linking. Also this match logic hidding vtables
329 from LTO symbol tables. */
330 if ((in_lto_p
|| flag_whole_program
)
331 && DECL_COMDAT (decl
)
332 && comdat_can_be_unshared_p (this))
335 /* When doing link time optimizations, hidden symbols become local. */
337 && (DECL_VISIBILITY (decl
) == VISIBILITY_HIDDEN
338 || DECL_VISIBILITY (decl
) == VISIBILITY_INTERNAL
)
339 /* Be sure that node is defined in IR file, not in other object
340 file. In that case we don't set used_from_other_object_file. */
343 else if (!flag_whole_program
)
346 /* Do not attempt to privatize COMDATS by default.
347 This would break linking with C++ libraries sharing
350 FIXME: We can do so for readonly vars with no address taken and
351 possibly also for vtables since no direct pointer comparsion is done.
352 It might be interesting to do so to reduce linking overhead. */
353 if (DECL_COMDAT (decl
) || DECL_WEAK (decl
))
358 /* Return true if reference to NODE can be replaced by a local alias.
359 Local aliases save dynamic linking overhead and enable more optimizations.
363 can_replace_by_local_alias (symtab_node
*node
)
365 return (node
->get_availability () > AVAIL_INTERPOSABLE
366 && !decl_binds_to_current_def_p (node
->decl
)
367 && !node
->can_be_discarded_p ());
370 /* Return true if we can replace refernece to NODE by local alias
371 within a virtual table. Generally we can replace function pointers
372 and virtual table pointers. */
375 can_replace_by_local_alias_in_vtable (symtab_node
*node
)
377 if (is_a
<varpool_node
*> (node
)
378 && !DECL_VIRTUAL_P (node
->decl
))
380 return can_replace_by_local_alias (node
);
383 /* walk_tree callback that rewrites initializer references. */
386 update_vtable_references (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
388 if (TREE_CODE (*tp
) == VAR_DECL
389 || TREE_CODE (*tp
) == FUNCTION_DECL
)
391 if (can_replace_by_local_alias_in_vtable (symtab_node::get (*tp
)))
392 *tp
= symtab_node::get (*tp
)->noninterposable_alias ()->decl
;
395 else if (IS_TYPE_OR_DECL_P (*tp
))
400 /* In LTO we can remove COMDAT groups and weak symbols.
401 Either turn them into normal symbols or external symbol depending on
405 update_visibility_by_resolution_info (symtab_node
* node
)
409 if (!node
->externally_visible
410 || (!DECL_WEAK (node
->decl
) && !DECL_ONE_ONLY (node
->decl
))
411 || node
->resolution
== LDPR_UNKNOWN
)
414 define
= (node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
415 || node
->resolution
== LDPR_PREVAILING_DEF
416 || node
->resolution
== LDPR_UNDEF
417 || node
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
);
419 /* The linker decisions ought to agree in the whole group. */
420 if (node
->same_comdat_group
)
421 for (symtab_node
*next
= node
->same_comdat_group
;
422 next
!= node
; next
= next
->same_comdat_group
)
423 gcc_assert (!next
->externally_visible
424 || define
== (next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
425 || next
->resolution
== LDPR_PREVAILING_DEF
426 || next
->resolution
== LDPR_UNDEF
427 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
));
429 if (node
->same_comdat_group
)
430 for (symtab_node
*next
= node
->same_comdat_group
;
431 next
!= node
; next
= next
->same_comdat_group
)
433 next
->set_comdat_group (NULL
);
434 DECL_WEAK (next
->decl
) = false;
435 if (next
->externally_visible
437 DECL_EXTERNAL (next
->decl
) = true;
439 node
->set_comdat_group (NULL
);
440 DECL_WEAK (node
->decl
) = false;
442 DECL_EXTERNAL (node
->decl
) = true;
443 node
->dissolve_same_comdat_group_list ();
446 /* Decide on visibility of all symbols. */
449 function_and_variable_visibility (bool whole_program
)
451 struct cgraph_node
*node
;
454 /* All aliases should be procssed at this point. */
455 gcc_checking_assert (!alias_pairs
|| !alias_pairs
->length ());
457 FOR_EACH_FUNCTION (node
)
459 int flags
= flags_from_decl_or_type (node
->decl
);
461 /* Optimize away PURE and CONST constructors and destructors. */
463 && (flags
& (ECF_CONST
| ECF_PURE
))
464 && !(flags
& ECF_LOOPING_CONST_OR_PURE
))
466 DECL_STATIC_CONSTRUCTOR (node
->decl
) = 0;
467 DECL_STATIC_DESTRUCTOR (node
->decl
) = 0;
470 /* Frontends and alias code marks nodes as needed before parsing is finished.
471 We may end up marking as node external nodes where this flag is meaningless
473 if (DECL_EXTERNAL (node
->decl
) || !node
->definition
)
475 node
->force_output
= 0;
476 node
->forced_by_abi
= 0;
479 /* C++ FE on lack of COMDAT support create local COMDAT functions
480 (that ought to be shared but can not due to object format
481 limitations). It is necessary to keep the flag to make rest of C++ FE
482 happy. Clear the flag here to avoid confusion in middle-end. */
483 if (DECL_COMDAT (node
->decl
) && !TREE_PUBLIC (node
->decl
))
484 DECL_COMDAT (node
->decl
) = 0;
486 /* For external decls stop tracking same_comdat_group. It doesn't matter
487 what comdat group they are in when they won't be emitted in this TU. */
488 if (node
->same_comdat_group
&& DECL_EXTERNAL (node
->decl
))
490 #ifdef ENABLE_CHECKING
493 for (n
= node
->same_comdat_group
;
495 n
= n
->same_comdat_group
)
496 /* If at least one of same comdat group functions is external,
497 all of them have to be, otherwise it is a front-end bug. */
498 gcc_assert (DECL_EXTERNAL (n
->decl
));
500 node
->dissolve_same_comdat_group_list ();
502 gcc_assert ((!DECL_WEAK (node
->decl
)
503 && !DECL_COMDAT (node
->decl
))
504 || TREE_PUBLIC (node
->decl
)
506 || DECL_EXTERNAL (node
->decl
));
507 if (cgraph_externally_visible_p (node
, whole_program
))
509 gcc_assert (!node
->global
.inlined_to
);
510 node
->externally_visible
= true;
514 node
->externally_visible
= false;
515 node
->forced_by_abi
= false;
517 if (!node
->externally_visible
518 && node
->definition
&& !node
->weakref
519 && !DECL_EXTERNAL (node
->decl
))
521 gcc_assert (whole_program
|| in_lto_p
522 || !TREE_PUBLIC (node
->decl
));
523 node
->unique_name
= ((node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
525 || node
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
526 && TREE_PUBLIC (node
->decl
));
527 node
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
528 if (node
->same_comdat_group
&& TREE_PUBLIC (node
->decl
))
530 symtab_node
*next
= node
;
532 /* Set all members of comdat group local. */
533 if (node
->same_comdat_group
)
534 for (next
= node
->same_comdat_group
;
536 next
= next
->same_comdat_group
)
538 next
->set_comdat_group (NULL
);
540 next
->set_section (NULL
);
541 next
->make_decl_local ();
542 next
->unique_name
= ((next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
544 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
545 && TREE_PUBLIC (next
->decl
));
547 /* cgraph_externally_visible_p has already checked all other nodes
548 in the group and they will all be made local. We need to
549 dissolve the group at once so that the predicate does not
551 node
->dissolve_same_comdat_group_list ();
553 if (TREE_PUBLIC (node
->decl
))
554 node
->set_comdat_group (NULL
);
555 if (DECL_COMDAT (node
->decl
) && !node
->alias
)
556 node
->set_section (NULL
);
557 node
->make_decl_local ();
560 if (node
->thunk
.thunk_p
561 && !node
->thunk
.add_pointer_bounds_args
562 && TREE_PUBLIC (node
->decl
))
564 struct cgraph_node
*decl_node
= node
;
566 decl_node
= decl_node
->callees
->callee
->function_symbol ();
568 /* Thunks have the same visibility as function they are attached to.
569 Make sure the C++ front end set this up properly. */
570 if (DECL_ONE_ONLY (decl_node
->decl
))
572 gcc_checking_assert (DECL_COMDAT (node
->decl
)
573 == DECL_COMDAT (decl_node
->decl
));
574 gcc_checking_assert (node
->in_same_comdat_group_p (decl_node
));
575 gcc_checking_assert (node
->same_comdat_group
);
577 node
->forced_by_abi
= decl_node
->forced_by_abi
;
578 if (DECL_EXTERNAL (decl_node
->decl
))
579 DECL_EXTERNAL (node
->decl
) = 1;
582 update_visibility_by_resolution_info (node
);
584 FOR_EACH_DEFINED_FUNCTION (node
)
586 node
->local
.local
|= node
->local_p ();
588 /* If we know that function can not be overwritten by a different semantics
589 and moreover its section can not be discarded, replace all direct calls
590 by calls to an noninterposable alias. This make dynamic linking
591 cheaper and enable more optimization.
593 TODO: We can also update virtual tables. */
595 && can_replace_by_local_alias (node
))
597 cgraph_node
*alias
= dyn_cast
<cgraph_node
*>
598 (node
->noninterposable_alias ());
600 if (alias
&& alias
!= node
)
602 while (node
->callers
)
604 struct cgraph_edge
*e
= node
->callers
;
606 e
->redirect_callee (alias
);
607 if (gimple_has_body_p (e
->caller
->decl
))
609 push_cfun (DECL_STRUCT_FUNCTION (e
->caller
->decl
));
610 e
->redirect_call_stmt_to_callee ();
617 FOR_EACH_VARIABLE (vnode
)
619 /* weak flag makes no sense on local variables. */
620 gcc_assert (!DECL_WEAK (vnode
->decl
)
622 || TREE_PUBLIC (vnode
->decl
)
623 || DECL_EXTERNAL (vnode
->decl
));
624 /* In several cases declarations can not be common:
626 - when declaration has initializer
628 - when it has specific section
629 - when it resides in non-generic address space.
630 - if declaration is local, it will get into .local common section
631 so common flag is not needed. Frontends still produce these in
632 certain cases, such as for:
634 static int a __attribute__ ((common))
636 Canonicalize things here and clear the redundant flag. */
637 if (DECL_COMMON (vnode
->decl
)
638 && (!(TREE_PUBLIC (vnode
->decl
)
639 || DECL_EXTERNAL (vnode
->decl
))
640 || (DECL_INITIAL (vnode
->decl
)
641 && DECL_INITIAL (vnode
->decl
) != error_mark_node
)
642 || DECL_WEAK (vnode
->decl
)
643 || DECL_SECTION_NAME (vnode
->decl
) != NULL
644 || ! (ADDR_SPACE_GENERIC_P
645 (TYPE_ADDR_SPACE (TREE_TYPE (vnode
->decl
))))))
646 DECL_COMMON (vnode
->decl
) = 0;
648 FOR_EACH_DEFINED_VARIABLE (vnode
)
650 if (!vnode
->definition
)
652 if (vnode
->externally_visible_p ())
653 vnode
->externally_visible
= true;
656 vnode
->externally_visible
= false;
657 vnode
->forced_by_abi
= false;
659 if (lookup_attribute ("no_reorder",
660 DECL_ATTRIBUTES (vnode
->decl
)))
661 vnode
->no_reorder
= 1;
662 if (!vnode
->externally_visible
665 gcc_assert (in_lto_p
|| whole_program
|| !TREE_PUBLIC (vnode
->decl
));
666 vnode
->unique_name
= ((vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY
667 || vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
668 && TREE_PUBLIC (vnode
->decl
));
669 if (vnode
->same_comdat_group
&& TREE_PUBLIC (vnode
->decl
))
671 symtab_node
*next
= vnode
;
673 /* Set all members of comdat group local. */
674 if (vnode
->same_comdat_group
)
675 for (next
= vnode
->same_comdat_group
;
677 next
= next
->same_comdat_group
)
679 next
->set_comdat_group (NULL
);
681 next
->set_section (NULL
);
682 next
->make_decl_local ();
683 next
->unique_name
= ((next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
685 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
686 && TREE_PUBLIC (next
->decl
));
688 vnode
->dissolve_same_comdat_group_list ();
690 if (TREE_PUBLIC (vnode
->decl
))
691 vnode
->set_comdat_group (NULL
);
692 if (DECL_COMDAT (vnode
->decl
) && !vnode
->alias
)
693 vnode
->set_section (NULL
);
694 vnode
->make_decl_local ();
695 vnode
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
697 update_visibility_by_resolution_info (vnode
);
699 /* Update virtual tables to point to local aliases where possible. */
700 if (DECL_VIRTUAL_P (vnode
->decl
)
701 && !DECL_EXTERNAL (vnode
->decl
))
707 /* See if there is something to update. */
708 for (i
= 0; vnode
->iterate_referring (i
, ref
); i
++)
709 if (ref
->use
== IPA_REF_ADDR
710 && can_replace_by_local_alias_in_vtable (ref
->referred
))
717 hash_set
<tree
> visited_nodes
;
719 vnode
->get_constructor ();
720 walk_tree (&DECL_INITIAL (vnode
->decl
),
721 update_vtable_references
, NULL
, &visited_nodes
);
722 vnode
->remove_all_references ();
723 record_references_in_initializer (vnode
->decl
, false);
730 fprintf (dump_file
, "\nMarking local functions:");
731 FOR_EACH_DEFINED_FUNCTION (node
)
732 if (node
->local
.local
)
733 fprintf (dump_file
, " %s", node
->name ());
734 fprintf (dump_file
, "\n\n");
735 fprintf (dump_file
, "\nMarking externally visible functions:");
736 FOR_EACH_DEFINED_FUNCTION (node
)
737 if (node
->externally_visible
)
738 fprintf (dump_file
, " %s", node
->name ());
739 fprintf (dump_file
, "\n\n");
740 fprintf (dump_file
, "\nMarking externally visible variables:");
741 FOR_EACH_DEFINED_VARIABLE (vnode
)
742 if (vnode
->externally_visible
)
743 fprintf (dump_file
, " %s", vnode
->name ());
744 fprintf (dump_file
, "\n\n");
746 symtab
->function_flags_ready
= true;
750 /* Local function pass handling visibilities. This happens before LTO streaming
751 so in particular -fwhole-program should be ignored at this level. */
755 const pass_data pass_data_ipa_function_and_variable_visibility
=
757 SIMPLE_IPA_PASS
, /* type */
758 "visibility", /* name */
759 OPTGROUP_NONE
, /* optinfo_flags */
760 TV_CGRAPHOPT
, /* tv_id */
761 0, /* properties_required */
762 0, /* properties_provided */
763 0, /* properties_destroyed */
764 0, /* todo_flags_start */
765 ( TODO_remove_functions
| TODO_dump_symtab
), /* todo_flags_finish */
768 /* Bring functions local at LTO time with -fwhole-program. */
771 whole_program_function_and_variable_visibility (void)
773 function_and_variable_visibility (flag_whole_program
);
775 ipa_discover_readonly_nonaddressable_vars ();
783 const pass_data pass_data_ipa_whole_program_visibility
=
786 "whole-program", /* name */
787 OPTGROUP_NONE
, /* optinfo_flags */
788 TV_CGRAPHOPT
, /* tv_id */
789 0, /* properties_required */
790 0, /* properties_provided */
791 0, /* properties_destroyed */
792 0, /* todo_flags_start */
793 ( TODO_remove_functions
| TODO_dump_symtab
), /* todo_flags_finish */
796 class pass_ipa_whole_program_visibility
: public ipa_opt_pass_d
799 pass_ipa_whole_program_visibility (gcc::context
*ctxt
)
800 : ipa_opt_pass_d (pass_data_ipa_whole_program_visibility
, ctxt
,
801 NULL
, /* generate_summary */
802 NULL
, /* write_summary */
803 NULL
, /* read_summary */
804 NULL
, /* write_optimization_summary */
805 NULL
, /* read_optimization_summary */
806 NULL
, /* stmt_fixup */
807 0, /* function_transform_todo_flags_start */
808 NULL
, /* function_transform */
809 NULL
) /* variable_transform */
812 /* opt_pass methods: */
814 virtual bool gate (function
*)
816 /* Do not re-run on ltrans stage. */
819 virtual unsigned int execute (function
*)
821 return whole_program_function_and_variable_visibility ();
824 }; // class pass_ipa_whole_program_visibility
829 make_pass_ipa_whole_program_visibility (gcc::context
*ctxt
)
831 return new pass_ipa_whole_program_visibility (ctxt
);
834 class pass_ipa_function_and_variable_visibility
: public simple_ipa_opt_pass
837 pass_ipa_function_and_variable_visibility (gcc::context
*ctxt
)
838 : simple_ipa_opt_pass (pass_data_ipa_function_and_variable_visibility
,
842 /* opt_pass methods: */
843 virtual unsigned int execute (function
*)
845 return function_and_variable_visibility (flag_whole_program
&& !flag_lto
);
848 }; // class pass_ipa_function_and_variable_visibility
850 simple_ipa_opt_pass
*
851 make_pass_ipa_function_and_variable_visibility (gcc::context
*ctxt
)
853 return new pass_ipa_function_and_variable_visibility (ctxt
);