[PATCH] Line map table allocation

https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00434.html
	* line-map.c: (linemap_init): Set default allocator here.
	(new_linemap): Rather than here.  Refactor allocation logic.

From-SVN: r263366
This commit is contained in:
Nathan Sidwell 2018-08-07 21:28:51 +00:00 committed by Nathan Sidwell
parent 0ec78a9369
commit e81c3c4dc1
2 changed files with 45 additions and 60 deletions

View File

@ -1,3 +1,8 @@
2018-08-07 Nathan Sidwell <nathan@acm.org>
* line-map.c: (linemap_init): Set default allocator here.
(new_linemap): Rather than here. Refactor allocation logic.
2018-07-20 David Malcolm <dmalcolm@redhat.com> 2018-07-20 David Malcolm <dmalcolm@redhat.com>
* include/line-map.h (rich_location::set_range): Remove redundant * include/line-map.h (rich_location::set_range): Remove redundant

View File

@ -346,6 +346,8 @@ linemap_init (struct line_maps *set,
#else #else
new (set) line_maps(); new (set) line_maps();
#endif #endif
/* Set default reallocator (used for initial alloc too). */
set->reallocator = xrealloc;
set->highest_location = RESERVED_LOCATION_COUNT - 1; set->highest_location = RESERVED_LOCATION_COUNT - 1;
set->highest_line = RESERVED_LOCATION_COUNT - 1; set->highest_line = RESERVED_LOCATION_COUNT - 1;
set->location_adhoc_data_map.htab = set->location_adhoc_data_map.htab =
@ -376,82 +378,60 @@ linemap_check_files_exited (struct line_maps *set)
static struct line_map * static struct line_map *
new_linemap (struct line_maps *set, source_location start_location) new_linemap (struct line_maps *set, source_location start_location)
{ {
struct line_map *result; bool macro_p = start_location >= LINE_MAP_MAX_LOCATION;
bool macro_map_p = start_location >= LINE_MAP_MAX_LOCATION; unsigned num_maps_allocated = LINEMAPS_ALLOCATED (set, macro_p);
unsigned num_maps_used = LINEMAPS_USED (set, macro_p);
if (LINEMAPS_USED (set, macro_map_p) == LINEMAPS_ALLOCATED (set, macro_map_p)) if (num_maps_used == num_maps_allocated)
{ {
/* We ran out of allocated line maps. Let's allocate more. */ /* We need more space! */
size_t alloc_size; if (!num_maps_allocated)
num_maps_allocated = 128;
num_maps_allocated *= 2;
/* Cast away extern "C" from the type of xrealloc. */ size_t size_of_a_map;
line_map_realloc reallocator = (set->reallocator void *buffer;
? set->reallocator if (macro_p)
: (line_map_realloc) xrealloc); {
line_map_round_alloc_size_func round_alloc_size = size_of_a_map = sizeof (line_map_macro);
set->round_alloc_size; buffer = set->info_macro.maps;
}
size_t map_size = (macro_map_p else
? sizeof (line_map_macro) {
: sizeof (line_map_ordinary)); size_of_a_map = sizeof (line_map_ordinary);
buffer = set->info_ordinary.maps;
}
/* We are going to execute some dance to try to reduce the /* We are going to execute some dance to try to reduce the
overhead of the memory allocator, in case we are using the overhead of the memory allocator, in case we are using the
ggc-page.c one. ggc-page.c one.
The actual size of memory we are going to get back from the The actual size of memory we are going to get back from the
allocator is the smallest power of 2 that is greater than the allocator may well be larger than what we ask for. Use this
size we requested. So let's consider that size then. */ hook to find what that size is. */
size_t alloc_size
alloc_size = = set->round_alloc_size (num_maps_allocated * size_of_a_map);
(2 * LINEMAPS_ALLOCATED (set, macro_map_p) + 256)
* map_size;
/* Get the actual size of memory that is going to be allocated
by the allocator. */
alloc_size = round_alloc_size (alloc_size);
/* Now alloc_size contains the exact memory size we would get if /* Now alloc_size contains the exact memory size we would get if
we have asked for the initial alloc_size amount of memory. we have asked for the initial alloc_size amount of memory.
Let's get back to the number of macro map that amounts Let's get back to the number of map that amounts to. */
to. */ unsigned num_maps = alloc_size / size_of_a_map;
LINEMAPS_ALLOCATED (set, macro_map_p) = buffer = set->reallocator (buffer, num_maps * size_of_a_map);
alloc_size / map_size; memset ((char *)buffer + num_maps_used * size_of_a_map, 0,
(num_maps - num_maps_used) * size_of_a_map);
if (macro_p)
set->info_macro.maps = (line_map_macro *)buffer;
else
set->info_ordinary.maps = (line_map_ordinary *)buffer;
LINEMAPS_ALLOCATED (set, macro_p) = num_maps;
}
/* And now let's really do the re-allocation. */ line_map *result = (macro_p ? (line_map *)&set->info_macro.maps[num_maps_used]
if (macro_map_p) : (line_map *)&set->info_ordinary.maps[num_maps_used]);
{ LINEMAPS_USED (set, macro_p)++;
set->info_macro.maps
= (line_map_macro *) (*reallocator) (set->info_macro.maps,
(LINEMAPS_ALLOCATED (set, macro_map_p)
* map_size));
result = &set->info_macro.maps[LINEMAPS_USED (set, macro_map_p)];
}
else
{
set->info_ordinary.maps =
(line_map_ordinary *) (*reallocator) (set->info_ordinary.maps,
(LINEMAPS_ALLOCATED (set, macro_map_p)
* map_size));
result = &set->info_ordinary.maps[LINEMAPS_USED (set, macro_map_p)];
}
memset (result, 0,
((LINEMAPS_ALLOCATED (set, macro_map_p)
- LINEMAPS_USED (set, macro_map_p))
* map_size));
}
else
{
if (macro_map_p)
result = &set->info_macro.maps[LINEMAPS_USED (set, macro_map_p)];
else
result = &set->info_ordinary.maps[LINEMAPS_USED (set, macro_map_p)];
}
result->start_location = start_location; result->start_location = start_location;
LINEMAPS_USED (set, macro_map_p)++;
return result; return result;
} }