https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102228

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rgue...@gcc.gnu.org>:

https://gcc.gnu.org/g:716a5836928ee6d8fb884d9a2fbc1b1386ec8994

commit r12-3421-g716a5836928ee6d8fb884d9a2fbc1b1386ec8994
Author: Richard Biener <rguent...@suse.de>
Date:   Wed Sep 8 10:39:27 2021 +0200

    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  <rguent...@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.

Reply via email to