public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-4899] Refactor section name ref counting
@ 2020-11-11 3:54 Jeff Law
0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2020-11-11 3:54 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e79de0682e6cb6fe041a22f81cc65375c8c15bff
commit r11-4899-ge79de0682e6cb6fe041a22f81cc65375c8c15bff
Author: Strager Neds <strager.nds@gmail.com>
Date: Tue Nov 10 20:53:14 2020 -0700
Refactor section name ref counting
gcc/
* symtab.c (symtab_node::set_section_for_node): Extract reference
counting logic into ...
(retain_section_hash_entry): ... here (new function) and ...
(release_section_hash_entry): ... here (new function).
Diff:
---
gcc/symtab.c | 55 ++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 19 deletions(-)
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 883cc3eae0d..c84259f1032 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -368,6 +368,36 @@ section_name_hasher::equal (section_hash_entry *n1, const char *name)
return n1->name == name || !strcmp (n1->name, name);
}
+/* Bump the reference count on ENTRY so that it is retained. */
+
+static section_hash_entry *
+retain_section_hash_entry (section_hash_entry *entry)
+{
+ entry->ref_count++;
+ return entry;
+}
+
+/* Drop the reference count on ENTRY and remove it if the reference
+ count drops to zero. */
+
+static void
+release_section_hash_entry (section_hash_entry *entry)
+{
+ if (entry)
+ {
+ entry->ref_count--;
+ if (!entry->ref_count)
+ {
+ hashval_t hash = htab_hash_string (entry->name);
+ section_hash_entry **slot
+ = symtab->section_hash->find_slot_with_hash (entry->name,
+ hash, INSERT);
+ ggc_free (entry);
+ symtab->section_hash->clear_slot (slot);
+ }
+ }
+}
+
/* Add node into symbol table. This function is not used directly, but via
cgraph/varpool node creation routines. */
@@ -1609,46 +1639,33 @@ void
symtab_node::set_section_for_node (const char *section)
{
const char *current = get_section ();
- section_hash_entry **slot;
if (current == section
|| (current && section
&& !strcmp (current, section)))
return;
- if (current)
- {
- x_section->ref_count--;
- if (!x_section->ref_count)
- {
- hashval_t hash = htab_hash_string (x_section->name);
- slot = symtab->section_hash->find_slot_with_hash (x_section->name,
- hash, INSERT);
- ggc_free (x_section);
- symtab->section_hash->clear_slot (slot);
- }
- x_section = NULL;
- }
+ release_section_hash_entry (x_section);
if (!section)
{
+ x_section = NULL;
implicit_section = false;
return;
}
if (!symtab->section_hash)
symtab->section_hash = hash_table<section_name_hasher>::create_ggc (10);
- slot = symtab->section_hash->find_slot_with_hash (section,
- htab_hash_string (section),
- INSERT);
+ section_hash_entry **slot = symtab->section_hash->find_slot_with_hash
+ (section, htab_hash_string (section), INSERT);
if (*slot)
- x_section = (section_hash_entry *)*slot;
+ x_section = retain_section_hash_entry (*slot);
else
{
int len = strlen (section);
*slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
+ x_section->ref_count = 1;
x_section->name = ggc_vec_alloc<char> (len + 1);
memcpy (x_section->name, section, len + 1);
}
- x_section->ref_count++;
}
/* Worker for set_section. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-11 3:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11 3:54 [gcc r11-4899] Refactor section name ref counting Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).