c++: Prune unneeded macro locations
authorNathan Sidwell <nathan@acm.org>
Wed, 22 Jun 2022 12:54:30 +0000 (05:54 -0700)
committerNathan Sidwell <nathan@acm.org>
Thu, 23 Jun 2022 12:16:24 +0000 (05:16 -0700)
commitc01fe6729e607fd064eb27db2a9420aedb75ffd4
treedaa6ef569dd5d8f3efb9bff77f98118a7a3b16e4
parent509cdb441614eab2a0fe90a970a927538b832bcd
c++: Prune unneeded macro locations

This implements garbage collection on locations within macro
expansions, when streaming out a CMI.  When doing the reachability
walks, we now note which macro locations we need and then only write
those locations.  The complication here is that every macro expansion
location has an independently calculated offset.  This complicates
writing, but reading remains the same -- the macro locations of a CMI
continue to form a contiguous block.

For std headers this reduced the number of macro maps by 40% and the
number of locations by 16%.  For a GMF including iostream, it reduced
it by 80% and 60% respectively.

Ordinary locations are still transformed en-mass.  They are somewhat
more complicated to apply a similar optimization to.

gcc/cp/
* module.cc (struct macro_info): New.
(struct macro_traits): New.
(macro_remap, macro_table): New globals.
(depset::hash::find_dependencies): Note namespace location.
(module_for_macro_loc): Adjust.
(module_state::note_location): New.
(module_state::Write_location): Note location when not
streaming. Adjust macro location streaming.
(module_state::read_location): Adjust macro location
streaming.
(module_state::write_init_maps): New.
(module_state::write_prepare_maps): Reimplement macro map
preparation.
(module_state::write_macro_maps): Reimplement.
(module_state::read_macro_maps): Likewise.
(module_state::write_begin): Adjust.
gcc/testsuite/
* g++.dg/modules/loc-prune-1.C: New.
* g++.dg/modules/loc-prune-2.C: New.
* g++.dg/modules/loc-prune-3.C: New.
* g++.dg/modules/pr98718_a.C: Adjust.
* g++.dg/modules/pr98718_b.C: Adjust.
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/loc-prune-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/loc-prune-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/loc-prune-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr98718_a.C
gcc/testsuite/g++.dg/modules/pr98718_b.C