From b119c05542a9574a1c27f9bba63efbafc12b248b Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Fri, 3 May 2019 14:37:22 +0200
Subject: [PATCH] Come up with is_empty for hash_{table,map,set}.

2019-05-03  Martin Liska  <mliska@suse.cz>

	* 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  <mliska@suse.cz>

	* 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
---
 gcc/ChangeLog                  | 25 +++++++++++++++++++++++++
 gcc/cp/ChangeLog               |  6 ++++++
 gcc/cp/call.c                  |  2 +-
 gcc/cp/parser.c                |  2 +-
 gcc/dwarf2out.c                |  2 +-
 gcc/gimple-ssa-store-merging.c |  2 +-
 gcc/gimplify.c                 |  4 ++--
 gcc/hash-map-tests.c           |  2 +-
 gcc/hash-map.h                 |  3 +++
 gcc/hash-set.h                 |  3 +++
 gcc/hash-table.h               |  3 +++
 gcc/ipa-icf.c                  |  2 +-
 gcc/postreload-gcse.c          |  4 ++--
 gcc/predict.c                  |  2 +-
 gcc/tree-parloops.c            | 18 +++++++++---------
 gcc/var-tracking.c             |  6 +++---
 16 files changed, 63 insertions(+), 23 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d656ad76ab93..ac134c60419c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,28 @@
+2019-05-03  Martin Liska  <mliska@suse.cz>
+
+	* 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  <rguenther@suse.de>
 
 	PR tree-optimization/90316
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 129a00a5314c..d9b7d2bb36dd 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-03  Martin Liska  <mliska@suse.cz>
+
+	* 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  <nathan@acm.org>
 
 	* semantics.c (finish_id_expression_1): Remove unreachable code.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 23898f0659fb..1a79017eff46 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 3d908916ae3f..332f4bfcebd7 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 b9a624e1ac7f..366c904491ad 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 4a8cf6f847fd..81e6269cc8a3 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 e59f38261c36..b6c60855351c 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 acbfdb9e9ab2..b79c78216844 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 9d41696902e7..a3ef283a1f9b 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 8e1f38b1965f..de3532f5f680 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 7ba6356f3aef..4178616478e2 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 e4c9dda0df1e..074181491da9 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 a165351ca961..e47376708837 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 *, dump_expr_hash_table_entry> (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 60a19d7edd12..b010c20ff7d3 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 2fddc59beb21..968368f7f441 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 <tree, add_field_for_name> (type);
-      if (reduction_list && reduction_list->elements () > 0)
+      if (reduction_list && !reduction_list->is_empty ())
 	{
 	  /* Create the fields for reductions.  */
 	  reduction_list->traverse <tree, add_field_for_reduction> (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 <struct clsn_data *, create_stores_for_reduction>
@@ -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 <struct loop *, initialize_reductions> (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 55ff354c37c7..c9de93473d16 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 <void *, dump_var_tracking_slot> (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.  */
-- 
GitLab