Skip to content

Commit df7705b

Browse files
Jan HubickaJan Hubicka
authored andcommitted
cgraph.h (+varpool_can_remove_if_no_refs): Move here from ......
* cgraph.h (+varpool_can_remove_if_no_refs): Move here from ...; when !flag_toplevel_reorder do not remove unless variable is COMDAT or ARTIFICIAL. * ipa.c (varpool_can_remove_if_no_refs): ... here. (cgraph_remove_unreachable_nodes): Only analyzed nodes needs to stay. * cgraphunit.c (cgraph_analyze_functions): Dump varpool, too. * varpool.c (decide_is_variable_needed): Do not handle visibility issues. (varpool_finalize_decl): Likewise. (varpool_remove_unreferenced_decls): Use varpool_mark_needed_node; update outdated comment on DECL_RTL_SET_P check. From-SVN: r166812
1 parent 3e794bf commit df7705b

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

gcc/ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2010-11-16 Jan Hubicka <[email protected]>
2+
3+
* cgraph.h (+varpool_can_remove_if_no_refs): Move here from ...;
4+
when !flag_toplevel_reorder do not remove unless variable is
5+
COMDAT or ARTIFICIAL.
6+
* ipa.c (varpool_can_remove_if_no_refs): ... here.
7+
(cgraph_remove_unreachable_nodes): Only analyzed nodes needs to stay.
8+
* cgraphunit.c (cgraph_analyze_functions): Dump varpool, too.
9+
* varpool.c (decide_is_variable_needed): Do not handle visibility issues.
10+
(varpool_finalize_decl): Likewise.
11+
(varpool_remove_unreferenced_decls): Use varpool_mark_needed_node; update
12+
outdated comment on DECL_RTL_SET_P check.
13+
114
2010-11-16 Rainer Orth <[email protected]>
215

316
* config/sol2.h (NM_FLAGS): Define.

gcc/cgraph.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,18 @@ cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
928928
return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
929929
}
930930

931+
/* Return true when function NODE can be removed from callgraph
932+
if all direct calls are eliminated. */
933+
934+
static inline bool
935+
varpool_can_remove_if_no_refs (struct varpool_node *node)
936+
{
937+
return (!node->force_output && !node->used_from_other_partition
938+
&& (flag_toplevel_reorder || DECL_COMDAT (node->decl)
939+
|| DECL_ARTIFICIAL (node->decl))
940+
&& (DECL_COMDAT (node->decl) || !node->externally_visible));
941+
}
942+
931943
/* Return true when all references to VNODE must be visible in ipa_ref_list.
932944
i.e. if the variable is not externally visible or not used in some magic
933945
way (asm statement or such).

gcc/cgraphunit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ cgraph_analyze_functions (void)
943943
fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
944944
fprintf (cgraph_dump_file, "\n\nInitial ");
945945
dump_cgraph (cgraph_dump_file);
946+
dump_varpool (cgraph_dump_file);
946947
}
947948

948949
if (cgraph_dump_file)
@@ -972,6 +973,7 @@ cgraph_analyze_functions (void)
972973
{
973974
fprintf (cgraph_dump_file, "\n\nReclaimed ");
974975
dump_cgraph (cgraph_dump_file);
976+
dump_varpool (cgraph_dump_file);
975977
}
976978
bitmap_obstack_release (NULL);
977979
first_analyzed = cgraph_nodes;
@@ -1816,6 +1818,7 @@ cgraph_optimize (void)
18161818
{
18171819
fprintf (cgraph_dump_file, "\nFinal ");
18181820
dump_cgraph (cgraph_dump_file);
1821+
dump_varpool (cgraph_dump_file);
18191822
}
18201823
#ifdef ENABLE_CHECKING
18211824
verify_cgraph ();

gcc/ipa.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,6 @@ process_references (struct ipa_ref_list *list,
188188
}
189189
}
190190

191-
/* Return true when function NODE can be removed from callgraph
192-
if all direct calls are eliminated. */
193-
194-
static inline bool
195-
varpool_can_remove_if_no_refs (struct varpool_node *node)
196-
{
197-
return (!node->force_output && !node->used_from_other_partition
198-
&& (DECL_COMDAT (node->decl) || !node->externally_visible));
199-
}
200-
201191
/* Return true when function can be marked local. */
202192

203193
static bool
@@ -269,7 +259,8 @@ cgraph_remove_unreachable_nodes (bool before_inlining_p, FILE *file)
269259
{
270260
vnode->next_needed = NULL;
271261
vnode->prev_needed = NULL;
272-
if (!varpool_can_remove_if_no_refs (vnode))
262+
if (vnode->analyzed
263+
&& !varpool_can_remove_if_no_refs (vnode))
273264
{
274265
vnode->needed = false;
275266
varpool_mark_needed_node (vnode);

gcc/varpool.c

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -331,31 +331,24 @@ varpool_reset_queue (void)
331331
bool
332332
decide_is_variable_needed (struct varpool_node *node, tree decl)
333333
{
334-
if (node->used_from_other_partition)
335-
return true;
336334
/* If the user told us it is used, then it must be so. */
337-
if ((node->externally_visible && !DECL_COMDAT (decl))
338-
|| node->force_output)
335+
if (node->force_output)
339336
return true;
340337

338+
gcc_assert (!DECL_EXTERNAL (decl));
339+
341340
/* Externally visible variables must be output. The exception is
342341
COMDAT variables that must be output only when they are needed. */
343342
if (TREE_PUBLIC (decl)
344-
&& !flag_whole_program
345-
&& !flag_lto
346343
&& !DECL_COMDAT (decl)
347344
&& !DECL_EXTERNAL (decl))
348345
return true;
349346

350347
/* When not reordering top level variables, we have to assume that
351348
we are going to keep everything. */
352-
if (flag_toplevel_reorder)
353-
return false;
354-
355-
/* We want to emit COMDAT variables only when absolutely necessary. */
356-
if (DECL_COMDAT (decl))
357-
return false;
358-
return true;
349+
if (!flag_toplevel_reorder)
350+
return true;
351+
return false;
359352
}
360353

361354
/* Return if DECL is constant and its initial value is known (so we can do
@@ -427,11 +420,6 @@ varpool_finalize_decl (tree decl)
427420

428421
if (decide_is_variable_needed (node, decl))
429422
varpool_mark_needed_node (node);
430-
/* Since we reclaim unreachable nodes at the end of every language
431-
level unit, we need to be conservative about possible entry points
432-
there. */
433-
else if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
434-
varpool_mark_needed_node (node);
435423
if (cgraph_global_info_ready)
436424
varpool_assemble_pending_decls ();
437425
}
@@ -557,18 +545,14 @@ varpool_remove_unreferenced_decls (void)
557545

558546
while (node)
559547
{
560-
tree decl = node->decl;
561548
next = node->next_needed;
562549
node->needed = 0;
563550

564-
if (node->finalized
565-
&& (decide_is_variable_needed (node, decl)
566-
/* ??? Cgraph does not yet rule the world with an iron hand,
567-
and does not control the emission of debug information.
568-
After a variable has its DECL_RTL set, we must assume that
569-
it may be referenced by the debug information, and we can
570-
no longer elide it. */
571-
|| DECL_RTL_SET_P (decl)))
551+
if (node->analyzed
552+
&& (!varpool_can_remove_if_no_refs (node)
553+
/* We just expanded all function bodies. See if any of
554+
them needed the variable. */
555+
|| DECL_RTL_SET_P (node->decl)))
572556
varpool_mark_needed_node (node);
573557

574558
node = next;

0 commit comments

Comments
 (0)