I'm bootstrapping and testing the following patch that inlines create_var_ann into its single caller and removes calls to add_referenced_vars when the var is global (which would be a no-op and in a future patch will assert).
Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu. Richard. 2012-05-24 Richard Guenther <rguent...@suse.de> * tree-flow.h (create_var_ann): Remove. * tree-dfa.c (create_var_ann): Remove and inline into its single caller ... (add_referenced_var_1): ... here. * varpool.c (add_new_static_var): Do not call add_referenced_var for global vars. * gimple-fold.c (canonicalize_constructor_val): Likewise. * tree-switch-conversion.c (build_one_array): Likewise. * tree-profile.c (gimple_gen_ic_profiler): Likewise. * tree-inline.c (remap_gimple_op_r): Likewise. Check gimple_referenced_vars instead of gimple_in_ssa_p. (copy_tree_body_r): Likewise. (setup_one_parameter): Likewise. (declare_return_variable): Likewise. (tree_function_versioning): Likewise. Index: gcc/tree-flow.h =================================================================== --- gcc/tree-flow.h (revision 187825) +++ gcc/tree-flow.h (working copy) @@ -482,7 +482,6 @@ extern int op_prio (const_tree); extern const char *op_symbol_code (enum tree_code); /* In tree-dfa.c */ -extern var_ann_t create_var_ann (tree); extern void renumber_gimple_stmt_uids (void); extern void renumber_gimple_stmt_uids_in_blocks (basic_block *, int); extern void dump_dfa_stats (FILE *); Index: gcc/varpool.c =================================================================== --- gcc/varpool.c (revision 187825) +++ gcc/varpool.c (working copy) @@ -458,7 +458,6 @@ add_new_static_var (tree type) DECL_ABSTRACT (new_decl) = 0; lang_hooks.dup_lang_specific_decl (new_decl); new_node = varpool_node (new_decl); - add_referenced_var (new_decl); varpool_finalize_decl (new_decl); return new_node->symbol.decl; Index: gcc/tree-inline.c =================================================================== --- gcc/tree-inline.c (revision 187825) +++ gcc/tree-inline.c (working copy) @@ -876,8 +876,8 @@ remap_gimple_op_r (tree *tp, int *walk_s /* Global variables we haven't seen yet need to go into referenced vars. If not referenced from types only. */ - if (gimple_in_ssa_p (cfun) - && TREE_CODE (*tp) == VAR_DECL + if (gimple_referenced_vars (cfun) + && TREE_CODE (*tp) == VAR_DECL && !is_global_var (*tp) && id->remapping_type_depth == 0 && !processing_debug_stmt) add_referenced_var (*tp); @@ -1119,8 +1119,8 @@ copy_tree_body_r (tree *tp, int *walk_su /* Global variables we haven't seen yet needs to go into referenced vars. If not referenced from types or debug stmts only. */ - if (gimple_in_ssa_p (cfun) - && TREE_CODE (*tp) == VAR_DECL + if (gimple_referenced_vars (cfun) + && TREE_CODE (*tp) == VAR_DECL && !is_global_var (*tp) && id->remapping_type_depth == 0 && !processing_debug_stmt) add_referenced_var (*tp); @@ -2604,11 +2604,11 @@ setup_one_parameter (copy_body_data *id, /* We are eventually using the value - make sure all variables referenced therein are properly recorded. */ if (value - && gimple_in_ssa_p (cfun) + && gimple_referenced_vars (cfun) && TREE_CODE (value) == ADDR_EXPR) { tree base = get_base_address (TREE_OPERAND (value, 0)); - if (base && TREE_CODE (base) == VAR_DECL) + if (base && TREE_CODE (base) == VAR_DECL && !is_global_var (base)) add_referenced_var (base); } @@ -2917,7 +2917,7 @@ declare_return_variable (copy_body_data gcc_assert (TREE_CODE (TYPE_SIZE_UNIT (callee_type)) == INTEGER_CST); var = copy_result_decl_to_var (result, id); - if (gimple_in_ssa_p (cfun)) + if (gimple_referenced_vars (cfun)) add_referenced_var (var); DECL_SEEN_IN_BIND_EXPR_P (var) = 1; @@ -2978,7 +2978,7 @@ declare_return_variable (copy_body_data && !is_gimple_val (var)) { tree temp = create_tmp_var (TREE_TYPE (result), "retvalptr"); - if (gimple_in_ssa_p (id->src_cfun)) + if (gimple_referenced_vars (cfun)) add_referenced_var (temp); insert_decl_map (id, result, temp); /* When RESULT_DECL is in SSA form, we need to remap and initialize @@ -5194,10 +5194,8 @@ tree_function_versioning (tree old_decl, if (TREE_CODE (op) == ADDR_EXPR) { - op = TREE_OPERAND (op, 0); - while (handled_component_p (op)) - op = TREE_OPERAND (op, 0); - if (TREE_CODE (op) == VAR_DECL) + op = get_base_address (TREE_OPERAND (op, 0)); + if (op && TREE_CODE (op) == VAR_DECL && !is_global_var (op)) add_referenced_var (op); } gcc_assert (TREE_CODE (replace_info->old_tree) == PARM_DECL); Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 187825) +++ gcc/gimple-fold.c (working copy) @@ -164,7 +164,8 @@ canonicalize_constructor_val (tree cval, if (TREE_CODE (base) == VAR_DECL) { TREE_ADDRESSABLE (base) = 1; - if (cfun && gimple_referenced_vars (cfun)) + if (cfun && gimple_referenced_vars (cfun) + && !is_global_var (base)) add_referenced_var (base); } else if (TREE_CODE (base) == FUNCTION_DECL) Index: gcc/tree-switch-conversion.c =================================================================== --- gcc/tree-switch-conversion.c (revision 187825) +++ gcc/tree-switch-conversion.c (working copy) @@ -630,7 +630,6 @@ build_one_array (gimple swtch, int num, DECL_ARTIFICIAL (decl) = 1; TREE_CONSTANT (decl) = 1; TREE_READONLY (decl) = 1; - add_referenced_var (decl); varpool_finalize_decl (decl); fetch = build4 (ARRAY_REF, value_type, decl, tidx, NULL_TREE, Index: gcc/tree-profile.c =================================================================== --- gcc/tree-profile.c (revision 187825) +++ gcc/tree-profile.c (working copy) @@ -347,7 +347,6 @@ gimple_gen_ic_profiler (histogram_value gimple_assign_set_lhs (stmt2, make_ssa_name (tmp1, stmt2)); find_referenced_vars_in (stmt2); stmt3 = gimple_build_assign (ic_void_ptr_var, gimple_assign_lhs (stmt2)); - add_referenced_var (ic_void_ptr_var); gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); @@ -383,11 +382,9 @@ gimple_gen_ic_func_profiler (void) counter_ptr = force_gimple_operand_gsi (&gsi, ic_gcov_type_ptr_var, true, NULL_TREE, true, GSI_SAME_STMT); - add_referenced_var (ic_gcov_type_ptr_var); ptr_var = force_gimple_operand_gsi (&gsi, ic_void_ptr_var, true, NULL_TREE, true, GSI_SAME_STMT); - add_referenced_var (ic_void_ptr_var); tree_uid = build_int_cst (gcov_type_node, current_function_funcdef_no); stmt1 = gimple_build_call (tree_indirect_call_profiler_fn, 4, counter_ptr, tree_uid, cur_func, ptr_var); Index: gcc/tree-dfa.c =================================================================== *** gcc/tree-dfa.c (revision 187825) --- gcc/tree-dfa.c (working copy) *************** struct gimple_opt_pass pass_referenced_v *** 118,144 **** }; - /*--------------------------------------------------------------------------- - Manage annotations - ---------------------------------------------------------------------------*/ - /* Create a new annotation for a _DECL node T. */ - - var_ann_t - create_var_ann (tree t) - { - var_ann_t ann; - - gcc_assert (t); - gcc_assert (TREE_CODE (t) == VAR_DECL - || TREE_CODE (t) == PARM_DECL - || TREE_CODE (t) == RESULT_DECL); - - ann = ggc_alloc_cleared_var_ann_d (); - *DECL_VAR_ANN_PTR (t) = ann; - - return ann; - } - /* Renumber all of the gimple stmt uids. */ void --- 118,123 ---- *************** add_referenced_var_1 (tree var, struct f *** 587,593 **** return false; if (!*DECL_VAR_ANN_PTR (var)) ! create_var_ann (var); /* Insert VAR into the referenced_vars hash table if it isn't present. */ if (referenced_var_check_and_insert (var, fn)) --- 566,572 ---- return false; if (!*DECL_VAR_ANN_PTR (var)) ! *DECL_VAR_ANN_PTR (var) = ggc_alloc_cleared_var_ann_d (); /* Insert VAR into the referenced_vars hash table if it isn't present. */ if (referenced_var_check_and_insert (var, fn))