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"
81 #include "tree-pass.h"
82 #include "pointer-set.h"
84 #include "gimple-expr.h"
86 /* Return true when NODE can not be local. Worker for cgraph_local_node_p. */
89 cgraph_non_local_node_p_1 (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
91 /* FIXME: Aliases can be local, but i386 gets thunks wrong then. */
92 return !(cgraph_only_called_directly_or_aliased_p (node
)
93 && !ipa_ref_has_aliases_p (&node
->ref_list
)
95 && !DECL_EXTERNAL (node
->decl
)
96 && !node
->externally_visible
97 && !node
->used_from_other_partition
98 && !node
->in_other_partition
);
101 /* Return true when function can be marked local. */
104 cgraph_local_node_p (struct cgraph_node
*node
)
106 struct cgraph_node
*n
= cgraph_function_or_thunk_node (node
, NULL
);
108 /* FIXME: thunks can be considered local, but we need prevent i386
109 from attempting to change calling convention of them. */
110 if (n
->thunk
.thunk_p
)
112 return !cgraph_for_node_and_aliases (n
,
113 cgraph_non_local_node_p_1
, NULL
, true);
117 /* Return true when there is a reference to node and it is not vtable. */
119 address_taken_from_non_vtable_p (symtab_node
*node
)
123 for (i
= 0; ipa_ref_list_referring_iterate (&node
->ref_list
,
125 if (ref
->use
== IPA_REF_ADDR
)
128 if (is_a
<cgraph_node
*> (ref
->referring
))
130 node
= ipa_ref_referring_varpool_node (ref
);
131 if (!DECL_VIRTUAL_P (node
->decl
))
137 /* A helper for comdat_can_be_unshared_p. */
140 comdat_can_be_unshared_p_1 (symtab_node
*node
)
142 if (!node
->externally_visible
)
144 /* When address is taken, we don't know if equality comparison won't
145 break eventually. Exception are virutal functions, C++
146 constructors/destructors and vtables, where this is not possible by
147 language standard. */
148 if (!DECL_VIRTUAL_P (node
->decl
)
149 && (TREE_CODE (node
->decl
) != FUNCTION_DECL
150 || (!DECL_CXX_CONSTRUCTOR_P (node
->decl
)
151 && !DECL_CXX_DESTRUCTOR_P (node
->decl
)))
152 && address_taken_from_non_vtable_p (node
))
155 /* If the symbol is used in some weird way, better to not touch it. */
156 if (node
->force_output
)
159 /* Explicit instantiations needs to be output when possibly
161 if (node
->forced_by_abi
162 && TREE_PUBLIC (node
->decl
)
163 && (node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY
164 && !flag_whole_program
))
167 /* Non-readonly and volatile variables can not be duplicated. */
168 if (is_a
<varpool_node
*> (node
)
169 && (!TREE_READONLY (node
->decl
)
170 || TREE_THIS_VOLATILE (node
->decl
)))
175 /* COMDAT functions must be shared only if they have address taken,
176 otherwise we can produce our own private implementation with
178 Return true when turning COMDAT functoin static can not lead to wrong
179 code when the resulting object links with a library defining same COMDAT.
181 Virtual functions do have their addresses taken from the vtables,
182 but in C++ there is no way to compare their addresses for equality. */
185 comdat_can_be_unshared_p (symtab_node
*node
)
187 if (!comdat_can_be_unshared_p_1 (node
))
189 if (node
->same_comdat_group
)
193 /* If more than one function is in the same COMDAT group, it must
194 be shared even if just one function in the comdat group has
196 for (next
= node
->same_comdat_group
;
197 next
!= node
; next
= next
->same_comdat_group
)
198 if (!comdat_can_be_unshared_p_1 (next
))
204 /* Return true when function NODE should be considered externally visible. */
207 cgraph_externally_visible_p (struct cgraph_node
*node
,
210 if (!node
->definition
)
212 if (!TREE_PUBLIC (node
->decl
)
213 || DECL_EXTERNAL (node
->decl
))
216 /* Do not try to localize built-in functions yet. One of problems is that we
217 end up mangling their asm for WHOPR that makes it impossible to call them
218 using the implicit built-in declarations anymore. Similarly this enables
219 us to remove them as unreachable before actual calls may appear during
220 expansion or folding. */
221 if (DECL_BUILT_IN (node
->decl
))
224 /* If linker counts on us, we must preserve the function. */
225 if (symtab_used_from_object_file_p (node
))
227 if (DECL_PRESERVE_P (node
->decl
))
229 if (lookup_attribute ("externally_visible",
230 DECL_ATTRIBUTES (node
->decl
)))
232 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
233 && lookup_attribute ("dllexport",
234 DECL_ATTRIBUTES (node
->decl
)))
236 if (node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
)
238 /* When doing LTO or whole program, we can bring COMDAT functoins static.
239 This improves code quality and we know we will duplicate them at most twice
240 (in the case that we are not using plugin and link with object file
241 implementing same COMDAT) */
242 if ((in_lto_p
|| whole_program
)
243 && DECL_COMDAT (node
->decl
)
244 && comdat_can_be_unshared_p (node
))
247 /* When doing link time optimizations, hidden symbols become local. */
249 && (DECL_VISIBILITY (node
->decl
) == VISIBILITY_HIDDEN
250 || DECL_VISIBILITY (node
->decl
) == VISIBILITY_INTERNAL
)
251 /* Be sure that node is defined in IR file, not in other object
252 file. In that case we don't set used_from_other_object_file. */
255 else if (!whole_program
)
258 if (MAIN_NAME_P (DECL_NAME (node
->decl
)))
264 /* Return true when variable VNODE should be considered externally visible. */
267 varpool_externally_visible_p (varpool_node
*vnode
)
269 if (DECL_EXTERNAL (vnode
->decl
))
272 if (!TREE_PUBLIC (vnode
->decl
))
275 /* If linker counts on us, we must preserve the function. */
276 if (symtab_used_from_object_file_p (vnode
))
279 if (DECL_HARD_REGISTER (vnode
->decl
))
281 if (DECL_PRESERVE_P (vnode
->decl
))
283 if (lookup_attribute ("externally_visible",
284 DECL_ATTRIBUTES (vnode
->decl
)))
286 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
287 && lookup_attribute ("dllexport",
288 DECL_ATTRIBUTES (vnode
->decl
)))
291 /* See if we have linker information about symbol not being used or
292 if we need to make guess based on the declaration.
294 Even if the linker clams the symbol is unused, never bring internal
295 symbols that are declared by user as used or externally visible.
296 This is needed for i.e. references from asm statements. */
297 if (symtab_used_from_object_file_p (vnode
))
299 if (vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY
)
302 /* As a special case, the COMDAT virtual tables can be unshared.
303 In LTO mode turn vtables into static variables. The variable is readonly,
304 so this does not enable more optimization, but referring static var
305 is faster for dynamic linking. Also this match logic hidding vtables
306 from LTO symbol tables. */
307 if ((in_lto_p
|| flag_whole_program
)
308 && DECL_COMDAT (vnode
->decl
)
309 && comdat_can_be_unshared_p (vnode
))
312 /* When doing link time optimizations, hidden symbols become local. */
314 && (DECL_VISIBILITY (vnode
->decl
) == VISIBILITY_HIDDEN
315 || DECL_VISIBILITY (vnode
->decl
) == VISIBILITY_INTERNAL
)
316 /* Be sure that node is defined in IR file, not in other object
317 file. In that case we don't set used_from_other_object_file. */
318 && vnode
->definition
)
320 else if (!flag_whole_program
)
323 /* Do not attempt to privatize COMDATS by default.
324 This would break linking with C++ libraries sharing
327 FIXME: We can do so for readonly vars with no address taken and
328 possibly also for vtables since no direct pointer comparsion is done.
329 It might be interesting to do so to reduce linking overhead. */
330 if (DECL_COMDAT (vnode
->decl
) || DECL_WEAK (vnode
->decl
))
335 /* Return true if reference to NODE can be replaced by a local alias.
336 Local aliases save dynamic linking overhead and enable more optimizations.
340 can_replace_by_local_alias (symtab_node
*node
)
342 return (symtab_node_availability (node
) > AVAIL_OVERWRITABLE
343 && !symtab_can_be_discarded (node
));
346 /* Return true if we can replace refernece to NODE by local alias
347 within a virtual table. Generally we can replace function pointers
348 and virtual table pointers. */
351 can_replace_by_local_alias_in_vtable (symtab_node
*node
)
353 if (is_a
<varpool_node
*> (node
)
354 && !DECL_VIRTUAL_P (node
->decl
))
356 return can_replace_by_local_alias (node
);
359 /* walk_tree callback that rewrites initializer references. */
362 update_vtable_references (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
364 if (TREE_CODE (*tp
) == VAR_DECL
365 || TREE_CODE (*tp
) == FUNCTION_DECL
)
367 if (can_replace_by_local_alias_in_vtable (symtab_get_node (*tp
)))
368 *tp
= symtab_nonoverwritable_alias (symtab_get_node (*tp
))->decl
;
371 else if (IS_TYPE_OR_DECL_P (*tp
))
376 /* In LTO we can remove COMDAT groups and weak symbols.
377 Either turn them into normal symbols or external symbol depending on
381 update_visibility_by_resolution_info (symtab_node
* node
)
385 if (!node
->externally_visible
386 || (!DECL_WEAK (node
->decl
) && !DECL_ONE_ONLY (node
->decl
))
387 || node
->resolution
== LDPR_UNKNOWN
)
390 define
= (node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
391 || node
->resolution
== LDPR_PREVAILING_DEF
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
)
398 gcc_assert (!node
->externally_visible
399 || define
== (next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
400 || next
->resolution
== LDPR_PREVAILING_DEF
401 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
));
403 if (node
->same_comdat_group
)
404 for (symtab_node
*next
= node
->same_comdat_group
;
405 next
!= node
; next
= next
->same_comdat_group
)
407 next
->set_comdat_group (NULL
);
408 DECL_WEAK (next
->decl
) = false;
409 if (next
->externally_visible
411 DECL_EXTERNAL (next
->decl
) = true;
413 node
->set_comdat_group (NULL
);
414 DECL_WEAK (node
->decl
) = false;
416 DECL_EXTERNAL (node
->decl
) = true;
417 symtab_dissolve_same_comdat_group_list (node
);
420 /* Decide on visibility of all symbols. */
423 function_and_variable_visibility (bool whole_program
)
425 struct cgraph_node
*node
;
428 /* All aliases should be procssed at this point. */
429 gcc_checking_assert (!alias_pairs
|| !alias_pairs
->length ());
431 FOR_EACH_FUNCTION (node
)
433 int flags
= flags_from_decl_or_type (node
->decl
);
435 /* Optimize away PURE and CONST constructors and destructors. */
437 && (flags
& (ECF_CONST
| ECF_PURE
))
438 && !(flags
& ECF_LOOPING_CONST_OR_PURE
))
440 DECL_STATIC_CONSTRUCTOR (node
->decl
) = 0;
441 DECL_STATIC_DESTRUCTOR (node
->decl
) = 0;
444 /* Frontends and alias code marks nodes as needed before parsing is finished.
445 We may end up marking as node external nodes where this flag is meaningless
447 if (DECL_EXTERNAL (node
->decl
) || !node
->definition
)
449 node
->force_output
= 0;
450 node
->forced_by_abi
= 0;
453 /* C++ FE on lack of COMDAT support create local COMDAT functions
454 (that ought to be shared but can not due to object format
455 limitations). It is necessary to keep the flag to make rest of C++ FE
456 happy. Clear the flag here to avoid confusion in middle-end. */
457 if (DECL_COMDAT (node
->decl
) && !TREE_PUBLIC (node
->decl
))
458 DECL_COMDAT (node
->decl
) = 0;
460 /* For external decls stop tracking same_comdat_group. It doesn't matter
461 what comdat group they are in when they won't be emitted in this TU. */
462 if (node
->same_comdat_group
&& DECL_EXTERNAL (node
->decl
))
464 #ifdef ENABLE_CHECKING
467 for (n
= node
->same_comdat_group
;
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 symtab_dissolve_same_comdat_group_list (node
);
476 gcc_assert ((!DECL_WEAK (node
->decl
)
477 && !DECL_COMDAT (node
->decl
))
478 || TREE_PUBLIC (node
->decl
)
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;
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
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
;
510 next
= next
->same_comdat_group
)
512 next
->set_comdat_group (NULL
);
513 symtab_make_decl_local (next
->decl
);
514 next
->unique_name
= ((next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
516 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
517 && TREE_PUBLIC (next
->decl
));
519 /* cgraph_externally_visible_p has already checked all other nodes
520 in the group and they will all be made local. We need to
521 dissolve the group at once so that the predicate does not
523 symtab_dissolve_same_comdat_group_list (node
);
525 if (TREE_PUBLIC (node
->decl
))
526 node
->set_comdat_group (NULL
);
527 symtab_make_decl_local (node
->decl
);
530 if (node
->thunk
.thunk_p
531 && TREE_PUBLIC (node
->decl
))
533 struct cgraph_node
*decl_node
= node
;
535 decl_node
= cgraph_function_node (decl_node
->callees
->callee
, NULL
);
537 /* Thunks have the same visibility as function they are attached to.
538 Make sure the C++ front end set this up properly. */
539 if (DECL_ONE_ONLY (decl_node
->decl
))
541 gcc_checking_assert (DECL_COMDAT (node
->decl
)
542 == DECL_COMDAT (decl_node
->decl
));
543 gcc_checking_assert (symtab_in_same_comdat_p (node
, decl_node
));
544 gcc_checking_assert (node
->same_comdat_group
);
546 node
->forced_by_abi
= decl_node
->forced_by_abi
;
547 if (DECL_EXTERNAL (decl_node
->decl
))
548 DECL_EXTERNAL (node
->decl
) = 1;
551 update_visibility_by_resolution_info (node
);
553 FOR_EACH_DEFINED_FUNCTION (node
)
555 node
->local
.local
|= cgraph_local_node_p (node
);
557 /* If we know that function can not be overwritten by a different semantics
558 and moreover its section can not be discarded, replace all direct calls
559 by calls to an nonoverwritable alias. This make dynamic linking
560 cheaper and enable more optimization.
562 TODO: We can also update virtual tables. */
563 if (node
->callers
&& can_replace_by_local_alias (node
))
565 struct cgraph_node
*alias
= cgraph (symtab_nonoverwritable_alias (node
));
567 if (alias
&& alias
!= node
)
569 while (node
->callers
)
571 struct cgraph_edge
*e
= node
->callers
;
573 cgraph_redirect_edge_callee (e
, alias
);
574 if (gimple_has_body_p (e
->caller
->decl
))
576 push_cfun (DECL_STRUCT_FUNCTION (e
->caller
->decl
));
577 cgraph_redirect_edge_call_stmt_to_callee (e
);
584 FOR_EACH_VARIABLE (vnode
)
586 /* weak flag makes no sense on local variables. */
587 gcc_assert (!DECL_WEAK (vnode
->decl
)
589 || TREE_PUBLIC (vnode
->decl
)
590 || DECL_EXTERNAL (vnode
->decl
));
591 /* In several cases declarations can not be common:
593 - when declaration has initializer
595 - when it has specific section
596 - when it resides in non-generic address space.
597 - if declaration is local, it will get into .local common section
598 so common flag is not needed. Frontends still produce these in
599 certain cases, such as for:
601 static int a __attribute__ ((common))
603 Canonicalize things here and clear the redundant flag. */
604 if (DECL_COMMON (vnode
->decl
)
605 && (!(TREE_PUBLIC (vnode
->decl
)
606 || DECL_EXTERNAL (vnode
->decl
))
607 || (DECL_INITIAL (vnode
->decl
)
608 && DECL_INITIAL (vnode
->decl
) != error_mark_node
)
609 || DECL_WEAK (vnode
->decl
)
610 || DECL_SECTION_NAME (vnode
->decl
) != NULL
611 || ! (ADDR_SPACE_GENERIC_P
612 (TYPE_ADDR_SPACE (TREE_TYPE (vnode
->decl
))))))
613 DECL_COMMON (vnode
->decl
) = 0;
615 FOR_EACH_DEFINED_VARIABLE (vnode
)
617 if (!vnode
->definition
)
619 if (varpool_externally_visible_p (vnode
))
620 vnode
->externally_visible
= true;
623 vnode
->externally_visible
= false;
624 vnode
->forced_by_abi
= false;
626 if (!vnode
->externally_visible
629 gcc_assert (in_lto_p
|| whole_program
|| !TREE_PUBLIC (vnode
->decl
));
630 vnode
->unique_name
= ((vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY
631 || vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
632 && TREE_PUBLIC (vnode
->decl
));
633 if (vnode
->same_comdat_group
&& TREE_PUBLIC (vnode
->decl
))
635 symtab_node
*next
= vnode
;
637 /* Set all members of comdat group local. */
638 if (vnode
->same_comdat_group
)
639 for (next
= vnode
->same_comdat_group
;
641 next
= next
->same_comdat_group
)
643 next
->set_comdat_group (NULL
);
644 symtab_make_decl_local (next
->decl
);
645 next
->unique_name
= ((next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
647 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
648 && TREE_PUBLIC (next
->decl
));
650 symtab_dissolve_same_comdat_group_list (vnode
);
652 if (TREE_PUBLIC (vnode
->decl
))
653 vnode
->set_comdat_group (NULL
);
654 symtab_make_decl_local (vnode
->decl
);
655 vnode
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
657 update_visibility_by_resolution_info (vnode
);
659 /* Update virutal tables to point to local aliases where possible. */
660 if (DECL_VIRTUAL_P (vnode
->decl
)
661 && !DECL_EXTERNAL (vnode
->decl
))
667 /* See if there is something to update. */
668 for (i
= 0; ipa_ref_list_referring_iterate (&vnode
->ref_list
,
670 if (ref
->use
== IPA_REF_ADDR
671 && can_replace_by_local_alias_in_vtable (ref
->referred
))
678 struct pointer_set_t
*visited_nodes
= pointer_set_create ();
679 walk_tree (&DECL_INITIAL (vnode
->decl
),
680 update_vtable_references
, NULL
, visited_nodes
);
681 pointer_set_destroy (visited_nodes
);
682 ipa_remove_all_references (&vnode
->ref_list
);
683 record_references_in_initializer (vnode
->decl
, false);
690 fprintf (dump_file
, "\nMarking local functions:");
691 FOR_EACH_DEFINED_FUNCTION (node
)
692 if (node
->local
.local
)
693 fprintf (dump_file
, " %s", node
->name ());
694 fprintf (dump_file
, "\n\n");
695 fprintf (dump_file
, "\nMarking externally visible functions:");
696 FOR_EACH_DEFINED_FUNCTION (node
)
697 if (node
->externally_visible
)
698 fprintf (dump_file
, " %s", node
->name ());
699 fprintf (dump_file
, "\n\n");
700 fprintf (dump_file
, "\nMarking externally visible variables:");
701 FOR_EACH_DEFINED_VARIABLE (vnode
)
702 if (vnode
->externally_visible
)
703 fprintf (dump_file
, " %s", vnode
->name ());
704 fprintf (dump_file
, "\n\n");
706 cgraph_function_flags_ready
= true;
710 /* Local function pass handling visibilities. This happens before LTO streaming
711 so in particular -fwhole-program should be ignored at this level. */
715 const pass_data pass_data_ipa_function_and_variable_visibility
=
717 SIMPLE_IPA_PASS
, /* type */
718 "visibility", /* name */
719 OPTGROUP_NONE
, /* optinfo_flags */
720 true, /* has_execute */
721 TV_CGRAPHOPT
, /* tv_id */
722 0, /* properties_required */
723 0, /* properties_provided */
724 0, /* properties_destroyed */
725 0, /* todo_flags_start */
726 ( TODO_remove_functions
| TODO_dump_symtab
), /* todo_flags_finish */
729 /* Bring functions local at LTO time with -fwhole-program. */
732 whole_program_function_and_variable_visibility (void)
734 function_and_variable_visibility (flag_whole_program
);
736 ipa_discover_readonly_nonaddressable_vars ();
744 const pass_data pass_data_ipa_whole_program_visibility
=
747 "whole-program", /* name */
748 OPTGROUP_NONE
, /* optinfo_flags */
749 true, /* has_execute */
750 TV_CGRAPHOPT
, /* tv_id */
751 0, /* properties_required */
752 0, /* properties_provided */
753 0, /* properties_destroyed */
754 0, /* todo_flags_start */
755 ( TODO_remove_functions
| TODO_dump_symtab
), /* todo_flags_finish */
758 class pass_ipa_whole_program_visibility
: public ipa_opt_pass_d
761 pass_ipa_whole_program_visibility (gcc::context
*ctxt
)
762 : ipa_opt_pass_d (pass_data_ipa_whole_program_visibility
, ctxt
,
763 NULL
, /* generate_summary */
764 NULL
, /* write_summary */
765 NULL
, /* read_summary */
766 NULL
, /* write_optimization_summary */
767 NULL
, /* read_optimization_summary */
768 NULL
, /* stmt_fixup */
769 0, /* function_transform_todo_flags_start */
770 NULL
, /* function_transform */
771 NULL
) /* variable_transform */
774 /* opt_pass methods: */
776 virtual bool gate (function
*)
778 /* Do not re-run on ltrans stage. */
781 virtual unsigned int execute (function
*)
783 return whole_program_function_and_variable_visibility ();
786 }; // class pass_ipa_whole_program_visibility
791 make_pass_ipa_whole_program_visibility (gcc::context
*ctxt
)
793 return new pass_ipa_whole_program_visibility (ctxt
);
796 class pass_ipa_function_and_variable_visibility
: public simple_ipa_opt_pass
799 pass_ipa_function_and_variable_visibility (gcc::context
*ctxt
)
800 : simple_ipa_opt_pass (pass_data_ipa_function_and_variable_visibility
,
804 /* opt_pass methods: */
805 virtual unsigned int execute (function
*)
807 return function_and_variable_visibility (flag_whole_program
&& !flag_lto
);
810 }; // class pass_ipa_function_and_variable_visibility
812 simple_ipa_opt_pass
*
813 make_pass_ipa_function_and_variable_visibility (gcc::context
*ctxt
)
815 return new pass_ipa_function_and_variable_visibility (ctxt
);