1 /* Basic IPA optimizations and utilities.
2 Copyright (C) 2003-2013 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/>. */
22 #include "coretypes.h"
26 #include "tree-pass.h"
30 #include "pointer-set.h"
32 #include "tree-iterator.h"
33 #include "ipa-utils.h"
34 #include "ipa-inline.h"
35 #include "tree-inline.h"
39 /* Return true when NODE can not be local. Worker for cgraph_local_node_p. */
42 cgraph_non_local_node_p_1 (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
44 /* FIXME: Aliases can be local, but i386 gets thunks wrong then. */
45 return !(cgraph_only_called_directly_or_aliased_p (node
)
46 && !ipa_ref_has_aliases_p (&node
->ref_list
)
48 && !DECL_EXTERNAL (node
->decl
)
49 && !node
->externally_visible
50 && !node
->used_from_other_partition
51 && !node
->in_other_partition
);
54 /* Return true when function can be marked local. */
57 cgraph_local_node_p (struct cgraph_node
*node
)
59 struct cgraph_node
*n
= cgraph_function_or_thunk_node (node
, NULL
);
61 /* FIXME: thunks can be considered local, but we need prevent i386
62 from attempting to change calling convention of them. */
65 return !cgraph_for_node_and_aliases (n
,
66 cgraph_non_local_node_p_1
, NULL
, true);
70 /* Return true when NODE has ADDR reference. */
73 has_addr_references_p (struct cgraph_node
*node
,
74 void *data ATTRIBUTE_UNUSED
)
79 for (i
= 0; ipa_ref_list_referring_iterate (&node
->ref_list
,
81 if (ref
->use
== IPA_REF_ADDR
)
86 /* Look for all functions inlined to NODE and update their inlined_to pointers
90 update_inlined_to_pointer (struct cgraph_node
*node
, struct cgraph_node
*inlined_to
)
92 struct cgraph_edge
*e
;
93 for (e
= node
->callees
; e
; e
= e
->next_callee
)
94 if (e
->callee
->global
.inlined_to
)
96 e
->callee
->global
.inlined_to
= inlined_to
;
97 update_inlined_to_pointer (e
->callee
, inlined_to
);
101 /* Add symtab NODE to queue starting at FIRST.
103 The queue is linked via AUX pointers and terminated by pointer to 1.
104 We enqueue nodes at two occasions: when we find them reachable or when we find
105 their bodies needed for further clonning. In the second case we mark them
106 by pointer to 2 after processing so they are re-queue when they become
110 enqueue_node (symtab_node node
, symtab_node
*first
,
111 struct pointer_set_t
*reachable
)
113 /* Node is still in queue; do nothing. */
114 if (node
->aux
&& node
->aux
!= (void *) 2)
116 /* Node was already processed as unreachable, re-enqueue
117 only if it became reachable now. */
118 if (node
->aux
== (void *)2 && !pointer_set_contains (reachable
, node
))
124 /* Process references. */
127 process_references (struct ipa_ref_list
*list
,
129 bool before_inlining_p
,
130 struct pointer_set_t
*reachable
)
134 for (i
= 0; ipa_ref_list_reference_iterate (list
, i
, ref
); i
++)
136 symtab_node node
= ref
->referred
;
138 if (node
->definition
&& !node
->in_other_partition
139 && ((!DECL_EXTERNAL (node
->decl
) || node
->alias
)
140 || (before_inlining_p
141 /* We use variable constructors during late complation for
142 constant folding. Keep references alive so partitioning
143 knows about potential references. */
144 || (TREE_CODE (node
->decl
) == VAR_DECL
146 && ctor_for_folding (node
->decl
)
147 != error_mark_node
))))
148 pointer_set_insert (reachable
, node
);
149 enqueue_node (node
, first
, reachable
);
153 /* EDGE is an polymorphic call. If BEFORE_INLINING_P is set, mark
154 all its potential targets as reachable to permit later inlining if
155 devirtualization happens. After inlining still keep their declarations
156 around, so we can devirtualize to a direct call.
158 Also try to make trivial devirutalization when no or only one target is
162 walk_polymorphic_call_targets (pointer_set_t
*reachable_call_targets
,
163 struct cgraph_edge
*edge
,
165 pointer_set_t
*reachable
, bool before_inlining_p
)
170 vec
<cgraph_node
*>targets
171 = possible_polymorphic_call_targets
172 (edge
, &final
, &cache_token
);
174 if (!pointer_set_insert (reachable_call_targets
,
177 for (i
= 0; i
< targets
.length (); i
++)
179 struct cgraph_node
*n
= targets
[i
];
181 /* Do not bother to mark virtual methods in anonymous namespace;
182 either we will find use of virtual table defining it, or it is
184 if (TREE_CODE (TREE_TYPE (n
->decl
)) == METHOD_TYPE
185 && type_in_anonymous_namespace_p
186 (method_class_type (TREE_TYPE (n
->decl
))))
189 /* Prior inlining, keep alive bodies of possible targets for
192 && before_inlining_p
)
193 pointer_set_insert (reachable
, n
);
195 /* Even after inlining we want to keep the possible targets in the
196 boundary, so late passes can still produce direct call even if
197 the chance for inlining is lost. */
198 enqueue_node (n
, first
, reachable
);
202 /* Very trivial devirtualization; when the type is
203 final or anonymous (so we know all its derivation)
204 and there is only one possible virtual call target,
205 make the edge direct. */
208 if (targets
.length () <= 1)
210 cgraph_node
*target
, *node
= edge
->caller
;
211 if (targets
.length () == 1)
214 target
= cgraph_get_create_node
215 (builtin_decl_implicit (BUILT_IN_UNREACHABLE
));
219 "Devirtualizing call in %s/%i to %s/%i\n",
220 cgraph_node_name (edge
->caller
),
222 cgraph_node_name (target
), target
->order
);
223 edge
= cgraph_make_edge_direct (edge
, target
);
224 if (!inline_summary_vec
&& edge
->call_stmt
)
225 cgraph_redirect_edge_call_stmt_to_callee (edge
);
227 inline_update_overall_summary (node
);
232 /* Perform reachability analysis and reclaim all unreachable nodes.
234 The algorithm is basically mark&sweep but with some extra refinements:
236 - reachable extern inline functions needs special handling; the bodies needs
237 to stay in memory until inlining in hope that they will be inlined.
238 After inlining we release their bodies and turn them into unanalyzed
239 nodes even when they are reachable.
241 BEFORE_INLINING_P specify whether we are before or after inlining.
243 - virtual functions are kept in callgraph even if they seem unreachable in
244 hope calls to them will be devirtualized.
246 Again we remove them after inlining. In late optimization some
247 devirtualization may happen, but it is not importnat since we won't inline
248 the call. In theory early opts and IPA should work out all important cases.
250 - virtual clones needs bodies of their origins for later materialization;
251 this means that we want to keep the body even if the origin is unreachable
252 otherwise. To avoid origin from sitting in the callgraph and being
253 walked by IPA passes, we turn them into unanalyzed nodes with body
256 We maintain set of function declaration where body needs to stay in
257 body_needed_for_clonning
259 Inline clones represent special case: their declaration match the
260 declaration of origin and cgraph_remove_node already knows how to
261 reshape callgraph and preserve body when offline copy of function or
262 inline clone is being removed.
264 - C++ virtual tables keyed to other unit are represented as DECL_EXTERNAL
265 variables with DECL_INITIAL set. We finalize these and keep reachable
266 ones around for constant folding purposes. After inlining we however
267 stop walking their references to let everything static referneced by them
268 to be removed when it is otherwise unreachable.
270 We maintain queue of both reachable symbols (i.e. defined symbols that needs
271 to stay) and symbols that are in boundary (i.e. external symbols referenced
272 by reachable symbols or origins of clones). The queue is represented
273 as linked list by AUX pointer terminated by 1.
275 A the end we keep all reachable symbols. For symbols in boundary we always
276 turn definition into a declaration, but we may keep function body around
277 based on body_needed_for_clonning
279 All symbols that enter the queue have AUX pointer non-zero and are in the
280 boundary. Pointer set REACHABLE is used to track reachable symbols.
282 Every symbol can be visited twice - once as part of boundary and once
283 as real reachable symbol. enqueue_node needs to decide whether the
284 node needs to be re-queued for second processing. For this purpose
285 we set AUX pointer of processed symbols in the boundary to constant 2. */
288 symtab_remove_unreachable_nodes (bool before_inlining_p
, FILE *file
)
290 symtab_node first
= (symtab_node
) (void *) 1;
291 struct cgraph_node
*node
, *next
;
292 struct varpool_node
*vnode
, *vnext
;
293 bool changed
= false;
294 struct pointer_set_t
*reachable
= pointer_set_create ();
295 struct pointer_set_t
*body_needed_for_clonning
= pointer_set_create ();
296 struct pointer_set_t
*reachable_call_targets
= pointer_set_create ();
298 timevar_push (TV_IPA_UNREACHABLE
);
299 #ifdef ENABLE_CHECKING
302 if (optimize
&& flag_devirtualize
)
303 build_type_inheritance_graph ();
305 fprintf (file
, "\nReclaiming functions:");
306 #ifdef ENABLE_CHECKING
307 FOR_EACH_FUNCTION (node
)
308 gcc_assert (!node
->aux
);
309 FOR_EACH_VARIABLE (vnode
)
310 gcc_assert (!vnode
->aux
);
312 /* Mark functions whose bodies are obviously needed.
313 This is mostly when they can be referenced externally. Inline clones
314 are special since their declarations are shared with master clone and thus
315 cgraph_can_remove_if_no_direct_calls_and_refs_p should not be called on them. */
316 FOR_EACH_FUNCTION (node
)
318 node
->used_as_abstract_origin
= false;
320 && !node
->global
.inlined_to
321 && !node
->in_other_partition
322 && !cgraph_can_remove_if_no_direct_calls_and_refs_p (node
))
324 gcc_assert (!node
->global
.inlined_to
);
325 pointer_set_insert (reachable
, node
);
326 enqueue_node (node
, &first
, reachable
);
329 gcc_assert (!node
->aux
);
332 /* Mark variables that are obviously needed. */
333 FOR_EACH_DEFINED_VARIABLE (vnode
)
334 if (!varpool_can_remove_if_no_refs (vnode
)
335 && !vnode
->in_other_partition
)
337 pointer_set_insert (reachable
, vnode
);
338 enqueue_node (vnode
, &first
, reachable
);
341 /* Perform reachability analysis. */
342 while (first
!= (symtab_node
) (void *) 1)
344 bool in_boundary_p
= !pointer_set_contains (reachable
, first
);
345 symtab_node node
= first
;
347 first
= (symtab_node
)first
->aux
;
349 /* If we are processing symbol in boundary, mark its AUX pointer for
350 possible later re-processing in enqueue_node. */
352 node
->aux
= (void *)2;
355 if (DECL_ABSTRACT_ORIGIN (node
->decl
))
357 struct cgraph_node
*origin_node
358 = cgraph_get_create_real_symbol_node (DECL_ABSTRACT_ORIGIN (node
->decl
));
359 origin_node
->used_as_abstract_origin
= true;
360 enqueue_node (origin_node
, &first
, reachable
);
362 /* If any symbol in a comdat group is reachable, force
363 all other in the same comdat group to be also reachable. */
364 if (node
->same_comdat_group
)
367 for (next
= node
->same_comdat_group
;
369 next
= next
->same_comdat_group
)
370 if (!pointer_set_insert (reachable
, next
))
371 enqueue_node (next
, &first
, reachable
);
373 /* Mark references as reachable. */
374 process_references (&node
->ref_list
, &first
,
375 before_inlining_p
, reachable
);
378 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (node
))
380 /* Mark the callees reachable unless they are direct calls to extern
381 inline functions we decided to not inline. */
384 struct cgraph_edge
*e
;
385 /* Keep alive possible targets for devirtualization. */
386 if (optimize
&& flag_devirtualize
)
388 struct cgraph_edge
*next
;
389 for (e
= cnode
->indirect_calls
; e
; e
= next
)
391 next
= e
->next_callee
;
392 if (e
->indirect_info
->polymorphic
)
393 walk_polymorphic_call_targets (reachable_call_targets
,
394 e
, &first
, reachable
,
398 for (e
= cnode
->callees
; e
; e
= e
->next_callee
)
400 if (e
->callee
->definition
401 && !e
->callee
->in_other_partition
402 && (!e
->inline_failed
403 || !DECL_EXTERNAL (e
->callee
->decl
)
405 || before_inlining_p
))
406 pointer_set_insert (reachable
, e
->callee
);
407 enqueue_node (e
->callee
, &first
, reachable
);
410 /* When inline clone exists, mark body to be preserved so when removing
411 offline copy of the function we don't kill it. */
412 if (cnode
->global
.inlined_to
)
413 pointer_set_insert (body_needed_for_clonning
, cnode
->decl
);
415 /* For non-inline clones, force their origins to the boundary and ensure
416 that body is not removed. */
417 while (cnode
->clone_of
)
419 bool noninline
= cnode
->clone_of
->decl
!= cnode
->decl
;
420 cnode
= cnode
->clone_of
;
423 pointer_set_insert (body_needed_for_clonning
, cnode
->decl
);
424 enqueue_node (cnode
, &first
, reachable
);
429 /* When we see constructor of external variable, keep referred nodes in the
430 boundary. This will also hold initializers of the external vars NODE
432 varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
);
434 && DECL_EXTERNAL (node
->decl
)
439 for (int i
= 0; ipa_ref_list_reference_iterate (&node
->ref_list
, i
, ref
); i
++)
440 enqueue_node (ref
->referred
, &first
, reachable
);
444 /* Remove unreachable functions. */
445 for (node
= cgraph_first_function (); node
; node
= next
)
447 next
= cgraph_next_function (node
);
449 /* If node is not needed at all, remove it. */
453 fprintf (file
, " %s", cgraph_node_name (node
));
454 cgraph_remove_node (node
);
457 /* If node is unreachable, remove its body. */
458 else if (!pointer_set_contains (reachable
, node
))
460 if (!pointer_set_contains (body_needed_for_clonning
, node
->decl
))
461 cgraph_release_function_body (node
);
462 else if (!node
->clone_of
)
463 gcc_assert (in_lto_p
|| DECL_RESULT (node
->decl
));
464 if (node
->definition
)
467 fprintf (file
, " %s", cgraph_node_name (node
));
468 node
->analyzed
= false;
469 node
->definition
= false;
470 node
->cpp_implicit_alias
= false;
472 node
->weakref
= false;
473 if (!node
->in_other_partition
)
474 node
->local
.local
= false;
475 cgraph_node_remove_callees (node
);
476 ipa_remove_all_references (&node
->ref_list
);
481 gcc_assert (node
->clone_of
|| !cgraph_function_with_gimple_body_p (node
)
482 || in_lto_p
|| DECL_RESULT (node
->decl
));
485 /* Inline clones might be kept around so their materializing allows further
486 cloning. If the function the clone is inlined into is removed, we need
487 to turn it into normal cone. */
488 FOR_EACH_FUNCTION (node
)
490 if (node
->global
.inlined_to
493 gcc_assert (node
->clones
);
494 node
->global
.inlined_to
= NULL
;
495 update_inlined_to_pointer (node
, node
);
500 /* Remove unreachable variables. */
502 fprintf (file
, "\nReclaiming variables:");
503 for (vnode
= varpool_first_variable (); vnode
; vnode
= vnext
)
505 vnext
= varpool_next_variable (vnode
);
507 /* For can_refer_decl_in_current_unit_p we want to track for
508 all external variables if they are defined in other partition
510 && (!flag_ltrans
|| !DECL_EXTERNAL (vnode
->decl
)))
513 fprintf (file
, " %s", varpool_node_name (vnode
));
514 varpool_remove_node (vnode
);
517 else if (!pointer_set_contains (reachable
, vnode
))
520 if (vnode
->definition
)
523 fprintf (file
, " %s", varpool_node_name (vnode
));
526 vnode
->definition
= false;
527 vnode
->analyzed
= false;
530 /* Keep body if it may be useful for constant folding. */
531 if ((init
= ctor_for_folding (vnode
->decl
)) == error_mark_node
)
532 varpool_remove_initializer (vnode
);
534 DECL_INITIAL (vnode
->decl
) = init
;
535 ipa_remove_all_references (&vnode
->ref_list
);
541 pointer_set_destroy (reachable
);
542 pointer_set_destroy (body_needed_for_clonning
);
543 pointer_set_destroy (reachable_call_targets
);
545 /* Now update address_taken flags and try to promote functions to be local. */
547 fprintf (file
, "\nClearing address taken flags:");
548 FOR_EACH_DEFINED_FUNCTION (node
)
549 if (node
->address_taken
550 && !node
->used_from_other_partition
)
552 if (!cgraph_for_node_and_aliases (node
, has_addr_references_p
, NULL
, true))
555 fprintf (file
, " %s", cgraph_node_name (node
));
556 node
->address_taken
= false;
558 if (cgraph_local_node_p (node
))
560 node
->local
.local
= true;
562 fprintf (file
, " (local)");
567 fprintf (file
, "\n");
569 #ifdef ENABLE_CHECKING
573 /* If we removed something, perhaps profile could be improved. */
574 if (changed
&& optimize
&& inline_edge_summary_vec
.exists ())
575 FOR_EACH_DEFINED_FUNCTION (node
)
576 ipa_propagate_frequency (node
);
578 timevar_pop (TV_IPA_UNREACHABLE
);
582 /* Discover variables that have no longer address taken or that are read only
583 and update their flags.
585 FIXME: This can not be done in between gimplify and omp_expand since
586 readonly flag plays role on what is shared and what is not. Currently we do
587 this transformation as part of whole program visibility and re-do at
588 ipa-reference pass (to take into account clonning), but it would
589 make sense to do it before early optimizations. */
592 ipa_discover_readonly_nonaddressable_vars (void)
594 struct varpool_node
*vnode
;
596 fprintf (dump_file
, "Clearing variable flags:");
597 FOR_EACH_VARIABLE (vnode
)
598 if (vnode
->definition
&& varpool_all_refs_explicit_p (vnode
)
599 && (TREE_ADDRESSABLE (vnode
->decl
)
600 || !TREE_READONLY (vnode
->decl
)))
602 bool written
= false;
603 bool address_taken
= false;
606 for (i
= 0; ipa_ref_list_referring_iterate (&vnode
->ref_list
,
608 && (!written
|| !address_taken
); i
++)
612 address_taken
= true;
620 if (TREE_ADDRESSABLE (vnode
->decl
) && !address_taken
)
623 fprintf (dump_file
, " %s (addressable)", varpool_node_name (vnode
));
624 TREE_ADDRESSABLE (vnode
->decl
) = 0;
626 if (!TREE_READONLY (vnode
->decl
) && !address_taken
&& !written
627 /* Making variable in explicit section readonly can cause section
629 See e.g. gcc.c-torture/compile/pr23237.c */
630 && DECL_SECTION_NAME (vnode
->decl
) == NULL
)
633 fprintf (dump_file
, " %s (read-only)", varpool_node_name (vnode
));
634 TREE_READONLY (vnode
->decl
) = 1;
638 fprintf (dump_file
, "\n");
641 /* Return true when there is a reference to node and it is not vtable. */
643 address_taken_from_non_vtable_p (symtab_node node
)
647 for (i
= 0; ipa_ref_list_referring_iterate (&node
->ref_list
,
649 if (ref
->use
== IPA_REF_ADDR
)
651 struct varpool_node
*node
;
652 if (is_a
<cgraph_node
> (ref
->referring
))
654 node
= ipa_ref_referring_varpool_node (ref
);
655 if (!DECL_VIRTUAL_P (node
->decl
))
661 /* A helper for comdat_can_be_unshared_p. */
664 comdat_can_be_unshared_p_1 (symtab_node node
)
666 /* When address is taken, we don't know if equality comparison won't
667 break eventually. Exception are virutal functions, C++
668 constructors/destructors and vtables, where this is not possible by
669 language standard. */
670 if (!DECL_VIRTUAL_P (node
->decl
)
671 && (TREE_CODE (node
->decl
) != FUNCTION_DECL
672 || (!DECL_CXX_CONSTRUCTOR_P (node
->decl
)
673 && !DECL_CXX_DESTRUCTOR_P (node
->decl
)))
674 && address_taken_from_non_vtable_p (node
))
677 /* If the symbol is used in some weird way, better to not touch it. */
678 if (node
->force_output
)
681 /* Explicit instantiations needs to be output when possibly
683 if (node
->forced_by_abi
684 && TREE_PUBLIC (node
->decl
)
685 && (node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY
686 && !flag_whole_program
))
689 /* Non-readonly and volatile variables can not be duplicated. */
690 if (is_a
<varpool_node
> (node
)
691 && (!TREE_READONLY (node
->decl
)
692 || TREE_THIS_VOLATILE (node
->decl
)))
697 /* COMDAT functions must be shared only if they have address taken,
698 otherwise we can produce our own private implementation with
700 Return true when turning COMDAT functoin static can not lead to wrong
701 code when the resulting object links with a library defining same COMDAT.
703 Virtual functions do have their addresses taken from the vtables,
704 but in C++ there is no way to compare their addresses for equality. */
707 comdat_can_be_unshared_p (symtab_node node
)
709 if (!comdat_can_be_unshared_p_1 (node
))
711 if (node
->same_comdat_group
)
715 /* If more than one function is in the same COMDAT group, it must
716 be shared even if just one function in the comdat group has
718 for (next
= node
->same_comdat_group
;
719 next
!= node
; next
= next
->same_comdat_group
)
720 if (!comdat_can_be_unshared_p_1 (next
))
726 /* Return true when function NODE should be considered externally visible. */
729 cgraph_externally_visible_p (struct cgraph_node
*node
,
732 if (!node
->definition
)
734 if (!TREE_PUBLIC (node
->decl
)
735 || DECL_EXTERNAL (node
->decl
))
738 /* Do not try to localize built-in functions yet. One of problems is that we
739 end up mangling their asm for WHOPR that makes it impossible to call them
740 using the implicit built-in declarations anymore. Similarly this enables
741 us to remove them as unreachable before actual calls may appear during
742 expansion or folding. */
743 if (DECL_BUILT_IN (node
->decl
))
746 /* If linker counts on us, we must preserve the function. */
747 if (symtab_used_from_object_file_p (node
))
749 if (DECL_PRESERVE_P (node
->decl
))
751 if (lookup_attribute ("externally_visible",
752 DECL_ATTRIBUTES (node
->decl
)))
754 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
755 && lookup_attribute ("dllexport",
756 DECL_ATTRIBUTES (node
->decl
)))
758 if (node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
)
760 /* When doing LTO or whole program, we can bring COMDAT functoins static.
761 This improves code quality and we know we will duplicate them at most twice
762 (in the case that we are not using plugin and link with object file
763 implementing same COMDAT) */
764 if ((in_lto_p
|| whole_program
)
765 && DECL_COMDAT (node
->decl
)
766 && comdat_can_be_unshared_p (node
))
769 /* When doing link time optimizations, hidden symbols become local. */
771 && (DECL_VISIBILITY (node
->decl
) == VISIBILITY_HIDDEN
772 || DECL_VISIBILITY (node
->decl
) == VISIBILITY_INTERNAL
)
773 /* Be sure that node is defined in IR file, not in other object
774 file. In that case we don't set used_from_other_object_file. */
777 else if (!whole_program
)
780 if (MAIN_NAME_P (DECL_NAME (node
->decl
)))
786 /* Return true when variable VNODE should be considered externally visible. */
789 varpool_externally_visible_p (struct varpool_node
*vnode
)
791 if (DECL_EXTERNAL (vnode
->decl
))
794 if (!TREE_PUBLIC (vnode
->decl
))
797 /* If linker counts on us, we must preserve the function. */
798 if (symtab_used_from_object_file_p (vnode
))
801 if (DECL_HARD_REGISTER (vnode
->decl
))
803 if (DECL_PRESERVE_P (vnode
->decl
))
805 if (lookup_attribute ("externally_visible",
806 DECL_ATTRIBUTES (vnode
->decl
)))
808 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
809 && lookup_attribute ("dllexport",
810 DECL_ATTRIBUTES (vnode
->decl
)))
813 /* See if we have linker information about symbol not being used or
814 if we need to make guess based on the declaration.
816 Even if the linker clams the symbol is unused, never bring internal
817 symbols that are declared by user as used or externally visible.
818 This is needed for i.e. references from asm statements. */
819 if (symtab_used_from_object_file_p (vnode
))
821 if (vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY
)
824 /* As a special case, the COMDAT virtual tables can be unshared.
825 In LTO mode turn vtables into static variables. The variable is readonly,
826 so this does not enable more optimization, but referring static var
827 is faster for dynamic linking. Also this match logic hidding vtables
828 from LTO symbol tables. */
829 if ((in_lto_p
|| flag_whole_program
)
830 && DECL_COMDAT (vnode
->decl
)
831 && comdat_can_be_unshared_p (vnode
))
834 /* When doing link time optimizations, hidden symbols become local. */
836 && (DECL_VISIBILITY (vnode
->decl
) == VISIBILITY_HIDDEN
837 || DECL_VISIBILITY (vnode
->decl
) == VISIBILITY_INTERNAL
)
838 /* Be sure that node is defined in IR file, not in other object
839 file. In that case we don't set used_from_other_object_file. */
840 && vnode
->definition
)
842 else if (!flag_whole_program
)
845 /* Do not attempt to privatize COMDATS by default.
846 This would break linking with C++ libraries sharing
849 FIXME: We can do so for readonly vars with no address taken and
850 possibly also for vtables since no direct pointer comparsion is done.
851 It might be interesting to do so to reduce linking overhead. */
852 if (DECL_COMDAT (vnode
->decl
) || DECL_WEAK (vnode
->decl
))
857 /* Return true if reference to NODE can be replaced by a local alias.
858 Local aliases save dynamic linking overhead and enable more optimizations.
862 can_replace_by_local_alias (symtab_node node
)
864 return (symtab_node_availability (node
) > AVAIL_OVERWRITABLE
865 && !symtab_can_be_discarded (node
));
868 /* Mark visibility of all functions.
870 A local function is one whose calls can occur only in the current
871 compilation unit and all its calls are explicit, so we can change
872 its calling convention. We simply mark all static functions whose
873 address is not taken as local.
875 We also change the TREE_PUBLIC flag of all declarations that are public
876 in language point of view but we want to overwrite this default
877 via visibilities for the backend point of view. */
880 function_and_variable_visibility (bool whole_program
)
882 struct cgraph_node
*node
;
883 struct varpool_node
*vnode
;
885 /* All aliases should be procssed at this point. */
886 gcc_checking_assert (!alias_pairs
|| !alias_pairs
->length ());
888 FOR_EACH_FUNCTION (node
)
890 int flags
= flags_from_decl_or_type (node
->decl
);
892 /* Optimize away PURE and CONST constructors and destructors. */
894 && (flags
& (ECF_CONST
| ECF_PURE
))
895 && !(flags
& ECF_LOOPING_CONST_OR_PURE
))
897 DECL_STATIC_CONSTRUCTOR (node
->decl
) = 0;
898 DECL_STATIC_DESTRUCTOR (node
->decl
) = 0;
901 /* Frontends and alias code marks nodes as needed before parsing is finished.
902 We may end up marking as node external nodes where this flag is meaningless
904 if (DECL_EXTERNAL (node
->decl
) || !node
->definition
)
906 node
->force_output
= 0;
907 node
->forced_by_abi
= 0;
910 /* C++ FE on lack of COMDAT support create local COMDAT functions
911 (that ought to be shared but can not due to object format
912 limitations). It is necessary to keep the flag to make rest of C++ FE
913 happy. Clear the flag here to avoid confusion in middle-end. */
914 if (DECL_COMDAT (node
->decl
) && !TREE_PUBLIC (node
->decl
))
915 DECL_COMDAT (node
->decl
) = 0;
917 /* For external decls stop tracking same_comdat_group. It doesn't matter
918 what comdat group they are in when they won't be emitted in this TU. */
919 if (node
->same_comdat_group
&& DECL_EXTERNAL (node
->decl
))
921 #ifdef ENABLE_CHECKING
924 for (n
= node
->same_comdat_group
;
926 n
= n
->same_comdat_group
)
927 /* If at least one of same comdat group functions is external,
928 all of them have to be, otherwise it is a front-end bug. */
929 gcc_assert (DECL_EXTERNAL (n
->decl
));
931 symtab_dissolve_same_comdat_group_list (node
);
933 gcc_assert ((!DECL_WEAK (node
->decl
)
934 && !DECL_COMDAT (node
->decl
))
935 || TREE_PUBLIC (node
->decl
)
937 || DECL_EXTERNAL (node
->decl
));
938 if (cgraph_externally_visible_p (node
, whole_program
))
940 gcc_assert (!node
->global
.inlined_to
);
941 node
->externally_visible
= true;
945 node
->externally_visible
= false;
946 node
->forced_by_abi
= false;
948 if (!node
->externally_visible
949 && node
->definition
&& !node
->weakref
950 && !DECL_EXTERNAL (node
->decl
))
952 gcc_assert (whole_program
|| in_lto_p
953 || !TREE_PUBLIC (node
->decl
));
954 node
->unique_name
= ((node
->resolution
== LDPR_PREVAILING_DEF_IRONLY
955 || node
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
956 && TREE_PUBLIC (node
->decl
));
957 symtab_make_decl_local (node
->decl
);
958 node
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
959 if (node
->same_comdat_group
)
960 /* cgraph_externally_visible_p has already checked all other nodes
961 in the group and they will all be made local. We need to
962 dissolve the group at once so that the predicate does not
964 symtab_dissolve_same_comdat_group_list (node
);
967 if (node
->thunk
.thunk_p
968 && TREE_PUBLIC (node
->decl
))
970 struct cgraph_node
*decl_node
= node
;
972 decl_node
= cgraph_function_node (decl_node
->callees
->callee
, NULL
);
974 /* Thunks have the same visibility as function they are attached to.
975 Make sure the C++ front end set this up properly. */
976 if (DECL_ONE_ONLY (decl_node
->decl
))
978 gcc_checking_assert (DECL_COMDAT (node
->decl
)
979 == DECL_COMDAT (decl_node
->decl
));
980 gcc_checking_assert (DECL_COMDAT_GROUP (node
->decl
)
981 == DECL_COMDAT_GROUP (decl_node
->decl
));
982 gcc_checking_assert (node
->same_comdat_group
);
984 if (DECL_EXTERNAL (decl_node
->decl
))
985 DECL_EXTERNAL (node
->decl
) = 1;
988 FOR_EACH_DEFINED_FUNCTION (node
)
990 node
->local
.local
|= cgraph_local_node_p (node
);
992 /* If we know that function can not be overwritten by a different semantics
993 and moreover its section can not be discarded, replace all direct calls
994 by calls to an nonoverwritable alias. This make dynamic linking
995 cheaper and enable more optimization.
997 TODO: We can also update virtual tables. */
998 if (node
->callers
&& can_replace_by_local_alias (node
))
1000 struct cgraph_node
*alias
= cgraph (symtab_nonoverwritable_alias (node
));
1002 if (alias
&& alias
!= node
)
1004 while (node
->callers
)
1006 struct cgraph_edge
*e
= node
->callers
;
1008 cgraph_redirect_edge_callee (e
, alias
);
1009 if (gimple_has_body_p (e
->caller
->decl
))
1011 push_cfun (DECL_STRUCT_FUNCTION (e
->caller
->decl
));
1012 cgraph_redirect_edge_call_stmt_to_callee (e
);
1019 FOR_EACH_VARIABLE (vnode
)
1021 /* weak flag makes no sense on local variables. */
1022 gcc_assert (!DECL_WEAK (vnode
->decl
)
1024 || TREE_PUBLIC (vnode
->decl
)
1025 || DECL_EXTERNAL (vnode
->decl
));
1026 /* In several cases declarations can not be common:
1028 - when declaration has initializer
1029 - when it is in weak
1030 - when it has specific section
1031 - when it resides in non-generic address space.
1032 - if declaration is local, it will get into .local common section
1033 so common flag is not needed. Frontends still produce these in
1034 certain cases, such as for:
1036 static int a __attribute__ ((common))
1038 Canonicalize things here and clear the redundant flag. */
1039 if (DECL_COMMON (vnode
->decl
)
1040 && (!(TREE_PUBLIC (vnode
->decl
)
1041 || DECL_EXTERNAL (vnode
->decl
))
1042 || (DECL_INITIAL (vnode
->decl
)
1043 && DECL_INITIAL (vnode
->decl
) != error_mark_node
)
1044 || DECL_WEAK (vnode
->decl
)
1045 || DECL_SECTION_NAME (vnode
->decl
) != NULL
1046 || ! (ADDR_SPACE_GENERIC_P
1047 (TYPE_ADDR_SPACE (TREE_TYPE (vnode
->decl
))))))
1048 DECL_COMMON (vnode
->decl
) = 0;
1050 FOR_EACH_DEFINED_VARIABLE (vnode
)
1052 if (!vnode
->definition
)
1054 if (varpool_externally_visible_p (vnode
))
1055 vnode
->externally_visible
= true;
1058 vnode
->externally_visible
= false;
1059 vnode
->forced_by_abi
= false;
1061 if (!vnode
->externally_visible
1064 gcc_assert (in_lto_p
|| whole_program
|| !TREE_PUBLIC (vnode
->decl
));
1065 vnode
->unique_name
= ((vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY
1066 || vnode
->resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
)
1067 && TREE_PUBLIC (vnode
->decl
));
1068 symtab_make_decl_local (vnode
->decl
);
1069 if (vnode
->same_comdat_group
)
1070 symtab_dissolve_same_comdat_group_list (vnode
);
1071 vnode
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
1077 fprintf (dump_file
, "\nMarking local functions:");
1078 FOR_EACH_DEFINED_FUNCTION (node
)
1079 if (node
->local
.local
)
1080 fprintf (dump_file
, " %s", cgraph_node_name (node
));
1081 fprintf (dump_file
, "\n\n");
1082 fprintf (dump_file
, "\nMarking externally visible functions:");
1083 FOR_EACH_DEFINED_FUNCTION (node
)
1084 if (node
->externally_visible
)
1085 fprintf (dump_file
, " %s", cgraph_node_name (node
));
1086 fprintf (dump_file
, "\n\n");
1087 fprintf (dump_file
, "\nMarking externally visible variables:");
1088 FOR_EACH_DEFINED_VARIABLE (vnode
)
1089 if (vnode
->externally_visible
)
1090 fprintf (dump_file
, " %s", varpool_node_name (vnode
));
1091 fprintf (dump_file
, "\n\n");
1093 cgraph_function_flags_ready
= true;
1097 /* Local function pass handling visibilities. This happens before LTO streaming
1098 so in particular -fwhole-program should be ignored at this level. */
1101 local_function_and_variable_visibility (void)
1103 return function_and_variable_visibility (flag_whole_program
&& !flag_lto
);
1108 const pass_data pass_data_ipa_function_and_variable_visibility
=
1110 SIMPLE_IPA_PASS
, /* type */
1111 "visibility", /* name */
1112 OPTGROUP_NONE
, /* optinfo_flags */
1113 false, /* has_gate */
1114 true, /* has_execute */
1115 TV_CGRAPHOPT
, /* tv_id */
1116 0, /* properties_required */
1117 0, /* properties_provided */
1118 0, /* properties_destroyed */
1119 0, /* todo_flags_start */
1120 ( TODO_remove_functions
| TODO_dump_symtab
), /* todo_flags_finish */
1123 class pass_ipa_function_and_variable_visibility
: public simple_ipa_opt_pass
1126 pass_ipa_function_and_variable_visibility (gcc::context
*ctxt
)
1127 : simple_ipa_opt_pass (pass_data_ipa_function_and_variable_visibility
,
1131 /* opt_pass methods: */
1132 unsigned int execute () {
1133 return local_function_and_variable_visibility ();
1136 }; // class pass_ipa_function_and_variable_visibility
1140 simple_ipa_opt_pass
*
1141 make_pass_ipa_function_and_variable_visibility (gcc::context
*ctxt
)
1143 return new pass_ipa_function_and_variable_visibility (ctxt
);
1146 /* Free inline summary. */
1149 free_inline_summary (void)
1151 inline_free_summary ();
1157 const pass_data pass_data_ipa_free_inline_summary
=
1159 SIMPLE_IPA_PASS
, /* type */
1160 "*free_inline_summary", /* name */
1161 OPTGROUP_NONE
, /* optinfo_flags */
1162 false, /* has_gate */
1163 true, /* has_execute */
1164 TV_IPA_FREE_INLINE_SUMMARY
, /* tv_id */
1165 0, /* properties_required */
1166 0, /* properties_provided */
1167 0, /* properties_destroyed */
1168 0, /* todo_flags_start */
1169 0, /* todo_flags_finish */
1172 class pass_ipa_free_inline_summary
: public simple_ipa_opt_pass
1175 pass_ipa_free_inline_summary (gcc::context
*ctxt
)
1176 : simple_ipa_opt_pass (pass_data_ipa_free_inline_summary
, ctxt
)
1179 /* opt_pass methods: */
1180 unsigned int execute () { return free_inline_summary (); }
1182 }; // class pass_ipa_free_inline_summary
1186 simple_ipa_opt_pass
*
1187 make_pass_ipa_free_inline_summary (gcc::context
*ctxt
)
1189 return new pass_ipa_free_inline_summary (ctxt
);
1192 /* Do not re-run on ltrans stage. */
1195 gate_whole_program_function_and_variable_visibility (void)
1197 return !flag_ltrans
;
1200 /* Bring functionss local at LTO time with -fwhole-program. */
1203 whole_program_function_and_variable_visibility (void)
1205 function_and_variable_visibility (flag_whole_program
);
1207 ipa_discover_readonly_nonaddressable_vars ();
1213 const pass_data pass_data_ipa_whole_program_visibility
=
1215 IPA_PASS
, /* type */
1216 "whole-program", /* name */
1217 OPTGROUP_NONE
, /* optinfo_flags */
1218 true, /* has_gate */
1219 true, /* has_execute */
1220 TV_CGRAPHOPT
, /* tv_id */
1221 0, /* properties_required */
1222 0, /* properties_provided */
1223 0, /* properties_destroyed */
1224 0, /* todo_flags_start */
1225 ( TODO_remove_functions
| TODO_dump_symtab
), /* todo_flags_finish */
1228 class pass_ipa_whole_program_visibility
: public ipa_opt_pass_d
1231 pass_ipa_whole_program_visibility (gcc::context
*ctxt
)
1232 : ipa_opt_pass_d (pass_data_ipa_whole_program_visibility
, ctxt
,
1233 NULL
, /* generate_summary */
1234 NULL
, /* write_summary */
1235 NULL
, /* read_summary */
1236 NULL
, /* write_optimization_summary */
1237 NULL
, /* read_optimization_summary */
1238 NULL
, /* stmt_fixup */
1239 0, /* function_transform_todo_flags_start */
1240 NULL
, /* function_transform */
1241 NULL
) /* variable_transform */
1244 /* opt_pass methods: */
1246 return gate_whole_program_function_and_variable_visibility ();
1248 unsigned int execute () {
1249 return whole_program_function_and_variable_visibility ();
1252 }; // class pass_ipa_whole_program_visibility
1257 make_pass_ipa_whole_program_visibility (gcc::context
*ctxt
)
1259 return new pass_ipa_whole_program_visibility (ctxt
);
1262 /* Generate and emit a static constructor or destructor. WHICH must
1263 be one of 'I' (for a constructor), 'D' (for a destructor), 'P'
1264 (for chp static vars constructor) or 'B' (for chkp static bounds
1265 constructor). BODY is a STATEMENT_LIST containing GENERIC
1266 statements. PRIORITY is the initialization priority for this
1267 constructor or destructor.
1269 FINAL specify whether the externally visible name for collect2 should
1273 cgraph_build_static_cdtor_1 (char which
, tree body
, int priority
, bool final
)
1275 static int counter
= 0;
1277 tree decl
, name
, resdecl
;
1279 /* The priority is encoded in the constructor or destructor name.
1280 collect2 will sort the names and arrange that they are called at
1283 sprintf (which_buf
, "%c_%.5d_%d", which
, priority
, counter
++);
1285 /* Proudce sane name but one not recognizable by collect2, just for the
1286 case we fail to inline the function. */
1287 sprintf (which_buf
, "sub_%c_%.5d_%d", which
, priority
, counter
++);
1288 name
= get_file_function_name (which_buf
);
1290 decl
= build_decl (input_location
, FUNCTION_DECL
, name
,
1291 build_function_type_list (void_type_node
, NULL_TREE
));
1292 current_function_decl
= decl
;
1294 resdecl
= build_decl (input_location
,
1295 RESULT_DECL
, NULL_TREE
, void_type_node
);
1296 DECL_ARTIFICIAL (resdecl
) = 1;
1297 DECL_RESULT (decl
) = resdecl
;
1298 DECL_CONTEXT (resdecl
) = decl
;
1300 allocate_struct_function (decl
, false);
1302 TREE_STATIC (decl
) = 1;
1303 TREE_USED (decl
) = 1;
1304 DECL_ARTIFICIAL (decl
) = 1;
1305 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
1306 DECL_SAVED_TREE (decl
) = body
;
1307 if (!targetm
.have_ctors_dtors
&& final
)
1309 TREE_PUBLIC (decl
) = 1;
1310 DECL_PRESERVE_P (decl
) = 1;
1312 DECL_UNINLINABLE (decl
) = 1;
1314 DECL_INITIAL (decl
) = make_node (BLOCK
);
1315 TREE_USED (DECL_INITIAL (decl
)) = 1;
1317 DECL_SOURCE_LOCATION (decl
) = input_location
;
1318 cfun
->function_end_locus
= input_location
;
1323 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1324 decl_init_priority_insert (decl
, priority
);
1327 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1328 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("chkp ctor"),
1331 decl_init_priority_insert (decl
, priority
);
1334 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1335 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("bnd_legacy"),
1338 decl_init_priority_insert (decl
, priority
);
1341 DECL_STATIC_DESTRUCTOR (decl
) = 1;
1342 decl_fini_priority_insert (decl
, priority
);
1348 gimplify_function_tree (decl
);
1350 cgraph_add_new_function (decl
, false);
1353 current_function_decl
= NULL
;
1356 /* Generate and emit a static constructor or destructor. WHICH must
1357 be one of 'I' (for a constructor), 'D' (for a destructor), 'P'
1358 (for chkp static vars constructor) or 'B' (for chkp static bounds
1359 constructor). BODY is a STATEMENT_LIST containing GENERIC
1360 statements. PRIORITY is the initialization priority for this
1361 constructor or destructor. */
1364 cgraph_build_static_cdtor (char which
, tree body
, int priority
)
1366 cgraph_build_static_cdtor_1 (which
, body
, priority
, false);
1369 /* A vector of FUNCTION_DECLs declared as static constructors. */
1370 static vec
<tree
> static_ctors
;
1371 /* A vector of FUNCTION_DECLs declared as static destructors. */
1372 static vec
<tree
> static_dtors
;
1374 /* When target does not have ctors and dtors, we call all constructor
1375 and destructor by special initialization/destruction function
1376 recognized by collect2.
1378 When we are going to build this function, collect all constructors and
1379 destructors and turn them into normal functions. */
1382 record_cdtor_fn (struct cgraph_node
*node
)
1384 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1385 static_ctors
.safe_push (node
->decl
);
1386 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1387 static_dtors
.safe_push (node
->decl
);
1388 node
= cgraph_get_node (node
->decl
);
1389 DECL_DISREGARD_INLINE_LIMITS (node
->decl
) = 1;
1392 /* Define global constructors/destructor functions for the CDTORS, of
1393 which they are LEN. The CDTORS are sorted by initialization
1394 priority. If CTOR_P is true, these are constructors; otherwise,
1395 they are destructors. */
1398 build_cdtor (bool ctor_p
, vec
<tree
> cdtors
)
1401 size_t len
= cdtors
.length ();
1408 priority_type priority
;
1417 p
= ctor_p
? DECL_INIT_PRIORITY (fn
) : DECL_FINI_PRIORITY (fn
);
1420 else if (p
!= priority
)
1426 /* When there is only one cdtor and target supports them, do nothing. */
1428 && targetm
.have_ctors_dtors
)
1433 /* Find the next batch of constructors/destructors with the same
1434 initialization priority. */
1439 call
= build_call_expr (fn
, 0);
1441 DECL_STATIC_CONSTRUCTOR (fn
) = 0;
1443 DECL_STATIC_DESTRUCTOR (fn
) = 0;
1444 /* We do not want to optimize away pure/const calls here.
1445 When optimizing, these should be already removed, when not
1446 optimizing, we want user to be able to breakpoint in them. */
1447 TREE_SIDE_EFFECTS (call
) = 1;
1448 append_to_statement_list (call
, &body
);
1450 gcc_assert (body
!= NULL_TREE
);
1451 /* Generate a function to call all the function of like
1453 cgraph_build_static_cdtor_1 (ctor_p
? 'I' : 'D', body
, priority
, true);
1457 /* Comparison function for qsort. P1 and P2 are actually of type
1458 "tree *" and point to static constructors. DECL_INIT_PRIORITY is
1459 used to determine the sort order. */
1462 compare_ctor (const void *p1
, const void *p2
)
1469 f1
= *(const tree
*)p1
;
1470 f2
= *(const tree
*)p2
;
1471 priority1
= DECL_INIT_PRIORITY (f1
);
1472 priority2
= DECL_INIT_PRIORITY (f2
);
1474 if (priority1
< priority2
)
1476 else if (priority1
> priority2
)
1479 /* Ensure a stable sort. Constructors are executed in backwarding
1480 order to make LTO initialize braries first. */
1481 return DECL_UID (f2
) - DECL_UID (f1
);
1484 /* Comparison function for qsort. P1 and P2 are actually of type
1485 "tree *" and point to static destructors. DECL_FINI_PRIORITY is
1486 used to determine the sort order. */
1489 compare_dtor (const void *p1
, const void *p2
)
1496 f1
= *(const tree
*)p1
;
1497 f2
= *(const tree
*)p2
;
1498 priority1
= DECL_FINI_PRIORITY (f1
);
1499 priority2
= DECL_FINI_PRIORITY (f2
);
1501 if (priority1
< priority2
)
1503 else if (priority1
> priority2
)
1506 /* Ensure a stable sort. */
1507 return DECL_UID (f1
) - DECL_UID (f2
);
1510 /* Generate functions to call static constructors and destructors
1511 for targets that do not support .ctors/.dtors sections. These
1512 functions have magic names which are detected by collect2. */
1515 build_cdtor_fns (void)
1517 if (!static_ctors
.is_empty ())
1519 gcc_assert (!targetm
.have_ctors_dtors
|| in_lto_p
);
1520 static_ctors
.qsort (compare_ctor
);
1521 build_cdtor (/*ctor_p=*/true, static_ctors
);
1524 if (!static_dtors
.is_empty ())
1526 gcc_assert (!targetm
.have_ctors_dtors
|| in_lto_p
);
1527 static_dtors
.qsort (compare_dtor
);
1528 build_cdtor (/*ctor_p=*/false, static_dtors
);
1532 /* Look for constructors and destructors and produce function calling them.
1533 This is needed for targets not supporting ctors or dtors, but we perform the
1534 transformation also at linktime to merge possibly numerous
1535 constructors/destructors into single function to improve code locality and
1539 ipa_cdtor_merge (void)
1541 struct cgraph_node
*node
;
1542 FOR_EACH_DEFINED_FUNCTION (node
)
1543 if (DECL_STATIC_CONSTRUCTOR (node
->decl
)
1544 || DECL_STATIC_DESTRUCTOR (node
->decl
))
1545 record_cdtor_fn (node
);
1547 static_ctors
.release ();
1548 static_dtors
.release ();
1552 /* Perform the pass when we have no ctors/dtors support
1553 or at LTO time to merge multiple constructors into single
1557 gate_ipa_cdtor_merge (void)
1559 return !targetm
.have_ctors_dtors
|| (optimize
&& in_lto_p
);
1564 const pass_data pass_data_ipa_cdtor_merge
=
1566 IPA_PASS
, /* type */
1568 OPTGROUP_NONE
, /* optinfo_flags */
1569 true, /* has_gate */
1570 true, /* has_execute */
1571 TV_CGRAPHOPT
, /* tv_id */
1572 0, /* properties_required */
1573 0, /* properties_provided */
1574 0, /* properties_destroyed */
1575 0, /* todo_flags_start */
1576 0, /* todo_flags_finish */
1579 class pass_ipa_cdtor_merge
: public ipa_opt_pass_d
1582 pass_ipa_cdtor_merge (gcc::context
*ctxt
)
1583 : ipa_opt_pass_d (pass_data_ipa_cdtor_merge
, ctxt
,
1584 NULL
, /* generate_summary */
1585 NULL
, /* write_summary */
1586 NULL
, /* read_summary */
1587 NULL
, /* write_optimization_summary */
1588 NULL
, /* read_optimization_summary */
1589 NULL
, /* stmt_fixup */
1590 0, /* function_transform_todo_flags_start */
1591 NULL
, /* function_transform */
1592 NULL
) /* variable_transform */
1595 /* opt_pass methods: */
1596 bool gate () { return gate_ipa_cdtor_merge (); }
1597 unsigned int execute () { return ipa_cdtor_merge (); }
1599 }; // class pass_ipa_cdtor_merge
1604 make_pass_ipa_cdtor_merge (gcc::context
*ctxt
)
1606 return new pass_ipa_cdtor_merge (ctxt
);