aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl2.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2021-09-08 10:39:27 +0200
committerRichard Biener <rguenther@suse.de>2021-09-08 17:43:40 +0200
commit716a5836928ee6d8fb884d9a2fbc1b1386ec8994 (patch)
tree68472729eae9fb81184f64aaeaed5099f7680e7a /gcc/cp/decl2.c
parentd27d694151c5604d2daba23dd2a328ae70b65194 (diff)
downloadgcc-716a5836928ee6d8fb884d9a2fbc1b1386ec8994.zip
gcc-716a5836928ee6d8fb884d9a2fbc1b1386ec8994.tar.gz
gcc-716a5836928ee6d8fb884d9a2fbc1b1386ec8994.tar.bz2
c++/102228 - make lookup_anon_field O(1)
For the testcase in PR101555 lookup_anon_field takes the majority of parsing time followed by get_class_binding_direct/fields_linear_search which is PR83309. The situation with anon aggregates is particularly dire when we need to build accesses to their members and the anon aggregates are nested. There for each such access we recursively build sub-accesses to the anon aggregate FIELD_DECLs bottom-up, DFS searching for them. That's inefficient since as I believe there's a 1:1 relationship between anon aggregate types and the FIELD_DECL used to place them. The patch below does away with the search in lookup_anon_field and instead records the single FIELD_DECL in the anon aggregate types lang-specific data, re-using the RTTI typeinfo_var field. That speeds up the compile of the testcase with -fsyntax-only from about 4.5s to slightly less than 1s. I tried to poke holes into the 1:1 relationship idea with my C++ knowledge but failed (which might not say much). It also leaves a hole for the case when the C++ FE itself duplicates such type and places it at a semantically different position. I've tried to poke holes into it with the duplication mechanism I understand (templates) but failed. 2021-09-08 Richard Biener <rguenther@suse.de> PR c++/102228 gcc/cp/ * cp-tree.h (ANON_AGGR_TYPE_FIELD): New define. * decl.c (fixup_anonymous_aggr): Wipe RTTI info put in place on invalid code. * decl2.c (reset_type_linkage): Guard CLASSTYPE_TYPEINFO_VAR access. * module.cc (trees_in::read_class_def): Likewise. Reconstruct ANON_AGGR_TYPE_FIELD. * semantics.c (finish_member_declaration): Populate ANON_AGGR_TYPE_FIELD for anon aggregate typed members. * typeck.c (lookup_anon_field): Remove DFS search and return ANON_AGGR_TYPE_FIELD directly.
Diffstat (limited to 'gcc/cp/decl2.c')
-rw-r--r--gcc/cp/decl2.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 107edca..a79a70b 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -2977,14 +2977,15 @@ reset_type_linkage (tree type)
SET_DECL_ASSEMBLER_NAME (vt, name);
reset_decl_linkage (vt);
}
- if (tree ti = CLASSTYPE_TYPEINFO_VAR (type))
- {
- tree name = mangle_typeinfo_for_type (type);
- DECL_NAME (ti) = name;
- SET_DECL_ASSEMBLER_NAME (ti, name);
- TREE_TYPE (name) = type;
- reset_decl_linkage (ti);
- }
+ if (!ANON_AGGR_TYPE_P (type))
+ if (tree ti = CLASSTYPE_TYPEINFO_VAR (type))
+ {
+ tree name = mangle_typeinfo_for_type (type);
+ DECL_NAME (ti) = name;
+ SET_DECL_ASSEMBLER_NAME (ti, name);
+ TREE_TYPE (name) = type;
+ reset_decl_linkage (ti);
+ }
for (tree m = TYPE_FIELDS (type); m; m = DECL_CHAIN (m))
{
tree mem = STRIP_TEMPLATE (m);