From: Martin Liska Date: Fri, 3 May 2019 12:37:22 +0000 (+0200) Subject: Come up with is_empty for hash_{table,map,set}. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b119c05542a9574a1c27f9bba63efbafc12b248b;p=gcc.git Come up with is_empty for hash_{table,map,set}. 2019-05-03 Martin Liska * hash-map.h: Add is_empty function. * hash-set.h: Likewise. * hash-table.h: Likewise. * dwarf2out.c (dwarf2out_finish): Use is_empty instead of elements () == 0 (and similar usages). * gimple-ssa-store-merging.c (pass_store_merging::terminate_and_process_all_chains): Likewise. * gimplify.c (gimplify_bind_expr): Likewise. (gimplify_switch_expr): Likewise. * hash-map-tests.c (test_map_of_strings_to_int): Likewise. * ipa-icf.c (sem_item_optimizer::remove_symtab_node): Likewise. * postreload-gcse.c (dump_hash_table): Likewise. (gcse_after_reload_main): Likewise. * predict.c (combine_predictions_for_bb): Likewise. * tree-parloops.c (reduction_phi): Likewise. (separate_decls_in_region): Likewise. (transform_to_exit_first_loop): Likewise. (gen_parallel_loop): Likewise. (gather_scalar_reductions): Likewise. (try_create_reduction_list): Likewise. * var-tracking.c (dump_vars): Likewise. (emit_notes_for_changes): Likewise. (vt_emit_notes): Likewise. 2019-05-03 Martin Liska * call.c (build_aggr_conv): Use is_empty instead of elements () == 0 (and similar usages). * parser.c (cp_parser_lambda_introducer): Likewise. From-SVN: r270851 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d656ad76ab9..ac134c60419 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,28 @@ +2019-05-03 Martin Liska + + * hash-map.h: Add is_empty function. + * hash-set.h: Likewise. + * hash-table.h: Likewise. + * dwarf2out.c (dwarf2out_finish): Use is_empty instead of + elements () == 0 (and similar usages). + * gimple-ssa-store-merging.c (pass_store_merging::terminate_and_process_all_chains): Likewise. + * gimplify.c (gimplify_bind_expr): Likewise. + (gimplify_switch_expr): Likewise. + * hash-map-tests.c (test_map_of_strings_to_int): Likewise. + * ipa-icf.c (sem_item_optimizer::remove_symtab_node): Likewise. + * postreload-gcse.c (dump_hash_table): Likewise. + (gcse_after_reload_main): Likewise. + * predict.c (combine_predictions_for_bb): Likewise. + * tree-parloops.c (reduction_phi): Likewise. + (separate_decls_in_region): Likewise. + (transform_to_exit_first_loop): Likewise. + (gen_parallel_loop): Likewise. + (gather_scalar_reductions): Likewise. + (try_create_reduction_list): Likewise. + * var-tracking.c (dump_vars): Likewise. + (emit_notes_for_changes): Likewise. + (vt_emit_notes): Likewise. + 2019-05-03 Richard Biener PR tree-optimization/90316 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 129a00a5314..d9b7d2bb36d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-05-03 Martin Liska + + * call.c (build_aggr_conv): Use is_empty instead of + elements () == 0 (and similar usages). + * parser.c (cp_parser_lambda_introducer): Likewise. + 2019-05-02 Nathan Sidwell * semantics.c (finish_id_expression_1): Remove unreachable code. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 23898f0659f..1a79017eff4 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -986,7 +986,7 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain) tree val; bool ok; - if (pset.elements () && field_in_pset (pset, field)) + if (!pset.is_empty () && field_in_pset (pset, field)) continue; if (i < CONSTRUCTOR_NELTS (ctor)) { diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3d908916ae3..332f4bfcebd 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10769,7 +10769,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr) Optimize for the zero or one explicit captures cases and only create the hash_set after adding second capture. */ bool found = false; - if (ids.elements ()) + if (!ids.is_empty ()) found = ids.add (capture_id); else if (first_capture_id == NULL_TREE) first_capture_id = capture_id; diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index b9a624e1ac7..366c904491a 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -31321,7 +31321,7 @@ dwarf2out_finish (const char *filename) flush_limbo_die_list (); if (inline_entry_data_table) - gcc_assert (inline_entry_data_table->elements () == 0); + gcc_assert (inline_entry_data_table->is_empty ()); if (flag_checking) { diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index 4a8cf6f847f..81e6269cc8a 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -2150,7 +2150,7 @@ pass_store_merging::terminate_and_process_all_chains () bool ret = false; while (m_stores_head) ret |= terminate_and_release_chain (m_stores_head); - gcc_assert (m_stores.elements () == 0); + gcc_assert (m_stores.is_empty ()); gcc_assert (m_stores_head == NULL); return ret; diff --git a/gcc/gimplify.c b/gcc/gimplify.c index e59f38261c3..b6c60855351 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1423,7 +1423,7 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p) oacc_declare_returns->remove (t); - if (oacc_declare_returns->elements () == 0) + if (oacc_declare_returns->is_empty ()) { delete oacc_declare_returns; oacc_declare_returns = NULL; @@ -2418,7 +2418,7 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) if (gimplify_ctxp->live_switch_vars) { - gcc_assert (gimplify_ctxp->live_switch_vars->elements () == 0); + gcc_assert (gimplify_ctxp->live_switch_vars->is_empty ()); delete gimplify_ctxp->live_switch_vars; } gimplify_ctxp->live_switch_vars = saved_live_switch_vars; diff --git a/gcc/hash-map-tests.c b/gcc/hash-map-tests.c index acbfdb9e9ab..b79c7821684 100644 --- a/gcc/hash-map-tests.c +++ b/gcc/hash-map-tests.c @@ -53,7 +53,7 @@ test_map_of_strings_to_int () const char *eric = "half a bee"; /* A fresh hash_map should be empty. */ - ASSERT_EQ (0, m.elements ()); + ASSERT_TRUE (m.is_empty ()); ASSERT_EQ (NULL, m.get (ostrich)); /* Populate the hash_map. */ diff --git a/gcc/hash-map.h b/gcc/hash-map.h index 9d41696902e..a3ef283a1f9 100644 --- a/gcc/hash-map.h +++ b/gcc/hash-map.h @@ -211,6 +211,9 @@ public: void empty () { m_table.empty(); } + /* Return true when there are no elements in this hash map. */ + bool is_empty () const { return m_table.is_empty (); } + class iterator { public: diff --git a/gcc/hash-set.h b/gcc/hash-set.h index 8e1f38b1965..de3532f5f68 100644 --- a/gcc/hash-set.h +++ b/gcc/hash-set.h @@ -88,6 +88,9 @@ public: void empty () { m_table.empty (); } + /* Return true when there are no elements in this hash set. */ + bool is_empty () const { return m_table.is_empty (); } + class iterator { public: diff --git a/gcc/hash-table.h b/gcc/hash-table.h index 7ba6356f3ae..4178616478e 100644 --- a/gcc/hash-table.h +++ b/gcc/hash-table.h @@ -402,6 +402,9 @@ public: /* This function clears all entries in this hash table. */ void empty () { if (elements ()) empty_slow (); } + /* Return true when there are no elements in this hash table. */ + bool is_empty () const { return elements () == 0; } + /* This function clears a specified SLOT in a hash table. It is useful when you've already done the lookup and don't want to do it again. */ diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index e4c9dda0df1..074181491da 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -2475,7 +2475,7 @@ sem_item_optimizer::varpool_removal_hook (varpool_node *node, void *data) void sem_item_optimizer::remove_symtab_node (symtab_node *node) { - gcc_assert (!m_classes.elements ()); + gcc_assert (m_classes.is_empty ()); m_removed_items_set.add (node); } diff --git a/gcc/postreload-gcse.c b/gcc/postreload-gcse.c index a165351ca96..e4737670883 100644 --- a/gcc/postreload-gcse.c +++ b/gcc/postreload-gcse.c @@ -504,7 +504,7 @@ dump_hash_table (FILE *file) (long) expr_table->size (), (long) expr_table->elements (), expr_table->collisions ()); - if (expr_table->elements () > 0) + if (!expr_table->is_empty ()) { fprintf (file, "\n\ntable entries:\n"); expr_table->traverse (file); @@ -1386,7 +1386,7 @@ gcse_after_reload_main (rtx f ATTRIBUTE_UNUSED) if (dump_file) dump_hash_table (dump_file); - if (expr_table->elements () > 0) + if (!expr_table->is_empty ()) { /* Knowing which MEMs are transparent through a block can signifiantly increase the number of redundant loads found. So compute transparency diff --git a/gcc/predict.c b/gcc/predict.c index 60a19d7edd1..b010c20ff7d 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -1252,7 +1252,7 @@ combine_predictions_for_bb (basic_block bb, bool dry_run) if (dump_file) { fprintf (dump_file, "Predictions for bb %i\n", bb->index); - if (unlikely_edges.elements () == 0) + if (unlikely_edges.is_empty ()) fprintf (dump_file, "%i edges in bb %i predicted to even probabilities\n", nedges, bb->index); diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c index 2fddc59beb2..968368f7f44 100644 --- a/gcc/tree-parloops.c +++ b/gcc/tree-parloops.c @@ -238,7 +238,7 @@ reduction_phi (reduction_info_table_type *reduction_list, gimple *phi) { struct reduction_info tmpred, *red; - if (reduction_list->elements () == 0 || phi == NULL) + if (reduction_list->is_empty () || phi == NULL) return NULL; if (gimple_uid (phi) == (unsigned int)-1 @@ -1390,7 +1390,7 @@ separate_decls_in_region (edge entry, edge exit, } } - if (name_copies.elements () == 0 && reduction_list->elements () == 0) + if (name_copies.is_empty () && reduction_list->is_empty ()) { /* It may happen that there is nothing to copy (if there are only loop carried and external variables in the loop). */ @@ -1407,7 +1407,7 @@ separate_decls_in_region (edge entry, edge exit, TYPE_NAME (type) = type_name; name_copies.traverse (type); - if (reduction_list && reduction_list->elements () > 0) + if (reduction_list && !reduction_list->is_empty ()) { /* Create the fields for reductions. */ reduction_list->traverse (type); @@ -1430,7 +1430,7 @@ separate_decls_in_region (edge entry, edge exit, /* Load the calculation from memory (after the join of the threads). */ - if (reduction_list && reduction_list->elements () > 0) + if (reduction_list && !reduction_list->is_empty ()) { reduction_list ->traverse @@ -1991,7 +1991,7 @@ transform_to_exit_first_loop (struct loop *loop, PHI_RESULT of this phi is the resulting value of the reduction variable when exiting the loop. */ - if (reduction_list->elements () > 0) + if (!reduction_list->is_empty ()) { struct reduction_info *red; @@ -2440,7 +2440,7 @@ gen_parallel_loop (struct loop *loop, } /* Generate initializations for reductions. */ - if (reduction_list->elements () > 0) + if (!reduction_list->is_empty ()) reduction_list->traverse (loop); /* Eliminate the references to local variables from the loop. */ @@ -2476,7 +2476,7 @@ gen_parallel_loop (struct loop *loop, loc = gimple_location (cond_stmt); create_parallel_loop (loop, create_loop_fn (loc), arg_struct, new_arg_struct, n_threads, loc, oacc_kernels_p); - if (reduction_list->elements () > 0) + if (!reduction_list->is_empty ()) create_call_for_reduction (loop, reduction_list, &clsn_data); scev_reset (); @@ -2679,7 +2679,7 @@ gather_scalar_reductions (loop_p loop, reduction_info_table_type *reduction_list } gather_done: - if (reduction_list->elements () == 0) + if (reduction_list->is_empty ()) return; /* As gimple_uid is used by the vectorizer in between vect_analyze_loop_form @@ -2806,7 +2806,7 @@ try_create_reduction_list (loop_p loop, fprintf (dump_file, " checking if it is part of reduction pattern:\n"); } - if (reduction_list->elements () == 0) + if (reduction_list->is_empty ()) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, diff --git a/gcc/var-tracking.c b/gcc/var-tracking.c index 55ff354c37c..c9de93473d1 100644 --- a/gcc/var-tracking.c +++ b/gcc/var-tracking.c @@ -7332,7 +7332,7 @@ dump_var (variable *var) static void dump_vars (variable_table_type *vars) { - if (vars->elements () > 0) + if (!vars->is_empty ()) { fprintf (dump_file, "Variables:\n"); vars->traverse (NULL); @@ -9060,7 +9060,7 @@ emit_notes_for_changes (rtx_insn *insn, enum emit_note_where where, emit_note_data data; variable_table_type *htab = shared_hash_htab (vars); - if (!changed_variables->elements ()) + if (changed_variables->is_empty ()) return; if (MAY_HAVE_DEBUG_BIND_INSNS) @@ -9538,7 +9538,7 @@ vt_emit_notes (void) basic_block bb; dataflow_set cur; - gcc_assert (!changed_variables->elements ()); + gcc_assert (changed_variables->is_empty ()); /* Free memory occupied by the out hash tables, as they aren't used anymore. */