public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] stringpool clean
@ 2017-06-30 17:05 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2017-06-30 17:05 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 768 bytes --]

The string pool provides 'empty_string', a zero-length string.  But we 
only use it in 3 places, preferring the more obvious "" elsewhere. 
These days we have linkers that can do string table merging, so any size 
optimimization empty_string might have bought us is long gone.  So 
nuking empty_string.

Then the ggc_string allocator decides to use  ggc_internal_cleared_alloc 
before replacing the just-cleared contents with the string being 
allocated.  So let's just call ggc_alloc_atomic.

Finally, there's some curious optimization for strings of one digit.  I 
fail to see the point of that, so also nuked.

I did discover that the dwarf machinery likes creating zero length 
strings, so I kept that optimization.

applied as obvious.

nathan
-- 
Nathan Sidwell

[-- Attachment #2: string-clean.diff --]
[-- Type: text/x-patch, Size: 3194 bytes --]

2017-06-30  Nathan Sidwell  <nathan@acm.org>

	* ggc.h (empty_string): Delete.
	* cfgexpand.c (expand_asm_stmt): Use plain "".
	* optabs.c (expand_asm_memory_barrier): Likewise.
	* stringpool.c (empty_string): Delete.
	(digit_vector, digit_string): Delete.
	(ggc_alloc_string): Use plain "", don't optimize single digit
	strings.  Use ggc_alloc_atomic.

Index: cfgexpand.c
===================================================================
--- cfgexpand.c	(revision 249835)
+++ cfgexpand.c	(working copy)
@@ -3165,7 +3165,7 @@ expand_asm_stmt (gasm *stmt)
   rtx body = gen_rtx_ASM_OPERANDS ((noutputs == 0 ? VOIDmode
 				    : GET_MODE (output_rvec[0])),
 				   ggc_strdup (gimple_asm_string (stmt)),
-				   empty_string, 0, argvec, constraintvec,
+				   "", 0, argvec, constraintvec,
 				   labelvec, locus);
   MEM_VOLATILE_P (body) = gimple_asm_volatile_p (stmt);
 
Index: ggc.h
===================================================================
--- ggc.h	(revision 249848)
+++ ggc.h	(working copy)
@@ -24,9 +24,6 @@ along with GCC; see the file COPYING3.
 /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with
    an external gc library that might be linked in.  */
 
-/* Constants for general use.  */
-extern const char empty_string[];	/* empty string */
-
 /* Internal functions and data structures used by the GTY
    machinery, including the generated gt*.[hc] files.  */
 
Index: optabs.c
===================================================================
--- optabs.c	(revision 249835)
+++ optabs.c	(working copy)
@@ -6278,7 +6278,7 @@ expand_asm_memory_barrier (void)
 {
   rtx asm_op, clob;
 
-  asm_op = gen_rtx_ASM_OPERANDS (VOIDmode, empty_string, empty_string, 0,
+  asm_op = gen_rtx_ASM_OPERANDS (VOIDmode, "", "", 0,
 				 rtvec_alloc (0), rtvec_alloc (0),
 				 rtvec_alloc (0), UNKNOWN_LOCATION);
   MEM_VOLATILE_P (asm_op) = 1;
Index: stringpool.c
===================================================================
--- stringpool.c	(revision 249835)
+++ stringpool.c	(working copy)
@@ -30,18 +30,6 @@ along with GCC; see the file COPYING3.
 #include "coretypes.h"
 #include "tree.h"
 
-/* The "" allocated string.  */
-const char empty_string[] = "";
-
-/* Character strings, each containing a single decimal digit.
-   Written this way to save space.  */
-static const char digit_vector[] = {
-  '0', 0, '1', 0, '2', 0, '3', 0, '4', 0,
-  '5', 0, '6', 0, '7', 0, '8', 0, '9', 0
-};
-
-#define digit_string(d) (digit_vector + ((d) * 2))
-
 struct ht *ident_hash;
 
 static hashnode alloc_node (cpp_hash_table *);
@@ -82,19 +70,16 @@ alloc_node (cpp_hash_table *table ATTRIB
 const char *
 ggc_alloc_string (const char *contents, int length MEM_STAT_DECL)
 {
-  char *result;
-
   if (length == -1)
     length = strlen (contents);
 
-  if (length == 0)
-    return empty_string;
-  if (length == 1 && ISDIGIT (contents[0]))
-    return digit_string (contents[0] - '0');
+  if (!length)
+    return "";
 
-  result = (char *) ggc_internal_cleared_alloc (length + 1 PASS_MEM_STAT);
+  char *result = (char *) ggc_alloc_atomic (length + 1);
   memcpy (result, contents, length);
   result[length] = '\0';
+
   return (const char *) result;
 }
 

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

only message in thread, other threads:[~2017-06-30 17:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-30 17:05 [PATCH] stringpool clean Nathan Sidwell

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).