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"
87 /* Return true when NODE can not be local. Worker for cgraph_local_node_p. */
90 cgraph_node::non_local_p (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
92 /* FIXME: Aliases can be local, but i386 gets thunks wrong then. */
93 return !(node
->only_called_directly_or_aliased_p ()
94 && !node
->has_aliases_p ()
96 && !DECL_EXTERNAL (node
->decl
)
97 && !node
->externally_visible
98 && !node
->used_from_other_partition
99 && !node
->in_other_partition
);
102 /* Return true when function can be marked local. */
105 cgraph_node::local_p (void)
107 cgraph_node
*n
= ultimate_alias_target ();
109 /* FIXME: thunks can be considered local, but we need prevent i386
110 from attempting to change calling convention of them. */
111 if (n
->thunk
.thunk_p
)
113 return !n
->call_for_symbol_thunks_and_aliases (cgraph_node::non_local_p
,
118 /* Return true when there is a reference to node and it is not vtable. */
121 symtab_node::address_taken_from_non_vtable_p (void)
124 struct ipa_ref
*ref
= NULL
;
126 for (i
= 0; iterate_referring (i
, ref
); i
++)
127 if (ref
->use
== IPA_REF_ADDR
)
130 if (is_a
<cgraph_node
*> (ref
->referring
))
132 node
= dyn_cast
<varpool_node
*> (ref
->referring
);
133 if (!DECL_VIRTUAL_P (node
->decl
))
139 /* A helper for comdat_can_be_unshared_p. */
142 comdat_can_be_unshared_p_1 (symtab_node
*node
)
144 if (!node
->externally_visible
)
146 /* When address is taken, we don't know if equality comparison won't
147 break eventually. Exception are virutal functions, C++
148 constructors/destructors and vtables, where this is not possible by
149 language standard. */
150 if (!DECL_VIRTUAL_P (node
->decl
)
151 && (TREE_CODE (node
->decl
) != FUNCTION_DECL
152 || (!DECL_CXX_CONSTRUCTOR_P (node
->decl
)
153 && !DECL_CXX_DESTRUCTOR_P (node
->decl
)))
154 && node
->address_taken_from_non_vtable_p ())
157 /* If the symbol is used in some weird way, better to not touch it. */
158 if (node
->force_output
)
161 /* Explicit instantiations needs to be output when possibly
163 if (node
->forced_by_abi
164 && TREE_PUBLIC (node
->decl
)
165 && (node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY
166 && !flag_whole_program
))
169 /* Non-readonly and volatile variables can not be duplicated. */
170 if (is_a
<varpool_node
*> (node
)
171 && (!TREE_READONLY (node
->decl
)
172 || TREE_THIS_VOLATILE (node
->decl
)))
177 /* COMDAT functions must be shared only if they have address taken,
178 otherwise we can produce our own private implementation with
180 Return true when turning COMDAT functoin static can not lead to wrong
181 code when the resulting object links with a library defining same COMDAT.
183 Virtual functions do have their addresses taken from the vtables,
184 but in C++ there is no way to compare their addresses for equality. */
187 comdat_can_be_unshared_p (symtab_node
*node
)
189 if (!comdat_can_be_unshared_p_1 (node
))
191 if (node
->same_comdat_group
)
195 /* If more than one function is in the same COMDAT group, it must
196 be shared even if just one function in the comdat group has
198 for (next
= node
->same_comdat_group
;
199 next
!= node
; next
= next
->same_comdat_group
)
200 if (!comdat_can_be_unshared_p_1 (next
))
206 /* Return true when function NODE should be considered externally visible. */
209 cgraph_externally_visible_p (struct cgraph_node
*node
,
212 if (!node
->definition
)
214 if (!TREE_PUBLIC (node
->decl
)
215 || DECL_EXTERNAL (node
->decl
))
218 /* Do not try to localize built-in functions yet. One of problems is that we
219 end up mangling their asm for WHOPR that makes it impossible to call them
220 using the implicit built-in declarations anymore. Similarly this enables
221 us to remove them as unreachable before actual calls may appear during
222 expansion or folding. */
223 if (DECL_BUILT_IN (node
->decl
))
226 /* If linker counts on us, we must preserve the function. */
227 if (node
->used_from_object_file_p ())
229 if (DECL_PRESERVE_P (node
->decl
))
231 if (lookup_attribute ("externally_visible",
232 DECL_ATTRIBUTES (node
->decl
)))
234 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
235 && lookup_attribute ("dllexport",
236 DECL_ATTRIBUTES (node
->decl
)))
238 if (node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
)
240 /* When doing LTO or whole program, we can bring COMDAT functoins static.
241 This improves code quality and we know we will duplicate them at most twice
242 (in the case that we are not using plugin and link with object file
243 implementing same COMDAT) */
244 if ((in_lto_p
|| whole_program
)
245 && DECL_COMDAT (node
->decl
)
246 && comdat_can_be_unshared_p (node
))
249 /* When doing link time optimizations, hidden symbols become local. */
251 && (DECL_VISIBILITY (node
->decl
) == VISIBILITY_HIDDEN
252 || DECL_VISIBILITY (node
->decl
) == VISIBILITY_INTERNAL
)
253 /* Be sure that node is defined in IR file, not in other object
254 file. In that case we don't set used_from_other_object_file. */
257 else if (!whole_program
)
260 if (MAIN_NAME_P (DECL_NAME (node
->decl
)))
266 /* Return true when variable VNODE should be considered externally visible. */
269 varpool_externally_visible_p (varpool_node
*vnode
)
271 if (DECL_EXTERNAL (vnode
->decl
))
274 if (!TREE_PUBLIC (vnode
->decl
))
277 /* If linker counts on us, we must preserve the function. */
278 if (vnode
->used_from_object_file_p ())
281 if (DECL_HARD_REGISTER (vnode
->decl
))
283 if (DECL_PRESERVE_P (vnode
->decl
))
285 if (lookup_attribute ("externally_visible",
286 DECL_ATTRIBUTES (vnode
->decl
)))
288 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
289 && lookup_attribute ("dllexport",
290 DECL_ATTRIBUTES (vnode
->decl
)))
293 /* See if we have linker information about symbol not being used or
294 if we need to make guess based on the declaration.
296 Even if the linker clams the symbol is unused, never bring internal
297 symbols that are declared by user as used or externally visible.
298 This is needed for i.e. references from asm statements. */
299 if (vnode
->used_from_object_file_p ())
301 if (vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY
)
304 /* As a special case, the COMDAT virtual tables can be unshared.
305 In LTO mode turn vtables into static variables. The variable is readonly,
306 so this does not enable more optimization, but referring static var
307 is faster for dynamic linking. Also this match logic hidding vtables
308 from LTO symbol tables. */
309 if ((in_lto_p
|| flag_whole_program
)
310 && DECL_COMDAT (vnode
->decl
)
311 && comdat_can_be_unshared_p (vnode
))
314 /* When doing link time optimizations, hidden symbols become local. */
316 && (DECL_VISIBILITY (vnode
->decl
) == VISIBILITY_HIDDEN
317 || DECL_VISIBILITY (vnode
->decl
) == VISIBILITY_INTERNAL
)
318 /* Be sure that node is defined in IR file, not in other object
319 file. In that case we don't set used_from_other_object_file. */
320 && vnode
->definition
)
322 else if (!flag_whole_program
)
325 /* Do not attempt to privatize COMDATS by default.
326 This would break linking with C++ libraries sharing
329 FIXME: We can do so for readonly vars with no address taken and
330 possibly also for vtables since no direct pointer comparsion is done.
331 It might be interesting to do so to reduce linking overhead. */
332 if (DECL_COMDAT (vnode
->decl
) || DECL_WEAK (vnode
->decl
))
337 /* Return true if reference to NODE can be replaced by a local alias.
338 Local aliases save dynamic linking overhead and enable more optimizations.
342 can_replace_by_local_alias (symtab_node
*node
)
344 return (node
->get_availability () > AVAIL_INTERPOSABLE
345 && !decl_binds_to_current_def_p (node
->decl
)
346 && !node
->can_be_discarded_p ());
349 /* Return true if we can replace refernece to NODE by local alias
350 within a virtual table. Generally we can replace function pointers
351 and virtual table pointers. */
354 can_replace_by_local_alias_in_vtable (symtab_node
*node
)
356 if (is_a
<varpool_node
*> (node
)
357 && !DECL_VIRTUAL_P (node
->decl
))
359 return can_replace_by_local_alias (node
);
362 /* walk_tree callback that rewrites initializer references. */
365 update_vtable_references (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
367 if (TREE_CODE (*tp
) == VAR_DECL
368 || TREE_CODE (*tp
) == FUNCTION_DECL
)
370 if (can_replace_by_local_alias_in_vtable (symtab_node::get (*tp
)))
371 *tp
= symtab_node::get (*tp
)->noninterposable_alias ()->decl
;
374 else if (IS_TYPE_OR_DECL_P (*tp
))
379 /* In LTO we can remove COMDAT groups and weak symbols.
380 Either turn them into normal symbols or external symbol depending on
384 update_visibility_by_resolution_info (symtab_node
* node
)
388 if (!node
->externally_visible
389 || (!DECL_WEAK (node
->decl
) && !DECL_ONE_ONLY (node
->decl
))
390 || node
->resolution
== LDPR_UNKNOWN
)
393 define
= (node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
394 || node
->resolution
== LDPR_PREVAILING_DEF
395 || node
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
);
397 /* The linker decisions ought to agree in the whole group. */
398 if (node
->same_comdat_group
)
399 for (symtab_node
*next
= node
->same_comdat_group
;
400 next
!= node
; next
= next
->same_comdat_group
)
401 gcc_assert (!node
->externally_visible
402 || define
== (next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
403 || next
->resolution
== LDPR_PREVAILING_DEF
404 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
));
406 if (node
->same_comdat_group
)
407 for (symtab_node
*next
= node
->same_comdat_group
;
408 next
!= node
; next
= next
->same_comdat_group
)
410 next
->set_comdat_group (NULL
);
411 DECL_WEAK (next
->decl
) = false;
412 if (next
->externally_visible
414 DECL_EXTERNAL (next
->decl
) = true;
416 node
->set_comdat_group (NULL
);
417 DECL_WEAK (node
->decl
) = false;
419 DECL_EXTERNAL (node
->decl
) = true;
420 node
->dissolve_same_comdat_group_list ();
423 /* Decide on visibility of all symbols. */
426 function_and_variable_visibility (bool whole_program
)
428 struct cgraph_node
*node
;
431 /* All aliases should be procssed at this point. */
432 gcc_checking_assert (!alias_pairs
|| !alias_pairs
->length ());
434 FOR_EACH_FUNCTION (node
)
436 int flags
= flags_from_decl_or_type (node
->decl
);
438 /* Optimize away PURE and CONST constructors and destructors. */
440 && (flags
& (ECF_CONST
| ECF_PURE
))
441 && !(flags
& ECF_LOOPING_CONST_OR_PURE
))
443 DECL_STATIC_CONSTRUCTOR (node
->decl
) = 0;
444 DECL_STATIC_DESTRUCTOR (node
->decl
) = 0;
447 /* Frontends and alias code marks nodes as needed before parsing is finished.
448 We may end up marking as node external nodes where this flag is meaningless
450 if (DECL_EXTERNAL (node
->decl
) || !node
->definition
)
452 node
->force_output
= 0;
453 node
->forced_by_abi
= 0;
456 /* C++ FE on lack of COMDAT support create local COMDAT functions
457 (that ought to be shared but can not due to object format
458 limitations). It is necessary to keep the flag to make rest of C++ FE
459 happy. Clear the flag here to avoid confusion in middle-end. */
460 if (DECL_COMDAT (node
->decl
) && !TREE_PUBLIC (node
->decl
))
461 DECL_COMDAT (node
->decl
) = 0;
463 /* For external decls stop tracking same_comdat_group. It doesn't matter
464 what comdat group they are in when they won't be emitted in this TU. */
465 if (node
->same_comdat_group
&& DECL_EXTERNAL (node
->decl
))
467 #ifdef ENABLE_CHECKING
470 for (n
= node
->same_comdat_group
;
472 n
= n
->same_comdat_group
)
473 /* If at least one of same comdat group functions is external,
474 all of them have to be, otherwise it is a front-end bug. */
475 gcc_assert (DECL_EXTERNAL (n
->decl
));
477 node
->dissolve_same_comdat_group_list ();
479 gcc_assert ((!DECL_WEAK (node
->decl
)
480 && !DECL_COMDAT (node
->decl
))
481 || TREE_PUBLIC (node
->decl
)
483 || DECL_EXTERNAL (node
->decl
));
484 if (cgraph_externally_visible_p (node
, whole_program
))
486 gcc_assert (!node
->global
.inlined_to
);
487 node
->externally_visible
= true;
491 node
->externally_visible
= false;
492 node
->forced_by_abi
= false;
494 if (!node
->externally_visible
495 && node
->definition
&& !node
->weakref
496 && !DECL_EXTERNAL (node
->decl
))
498 gcc_assert (whole_program
|| in_lto_p
499 || !TREE_PUBLIC (node
->decl
));
500 node
->unique_name
= ((node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
502 || node
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
503 && TREE_PUBLIC (node
->decl
));
504 node
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
505 if (node
->same_comdat_group
&& TREE_PUBLIC (node
->decl
))
507 symtab_node
*next
= node
;
509 /* Set all members of comdat group local. */
510 if (node
->same_comdat_group
)
511 for (next
= node
->same_comdat_group
;
513 next
= next
->same_comdat_group
)
515 next
->set_comdat_group (NULL
);
517 next
->set_section (NULL
);
518 next
->make_decl_local ();
519 next
->unique_name
= ((next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
521 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
522 && TREE_PUBLIC (next
->decl
));
524 /* cgraph_externally_visible_p has already checked all other nodes
525 in the group and they will all be made local. We need to
526 dissolve the group at once so that the predicate does not
528 node
->dissolve_same_comdat_group_list ();
530 if (TREE_PUBLIC (node
->decl
))
531 node
->set_comdat_group (NULL
);
532 if (DECL_COMDAT (node
->decl
) && !node
->alias
)
533 node
->set_section (NULL
);
534 node
->make_decl_local ();
537 if (node
->thunk
.thunk_p
538 && TREE_PUBLIC (node
->decl
))
540 struct cgraph_node
*decl_node
= node
;
542 decl_node
= decl_node
->callees
->callee
->function_symbol ();
544 /* Thunks have the same visibility as function they are attached to.
545 Make sure the C++ front end set this up properly. */
546 if (DECL_ONE_ONLY (decl_node
->decl
))
548 gcc_checking_assert (DECL_COMDAT (node
->decl
)
549 == DECL_COMDAT (decl_node
->decl
));
550 gcc_checking_assert (node
->in_same_comdat_group_p (decl_node
));
551 gcc_checking_assert (node
->same_comdat_group
);
553 node
->forced_by_abi
= decl_node
->forced_by_abi
;
554 if (DECL_EXTERNAL (decl_node
->decl
))
555 DECL_EXTERNAL (node
->decl
) = 1;
558 update_visibility_by_resolution_info (node
);
560 FOR_EACH_DEFINED_FUNCTION (node
)
562 node
->local
.local
|= node
->local_p ();
564 /* If we know that function can not be overwritten by a different semantics
565 and moreover its section can not be discarded, replace all direct calls
566 by calls to an noninterposable alias. This make dynamic linking
567 cheaper and enable more optimization.
569 TODO: We can also update virtual tables. */
571 && can_replace_by_local_alias (node
))
573 cgraph_node
*alias
= dyn_cast
<cgraph_node
*>
574 (node
->noninterposable_alias ());
576 if (alias
&& alias
!= node
)
578 while (node
->callers
)
580 struct cgraph_edge
*e
= node
->callers
;
582 cgraph_redirect_edge_callee (e
, alias
);
583 if (gimple_has_body_p (e
->caller
->decl
))
585 push_cfun (DECL_STRUCT_FUNCTION (e
->caller
->decl
));
586 cgraph_redirect_edge_call_stmt_to_callee (e
);
593 FOR_EACH_VARIABLE (vnode
)
595 /* weak flag makes no sense on local variables. */
596 gcc_assert (!DECL_WEAK (vnode
->decl
)
598 || TREE_PUBLIC (vnode
->decl
)
599 || DECL_EXTERNAL (vnode
->decl
));
600 /* In several cases declarations can not be common:
602 - when declaration has initializer
604 - when it has specific section
605 - when it resides in non-generic address space.
606 - if declaration is local, it will get into .local common section
607 so common flag is not needed. Frontends still produce these in
608 certain cases, such as for:
610 static int a __attribute__ ((common))
612 Canonicalize things here and clear the redundant flag. */
613 if (DECL_COMMON (vnode
->decl
)
614 && (!(TREE_PUBLIC (vnode
->decl
)
615 || DECL_EXTERNAL (vnode
->decl
))
616 || (DECL_INITIAL (vnode
->decl
)
617 && DECL_INITIAL (vnode
->decl
) != error_mark_node
)
618 || DECL_WEAK (vnode
->decl
)
619 || DECL_SECTION_NAME (vnode
->decl
) != NULL
620 || ! (ADDR_SPACE_GENERIC_P
621 (TYPE_ADDR_SPACE (TREE_TYPE (vnode
->decl
))))))
622 DECL_COMMON (vnode
->decl
) = 0;
624 FOR_EACH_DEFINED_VARIABLE (vnode
)
626 if (!vnode
->definition
)
628 if (varpool_externally_visible_p (vnode
))
629 vnode
->externally_visible
= true;
632 vnode
->externally_visible
= false;
633 vnode
->forced_by_abi
= false;
635 if (!vnode
->externally_visible
638 gcc_assert (in_lto_p
|| whole_program
|| !TREE_PUBLIC (vnode
->decl
));
639 vnode
->unique_name
= ((vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY
640 || vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
641 && TREE_PUBLIC (vnode
->decl
));
642 if (vnode
->same_comdat_group
&& TREE_PUBLIC (vnode
->decl
))
644 symtab_node
*next
= vnode
;
646 /* Set all members of comdat group local. */
647 if (vnode
->same_comdat_group
)
648 for (next
= vnode
->same_comdat_group
;
650 next
= next
->same_comdat_group
)
652 next
->set_comdat_group (NULL
);
654 next
->set_section (NULL
);
655 next
->make_decl_local ();
656 next
->unique_name
= ((next
->resolution
== LDPR_PREVAILING_DEF_IRONLY
658 || next
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
659 && TREE_PUBLIC (next
->decl
));
661 vnode
->dissolve_same_comdat_group_list ();
663 if (TREE_PUBLIC (vnode
->decl
))
664 vnode
->set_comdat_group (NULL
);
665 if (DECL_COMDAT (vnode
->decl
) && !vnode
->alias
)
666 vnode
->set_section (NULL
);
667 vnode
->make_decl_local ();
668 vnode
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
670 update_visibility_by_resolution_info (vnode
);
672 /* Update virtual tables to point to local aliases where possible. */
673 if (DECL_VIRTUAL_P (vnode
->decl
)
674 && !DECL_EXTERNAL (vnode
->decl
))
680 /* See if there is something to update. */
681 for (i
= 0; vnode
->iterate_referring (i
, ref
); i
++)
682 if (ref
->use
== IPA_REF_ADDR
683 && can_replace_by_local_alias_in_vtable (ref
->referred
))
690 struct pointer_set_t
*visited_nodes
= pointer_set_create ();
692 varpool_get_constructor (vnode
);
693 walk_tree (&DECL_INITIAL (vnode
->decl
),
694 update_vtable_references
, NULL
, visited_nodes
);
695 pointer_set_destroy (visited_nodes
);
696 vnode
->remove_all_references ();
697 record_references_in_initializer (vnode
->decl
, false);
704 fprintf (dump_file
, "\nMarking local functions:");
705 FOR_EACH_DEFINED_FUNCTION (node
)
706 if (node
->local
.local
)
707 fprintf (dump_file
, " %s", node
->name ());
708 fprintf (dump_file
, "\n\n");
709 fprintf (dump_file
, "\nMarking externally visible functions:");
710 FOR_EACH_DEFINED_FUNCTION (node
)
711 if (node
->externally_visible
)
712 fprintf (dump_file
, " %s", node
->name ());
713 fprintf (dump_file
, "\n\n");
714 fprintf (dump_file
, "\nMarking externally visible variables:");
715 FOR_EACH_DEFINED_VARIABLE (vnode
)
716 if (vnode
->externally_visible
)
717 fprintf (dump_file
, " %s", vnode
->name ());
718 fprintf (dump_file
, "\n\n");
720 cgraph_function_flags_ready
= true;
724 /* Local function pass handling visibilities. This happens before LTO streaming
725 so in particular -fwhole-program should be ignored at this level. */
729 const pass_data pass_data_ipa_function_and_variable_visibility
=
731 SIMPLE_IPA_PASS
, /* type */
732 "visibility", /* name */
733 OPTGROUP_NONE
, /* optinfo_flags */
734 TV_CGRAPHOPT
, /* tv_id */
735 0, /* properties_required */
736 0, /* properties_provided */
737 0, /* properties_destroyed */
738 0, /* todo_flags_start */
739 ( TODO_remove_functions
| TODO_dump_symtab
), /* todo_flags_finish */
742 /* Bring functions local at LTO time with -fwhole-program. */
745 whole_program_function_and_variable_visibility (void)
747 function_and_variable_visibility (flag_whole_program
);
749 ipa_discover_readonly_nonaddressable_vars ();
757 const pass_data pass_data_ipa_whole_program_visibility
=
760 "whole-program", /* name */
761 OPTGROUP_NONE
, /* optinfo_flags */
762 TV_CGRAPHOPT
, /* tv_id */
763 0, /* properties_required */
764 0, /* properties_provided */
765 0, /* properties_destroyed */
766 0, /* todo_flags_start */
767 ( TODO_remove_functions
| TODO_dump_symtab
), /* todo_flags_finish */
770 class pass_ipa_whole_program_visibility
: public ipa_opt_pass_d
773 pass_ipa_whole_program_visibility (gcc::context
*ctxt
)
774 : ipa_opt_pass_d (pass_data_ipa_whole_program_visibility
, ctxt
,
775 NULL
, /* generate_summary */
776 NULL
, /* write_summary */
777 NULL
, /* read_summary */
778 NULL
, /* write_optimization_summary */
779 NULL
, /* read_optimization_summary */
780 NULL
, /* stmt_fixup */
781 0, /* function_transform_todo_flags_start */
782 NULL
, /* function_transform */
783 NULL
) /* variable_transform */
786 /* opt_pass methods: */
788 virtual bool gate (function
*)
790 /* Do not re-run on ltrans stage. */
793 virtual unsigned int execute (function
*)
795 return whole_program_function_and_variable_visibility ();
798 }; // class pass_ipa_whole_program_visibility
803 make_pass_ipa_whole_program_visibility (gcc::context
*ctxt
)
805 return new pass_ipa_whole_program_visibility (ctxt
);
808 class pass_ipa_function_and_variable_visibility
: public simple_ipa_opt_pass
811 pass_ipa_function_and_variable_visibility (gcc::context
*ctxt
)
812 : simple_ipa_opt_pass (pass_data_ipa_function_and_variable_visibility
,
816 /* opt_pass methods: */
817 virtual unsigned int execute (function
*)
819 return function_and_variable_visibility (flag_whole_program
&& !flag_lto
);
822 }; // class pass_ipa_function_and_variable_visibility
824 simple_ipa_opt_pass
*
825 make_pass_ipa_function_and_variable_visibility (gcc::context
*ctxt
)
827 return new pass_ipa_function_and_variable_visibility (ctxt
);