On Wed, Aug 1, 2012 at 4:13 PM, Michael Matz <m...@suse.de> wrote: > Hi, > > On Wed, 1 Aug 2012, Michael Matz wrote: > >> The only remaining semantic of var_ann now is "if it's non-zero it's a >> non-global variable that was put into referenced_vars". > > And that's removed in this patch. Most of the time it's not very > interesting to know if a variable was put in referenced vars or not, in > the inliner we can use a different mean. > > So, this finally gets rid of the ugly variable annotations and hence a > pointer for each var_decl, parm_decl and result_decl. > > Regstrapped on x86_64-linux with the other two patches, no regressions. > Okay for trunk?
Ok! Thanks, Richard. > > Ciao, > Michael. > -- > * tree-complex.c (init_parameter_lattice_values): Don't call var_ann. > * tree-dfa.c (struct dfa_stats_d): Remove num_var_anns member. > (dump_dfa_stats): Don't dump stats about var anns. > (collect_dfa_stats): Don't collect them. > (add_referenced_var_1): Don't set var annotation pointers. > (remove_referenced_var): Ditto, and only remove it it's in the > hash table. > > * tree-flow-inline.h (var_ann): Remove. > * tree-flow.h (struct var_ann_d, var_ann_t): Remove. > > * tree-inline.c (remapped_type): Remove. > (can_be_nonlocal): Most variable will be considered live here, > return false earlier. > (remap_decls): Don't call var_ann, all variables will be considered > referenced here. > (copy_debug_stmt): Ditto, and use is_global_var. > > * tree-into-ssa.c (rewrite_debug_stmt_uses): Use get_current_def to > determine if a variable was referred to, not var_ann. > * tree-ssa-live.c (remove_unused_scope_block_p): Don't check var_ann. > (remove_unused_locals): Ditto. > * tree-ssa.c (delete_tree_ssa): Don't free/clear var ann pointers. > * tree-tailcall.c (arg_needs_copy_p): Don't check var_ann. > * tree.c (copy_node_stat): Don't clear var ann pointer. > * tree.h (tree_result_decl, tree_parm_decl, tree_var_decl): Remove > ann member. > (DECL_VAR_ANN_PTR): Remove. > > Index: gcc/tree-complex.c > =================================================================== > *** gcc.orig/tree-complex.c 2012-08-01 15:58:32.000000000 +0200 > --- gcc/tree-complex.c 2012-08-01 16:00:51.000000000 +0200 > *************** init_parameter_lattice_values (void) > *** 176,182 **** > > for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = DECL_CHAIN (parm)) > if (is_complex_reg (parm) > - && var_ann (parm) != NULL > && (ssa_name = gimple_default_def (cfun, parm)) != NULL_TREE) > VEC_replace (complex_lattice_t, complex_lattice_values, > SSA_NAME_VERSION (ssa_name), VARYING); > --- 176,181 ---- > Index: gcc/tree-dfa.c > =================================================================== > *** gcc.orig/tree-dfa.c 2012-08-01 15:59:27.000000000 +0200 > --- gcc/tree-dfa.c 2012-08-01 16:00:51.000000000 +0200 > *************** along with GCC; see the file COPYING3. > *** 46,52 **** > /* Counters used to display DFA and SSA statistics. */ > struct dfa_stats_d > { > - long num_var_anns; > long num_defs; > long num_uses; > long num_phis; > --- 46,51 ---- > *************** dump_dfa_stats (FILE *file) > *** 303,313 **** > fprintf (file, fmt_str_1, "Referenced variables", (unsigned > long)num_referenced_vars, > SCALE (size), LABEL (size)); > > - size = dfa_stats.num_var_anns * sizeof (struct var_ann_d); > - total += size; > - fprintf (file, fmt_str_1, "Variables annotated", dfa_stats.num_var_anns, > - SCALE (size), LABEL (size)); > - > size = dfa_stats.num_uses * sizeof (tree *); > total += size; > fprintf (file, fmt_str_1, "USE operands", dfa_stats.num_uses, > --- 302,307 ---- > *************** collect_dfa_stats (struct dfa_stats_d *d > *** 374,382 **** > > memset ((void *)dfa_stats_p, 0, sizeof (struct dfa_stats_d)); > > - /* Count all the variable annotations. */ > - dfa_stats_p->num_var_anns = htab_elements (gimple_referenced_vars (cfun)); > - > /* Walk all the statements in the function counting references. */ > FOR_EACH_BB (bb) > { > --- 368,373 ---- > *************** add_referenced_var_1 (tree var, struct f > *** 561,571 **** > /* Insert VAR into the referenced_vars hash table if it isn't present > and allocate its var-annotation. */ > if (referenced_var_check_and_insert (var, fn)) > ! { > ! gcc_checking_assert (!*DECL_VAR_ANN_PTR (var)); > ! *DECL_VAR_ANN_PTR (var) = ggc_alloc_cleared_var_ann_d (); > ! return true; > ! } > > return false; > } > --- 552,558 ---- > /* Insert VAR into the referenced_vars hash table if it isn't present > and allocate its var-annotation. */ > if (referenced_var_check_and_insert (var, fn)) > ! return true; > > return false; > } > *************** add_referenced_var_1 (tree var, struct f > *** 576,582 **** > void > remove_referenced_var (tree var) > { > - var_ann_t v_ann; > struct tree_decl_minimal in; > void **loc; > unsigned int uid = DECL_UID (var); > --- 563,568 ---- > *************** remove_referenced_var (tree var) > *** 587,600 **** > > gcc_checking_assert (!is_global_var (var)); > > - v_ann = var_ann (var); > - ggc_free (v_ann); > - *DECL_VAR_ANN_PTR (var) = NULL; > - > in.uid = uid; > loc = htab_find_slot_with_hash (gimple_referenced_vars (cfun), &in, uid, > NO_INSERT); > ! htab_clear_slot (gimple_referenced_vars (cfun), loc); > } > > > --- 573,583 ---- > > gcc_checking_assert (!is_global_var (var)); > > in.uid = uid; > loc = htab_find_slot_with_hash (gimple_referenced_vars (cfun), &in, uid, > NO_INSERT); > ! if (loc) > ! htab_clear_slot (gimple_referenced_vars (cfun), loc); > } > > > Index: gcc/tree-flow-inline.h > =================================================================== > *** gcc.orig/tree-flow-inline.h 2012-08-01 16:00:42.000000000 +0200 > --- gcc/tree-flow-inline.h 2012-08-01 16:00:51.000000000 +0200 > *************** next_referenced_var (referenced_var_iter > *** 136,150 **** > return (tree) next_htab_element (&iter->hti); > } > > - /* Return the variable annotation for T, which must be a _DECL node. > - Return NULL if the variable annotation doesn't already exist. */ > - static inline var_ann_t > - var_ann (const_tree t) > - { > - const var_ann_t *p = DECL_VAR_ANN_PTR (t); > - return p ? *p : NULL; > - } > - > /* Get the number of the next statement uid to be allocated. */ > static inline unsigned int > gimple_stmt_max_uid (struct function *fn) > --- 136,141 ---- > Index: gcc/tree-flow.h > =================================================================== > *** gcc.orig/tree-flow.h 2012-08-01 16:00:42.000000000 +0200 > --- gcc/tree-flow.h 2012-08-01 16:00:51.000000000 +0200 > *************** enum need_phi_state { > *** 177,189 **** > }; > > > - struct GTY(()) var_ann_d { > - /* Nonzero if this variable was used after SSA optimizations were > - applied. We set this when translating out of SSA form. */ > - unsigned donotuse : 1; > - }; > - > - > /* Immediate use lists are used to directly access all uses for an SSA > name and get pointers to the statement for each use. > > --- 177,182 ---- > *************** typedef struct immediate_use_iterator_d > *** 278,286 **** > > > > - typedef struct var_ann_d *var_ann_t; > - > - static inline var_ann_t var_ann (const_tree); > static inline void update_stmt (gimple); > static inline int get_lineno (const_gimple); > > --- 271,276 ---- > Index: gcc/tree-inline.c > =================================================================== > *** gcc.orig/tree-inline.c 2012-08-01 15:59:27.000000000 +0200 > --- gcc/tree-inline.c 2012-08-01 16:00:51.000000000 +0200 > *************** remap_type (tree type, copy_body_data *i > *** 501,526 **** > return tmp; > } > > - /* Return previously remapped type of TYPE in ID. Return NULL if TYPE > - is NULL or TYPE has not been remapped before. */ > - > - static tree > - remapped_type (tree type, copy_body_data *id) > - { > - tree *node; > - > - if (type == NULL) > - return type; > - > - /* See if we have remapped this type. */ > - node = (tree *) pointer_map_contains (id->decl_map, type); > - if (node) > - return *node; > - else > - return NULL; > - } > - > - /* The type only needs remapping if it's variably modified. */ > /* Decide if DECL can be put into BLOCK_NONLOCAL_VARs. */ > > static bool > --- 501,506 ---- > *************** can_be_nonlocal (tree decl, copy_body_da > *** 536,561 **** > && !auto_var_in_fn_p (decl, id->src_fn)) > return true; > > ! /* At the moment dwarf2out can handle only these types of nodes. We > ! can support more later. */ > ! if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) > ! return false; > ! > ! /* We must use global type. We call remapped_type instead of > ! remap_type since we don't want to remap this type here if it > ! hasn't been remapped before. */ > ! if (TREE_TYPE (decl) != remapped_type (TREE_TYPE (decl), id)) > ! return false; > ! > ! /* Wihtout SSA we can't tell if variable is used. */ > ! if (!gimple_in_ssa_p (cfun)) > ! return false; > ! > ! /* Live variables must be copied so we can attach DECL_RTL. */ > ! if (var_ann (decl)) > ! return false; > ! > ! return true; > } > > static tree > --- 516,522 ---- > && !auto_var_in_fn_p (decl, id->src_fn)) > return true; > > ! return false; > } > > static tree > *************** remap_decls (tree decls, VEC(tree,gc) ** > *** 571,579 **** > > if (can_be_nonlocal (old_var, id)) > { > if (TREE_CODE (old_var) == VAR_DECL > ! && ! DECL_EXTERNAL (old_var) > ! && (var_ann (old_var) || !gimple_in_ssa_p (cfun))) > add_local_decl (cfun, old_var); > if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE) > && !DECL_IGNORED_P (old_var) > --- 532,541 ---- > > if (can_be_nonlocal (old_var, id)) > { > + /* We need to add this variable to the local decls as otherwise > + nothing else will do so. */ > if (TREE_CODE (old_var) == VAR_DECL > ! && ! DECL_EXTERNAL (old_var)) > add_local_decl (cfun, old_var); > if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE) > && !DECL_IGNORED_P (old_var) > *************** copy_debug_stmt (gimple stmt, copy_body_ > *** 2371,2380 **** > t = *n; > } > else if (TREE_CODE (t) == VAR_DECL > ! && !TREE_STATIC (t) > ! && gimple_in_ssa_p (cfun) > ! && !pointer_map_contains (id->decl_map, t) > ! && !var_ann (t)) > /* T is a non-localized variable. */; > else > walk_tree (&t, remap_gimple_op_r, &wi, NULL); > --- 2333,2340 ---- > t = *n; > } > else if (TREE_CODE (t) == VAR_DECL > ! && !is_global_var (t) > ! && !pointer_map_contains (id->decl_map, t)) > /* T is a non-localized variable. */; > else > walk_tree (&t, remap_gimple_op_r, &wi, NULL); > Index: gcc/tree-into-ssa.c > =================================================================== > *** gcc.orig/tree-into-ssa.c 2012-08-01 15:59:25.000000000 +0200 > --- gcc/tree-into-ssa.c 2012-08-01 16:00:51.000000000 +0200 > *************** rewrite_debug_stmt_uses (gimple stmt) > *** 1274,1282 **** > > FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE) > { > ! tree var = USE_FROM_PTR (use_p), def = NULL_TREE; > gcc_assert (DECL_P (var)); > ! if (var_ann (var) == NULL) > { > if (TREE_CODE (var) == PARM_DECL && single_succ_p (ENTRY_BLOCK_PTR)) > { > --- 1274,1283 ---- > > FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE) > { > ! tree var = USE_FROM_PTR (use_p), def; > gcc_assert (DECL_P (var)); > ! def = get_current_def (var); > ! if (!def) > { > if (TREE_CODE (var) == PARM_DECL && single_succ_p (ENTRY_BLOCK_PTR)) > { > *************** rewrite_debug_stmt_uses (gimple stmt) > *** 1318,1355 **** > } > else > { > - def = get_current_def (var); > /* Check if get_current_def can be trusted. */ > ! if (def) > { > ! basic_block bb = gimple_bb (stmt); > ! basic_block def_bb > ! = SSA_NAME_IS_DEFAULT_DEF (def) > ! ? NULL : gimple_bb (SSA_NAME_DEF_STMT (def)); > > ! /* If definition is in current bb, it is fine. */ > ! if (bb == def_bb) > ! ; > ! /* If definition bb doesn't dominate the current bb, > ! it can't be used. */ > ! else if (def_bb && !dominated_by_p (CDI_DOMINATORS, bb, def_bb)) > ! def = NULL; > ! /* If there is just one definition and dominates the current > ! bb, it is fine. */ > ! else if (get_phi_state (var) == NEED_PHI_STATE_NO) > ; > else > ! { > ! struct def_blocks_d *db_p = get_def_blocks_for (var); > ! > ! /* If there are some non-debug uses in the current bb, > ! it is fine. */ > ! if (bitmap_bit_p (db_p->livein_blocks, bb->index)) > ! ; > ! /* Otherwise give up for now. */ > ! else > ! def = NULL; > ! } > } > } > if (def == NULL) > --- 1319,1352 ---- > } > else > { > /* Check if get_current_def can be trusted. */ > ! basic_block bb = gimple_bb (stmt); > ! basic_block def_bb > ! = SSA_NAME_IS_DEFAULT_DEF (def) > ! ? NULL : gimple_bb (SSA_NAME_DEF_STMT (def)); > ! > ! /* If definition is in current bb, it is fine. */ > ! if (bb == def_bb) > ! ; > ! /* If definition bb doesn't dominate the current bb, > ! it can't be used. */ > ! else if (def_bb && !dominated_by_p (CDI_DOMINATORS, bb, def_bb)) > ! def = NULL; > ! /* If there is just one definition and dominates the current > ! bb, it is fine. */ > ! else if (get_phi_state (var) == NEED_PHI_STATE_NO) > ! ; > ! else > { > ! struct def_blocks_d *db_p = get_def_blocks_for (var); > > ! /* If there are some non-debug uses in the current bb, > ! it is fine. */ > ! if (bitmap_bit_p (db_p->livein_blocks, bb->index)) > ; > + /* Otherwise give up for now. */ > else > ! def = NULL; > } > } > if (def == NULL) > Index: gcc/tree-ssa-live.c > =================================================================== > *** gcc.orig/tree-ssa-live.c 2012-08-01 16:00:42.000000000 +0200 > --- gcc/tree-ssa-live.c 2012-08-01 16:00:51.000000000 +0200 > *************** remove_unused_scope_block_p (tree scope, > *** 477,483 **** > at all so user can't get into the scopes at first place. */ > else if ((is_global_var (*t) > && !bitmap_bit_p (global_unused_vars, DECL_UID (*t))) > ! || (var_ann (*t) != NULL && is_used_p (*t))) > unused = false; > else if (TREE_CODE (*t) == LABEL_DECL && TREE_USED (*t)) > /* For labels that are still used in the IL, the decision to > --- 477,483 ---- > at all so user can't get into the scopes at first place. */ > else if ((is_global_var (*t) > && !bitmap_bit_p (global_unused_vars, DECL_UID (*t))) > ! || is_used_p (*t)) > unused = false; > else if (TREE_CODE (*t) == LABEL_DECL && TREE_USED (*t)) > /* For labels that are still used in the IL, the decision to > *************** remove_unused_locals (void) > *** 826,836 **** > if (bitmap_bit_p (global_unused_vars, DECL_UID (var))) > continue; > } > ! else if (var_ann (var) == NULL > ! || !is_used_p (var)) > { > ! if (var_ann (var)) > ! remove_referenced_var (var); > if (cfun->nonlocal_goto_save_area > && TREE_OPERAND (cfun->nonlocal_goto_save_area, 0) == var) > cfun->nonlocal_goto_save_area = NULL; > --- 826,834 ---- > if (bitmap_bit_p (global_unused_vars, DECL_UID (var))) > continue; > } > ! else if (!is_used_p (var)) > { > ! remove_referenced_var (var); > if (cfun->nonlocal_goto_save_area > && TREE_OPERAND (cfun->nonlocal_goto_save_area, 0) == var) > cfun->nonlocal_goto_save_area = NULL; > Index: gcc/tree-ssa.c > =================================================================== > *** gcc.orig/tree-ssa.c 2012-08-01 15:59:27.000000000 +0200 > --- gcc/tree-ssa.c 2012-08-01 16:00:51.000000000 +0200 > *************** struct gimple_opt_pass pass_init_datastr > *** 1150,1164 **** > void > delete_tree_ssa (void) > { > - referenced_var_iterator rvi; > - tree var; > - > /* Remove annotations from every referenced local variable. */ > - FOR_EACH_REFERENCED_VAR (cfun, var, rvi) > - { > - ggc_free (var_ann (var)); > - *DECL_VAR_ANN_PTR (var) = NULL; > - } > htab_delete (gimple_referenced_vars (cfun)); > cfun->gimple_df->referenced_vars = NULL; > > --- 1150,1156 ---- > Index: gcc/tree-tailcall.c > =================================================================== > *** gcc.orig/tree-tailcall.c 2012-08-01 15:59:25.000000000 +0200 > --- gcc/tree-tailcall.c 2012-08-01 16:00:51.000000000 +0200 > *************** arg_needs_copy_p (tree param) > *** 765,771 **** > { > tree def; > > ! if (!is_gimple_reg (param) || !var_ann (param)) > return false; > > /* Parameters that are only defined but never used need not be copied. */ > --- 765,771 ---- > { > tree def; > > ! if (!is_gimple_reg (param)) > return false; > > /* Parameters that are only defined but never used need not be copied. */ > Index: gcc/tree.c > =================================================================== > *** gcc.orig/tree.c 2012-08-01 15:58:32.000000000 +0200 > --- gcc/tree.c 2012-08-01 16:00:51.000000000 +0200 > *************** copy_node_stat (tree node MEM_STAT_DECL) > *** 961,968 **** > TREE_CHAIN (t) = 0; > TREE_ASM_WRITTEN (t) = 0; > TREE_VISITED (t) = 0; > - if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL) > - *DECL_VAR_ANN_PTR (t) = 0; > > if (TREE_CODE_CLASS (code) == tcc_declaration) > { > --- 961,966 ---- > Index: gcc/tree.h > =================================================================== > *** gcc.orig/tree.h 2012-08-01 15:58:32.000000000 +0200 > --- gcc/tree.h 2012-08-01 16:00:51.000000000 +0200 > *************** struct GTY(()) tree_label_decl { > *** 3116,3125 **** > int eh_landing_pad_nr; > }; > > - struct var_ann_d; > struct GTY(()) tree_result_decl { > struct tree_decl_with_rtl common; > - struct var_ann_d *ann; > }; > > struct GTY(()) tree_const_decl { > --- 3116,3123 ---- > *************** struct GTY(()) tree_const_decl { > *** 3138,3144 **** > struct GTY(()) tree_parm_decl { > struct tree_decl_with_rtl common; > rtx incoming_rtl; > - struct var_ann_d *ann; > }; > > > --- 3136,3141 ---- > *************** extern void decl_fini_priority_insert (t > *** 3355,3369 **** > #define VAR_DECL_IS_VIRTUAL_OPERAND(NODE) \ > (VAR_DECL_CHECK (NODE)->base.saturating_flag) > > - #define DECL_VAR_ANN_PTR(NODE) \ > - (TREE_CODE (NODE) == VAR_DECL ? &(NODE)->var_decl.ann \ > - : TREE_CODE (NODE) == PARM_DECL ? &(NODE)->parm_decl.ann \ > - : TREE_CODE (NODE) == RESULT_DECL ? &(NODE)->result_decl.ann \ > - : NULL) > - > struct GTY(()) tree_var_decl { > struct tree_decl_with_vis common; > - struct var_ann_d *ann; > }; > > > --- 3352,3359 ----