1 /* LTO partitioning logic routines.
2 Copyright 2009, 2010, 2011, 2012 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"
27 #include "lto-streamer.h"
30 #include "ipa-inline.h"
31 #include "ipa-utils.h"
32 #include "lto-partition.h"
34 /* Classifcation of symbols into classes WRT partitioning. */
37 /* External declarations are ignored by partitioning algorithms and they are
38 added into the boundary later via compute_ltrans_boundary. */
40 /* Partitioned symbols are pur into one of partitions. */
42 /* Duplicated symbols (such as comdat or constant pool references) are
43 copied into every node needing them via add_symbol_to_partition. */
47 VEC(ltrans_partition
, heap
) *ltrans_partitions
;
49 static void add_symbol_to_partition (ltrans_partition part
, symtab_node node
);
51 /* Classify symbol NODE. */
54 get_symbol_class (symtab_node node
)
56 /* Inline clones are always duplicated.
57 This include external delcarations. */
58 if (symtab_function_p (node
)
59 && cgraph (node
)->global
.inlined_to
)
60 return SYMBOL_DUPLICATE
;
62 /* External declarations are external. */
63 if (DECL_EXTERNAL (node
->symbol
.decl
))
64 return SYMBOL_EXTERNAL
;
66 if (symtab_variable_p (node
))
68 /* Constant pool references use local symbol names that can not
69 be promoted global. We should never put into a constant pool
70 objects that can not be duplicated across partitions. */
71 if (DECL_IN_CONSTANT_POOL (node
->symbol
.decl
))
72 return SYMBOL_DUPLICATE
;
73 gcc_checking_assert (varpool (node
)->analyzed
);
75 /* Functions that are cloned may stay in callgraph even if they are unused.
76 Handle them as external; compute_ltrans_boundary take care to make
77 proper things to happen (i.e. to make them appear in the boundary but
78 with body streamed, so clone can me materialized). */
79 else if (!cgraph (node
)->analyzed
)
80 return SYMBOL_EXTERNAL
;
82 /* Weakref aliases are always duplicated. */
83 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (node
->symbol
.decl
)))
84 return SYMBOL_DUPLICATE
;
86 /* Comdats are duplicated to every use unless they are keyed.
87 Those do not need duplication. */
88 if (DECL_COMDAT (node
->symbol
.decl
)
89 && !node
->symbol
.force_output
90 && !symtab_used_from_object_file_p ((symtab_node
) node
))
91 return SYMBOL_DUPLICATE
;
93 return SYMBOL_PARTITION
;
96 /* Create new partition with name NAME. */
98 static ltrans_partition
99 new_partition (const char *name
)
101 ltrans_partition part
= XCNEW (struct ltrans_partition_def
);
102 part
->encoder
= lto_symtab_encoder_new (false);
105 VEC_safe_push (ltrans_partition
, heap
, ltrans_partitions
, part
);
109 /* Free memory used by ltrans datastructures. */
112 free_ltrans_partitions (void)
115 ltrans_partition part
;
116 for (idx
= 0; VEC_iterate (ltrans_partition
, ltrans_partitions
, idx
, part
); idx
++)
118 if (part
->initializers_visited
)
119 pointer_set_destroy (part
->initializers_visited
);
120 /* Symtab encoder is freed after streaming. */
123 VEC_free (ltrans_partition
, heap
, ltrans_partitions
);
126 /* Return true if symbol is already in some partition. */
129 symbol_partitioned_p (symtab_node node
)
131 return node
->symbol
.aux
;
134 /* Add references into the partition. */
136 add_references_to_partition (ltrans_partition part
, symtab_node node
)
141 /* Add all duplicated references to the partition. */
142 for (i
= 0; ipa_ref_list_reference_iterate (&node
->symbol
.ref_list
, i
, ref
); i
++)
143 if (get_symbol_class (ref
->referred
) == SYMBOL_DUPLICATE
)
144 add_symbol_to_partition (part
, ref
->referred
);
145 /* References to a readonly variable may be constant foled into its value.
146 Recursively look into the initializers of the constant variable and add
148 else if (symtab_variable_p (ref
->referred
)
149 && const_value_known_p (ref
->referred
->symbol
.decl
)
150 && !lto_symtab_encoder_in_partition_p (part
->encoder
, ref
->referred
))
152 if (!part
->initializers_visited
)
153 part
->initializers_visited
= pointer_set_create ();
154 if (!pointer_set_insert (part
->initializers_visited
, ref
->referred
))
155 add_references_to_partition (part
, ref
->referred
);
159 /* Helper function for add_symbol_to_partition doing the actual dirty work
160 of adding NODE to PART. */
163 add_symbol_to_partition_1 (ltrans_partition part
, symtab_node node
)
165 enum symbol_class c
= get_symbol_class (node
);
170 /* If NODE is already there, we have nothing to do. */
171 if (lto_symtab_encoder_in_partition_p (part
->encoder
, (symtab_node
) node
))
174 /* non-duplicated aliases or tunks of a duplicated symbol needs to be output
177 Be lax about comdats; they may or may not be duplicated and we may
178 end up in need to duplicate keyed comdat because it has unkeyed alias. */
179 if (c
== SYMBOL_PARTITION
&& !DECL_COMDAT (node
->symbol
.decl
)
180 && symbol_partitioned_p (node
))
183 /* Be sure that we never try to duplicate partitioned symbol
184 or add external symbol. */
185 gcc_assert (c
!= SYMBOL_EXTERNAL
186 && (c
== SYMBOL_DUPLICATE
|| !symbol_partitioned_p (node
)));
188 lto_set_symtab_encoder_in_partition (part
->encoder
, (symtab_node
) node
);
190 if (symbol_partitioned_p (node
))
192 node
->symbol
.in_other_partition
= 1;
193 if (cgraph_dump_file
)
194 fprintf (cgraph_dump_file
, "Symbol node %s now used in multiple partitions\n",
195 symtab_node_name (node
));
197 node
->symbol
.aux
= (void *)((size_t)node
->symbol
.aux
+ 1);
199 if (symtab_function_p (node
))
201 struct cgraph_node
*cnode
= cgraph (node
);
202 struct cgraph_edge
*e
;
203 part
->insns
+= inline_summary (cnode
)->self_size
;
205 /* Add all inline clones and callees that are duplicated. */
206 for (e
= cnode
->callees
; e
; e
= e
->next_callee
)
207 if (!e
->inline_failed
)
208 add_symbol_to_partition_1 (part
, (symtab_node
) e
->callee
);
209 else if (get_symbol_class ((symtab_node
) e
->callee
) == SYMBOL_DUPLICATE
)
210 add_symbol_to_partition (part
, (symtab_node
) e
->callee
);
212 /* Add all thunks associated with the function. */
213 for (e
= cnode
->callers
; e
; e
= e
->next_caller
)
214 if (e
->caller
->thunk
.thunk_p
)
215 add_symbol_to_partition_1 (part
, (symtab_node
) e
->caller
);
218 add_references_to_partition (part
, node
);
220 /* Add all aliases associated with the symbol. */
221 for (i
= 0; ipa_ref_list_referring_iterate (&node
->symbol
.ref_list
, i
, ref
); i
++)
222 if (ref
->use
== IPA_REF_ALIAS
223 && !lookup_attribute ("weakref",
225 (ref
->referring
->symbol
.decl
)))
226 add_symbol_to_partition_1 (part
, ref
->referring
);
228 /* Ensure that SAME_COMDAT_GROUP lists all allways added in a group. */
229 if (node
->symbol
.same_comdat_group
)
230 for (node1
= node
->symbol
.same_comdat_group
;
231 node1
!= node
; node1
= node1
->symbol
.same_comdat_group
)
233 bool added
= add_symbol_to_partition_1 (part
, node1
);
239 /* If symbol NODE is really part of other symbol's definition (i.e. it is
240 internal label, thunk, alias or so), return the outer symbol.
241 When add_symbol_to_partition_1 is called on the outer symbol it must
242 eventually add NODE, too. */
244 contained_in_symbol (symtab_node node
)
246 /* Weakrefs are never contained in anything. */
247 if (lookup_attribute ("weakref",
248 DECL_ATTRIBUTES (node
->symbol
.decl
)))
250 if (symtab_function_p (node
))
252 struct cgraph_node
*cnode
= cgraph_function_node (cgraph (node
), NULL
);
253 if (cnode
->global
.inlined_to
)
254 cnode
= cnode
->global
.inlined_to
;
255 return (symtab_node
) cnode
;
257 else if (symtab_variable_p (node
))
258 return (symtab_node
) varpool_variable_node (varpool (node
), NULL
);
262 /* Add symbol NODE to partition. When definition of NODE is part
263 of other symbol definition, add the other symbol, too. */
266 add_symbol_to_partition (ltrans_partition part
, symtab_node node
)
270 /* Verify that we do not try to duplicate something that can not be. */
271 gcc_checking_assert (get_symbol_class (node
) == SYMBOL_DUPLICATE
272 || !symbol_partitioned_p (node
));
274 while ((node1
= contained_in_symbol (node
)) != node
)
277 /* If we have duplicated symbol contained in something we can not duplicate,
278 we are very badly screwed. The other way is possible, so we do not
279 assert this in add_symbol_to_partition_1.
281 Be lax about comdats; they may or may not be duplicated and we may
282 end up in need to duplicate keyed comdat because it has unkeyed alias. */
283 gcc_assert (get_symbol_class (node
) == SYMBOL_DUPLICATE
284 || DECL_COMDAT (node
->symbol
.decl
)
285 || !symbol_partitioned_p (node
));
286 add_symbol_to_partition_1 (part
, node
);
289 /* Undo all additions until number of cgraph nodes in PARITION is N_CGRAPH_NODES
290 and number of varpool nodes is N_VARPOOL_NODES. */
293 undo_partition (ltrans_partition partition
, unsigned int n_nodes
)
295 while (lto_symtab_encoder_size (partition
->encoder
) > (int)n_nodes
)
297 symtab_node node
= lto_symtab_encoder_deref (partition
->encoder
,
300 /* After UNDO we no longer know what was visited. */
301 if (partition
->initializers_visited
)
302 pointer_set_destroy (partition
->initializers_visited
);
303 partition
->initializers_visited
= NULL
;
305 if (symtab_function_p (node
))
306 partition
->insns
-= inline_summary (cgraph (node
))->self_size
;
307 lto_symtab_encoder_delete_node (partition
->encoder
, node
);
308 node
->symbol
.aux
= (void *)((size_t)node
->symbol
.aux
- 1);
312 /* Group cgrah nodes by input files. This is used mainly for testing
316 lto_1_to_1_map (void)
319 struct lto_file_decl_data
*file_data
;
320 struct pointer_map_t
*pmap
;
321 ltrans_partition partition
;
325 pmap
= pointer_map_create ();
327 FOR_EACH_SYMBOL (node
)
329 if (get_symbol_class (node
) != SYMBOL_PARTITION
330 || symbol_partitioned_p (node
))
333 file_data
= node
->symbol
.lto_file_data
;
337 slot
= pointer_map_contains (pmap
, file_data
);
339 partition
= (ltrans_partition
) *slot
;
342 partition
= new_partition (file_data
->file_name
);
343 slot
= pointer_map_insert (pmap
, file_data
);
349 && VEC_length (ltrans_partition
, ltrans_partitions
))
350 partition
= VEC_index (ltrans_partition
, ltrans_partitions
, 0);
353 partition
= new_partition ("");
354 slot
= pointer_map_insert (pmap
, NULL
);
359 add_symbol_to_partition (partition
, (symtab_node
) node
);
362 /* If the cgraph is empty, create one cgraph node set so that there is still
363 an output file for any variables that need to be exported in a DSO. */
365 new_partition ("empty");
367 pointer_map_destroy (pmap
);
371 /* Maximal partitioning. Put every new symbol into new partition if possible. */
377 ltrans_partition partition
;
380 FOR_EACH_SYMBOL (node
)
382 if (get_symbol_class (node
) != SYMBOL_PARTITION
383 || symbol_partitioned_p (node
))
385 partition
= new_partition (symtab_node_asm_name (node
));
386 add_symbol_to_partition (partition
, (symtab_node
) node
);
390 new_partition ("empty");
393 /* Helper function for qsort; sort nodes by order. */
395 node_cmp (const void *pa
, const void *pb
)
397 const struct cgraph_node
*a
= *(const struct cgraph_node
* const *) pa
;
398 const struct cgraph_node
*b
= *(const struct cgraph_node
* const *) pb
;
399 return b
->symbol
.order
- a
->symbol
.order
;
402 /* Helper function for qsort; sort nodes by order. */
404 varpool_node_cmp (const void *pa
, const void *pb
)
406 const struct varpool_node
*a
= *(const struct varpool_node
* const *) pa
;
407 const struct varpool_node
*b
= *(const struct varpool_node
* const *) pb
;
408 return b
->symbol
.order
- a
->symbol
.order
;
411 /* Group cgraph nodes into equally-sized partitions.
413 The partitioning algorithm is simple: nodes are taken in predefined order.
414 The order corresponds to the order we want functions to have in the final
415 output. In the future this will be given by function reordering pass, but
416 at the moment we use the topological order, which is a good approximation.
418 The goal is to partition this linear order into intervals (partitions) so
419 that all the partitions have approximately the same size and the number of
420 callgraph or IPA reference edges crossing boundaries is minimal.
422 This is a lot faster (O(n) in size of callgraph) than algorithms doing
423 priority-based graph clustering that are generally O(n^2) and, since
424 WHOPR is designed to make things go well across partitions, it leads
427 We compute the expected size of a partition as:
429 max (total_size / lto_partitions, min_partition_size)
431 We use dynamic expected size of partition so small programs are partitioned
432 into enough partitions to allow use of multiple CPUs, while large programs
433 are not partitioned too much. Creating too many partitions significantly
434 increases the streaming overhead.
436 In the future, we would like to bound the maximal size of partitions so as
437 to prevent the LTRANS stage from consuming too much memory. At the moment,
438 however, the WPA stage is the most memory intensive for large benchmarks,
439 since too many types and declarations are read into memory.
441 The function implements a simple greedy algorithm. Nodes are being added
442 to the current partition until after 3/4 of the expected partition size is
443 reached. Past this threshold, we keep track of boundary size (number of
444 edges going to other partitions) and continue adding functions until after
445 the current partition has grown to twice the expected partition size. Then
446 the process is undone to the point where the minimal ratio of boundary size
447 and in-partition calls was reached. */
450 lto_balanced_map (void)
453 int n_varpool_nodes
= 0, varpool_pos
= 0;
454 struct cgraph_node
**postorder
=
455 XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
456 struct cgraph_node
**order
= XNEWVEC (struct cgraph_node
*, cgraph_max_uid
);
457 struct varpool_node
**varpool_order
= NULL
;
458 int i
, postorder_len
;
459 struct cgraph_node
*node
;
460 int total_size
= 0, best_total_size
= 0;
462 ltrans_partition partition
;
463 int last_visited_node
= 0;
464 struct varpool_node
*vnode
;
465 int cost
= 0, internal
= 0;
466 int best_n_nodes
= 0, best_i
= 0, best_cost
=
467 INT_MAX
, best_internal
= 0;
469 int current_order
= -1;
471 FOR_EACH_VARIABLE (vnode
)
472 gcc_assert (!vnode
->symbol
.aux
);
473 /* Until we have better ordering facility, use toplogical order.
474 Include only nodes we will partition and compute estimate of program
475 size. Note that since nodes that are not partitioned might be put into
476 multiple partitions, this is just an estimate of real size. This is why
477 we keep partition_size updated after every partition is finalized. */
478 postorder_len
= ipa_reverse_postorder (postorder
);
480 for (i
= 0; i
< postorder_len
; i
++)
483 if (get_symbol_class ((symtab_node
) node
) == SYMBOL_PARTITION
)
485 order
[n_nodes
++] = node
;
486 total_size
+= inline_summary (node
)->size
;
491 if (!flag_toplevel_reorder
)
493 qsort (order
, n_nodes
, sizeof (struct cgraph_node
*), node_cmp
);
495 FOR_EACH_VARIABLE (vnode
)
496 if (get_symbol_class ((symtab_node
) vnode
) == SYMBOL_PARTITION
)
498 varpool_order
= XNEWVEC (struct varpool_node
*, n_varpool_nodes
);
501 FOR_EACH_VARIABLE (vnode
)
502 if (get_symbol_class ((symtab_node
) vnode
) == SYMBOL_PARTITION
)
503 varpool_order
[n_varpool_nodes
++] = vnode
;
504 qsort (varpool_order
, n_varpool_nodes
, sizeof (struct varpool_node
*),
508 /* Compute partition size and create the first partition. */
509 partition_size
= total_size
/ PARAM_VALUE (PARAM_LTO_PARTITIONS
);
510 if (partition_size
< PARAM_VALUE (MIN_PARTITION_SIZE
))
511 partition_size
= PARAM_VALUE (MIN_PARTITION_SIZE
);
513 partition
= new_partition ("");
514 if (cgraph_dump_file
)
515 fprintf (cgraph_dump_file
, "Total unit size: %i, partition size: %i\n",
516 total_size
, partition_size
);
518 for (i
= 0; i
< n_nodes
; i
++)
520 if (symbol_partitioned_p ((symtab_node
) order
[i
]))
523 current_order
= order
[i
]->symbol
.order
;
525 if (!flag_toplevel_reorder
)
526 while (varpool_pos
< n_varpool_nodes
527 && varpool_order
[varpool_pos
]->symbol
.order
< current_order
)
529 if (!symbol_partitioned_p ((symtab_node
) varpool_order
[varpool_pos
]))
530 add_symbol_to_partition (partition
, (symtab_node
) varpool_order
[varpool_pos
]);
534 add_symbol_to_partition (partition
, (symtab_node
) order
[i
]);
535 total_size
-= inline_summary (order
[i
])->size
;
538 /* Once we added a new node to the partition, we also want to add
539 all referenced variables unless they was already added into some
541 add_symbol_to_partition adds possibly multiple nodes and
542 variables that are needed to satisfy needs of ORDER[i].
543 We remember last visited cgraph and varpool node from last iteration
544 of outer loop that allows us to process every new addition.
546 At the same time we compute size of the boundary into COST. Every
547 callgraph or IPA reference edge leaving the partition contributes into
548 COST. Every edge inside partition was earlier computed as one leaving
549 it and thus we need to subtract it from COST. */
550 while (last_visited_node
< lto_symtab_encoder_size (partition
->encoder
))
552 struct ipa_ref_list
*refs
;
555 symtab_node snode
= lto_symtab_encoder_deref (partition
->encoder
,
558 if (symtab_function_p (snode
))
560 struct cgraph_edge
*edge
;
562 node
= cgraph (snode
);
563 refs
= &node
->symbol
.ref_list
;
567 gcc_assert (node
->analyzed
);
569 /* Compute boundary cost of callgraph edges. */
570 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
571 if (edge
->callee
->analyzed
)
573 int edge_cost
= edge
->frequency
;
578 gcc_assert (edge_cost
> 0);
579 index
= lto_symtab_encoder_lookup (partition
->encoder
,
580 (symtab_node
)edge
->callee
);
581 if (index
!= LCC_NOT_FOUND
582 && index
< last_visited_node
- 1)
583 cost
-= edge_cost
, internal
+= edge_cost
;
587 for (edge
= node
->callers
; edge
; edge
= edge
->next_caller
)
589 int edge_cost
= edge
->frequency
;
592 gcc_assert (edge
->caller
->analyzed
);
595 gcc_assert (edge_cost
> 0);
596 index
= lto_symtab_encoder_lookup (partition
->encoder
,
597 (symtab_node
)edge
->caller
);
598 if (index
!= LCC_NOT_FOUND
599 && index
< last_visited_node
- 1)
607 refs
= &snode
->symbol
.ref_list
;
611 /* Compute boundary cost of IPA REF edges and at the same time look into
612 variables referenced from current partition and try to add them. */
613 for (j
= 0; ipa_ref_list_reference_iterate (refs
, j
, ref
); j
++)
614 if (symtab_variable_p (ref
->referred
))
618 vnode
= ipa_ref_varpool_node (ref
);
619 if (!vnode
->finalized
)
621 if (!symbol_partitioned_p ((symtab_node
) vnode
) && flag_toplevel_reorder
622 && get_symbol_class ((symtab_node
) vnode
) == SYMBOL_PARTITION
)
623 add_symbol_to_partition (partition
, (symtab_node
) vnode
);
624 index
= lto_symtab_encoder_lookup (partition
->encoder
,
626 if (index
!= LCC_NOT_FOUND
627 && index
< last_visited_node
- 1)
636 node
= ipa_ref_node (ref
);
639 index
= lto_symtab_encoder_lookup (partition
->encoder
,
641 if (index
!= LCC_NOT_FOUND
642 && index
< last_visited_node
- 1)
647 for (j
= 0; ipa_ref_list_referring_iterate (refs
, j
, ref
); j
++)
648 if (symtab_variable_p (ref
->referring
))
652 vnode
= ipa_ref_referring_varpool_node (ref
);
653 gcc_assert (vnode
->finalized
);
654 if (!symbol_partitioned_p ((symtab_node
) vnode
) && flag_toplevel_reorder
655 && get_symbol_class ((symtab_node
) vnode
) == SYMBOL_PARTITION
)
656 add_symbol_to_partition (partition
, (symtab_node
) vnode
);
657 index
= lto_symtab_encoder_lookup (partition
->encoder
,
659 if (index
!= LCC_NOT_FOUND
660 && index
< last_visited_node
- 1)
669 node
= ipa_ref_referring_node (ref
);
670 gcc_assert (node
->analyzed
);
671 index
= lto_symtab_encoder_lookup (partition
->encoder
,
673 if (index
!= LCC_NOT_FOUND
674 && index
< last_visited_node
- 1)
681 /* If the partition is large enough, start looking for smallest boundary cost. */
682 if (partition
->insns
< partition_size
* 3 / 4
683 || best_cost
== INT_MAX
685 || (best_internal
* (HOST_WIDE_INT
) cost
686 > (internal
* (HOST_WIDE_INT
)best_cost
)))
687 && partition
->insns
< partition_size
* 5 / 4))
690 best_internal
= internal
;
692 best_n_nodes
= lto_symtab_encoder_size (partition
->encoder
);
693 best_total_size
= total_size
;
695 if (cgraph_dump_file
)
696 fprintf (cgraph_dump_file
, "Step %i: added %s/%i, size %i, cost %i/%i best %i/%i, step %i\n", i
,
697 cgraph_node_name (order
[i
]), order
[i
]->uid
, partition
->insns
, cost
, internal
,
698 best_cost
, best_internal
, best_i
);
699 /* Partition is too large, unwind into step when best cost was reached and
700 start new partition. */
701 if (partition
->insns
> 2 * partition_size
)
705 if (cgraph_dump_file
)
706 fprintf (cgraph_dump_file
, "Unwinding %i insertions to step %i\n",
708 undo_partition (partition
, best_n_nodes
);
711 /* When we are finished, avoid creating empty partition. */
712 while (i
< n_nodes
- 1 && symbol_partitioned_p ((symtab_node
) order
[i
+ 1]))
714 if (i
== n_nodes
- 1)
716 partition
= new_partition ("");
717 last_visited_node
= 0;
718 total_size
= best_total_size
;
721 if (cgraph_dump_file
)
722 fprintf (cgraph_dump_file
, "New partition\n");
726 /* Since the size of partitions is just approximate, update the size after
727 we finished current one. */
728 if (npartitions
< PARAM_VALUE (PARAM_LTO_PARTITIONS
))
729 partition_size
= total_size
730 / (PARAM_VALUE (PARAM_LTO_PARTITIONS
) - npartitions
);
732 partition_size
= INT_MAX
;
734 if (partition_size
< PARAM_VALUE (MIN_PARTITION_SIZE
))
735 partition_size
= PARAM_VALUE (MIN_PARTITION_SIZE
);
740 /* Varables that are not reachable from the code go into last partition. */
741 if (flag_toplevel_reorder
)
743 FOR_EACH_VARIABLE (vnode
)
744 if (get_symbol_class ((symtab_node
) vnode
) == SYMBOL_PARTITION
745 && !symbol_partitioned_p ((symtab_node
) vnode
))
746 add_symbol_to_partition (partition
, (symtab_node
) vnode
);
750 while (varpool_pos
< n_varpool_nodes
)
752 if (!symbol_partitioned_p ((symtab_node
) varpool_order
[varpool_pos
]))
753 add_symbol_to_partition (partition
, (symtab_node
) varpool_order
[varpool_pos
]);
756 free (varpool_order
);
761 /* Promote variable VNODE to be static. */
764 promote_symbol (symtab_node node
)
766 /* We already promoted ... */
767 if (DECL_VISIBILITY (node
->symbol
.decl
) == VISIBILITY_HIDDEN
768 && DECL_VISIBILITY_SPECIFIED (node
->symbol
.decl
)
769 && TREE_PUBLIC (node
->symbol
.decl
))
772 gcc_checking_assert (!TREE_PUBLIC (node
->symbol
.decl
)
773 && !DECL_EXTERNAL (node
->symbol
.decl
));
774 TREE_PUBLIC (node
->symbol
.decl
) = 1;
775 DECL_VISIBILITY (node
->symbol
.decl
) = VISIBILITY_HIDDEN
;
776 DECL_VISIBILITY_SPECIFIED (node
->symbol
.decl
) = true;
777 if (cgraph_dump_file
)
778 fprintf (cgraph_dump_file
,
779 "Promoting as hidden: %s\n", symtab_node_name (node
));
783 /* Find out all static decls that need to be promoted to global because
784 of cross file sharing. This function must be run in the WPA mode after
785 all inlinees are added. */
788 lto_promote_cross_file_statics (void)
792 gcc_assert (flag_wpa
);
794 /* First compute boundaries. */
795 n_sets
= VEC_length (ltrans_partition
, ltrans_partitions
);
796 for (i
= 0; i
< n_sets
; i
++)
798 ltrans_partition part
799 = VEC_index (ltrans_partition
, ltrans_partitions
, i
);
800 part
->encoder
= compute_ltrans_boundary (part
->encoder
);
803 /* Look at boundaries and promote symbols as needed. */
804 for (i
= 0; i
< n_sets
; i
++)
806 lto_symtab_encoder_iterator lsei
;
807 lto_symtab_encoder_t encoder
;
808 ltrans_partition part
809 = VEC_index (ltrans_partition
, ltrans_partitions
, i
);
811 encoder
= part
->encoder
;
812 for (lsei
= lsei_start (encoder
); !lsei_end_p (lsei
);
815 symtab_node node
= lsei_node (lsei
);
817 /* No need to promote if symbol already is externally visible ... */
818 if (node
->symbol
.externally_visible
819 /* ... or if it is part of current partition ... */
820 || lto_symtab_encoder_in_partition_p (encoder
, node
)
821 /* ... or if we do not partition it. This mean that it will
822 appear in every partition refernecing it. */
823 || get_symbol_class ((symtab_node
) node
) != SYMBOL_PARTITION
)
826 promote_symbol (node
);