From: Bill Wendling <morbo@google.com>
To: dwarves@vger.kernel.org, bpf@vger.kernel.org
Cc: arnaldo.melo@gmail.com, Bill Wendling <morbo@google.com>
Subject: [RFC PATCH 1/1] dwarf_loader: have all CUs use a single hash table
Date: Fri, 12 Feb 2021 13:16:07 -0800 [thread overview]
Message-ID: <20210212211607.2890660-2-morbo@google.com> (raw)
In-Reply-To: <20210212211607.2890660-1-morbo@google.com>
In some instances, e.g. with clang's LTO, a DWARF compilation units may
reference tags in other CUs. This presents us with a "chicken and egg"
problem, where in order to properly process on CU we need access to the
tags in all CUs.
This increases the runtime by ~28% (from 11.11s to 14.27s).
Signed-off-by: Bill Wendling <morbo@google.com>
---
dwarf_loader.c | 45 +++++++++++++++++++++++++++++++++------------
1 file changed, 33 insertions(+), 12 deletions(-)
diff --git a/dwarf_loader.c b/dwarf_loader.c
index b73d786..2b0d619 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -102,7 +102,7 @@ static void dwarf_tag__set_spec(struct dwarf_tag *dtag, dwarf_off_ref spec)
*(dwarf_off_ref *)(dtag + 1) = spec;
}
-#define HASHTAGS__BITS 15
+#define HASHTAGS__BITS 16
#define HASHTAGS__SIZE (1UL << HASHTAGS__BITS)
#define obstack_chunk_alloc malloc
@@ -117,21 +117,42 @@ static void *obstack_zalloc(struct obstack *obstack, size_t size)
return o;
}
+/* The tags and types hashes used by all "dwarf_cu" objects. */
+struct dwarf_cu_hash {
+ struct hlist_head tags[HASHTAGS__SIZE];
+ struct hlist_head types[HASHTAGS__SIZE];
+};
+
struct dwarf_cu {
- struct hlist_head hash_tags[HASHTAGS__SIZE];
- struct hlist_head hash_types[HASHTAGS__SIZE];
+ struct dwarf_cu_hash *hashes;
struct obstack obstack;
struct cu *cu;
struct dwarf_cu *type_unit;
};
+static struct dwarf_cu_hash *dwarf_cu__init_hashes(void)
+{
+ static struct dwarf_cu_hash *hashes = NULL;
+
+ if (!hashes) {
+ unsigned int i;
+
+ hashes = malloc(sizeof(struct dwarf_cu_hash));
+ if (!hashes)
+ return NULL;
+
+ for (i = 0; i < HASHTAGS__SIZE; ++i) {
+ INIT_HLIST_HEAD(&hashes->tags[i]);
+ INIT_HLIST_HEAD(&hashes->types[i]);
+ }
+ }
+
+ return hashes;
+}
+
static void dwarf_cu__init(struct dwarf_cu *dcu)
{
- unsigned int i;
- for (i = 0; i < HASHTAGS__SIZE; ++i) {
- INIT_HLIST_HEAD(&dcu->hash_tags[i]);
- INIT_HLIST_HEAD(&dcu->hash_types[i]);
- }
+ dcu->hashes = dwarf_cu__init_hashes();
obstack_init(&dcu->obstack);
dcu->type_unit = NULL;
}
@@ -166,8 +187,8 @@ static void cu__hash(struct cu *cu, struct tag *tag)
{
struct dwarf_cu *dcu = cu->priv;
struct hlist_head *hashtable = tag__is_tag_type(tag) ?
- dcu->hash_types :
- dcu->hash_tags;
+ dcu->hashes->types :
+ dcu->hashes->tags;
hashtags__hash(hashtable, tag->priv);
}
@@ -179,7 +200,7 @@ static struct dwarf_tag *dwarf_cu__find_tag_by_ref(const struct dwarf_cu *cu,
if (ref->from_types) {
return NULL;
}
- return hashtags__find(cu->hash_tags, ref->off);
+ return hashtags__find(cu->hashes->tags, ref->off);
}
static struct dwarf_tag *dwarf_cu__find_type_by_ref(const struct dwarf_cu *dcu,
@@ -193,7 +214,7 @@ static struct dwarf_tag *dwarf_cu__find_type_by_ref(const struct dwarf_cu *dcu,
return NULL;
}
}
- return hashtags__find(dcu->hash_types, ref->off);
+ return hashtags__find(dcu->hashes->types, ref->off);
}
extern struct strings *strings;
--
2.30.0.478.g8a0d178c01-goog
next prev parent reply other threads:[~2021-02-12 21:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-12 21:16 [RFC 0/1] Combining CUs into a single hash table Bill Wendling
2021-02-12 21:16 ` Bill Wendling [this message]
2021-02-23 20:44 ` Bill Wendling
2021-02-23 20:54 ` Arnaldo Carvalho de Melo
2021-03-14 7:05 ` Yonghong Song
2021-03-14 8:28 ` Bill Wendling
2021-03-14 23:33 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210212211607.2890660-2-morbo@google.com \
--to=morbo@google.com \
--cc=arnaldo.melo@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).