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.