summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-live.c
diff options
context:
space:
mode:
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2009-02-23 13:10:53 +0000
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2009-02-23 13:10:53 +0000
commit362676499c08b5b814947261088c1a614984efb1 (patch)
treed5fc8eef4ee0352c6b6283866a64b8d5d9ec3bde /gcc/tree-ssa-live.c
parent47863d1acad7e104874b244272cb69ba0ac7b839 (diff)
downloadgcc-362676499c08b5b814947261088c1a614984efb1.tar.gz
PR tree-optimization/37709
* tree.c (block_ultimate_origin): Move here from dwarf2out. * tree.h (block_ultimate_origin): Declare. * dwarf2out.c (block_ultimate_origin): Move to tree.c * tree-ssa-live.c (remove_unused_scope_block_p): Eliminate blocks containig no instructions nor live variables nor nested blocks. (dump_scope_block): New function. (remove_unused_locals): Enable removal of dead blocks by default; enable dumping at TDF_DETAILS. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@144381 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-live.c')
-rw-r--r--gcc/tree-ssa-live.c70
1 files changed, 57 insertions, 13 deletions
diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c
index 8ebf30ec926..81e65f732e1 100644
--- a/gcc/tree-ssa-live.c
+++ b/gcc/tree-ssa-live.c
@@ -485,10 +485,13 @@ remove_unused_scope_block_p (tree scope)
next = &TREE_CHAIN (*t);
/* Debug info of nested function refers to the block of the
- function. */
+ function. We might stil call it even if all statements
+ of function it was nested into was elliminated.
+
+ TODO: We can actually look into cgraph to see if function
+ will be output to file. */
if (TREE_CODE (*t) == FUNCTION_DECL)
unused = false;
-
/* Remove everything we don't generate debug info for. */
else if (DECL_IGNORED_P (*t))
{
@@ -506,15 +509,24 @@ remove_unused_scope_block_p (tree scope)
/* When we are not doing full debug info, we however can keep around
only the used variables for cfgexpand's memory packing saving quite
- a lot of memory. */
+ a lot of memory.
+
+ For sake of -g3, we keep around those vars but we don't count this as
+ use of block, so innermost block with no used vars and no instructions
+ can be considered dead. We only want to keep around blocks user can
+ breakpoint into and ask about value of optimized out variables.
+
+ Similarly we need to keep around types at least until all variables of
+ all nested blocks are gone. We track no information on whether given
+ type is used or not. */
+
else if (debug_info_level == DINFO_LEVEL_NORMAL
|| debug_info_level == DINFO_LEVEL_VERBOSE
/* Removing declarations before inlining is going to affect
DECL_UID that in turn is going to affect hashtables and
code generation. */
|| !cfun->after_inlining)
- unused = false;
-
+ ;
else
{
*t = TREE_CHAIN (*t);
@@ -537,10 +549,7 @@ remove_unused_scope_block_p (tree scope)
nsubblocks ++;
}
else
- {
- gcc_assert (!BLOCK_VARS (*t));
- *t = BLOCK_CHAIN (*t);
- }
+ *t = BLOCK_CHAIN (*t);
}
else
{
@@ -576,6 +585,38 @@ mark_all_vars_used (tree *expr_p, void *data)
walk_tree (expr_p, mark_all_vars_used_1, data, NULL);
}
+/* Dump scope blocks. */
+
+static void
+dump_scope_block (FILE *file, int indent, tree scope, int flags)
+{
+ tree var, t;
+
+ fprintf (file, "\n%*sScope block #%i %s\n",indent, "" , BLOCK_NUMBER (scope),
+ TREE_USED (scope) ? "" : "(unused)");
+ if (BLOCK_ABSTRACT_ORIGIN (scope) && DECL_P (block_ultimate_origin (scope)))
+ {
+ fprintf (file, "\n%*sOriginating from ",indent + 1, "");
+ print_generic_decl (file, block_ultimate_origin (scope), flags);
+ fprintf (file, "\n");
+ }
+ for (var = BLOCK_VARS (scope); var; var = TREE_CHAIN (var))
+ {
+ bool used = false;
+ var_ann_t ann;
+
+ if ((ann = var_ann (var))
+ && ann->used)
+ used = true;
+
+ fprintf (file, "%*s",indent, "");
+ print_generic_decl (file, var, flags);
+ fprintf (file, "%s\n", used ? "" : " (unused)");
+ }
+ for (t = BLOCK_SUBBLOCKS (scope); t ; t = BLOCK_CHAIN (t))
+ dump_scope_block (file, indent + 2, t, flags);
+}
+
/* Remove local variables that are not referenced in the IL. */
@@ -588,8 +629,7 @@ remove_unused_locals (void)
var_ann_t ann;
bitmap global_unused_vars = NULL;
- if (optimize)
- mark_scope_block_unused (DECL_INITIAL (current_function_decl));
+ mark_scope_block_unused (DECL_INITIAL (current_function_decl));
/* Assume all locals are unused. */
FOR_EACH_REFERENCED_VAR (t, rvi)
@@ -716,8 +756,12 @@ remove_unused_locals (void)
&& !TREE_ADDRESSABLE (t)
&& (optimize || DECL_ARTIFICIAL (t)))
remove_referenced_var (t);
- if (optimize)
- remove_unused_scope_block_p (DECL_INITIAL (current_function_decl));
+ remove_unused_scope_block_p (DECL_INITIAL (current_function_decl));
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Scope blocks after cleanups:\n");
+ dump_scope_block (dump_file, 0, DECL_INITIAL (current_function_decl), false);
+ }
}