+2004-07-21 Richard Henderson <rth@redhat.com>
+
+ * gimple-low.c (expand_var_p): Don't look at TREE_ADDRESSABLE,
+ TREE_THIS_VOLATILE, may_aliases, or optimization level.
+ (remove_useless_vars): Dump debugging info.
+ (expand_used_vars): Move ...
+ * cfgexpand.c (expand_used_vars): ... here. Make static.
+ * tree-flow-inline.h (set_is_used): New.
+ (set_default_def): Use get_var_ann.
+ * tree-flow.h: Update decls.
+ * tree-ssa-live.c (mark_all_vars_used_1, mark_all_vars_used): New.
+ (create_ssa_var_map): Use it.
+ * tree-ssa.c (set_is_used): Remove.
+
2004-07-22 Ben Elliston <bje@au.ibm.com>
* gdbinit.in: Set a breakpoint on internal_error.
#include "flags.h"
+/* Expand variables in the unexpanded_var_list. */
+
+static void
+expand_used_vars (void)
+{
+ tree cell;
+
+ cfun->unexpanded_var_list = nreverse (cfun->unexpanded_var_list);
+
+ for (cell = cfun->unexpanded_var_list; cell; cell = TREE_CHAIN (cell))
+ expand_var (TREE_VALUE (cell));
+
+ cfun->unexpanded_var_list = NULL_TREE;
+}
+
+
/* A subroutine of expand_gimple_basic_block. Expand one COND_EXPR.
Returns a new basic block if we've terminated the current basic
block and created a new one. */
/* Prepare the rtl middle end to start recording block changes. */
reset_block_changes ();
- /* Expand the variables recorded during gimple lowering. This must
- occur before the call to expand_function_start to ensure that
- all used variables are expanded before we expand anything on the
- PENDING_SIZES list. */
+ /* Expand the variables recorded during gimple lowering. */
expand_used_vars ();
/* Set up parameters and prepare for return, for the function. */
if (TREE_CODE (var) != VAR_DECL)
return true;
- /* Remove all unused, unaliased temporaries. Also remove unused, unaliased
- local variables during highly optimizing compilations. */
+ /* Leave statics and externals alone. */
+ if (TREE_STATIC (var) || DECL_EXTERNAL (var))
+ return true;
+
+ /* Remove all unused local variables. */
ann = var_ann (var);
- if (ann
- && ! ann->may_aliases
- && ! ann->used
- && ! TREE_ADDRESSABLE (var)
- && ! TREE_THIS_VOLATILE (var)
- && (DECL_ARTIFICIAL (var) || optimize >= 2))
+ if (!ann || !ann->used)
return false;
return true;
remove_useless_vars (void)
{
tree var, *cell;
+ FILE *df = NULL;
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ df = dump_file;
+ fputs ("Discarding as unused:\n", df);
+ }
for (cell = &cfun->unexpanded_var_list; *cell; )
{
if (!expand_var_p (var))
{
+ if (df)
+ {
+ fputs (" ", df);
+ print_generic_expr (df, var, dump_flags);
+ fputc ('\n', df);
+ }
+
*cell = TREE_CHAIN (*cell);
continue;
}
cell = &TREE_CHAIN (*cell);
}
-}
-
-/* Expand variables in the unexpanded_var_list. */
-
-void
-expand_used_vars (void)
-{
- tree cell;
-
- cfun->unexpanded_var_list = nreverse (cfun->unexpanded_var_list);
-
- for (cell = cfun->unexpanded_var_list; cell; cell = TREE_CHAIN (cell))
- expand_var (TREE_VALUE (cell));
- cfun->unexpanded_var_list = NULL_TREE;
+ if (df)
+ fputc ('\n', df);
}
struct tree_opt_pass pass_remove_useless_vars =
return -1;
}
+/* Mark VAR as used, so that it'll be preserved during rtl expansion. */
+
+static inline void
+set_is_used (tree var)
+{
+ var_ann_t ann = get_var_ann (var);
+ ann->used = 1;
+}
+
+
/* ----------------------------------------------------------------------- */
/* Return true if T is an executable statement. */
static inline void
set_default_def (tree var, tree def)
{
- var_ann_t ann = var_ann (var);
- if (ann == NULL)
- ann = create_var_ann (var);
+ var_ann_t ann = get_var_ann (var);
ann->default_def = def;
}
/* In gimple-low.c */
struct lower_data;
extern void lower_stmt_body (tree, struct lower_data *);
-extern void expand_used_vars (void);
extern void record_vars (tree);
extern bool block_may_fallthru (tree block);
extern void debug_tree_ssa_stats (void);
extern void ssa_remove_edge (edge);
extern edge ssa_redirect_edge (edge, basic_block);
-extern void set_is_used (tree);
extern bool tree_ssa_useless_type_conversion (tree);
extern bool tree_ssa_useless_type_conversion_1 (tree, tree);
extern void verify_ssa (void);
static inline int phi_arg_from_edge (tree, edge);
static inline bool is_call_clobbered (tree);
static inline void mark_call_clobbered (tree);
+static inline void set_is_used (tree);
/* In tree-eh.c */
extern void make_eh_edges (tree);
}
+/* Helper function for mark_all_vars_used, called via walk_tree. */
+
+static tree
+mark_all_vars_used_1 (tree *tp, int *walk_subtrees,
+ void *data ATTRIBUTE_UNUSED)
+{
+ tree t = *tp;
+
+ /* Only need to mark VAR_DECLS; parameters and return results are not
+ eliminated as unused. */
+ if (TREE_CODE (t) == VAR_DECL)
+ set_is_used (t);
+
+ if (DECL_P (t) || TYPE_P (t))
+ *walk_subtrees = 0;
+
+ return NULL;
+}
+
+/* Mark all VAR_DECLS under *EXPR_P as used, so that they won't be
+ eliminated during the tree->rtl conversion process. */
+
+static inline void
+mark_all_vars_used (tree *expr_p)
+{
+ walk_tree (expr_p, mark_all_vars_used_1, NULL, NULL);
+}
+
/* This function looks through the program and uses FLAGS to determine what
SSA versioned variables are given entries in a new partition table. This
new partition map is returned. */
arg = PHI_ARG_DEF (phi, i);
if (TREE_CODE (arg) == SSA_NAME)
register_ssa_partition (map, arg, true);
+
+ mark_all_vars_used (&PHI_ARG_DEF_TREE (phi, i));
}
}
for (x = 0; x < NUM_VUSES (vuses); x++)
{
tree var = VUSE_OP (vuses, x);
- set_is_used (var);
-
#if defined ENABLE_CHECKING
SET_BIT (used_in_virtual_ops, var_ann (SSA_NAME_VAR (var))->uid);
#endif
for (x = 0; x < NUM_V_MAY_DEFS (v_may_defs); x++)
{
tree var = V_MAY_DEF_OP (v_may_defs, x);
- set_is_used (var);
-
#if defined ENABLE_CHECKING
SET_BIT (used_in_virtual_ops, var_ann (SSA_NAME_VAR (var))->uid);
#endif
for (x = 0; x < NUM_V_MUST_DEFS (v_must_defs); x++)
{
tree var = V_MUST_DEF_OP (v_must_defs, x);
- set_is_used (var);
#if defined ENABLE_CHECKING
SET_BIT (used_in_virtual_ops, var_ann (SSA_NAME_VAR (var))->uid);
#endif
}
+
+ mark_all_vars_used (bsi_stmt_ptr (bsi));
}
}
}
-/* Set the USED bit in the annotation for T. */
-
-void
-set_is_used (tree t)
-{
- while (1)
- {
- if (SSA_VAR_P (t))
- break;
-
- if (TREE_CODE (t) == REALPART_EXPR || TREE_CODE (t) == IMAGPART_EXPR)
- t = TREE_OPERAND (t, 0);
- else
- while (handled_component_p (t))
- t = TREE_OPERAND (t, 0);
- }
-
- if (TREE_CODE (t) == SSA_NAME)
- t = SSA_NAME_VAR (t);
-
- var_ann (t)->used = 1;
-}
-
-
/* Initialize global DFA and SSA structures. */
void