From b544c348e13ad33d55f0d954370ab1fb0f2bf683 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 1 Jul 2021 17:44:51 -0400 Subject: input.c: move file caching globals to a new file_cache class This moves some global state from input.c to a new file_cache class, of which an instance is owned by global_dc. Various state is also made private. No functional change intended. gcc/ChangeLog: * diagnostic.h (diagnostic_context::m_file_cache): New field. * input.c (class fcache): Rename to... (class file_cache_slot): ...this, making most members private and prefixing fields with "m_". (file_cache_slot::get_file_path): New accessor. (file_cache_slot::get_use_count): New accessor. (file_cache_slot::missing_trailing_newline_p): New accessor. (file_cache_slot::inc_use_count): New. (fcache_buffer_size): Move to... (file_cache_slot::buffer_size): ...here. (fcache_line_record_size): Move to... (file_cache_slot::line_record_size): ...here. (fcache_tab): Delete, in favor of global_dc->m_file_cache. (fcache_tab_size): Move to file_cache::num_file_slots. (diagnostic_file_cache_init): Update for move of fcache_tab to global_dc->m_file_cache. (diagnostic_file_cache_fini): Likewise. (lookup_file_in_cache_tab): Convert to... (file_cache::lookup_file): ...this. (diagnostics_file_cache_forcibly_evict_file): Update for move of fcache_tab to global_dc->m_file_cache, moving most of implementation to... (file_cache::forcibly_evict_file): ...this new function and... (file_cache_slot::evict): ...this new function. (evicted_cache_tab_entry): Convert to... (file_cache::evicted_cache_tab_entry): ...this. (add_file_to_cache_tab): Convert to... (file_cache::add_file): ...this, moving bulk of implementation to... (file_cache_slot::create): ..this new function. (file_cache::file_cache): New. (file_cache::~file_cache): New. (lookup_or_add_file_to_cache_tab): Convert to... (file_cache::lookup_or_add_file): ..this new function. (fcache::fcache): Rename to... (file_cache_slot::file_cache_slot): ...this, adding "m_" prefixes to fields. (fcache::~fcache): Rename to... (file_cache_slot::~file_cache_slot): ...this, adding "m_" prefixes to fields. (needs_read): Convert to... (file_cache_slot::needs_read_p): ...this. (needs_grow): Convert to... (file_cache_slot::needs_grow_p): ...this. (maybe_grow): Convert to... (file_cache_slot::maybe_grow): ...this. (read_data): Convert to... (file_cache_slot::read_data): ...this. (maybe_read_data): Convert to... (file_cache_slot::maybe_read_data): ...this. (get_next_line): Convert to... (file_cache_slot::get_next_line): ...this. (goto_next_line): Convert to... (file_cache_slot::goto_next_line): ...this. (read_line_num): Convert to... (file_cache_slot::read_line_num): ...this. (location_get_source_line): Update for moving of globals to global_dc->m_file_cache. (location_missing_trailing_newline): Likewise. * input.h (class file_cache_slot): New forward decl. (class file_cache): New. Signed-off-by: David Malcolm --- gcc/input.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'gcc/input.h') diff --git a/gcc/input.h b/gcc/input.h index f1ef5d7..bbcec84 100644 --- a/gcc/input.h +++ b/gcc/input.h @@ -88,6 +88,39 @@ class char_span extern char_span location_get_source_line (const char *file_path, int line); extern bool location_missing_trailing_newline (const char *file_path); + +/* Forward decl of slot within file_cache, so that the definition doesn't + need to be in this header. */ +class file_cache_slot; + +/* A cache of source files for use when emitting diagnostics + (and in a few places in the C/C++ frontends). + + Results are only valid until the next call to the cache, as + slots can be evicted. + + Filenames are stored by pointer, and so must outlive the cache + instance. */ + +class file_cache +{ + public: + file_cache (); + ~file_cache (); + + file_cache_slot *lookup_or_add_file (const char *file_path); + void forcibly_evict_file (const char *file_path); + + private: + file_cache_slot *evicted_cache_tab_entry (unsigned *highest_use_count); + file_cache_slot *add_file (const char *file_path); + file_cache_slot *lookup_file (const char *file_path); + + private: + static const size_t num_file_slots = 16; + file_cache_slot *m_file_slots; +}; + extern expanded_location expand_location_to_spelling_point (location_t, enum location_aspect aspect -- cgit v1.1