Commit 36a3a7a3 by Jakub Jelinek Committed by Jakub Jelinek

hash-table.h (hash_table): Add Lazy template parameter defaulted to false...

	* hash-table.h (hash_table): Add Lazy template parameter defaulted
	to false, if true, don't alloc_entries during construction, but defer
	it to the first method that needs m_entries allocated.
	(hash_table::hash_table, hash_table::~hash_table,
	hash_table::alloc_entries, hash_table::find_empty_slot_for_expand,
	hash_table::too_empty_p, hash_table::expand, hash_table::empty_slow,
	hash_table::clear_slot, hash_table::traverse_noresize,
	hash_table::traverse, hash_table::iterator::slide): Adjust all methods.
	* hash-set.h (hash_set): Add Lazy template parameter defaulted to
	false.
	(hash_set::contains): If Lazy is true, use find_slot_with_hash with
	NO_INSERT instead of find_with_hash.
	(hash_set::traverse, hash_set::iterator, hash_set::iterator::m_iter,
	hash_set::m_table): Add Lazy to template params of hash_table.
	(gt_ggc_mx, gt_pch_nx): Use false as Lazy in hash_set template param.
	* attribs.c (test_attribute_exclusions): Likewise.
	* hash-set-tests.c (test_set_of_strings): Add iterator tests for
	hash_set.  Add tests for hash_set with Lazy = true.
c-family/
	* c-common.c (per_file_includes_t): Use false as Lazy in hash_set
	template param.
jit/
	* jit-recording.c (reproducer::m_set_identifiers): Use false as Lazy
	in hash_set template param.

From-SVN: r269859
parent 2e4182ae
2019-03-21 Jakub Jelinek <jakub@redhat.com>
* hash-table.h (hash_table): Add Lazy template parameter defaulted
to false, if true, don't alloc_entries during construction, but defer
it to the first method that needs m_entries allocated.
(hash_table::hash_table, hash_table::~hash_table,
hash_table::alloc_entries, hash_table::find_empty_slot_for_expand,
hash_table::too_empty_p, hash_table::expand, hash_table::empty_slow,
hash_table::clear_slot, hash_table::traverse_noresize,
hash_table::traverse, hash_table::iterator::slide): Adjust all methods.
* hash-set.h (hash_set): Add Lazy template parameter defaulted to
false.
(hash_set::contains): If Lazy is true, use find_slot_with_hash with
NO_INSERT instead of find_with_hash.
(hash_set::traverse, hash_set::iterator, hash_set::iterator::m_iter,
hash_set::m_table): Add Lazy to template params of hash_table.
(gt_ggc_mx, gt_pch_nx): Use false as Lazy in hash_set template param.
* attribs.c (test_attribute_exclusions): Likewise.
* hash-set-tests.c (test_set_of_strings): Add iterator tests for
hash_set. Add tests for hash_set with Lazy = true.
2019-03-21 Richard Biener <rguenther@suse.de> 2019-03-21 Richard Biener <rguenther@suse.de>
PR tree-optimization/89779 PR tree-optimization/89779
......
...@@ -2075,7 +2075,7 @@ test_attribute_exclusions () ...@@ -2075,7 +2075,7 @@ test_attribute_exclusions ()
const size_t ntables = ARRAY_SIZE (attribute_tables); const size_t ntables = ARRAY_SIZE (attribute_tables);
/* Set of pairs of mutually exclusive attributes. */ /* Set of pairs of mutually exclusive attributes. */
typedef hash_set<excl_pair, excl_hash_traits> exclusion_set; typedef hash_set<excl_pair, false, excl_hash_traits> exclusion_set;
exclusion_set excl_set; exclusion_set excl_set;
for (size_t ti0 = 0; ti0 != ntables; ++ti0) for (size_t ti0 = 0; ti0 != ntables; ++ti0)
......
2019-03-21 Jakub Jelinek <jakub@redhat.com>
* c-common.c (per_file_includes_t): Use false as Lazy in hash_set
template param.
2019-03-19 Martin Sebor <msebor@redhat.com> 2019-03-19 Martin Sebor <msebor@redhat.com>
PR tree-optimization/89688 PR tree-optimization/89688
......
...@@ -8731,7 +8731,7 @@ try_to_locate_new_include_insertion_point (const char *file, location_t loc) ...@@ -8731,7 +8731,7 @@ try_to_locate_new_include_insertion_point (const char *file, location_t loc)
no guarantee that two different diagnostics that are recommending no guarantee that two different diagnostics that are recommending
adding e.g. "<stdio.h>" are using the same buffer. */ adding e.g. "<stdio.h>" are using the same buffer. */
typedef hash_set <const char *, nofree_string_hash> per_file_includes_t; typedef hash_set <const char *, false, nofree_string_hash> per_file_includes_t;
/* The map itself. We don't need string comparison for the filename keys, /* The map itself. We don't need string comparison for the filename keys,
as they come from libcpp. */ as they come from libcpp. */
......
...@@ -44,6 +44,9 @@ test_set_of_strings () ...@@ -44,6 +44,9 @@ test_set_of_strings ()
ASSERT_EQ (false, s.contains (red)); ASSERT_EQ (false, s.contains (red));
for (hash_set<const char *>::iterator it = s.begin (); it != s.end (); ++it)
ASSERT_EQ (true, false);
/* Populate the hash_set. */ /* Populate the hash_set. */
ASSERT_EQ (false, s.add (red)); ASSERT_EQ (false, s.add (red));
ASSERT_EQ (false, s.add (green)); ASSERT_EQ (false, s.add (green));
...@@ -68,6 +71,67 @@ test_set_of_strings () ...@@ -68,6 +71,67 @@ test_set_of_strings ()
ASSERT_EQ (true, s.contains (green)); ASSERT_EQ (true, s.contains (green));
ASSERT_EQ (true, s.contains (blue)); ASSERT_EQ (true, s.contains (blue));
ASSERT_EQ (2, s.elements ()); ASSERT_EQ (2, s.elements ());
int seen = 0;
for (hash_set<const char *>::iterator it = s.begin (); it != s.end (); ++it)
{
int n = *it == green;
if (n == 0)
ASSERT_EQ (*it, blue);
ASSERT_EQ (seen & (1 << n), 0);
seen |= 1 << n;
}
ASSERT_EQ (seen, 3);
hash_set <const char *, true> t;
ASSERT_EQ (0, t.elements ());
ASSERT_EQ (false, t.contains (red));
for (hash_set<const char *, true>::iterator it = t.begin ();
it != t.end (); ++it)
ASSERT_EQ (true, false);
/* Populate the hash_set. */
ASSERT_EQ (false, t.add (red));
ASSERT_EQ (false, t.add (green));
ASSERT_EQ (false, t.add (blue));
ASSERT_EQ (true, t.add (green));
/* Verify that the values are now within the set. */
ASSERT_EQ (true, t.contains (red));
ASSERT_EQ (true, t.contains (green));
ASSERT_EQ (true, t.contains (blue));
ASSERT_EQ (3, t.elements ());
seen = 0;
for (hash_set<const char *, true>::iterator it = t.begin ();
it != t.end (); ++it)
{
int n = 2;
if (*it == green)
n = 0;
else if (*it == blue)
n = 1;
else
ASSERT_EQ (*it, red);
ASSERT_EQ (seen & (1 << n), 0);
seen |= 1 << n;
}
ASSERT_EQ (seen, 7);
/* Test removal. */
t.remove (red);
ASSERT_EQ (false, t.contains (red));
ASSERT_EQ (true, t.contains (green));
ASSERT_EQ (true, t.contains (blue));
ASSERT_EQ (2, t.elements ());
t.remove (red);
ASSERT_EQ (false, t.contains (red));
ASSERT_EQ (true, t.contains (green));
ASSERT_EQ (true, t.contains (blue));
ASSERT_EQ (2, t.elements ());
} }
/* Run all of the selftests within this file. */ /* Run all of the selftests within this file. */
......
...@@ -21,7 +21,8 @@ along with GCC; see the file COPYING3. If not see ...@@ -21,7 +21,8 @@ along with GCC; see the file COPYING3. If not see
#ifndef hash_set_h #ifndef hash_set_h
#define hash_set_h #define hash_set_h
template<typename KeyId, typename Traits = default_hash_traits<KeyId> > template<typename KeyId, bool Lazy = false,
typename Traits = default_hash_traits<KeyId> >
class hash_set class hash_set
{ {
public: public:
...@@ -32,12 +33,12 @@ public: ...@@ -32,12 +33,12 @@ public:
/* Create a hash_set in gc memory with space for at least n elements. */ /* Create a hash_set in gc memory with space for at least n elements. */
static hash_set * static hash_set *
create_ggc (size_t n) create_ggc (size_t n)
{ {
hash_set *set = ggc_alloc<hash_set> (); hash_set *set = ggc_alloc<hash_set> ();
new (set) hash_set (n, true); new (set) hash_set (n, true);
return set; return set;
} }
/* If key k isn't already in the map add it to the map, and /* If key k isn't already in the map add it to the map, and
return false. Otherwise return true. */ return false. Otherwise return true. */
...@@ -56,6 +57,9 @@ public: ...@@ -56,6 +57,9 @@ public:
bool contains (const Key &k) bool contains (const Key &k)
{ {
if (Lazy)
return (m_table.find_slot_with_hash (k, Traits::hash (k), NO_INSERT)
!= NULL);
Key &e = m_table.find_with_hash (k, Traits::hash (k)); Key &e = m_table.find_with_hash (k, Traits::hash (k));
return !Traits::is_empty (e); return !Traits::is_empty (e);
} }
...@@ -71,7 +75,7 @@ public: ...@@ -71,7 +75,7 @@ public:
template<typename Arg, bool (*f)(const typename Traits::value_type &, Arg)> template<typename Arg, bool (*f)(const typename Traits::value_type &, Arg)>
void traverse (Arg a) const void traverse (Arg a) const
{ {
for (typename hash_table<Traits>::iterator iter = m_table.begin (); for (typename hash_table<Traits, Lazy>::iterator iter = m_table.begin ();
iter != m_table.end (); ++iter) iter != m_table.end (); ++iter)
f (*iter, a); f (*iter, a);
} }
...@@ -87,7 +91,8 @@ public: ...@@ -87,7 +91,8 @@ public:
class iterator class iterator
{ {
public: public:
explicit iterator (const typename hash_table<Traits>::iterator &iter) : explicit iterator (const typename hash_table<Traits,
Lazy>::iterator &iter) :
m_iter (iter) {} m_iter (iter) {}
iterator &operator++ () iterator &operator++ ()
...@@ -109,7 +114,7 @@ public: ...@@ -109,7 +114,7 @@ public:
} }
private: private:
typename hash_table<Traits>::iterator m_iter; typename hash_table<Traits, Lazy>::iterator m_iter;
}; };
/* Standard iterator retrieval methods. */ /* Standard iterator retrieval methods. */
...@@ -120,11 +125,14 @@ public: ...@@ -120,11 +125,14 @@ public:
private: private:
template<typename T, typename U> friend void gt_ggc_mx (hash_set<T, U> *); template<typename T, typename U>
template<typename T, typename U> friend void gt_pch_nx (hash_set<T, U> *); friend void gt_ggc_mx (hash_set<T, false, U> *);
template<typename T, typename U> friend void gt_pch_nx (hash_set<T, U> *, gt_pointer_operator, void *); template<typename T, typename U>
friend void gt_pch_nx (hash_set<T, false, U> *);
template<typename T, typename U>
friend void gt_pch_nx (hash_set<T, false, U> *, gt_pointer_operator, void *);
hash_table<Traits> m_table; hash_table<Traits, Lazy> m_table;
}; };
/* Generic hash_set<TYPE> debug helper. /* Generic hash_set<TYPE> debug helper.
...@@ -169,21 +177,21 @@ debug_helper (hash_set<T> &ref) ...@@ -169,21 +177,21 @@ debug_helper (hash_set<T> &ref)
template<typename K, typename H> template<typename K, typename H>
static inline void static inline void
gt_ggc_mx (hash_set<K, H> *h) gt_ggc_mx (hash_set<K, false, H> *h)
{ {
gt_ggc_mx (&h->m_table); gt_ggc_mx (&h->m_table);
} }
template<typename K, typename H> template<typename K, typename H>
static inline void static inline void
gt_pch_nx (hash_set<K, H> *h) gt_pch_nx (hash_set<K, false, H> *h)
{ {
gt_pch_nx (&h->m_table); gt_pch_nx (&h->m_table);
} }
template<typename K, typename H> template<typename K, typename H>
static inline void static inline void
gt_pch_nx (hash_set<K, H> *h, gt_pointer_operator op, void *cookie) gt_pch_nx (hash_set<K, false, H> *h, gt_pointer_operator op, void *cookie)
{ {
op (&h->m_table.m_entries, cookie); op (&h->m_table.m_entries, cookie);
} }
......
2019-03-21 Jakub Jelinek <jakub@redhat.com>
* jit-recording.c (reproducer::m_set_identifiers): Use false as Lazy
in hash_set template param.
2019-02-05 Andrea Corallo <andrea.corallo@arm.com> 2019-02-05 Andrea Corallo <andrea.corallo@arm.com>
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag. * docs/topics/compatibility.rst (LIBGCCJIT_ABI_11): New ABI tag.
......
...@@ -245,7 +245,7 @@ class reproducer : public dump ...@@ -245,7 +245,7 @@ class reproducer : public dump
{ {
static void remove (const char *) {} static void remove (const char *) {}
}; };
hash_set<const char *, hash_traits> m_set_identifiers; hash_set<const char *, false, hash_traits> m_set_identifiers;
allocator m_allocator; allocator m_allocator;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment