comparison gcc/hash-table.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* A type-safe hash table template. 1 /* A type-safe hash table template.
2 Copyright (C) 2012-2017 Free Software Foundation, Inc. 2 Copyright (C) 2012-2018 Free Software Foundation, Inc.
3 Contributed by Lawrence Crowl <crowl@google.com> 3 Contributed by Lawrence Crowl <crowl@google.com>
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
559 mem-stats.h after hash_table declaration. */ 559 mem-stats.h after hash_table declaration. */
560 560
561 #include "mem-stats.h" 561 #include "mem-stats.h"
562 #include "hash-map.h" 562 #include "hash-map.h"
563 563
564 extern mem_alloc_description<mem_usage> hash_table_usage; 564 extern mem_alloc_description<mem_usage>& hash_table_usage (void);
565 565
566 /* Support function for statistics. */ 566 /* Support function for statistics. */
567 extern void dump_hash_table_loc_statistics (void); 567 extern void dump_hash_table_loc_statistics (void);
568 568
569 template<typename Descriptor, template<typename Type> class Allocator> 569 template<typename Descriptor, template<typename Type> class Allocator>
578 578
579 size_prime_index = hash_table_higher_prime_index (size); 579 size_prime_index = hash_table_higher_prime_index (size);
580 size = prime_tab[size_prime_index].prime; 580 size = prime_tab[size_prime_index].prime;
581 581
582 if (m_gather_mem_stats) 582 if (m_gather_mem_stats)
583 hash_table_usage.register_descriptor (this, origin, ggc 583 hash_table_usage ().register_descriptor (this, origin, ggc
584 FINAL_PASS_MEM_STAT); 584 FINAL_PASS_MEM_STAT);
585 585
586 m_entries = alloc_entries (size PASS_MEM_STAT); 586 m_entries = alloc_entries (size PASS_MEM_STAT);
587 m_size = size; 587 m_size = size;
588 m_size_prime_index = size_prime_index; 588 m_size_prime_index = size_prime_index;
598 m_gather_mem_stats (gather_mem_stats) 598 m_gather_mem_stats (gather_mem_stats)
599 { 599 {
600 size_t size = h.m_size; 600 size_t size = h.m_size;
601 601
602 if (m_gather_mem_stats) 602 if (m_gather_mem_stats)
603 hash_table_usage.register_descriptor (this, origin, ggc 603 hash_table_usage ().register_descriptor (this, origin, ggc
604 FINAL_PASS_MEM_STAT); 604 FINAL_PASS_MEM_STAT);
605 605
606 value_type *nentries = alloc_entries (size PASS_MEM_STAT); 606 value_type *nentries = alloc_entries (size PASS_MEM_STAT);
607 for (size_t i = 0; i < size; ++i) 607 for (size_t i = 0; i < size; ++i)
608 { 608 {
628 Allocator <value_type> ::data_free (m_entries); 628 Allocator <value_type> ::data_free (m_entries);
629 else 629 else
630 ggc_free (m_entries); 630 ggc_free (m_entries);
631 631
632 if (m_gather_mem_stats) 632 if (m_gather_mem_stats)
633 hash_table_usage.release_instance_overhead (this, 633 hash_table_usage ().release_instance_overhead (this,
634 sizeof (value_type) * m_size, 634 sizeof (value_type) * m_size,
635 true); 635 true);
636 } 636 }
637 637
638 /* This function returns an array of empty hash table elements. */ 638 /* This function returns an array of empty hash table elements. */
642 hash_table<Descriptor, Allocator>::alloc_entries (size_t n MEM_STAT_DECL) const 642 hash_table<Descriptor, Allocator>::alloc_entries (size_t n MEM_STAT_DECL) const
643 { 643 {
644 value_type *nentries; 644 value_type *nentries;
645 645
646 if (m_gather_mem_stats) 646 if (m_gather_mem_stats)
647 hash_table_usage.register_instance_overhead (sizeof (value_type) * n, this); 647 hash_table_usage ().register_instance_overhead (sizeof (value_type) * n, this);
648 648
649 if (!m_ggc) 649 if (!m_ggc)
650 nentries = Allocator <value_type> ::data_alloc (n); 650 nentries = Allocator <value_type> ::data_alloc (n);
651 else 651 else
652 nentries = ::ggc_cleared_vec_alloc<value_type> (n PASS_MEM_STAT); 652 nentries = ::ggc_cleared_vec_alloc<value_type> (n PASS_MEM_STAT);
734 } 734 }
735 735
736 value_type *nentries = alloc_entries (nsize); 736 value_type *nentries = alloc_entries (nsize);
737 737
738 if (m_gather_mem_stats) 738 if (m_gather_mem_stats)
739 hash_table_usage.release_instance_overhead (this, sizeof (value_type) 739 hash_table_usage ().release_instance_overhead (this, sizeof (value_type)
740 * osize); 740 * osize);
741 741
742 m_entries = nentries; 742 m_entries = nentries;
743 m_size = nsize; 743 m_size = nsize;
744 m_size_prime_index = nindex; 744 m_size_prime_index = nindex;
802 m_size = nsize; 802 m_size = nsize;
803 m_size_prime_index = nindex; 803 m_size_prime_index = nindex;
804 } 804 }
805 else 805 else
806 { 806 {
807 #ifndef BROKEN_VALUE_INITIALIZATION
807 for ( ; size; ++entries, --size) 808 for ( ; size; ++entries, --size)
808 *entries = value_type (); 809 *entries = value_type ();
810 #else
811 memset (entries, 0, size * sizeof (value_type));
812 #endif
809 } 813 }
810 m_n_deleted = 0; 814 m_n_deleted = 0;
811 m_n_elements = 0; 815 m_n_elements = 0;
812 } 816 }
813 817
1042 { 1046 {
1043 if (table::is_empty (h->m_entries[i]) 1047 if (table::is_empty (h->m_entries[i])
1044 || table::is_deleted (h->m_entries[i])) 1048 || table::is_deleted (h->m_entries[i]))
1045 continue; 1049 continue;
1046 1050
1047 E::ggc_mx (h->m_entries[i]); 1051 /* Use ggc_maxbe_mx so we don't mark right away for cache tables; we'll
1052 mark in gt_cleare_cache if appropriate. */
1053 E::ggc_maybe_mx (h->m_entries[i]);
1048 } 1054 }
1049 } 1055 }
1050 1056
1051 template<typename D> 1057 template<typename D>
1052 static inline void 1058 static inline void
1092 1098
1093 template<typename H> 1099 template<typename H>
1094 inline void 1100 inline void
1095 gt_cleare_cache (hash_table<H> *h) 1101 gt_cleare_cache (hash_table<H> *h)
1096 { 1102 {
1097 extern void gt_ggc_mx (typename H::value_type &t);
1098 typedef hash_table<H> table; 1103 typedef hash_table<H> table;
1099 if (!h) 1104 if (!h)
1100 return; 1105 return;
1101 1106
1102 for (typename table::iterator iter = h->begin (); iter != h->end (); ++iter) 1107 for (typename table::iterator iter = h->begin (); iter != h->end (); ++iter)
1104 { 1109 {
1105 int res = H::keep_cache_entry (*iter); 1110 int res = H::keep_cache_entry (*iter);
1106 if (res == 0) 1111 if (res == 0)
1107 h->clear_slot (&*iter); 1112 h->clear_slot (&*iter);
1108 else if (res != -1) 1113 else if (res != -1)
1109 gt_ggc_mx (*iter); 1114 H::ggc_mx (*iter);
1110 } 1115 }
1111 } 1116 }
1112 1117
1113 #endif /* TYPED_HASHTAB_H */ 1118 #endif /* TYPED_HASHTAB_H */