public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] libcpp: eliminate LINEMAPS_{,ORDINARY_,MACRO_}CACHE
@ 2023-10-08 22:59 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2023-10-08 22:59 UTC (permalink / raw)
  To: gcc-patches; +Cc: David Malcolm

It's simpler to use field access than to go through these inline
functions that look as if they are macros.

No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r14-4479-g45bae1809c3919.

libcpp/ChangeLog:
	* include/line-map.h (maps_info_ordinary::cache): Rename to...
	(maps_info_ordinary::m_cache): ...this.
	(maps_info_macro::cache): Rename to...
	(maps_info_macro::m_cache): ...this.
	(LINEMAPS_CACHE): Delete.
	(LINEMAPS_ORDINARY_CACHE): Delete.
	(LINEMAPS_MACRO_CACHE): Delete.
	* init.cc (read_original_filename): Update for adding "m_" prefix.
	* line-map.cc (linemap_add): Eliminate LINEMAPS_ORDINARY_CACHE in
	favor of a simple field access.
	(linemap_enter_macro): Likewise for LINEMAPS_MACRO_CACHE.
	(linemap_ordinary_map_lookup): Likewise for
	LINEMAPS_ORDINARY_CACHE, twice.
	(linemap_lookup_macro_index): Likewise for LINEMAPS_MACRO_CACHE.
---
 libcpp/include/line-map.h | 36 ++++++------------------------------
 libcpp/init.cc            |  2 +-
 libcpp/line-map.cc        | 12 ++++++------
 3 files changed, 13 insertions(+), 37 deletions(-)

diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 7a172f4c846..30f2284b5d1 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -733,7 +733,9 @@ struct GTY(()) maps_info_ordinary {
      or equal to ALLOCATED.  */
   unsigned int used;
 
-  mutable unsigned int cache;
+  /* The index of the last ordinary map that was looked up with
+     linemap_lookup.  */
+  mutable unsigned int m_cache;
 };
 
 struct GTY(()) maps_info_macro {
@@ -748,7 +750,9 @@ struct GTY(()) maps_info_macro {
      or equal to ALLOCATED.  */
   unsigned int used;
 
-  mutable unsigned int cache;
+  /* The index of the last macro map that was looked up with
+     linemap_lookup.  */
+  mutable unsigned int m_cache;
 };
 
 /* Data structure to associate a source_range together with an arbitrary
@@ -904,18 +908,6 @@ LINEMAPS_USED (line_maps *set, bool map_kind)
     return set->info_ordinary.used;
 }
 
-/* Returns the index of the last map that was looked up with
-   linemap_lookup. MAP_KIND shall be TRUE if we are interested in
-   macro maps, FALSE otherwise.  */
-inline unsigned int &
-LINEMAPS_CACHE (const line_maps *set, bool map_kind)
-{
-  if (map_kind)
-    return set->info_macro.cache;
-  else
-    return set->info_ordinary.cache;
-}
-
 /* Return the map at a given index.  */
 inline line_map *
 LINEMAPS_MAP_AT (const line_maps *set, bool map_kind, int index)
@@ -968,14 +960,6 @@ LINEMAPS_ORDINARY_USED (const line_maps *set)
   return LINEMAPS_USED (set, false);
 }
 
-/* Return the index of the last ordinary map that was looked up with
-   linemap_lookup.  */
-inline unsigned int &
-LINEMAPS_ORDINARY_CACHE (const line_maps *set)
-{
-  return LINEMAPS_CACHE (set, false);
-}
-
 /* Returns a pointer to the last ordinary map used in the line table
    SET.  */
 inline line_map_ordinary *
@@ -1016,14 +1000,6 @@ LINEMAPS_MACRO_USED (const line_maps *set)
   return LINEMAPS_USED (set, true);
 }
 
-/* Return the index of the last macro map that was looked up with
-   linemap_lookup.  */
-inline unsigned int &
-LINEMAPS_MACRO_CACHE (const line_maps *set)
-{
-  return LINEMAPS_CACHE (set, true);
-}
-
 /* Returns the last macro map used in the line table SET.  */
 inline line_map_macro *
 LINEMAPS_LAST_MACRO_MAP (const line_maps *set)
diff --git a/libcpp/init.cc b/libcpp/init.cc
index 9a20f8d8176..b97d7a7b00e 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -788,7 +788,7 @@ read_original_filename (cpp_reader *pfile)
 	      penult[1].reason = penult[0].reason;
 	      penult[0] = penult[1];
 	      pfile->line_table->info_ordinary.used--;
-	      pfile->line_table->info_ordinary.cache = 0;
+	      pfile->line_table->info_ordinary.m_cache = 0;
 	    }
 
 	  return true;
diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc
index 5b67a70429f..385d54c53b7 100644
--- a/libcpp/line-map.cc
+++ b/libcpp/line-map.cc
@@ -638,7 +638,7 @@ linemap_add (line_maps *set, enum lc_reason reason,
   map->sysp = sysp;
   map->to_file = to_file;
   map->to_line = to_line;
-  LINEMAPS_ORDINARY_CACHE (set) = LINEMAPS_ORDINARY_USED (set) - 1;
+  set->info_ordinary.m_cache = LINEMAPS_ORDINARY_USED (set) - 1;
   /* Do not store range_bits here.  That's readjusted in
      linemap_line_start.  */
   map->m_range_bits = map->m_column_and_range_bits = 0;
@@ -786,7 +786,7 @@ linemap_enter_macro (class line_maps *set, struct cpp_hashnode *macro_node,
   memset (MACRO_MAP_LOCATIONS (map), 0,
 	  2 * num_tokens * sizeof (location_t));
 
-  LINEMAPS_MACRO_CACHE (set) = LINEMAPS_MACRO_USED (set) - 1;
+  set->info_macro.m_cache = LINEMAPS_MACRO_USED (set) - 1;
 
   return map;
 }
@@ -1116,7 +1116,7 @@ linemap_ordinary_map_lookup (const line_maps *set, location_t line)
   if (set ==  NULL || line < RESERVED_LOCATION_COUNT)
     return NULL;
 
-  unsigned mn = LINEMAPS_ORDINARY_CACHE (set);
+  unsigned mn = set->info_ordinary.m_cache;
   unsigned mx = LINEMAPS_ORDINARY_USED (set);
 
   const line_map_ordinary *cached = LINEMAPS_ORDINARY_MAP_AT (set, mn);
@@ -1141,7 +1141,7 @@ linemap_ordinary_map_lookup (const line_maps *set, location_t line)
 	mn = md;
     }
 
-  LINEMAPS_ORDINARY_CACHE (set) = mn;
+  set->info_ordinary.m_cache = mn;
   const line_map_ordinary *result = LINEMAPS_ORDINARY_MAP_AT (set, mn);
   linemap_assert (line >= MAP_START_LOCATION (result));
   return result;
@@ -1173,7 +1173,7 @@ linemap_macro_map_lookup (const line_maps *set, location_t line)
 unsigned
 linemap_lookup_macro_index (const line_maps *set, location_t line)
 {
-  unsigned mn = LINEMAPS_MACRO_CACHE (set);
+  unsigned mn = set->info_macro.m_cache;
   unsigned mx = LINEMAPS_MACRO_USED (set);
   const struct line_map_macro *cached = LINEMAPS_MACRO_MAP_AT (set, mn);
 
@@ -1195,7 +1195,7 @@ linemap_lookup_macro_index (const line_maps *set, location_t line)
 	mx = md;
     }
 
-  LINEMAPS_MACRO_CACHE (set) = mx;
+  set->info_macro.m_cache = mx;
   return mx;
 }
 
-- 
2.26.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-08 22:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-08 22:59 [pushed] libcpp: eliminate LINEMAPS_{,ORDINARY_,MACRO_}CACHE David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).