diff options
author | Jason Merrill <jason@redhat.com> | 2025-03-24 15:28:04 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2025-03-29 08:46:23 -0400 |
commit | 5ac4be28822a4e6f506a69096f92d4675a7d5a72 (patch) | |
tree | 3cc651ae7c0810ac0a77ae87041d573c37528c09 | |
parent | 39bea4b71f0ee45756e68b9e74002b0ca25606e4 (diff) | |
download | gcc-5ac4be28822a4e6f506a69096f92d4675a7d5a72.zip gcc-5ac4be28822a4e6f506a69096f92d4675a7d5a72.tar.gz gcc-5ac4be28822a4e6f506a69096f92d4675a7d5a72.tar.bz2 |
c++: optimize push_to_top_level [PR64500]
Profiling showed that the loop to save away IDENTIFIER_BINDINGs from open
binding levels was taking 5% of total compilation time in the PR116285
testcase. This turned out to be because we were unnecessarily trying to do
this for namespaces, whose bindings are found through
DECL_NAMESPACE_BINDINGS, not IDENTIFIER_BINDING.
As a result we would frequently loop through everything in std::, checking
whether it needs to be stored, and never storing anything.
This change actually appears to speed up compilation for the PR116285
testcase by ~20%.
The replaced comments referred either to long-replaced handling of classes
and templates, or to wanting b to point to :: when the loop exits.
PR c++/64500
PR c++/116285
gcc/cp/ChangeLog:
* name-lookup.cc (push_to_top_level): Don't try to store_bindings
for namespace levels.
-rw-r--r-- | gcc/cp/name-lookup.cc | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index d3aa47b..df033ed 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -8675,6 +8675,9 @@ store_class_bindings (vec<cp_class_binding, va_gc> *names, static GTY((deletable)) struct saved_scope *free_saved_scope; +/* Temporarily make the current scope the global namespace, saving away + the current scope for pop_from_top_level. */ + void push_to_top_level (void) { @@ -8716,18 +8719,19 @@ push_to_top_level (void) store_class_bindings (previous_class_level->class_shadowed, &s->old_bindings); - /* Have to include the global scope, because class-scope decls - aren't listed anywhere useful. */ + /* Save and clear any IDENTIFIER_BINDING from local scopes. */ for (; b; b = b->level_chain) { tree t; - /* Template IDs are inserted into the global level. If they were - inserted into namespace level, finish_file wouldn't find them - when doing pending instantiations. Therefore, don't stop at - namespace level, but continue until :: . */ - if (global_scope_p (b)) - break; + /* We don't need to consider namespace scopes, they don't affect + IDENTIFIER_BINDING. */ + if (b->kind == sk_namespace) + { + /* Jump straight to '::'. */ + b = NAMESPACE_LEVEL (global_namespace); + break; + } store_bindings (b->names, &s->old_bindings); /* We also need to check class_shadowed to save class-level type |