]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cpphash.h (struct cpp_pool): Remove locks and locked.
authorNeil Booth <neil@daikokuya.demon.co.uk>
Wed, 26 Sep 2001 21:44:35 +0000 (21:44 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Wed, 26 Sep 2001 21:44:35 +0000 (21:44 +0000)
* cpphash.h (struct cpp_pool): Remove locks and locked.
(struct cpp_context): Add member buff.
(struct cpp_reader): Remove member argument_pool.
(_cpp_lock_pool, _cpp_unlock_pool): Remove.
* cppinit.c (cpp_create_reader, cpp_destroy): Argument_pool is dead.
* cpplex.c (chunk_suitable): Remove pool argument.
(MIN_BUFF_SIZE, BUFF_SIZE_UPPER_BOUND, EXTENDED_BUFF_SIZE): New.
(new_buff, _cpp_extend_buff): Update.
(_cpp_get_buff): Fix silly pointer bug.  Be more selective about
which buffer is returned.
(_cpp_next_chunk, _cpp_init_pool): Pool locking removed.
(_cpp_lock_pool, _cpp_unlock_pool): Remove.
* cppmacro.c (lock_pools, unlock_pools): Remove.
(push_ptoken_context): Take a _cpp_buff.
(enter_macro_context): Pool locking removed.
(replace_args): Use a _cpp_buff for the replacement list with
arguments replaced.
(push_token_context): Clear buff.
(expand_arg): Use _cpp_pop_context.
(_cpp_pop_context): Free a context's buffer, if any.

From-SVN: r45833

gcc/ChangeLog
gcc/cpphash.h
gcc/cppinit.c
gcc/cpplex.c
gcc/cppmacro.c

index 0e5933ed2d803e66e85d3a88c2a162b957ae53df..aa135529bca08cf66204fdbcfe4ab3bdacb1c6fd 100644 (file)
@@ -1,3 +1,26 @@
+2001-09-26  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * cpphash.h (struct cpp_pool): Remove locks and locked.
+       (struct cpp_context): Add member buff.
+       (struct cpp_reader): Remove member argument_pool.
+       (_cpp_lock_pool, _cpp_unlock_pool): Remove.
+       * cppinit.c (cpp_create_reader, cpp_destroy): Argument_pool is dead.
+       * cpplex.c (chunk_suitable): Remove pool argument.
+       (MIN_BUFF_SIZE, BUFF_SIZE_UPPER_BOUND, EXTENDED_BUFF_SIZE): New.
+       (new_buff, _cpp_extend_buff): Update.
+       (_cpp_get_buff): Fix silly pointer bug.  Be more selective about
+       which buffer is returned.
+       (_cpp_next_chunk, _cpp_init_pool): Pool locking removed.
+       (_cpp_lock_pool, _cpp_unlock_pool): Remove.
+       * cppmacro.c (lock_pools, unlock_pools): Remove.
+       (push_ptoken_context): Take a _cpp_buff.
+       (enter_macro_context): Pool locking removed.
+       (replace_args): Use a _cpp_buff for the replacement list with
+       arguments replaced.
+       (push_token_context): Clear buff.
+       (expand_arg): Use _cpp_pop_context.
+       (_cpp_pop_context): Free a context's buffer, if any.
+
 2001-09-26  DJ Delorie  <dj@redhat.com>
 
        * c-typeck.c (digest_init): Check for sizeless arrays.
index ee5b03e624a8e3172213c2b42be2719304af04cc..58ae27f0e5ff2f851d7cfd082a7452aae51071fc 100644 (file)
@@ -66,10 +66,9 @@ struct cpp_chunk
 typedef struct cpp_pool cpp_pool;
 struct cpp_pool
 {
-  struct cpp_chunk *cur, *locked, *first;
+  struct cpp_chunk *cur, *first;
   unsigned char *pos;          /* Current position.  */
   unsigned int align;
-  unsigned int locks;
 };
 
 /* A generic memory buffer.  */
@@ -134,6 +133,10 @@ struct cpp_context
   union utoken first;
   union utoken last;
 
+  /* If non-NULL, a buffer used for storage related to this context.
+     When the context is popped, the buffer is freed.  */
+  _cpp_buff *buff;
+
   /* For a macro context, these are the macro and its arguments.  */
   cpp_macro *macro;
 
@@ -267,7 +270,6 @@ struct cpp_reader
   cpp_pool ident_pool;         /* For all identifiers, and permanent
                                   numbers and strings.  */
   cpp_pool macro_pool;         /* For macro definitions.  Permanent.  */
-  cpp_pool argument_pool;      /* For macro arguments.  Temporary.   */
 
   /* Memory buffers.  */
   _cpp_buff *free_buffs;
@@ -436,8 +438,6 @@ extern unsigned char *_cpp_pool_reserve PARAMS ((cpp_pool *, unsigned int));
 extern unsigned char *_cpp_pool_alloc  PARAMS ((cpp_pool *, unsigned int));
 extern unsigned char *_cpp_next_chunk  PARAMS ((cpp_pool *, unsigned int,
                                                 unsigned char **));
-extern void _cpp_lock_pool             PARAMS ((cpp_pool *));
-extern void _cpp_unlock_pool           PARAMS ((cpp_pool *));
 
 /* In cppinit.c.  */
 extern bool _cpp_push_next_buffer      PARAMS ((cpp_reader *));
index 53e1c68b8a60eebd9332466fbeee11fd2de13210..42decd106123b21413791a30eae2788521fd7b7f 100644 (file)
@@ -530,9 +530,6 @@ cpp_create_reader (table, lang)
   /* Identifier pool initially 8K.  Unaligned, permanent pool.  */
   _cpp_init_pool (&pfile->ident_pool, 8 * 1024, 1, 0);
 
-  /* Argument pool initially 8K.  Aligned, temporary pool.  */
-  _cpp_init_pool (&pfile->argument_pool, 8 * 1024, 0, 1);
-
   /* Macro pool initially 8K.  Aligned, permanent pool.  */
   _cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0);
 
@@ -590,7 +587,6 @@ cpp_destroy (pfile)
 
   _cpp_free_pool (&pfile->ident_pool);
   _cpp_free_pool (&pfile->macro_pool);
-  _cpp_free_pool (&pfile->argument_pool);
   _cpp_free_buff (pfile->free_buffs);
 
   for (run = &pfile->base_run; run; run = runn)
index 1ad608de5b21a5ec5c1185d774bf0c92d74ae631..b5e979b764a46b83973edf7ec9b319177a7f42b3 100644 (file)
@@ -105,7 +105,7 @@ static int maybe_read_ucs PARAMS ((cpp_reader *, const unsigned char **,
 static tokenrun *next_tokenrun PARAMS ((tokenrun *));
 
 static cpp_chunk *new_chunk PARAMS ((unsigned int));
-static int chunk_suitable PARAMS ((cpp_pool *, cpp_chunk *, unsigned int));
+static int chunk_suitable PARAMS ((cpp_chunk *, unsigned int));
 static unsigned int hex_digit_value PARAMS ((unsigned int));
 static _cpp_buff *new_buff PARAMS ((unsigned int));
 
@@ -2115,7 +2115,16 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen)
   return result;
 }
 
-/* Memory buffers.  */
+/* Memory buffers.  Changing these three constants can have a dramatic
+   effect on performance.  The values here are reasonable defaults,
+   but might be tuned.  If you adjust them, be sure to test across a
+   range of uses of cpplib, including heavy nested function-like macro
+   expansion.  Also check the change in peak memory usage (NJAMD is a
+   good tool for this).  */
+#define MIN_BUFF_SIZE 8000
+#define BUFF_SIZE_UPPER_BOUND(MIN_SIZE) (8000 + (MIN_SIZE) * 3 / 2)
+#define EXTENDED_BUFF_SIZE(BUFF, MIN_EXTRA) \
+       (MIN_EXTRA + ((BUFF)->limit - (BUFF)->cur) * 2)
 
 struct dummy
 {
@@ -2138,8 +2147,8 @@ new_buff (len)
   _cpp_buff *result;
   char *base;
 
-  if (len < 4000)
-    len = 4000;
+  if (len < MIN_BUFF_SIZE)
+    len = MIN_BUFF_SIZE;
   len = CPP_ALIGN (len, DEFAULT_ALIGNMENT);
 
   base = xmalloc (len + sizeof (_cpp_buff));
@@ -2175,10 +2184,15 @@ _cpp_get_buff (pfile, min_size)
 
   for (p = &pfile->free_buffs;; p = &(*p)->next)
     {
-      if (*p == NULL || (*p)->next == NULL)
+      unsigned int size;
+
+      if (*p == NULL)
        return new_buff (min_size);
-      result = (*p)->next;
-      if ((unsigned int) (result->limit - result->base) > min_size)
+      result = *p;
+      size = result->limit - result->base;
+      /* Return a buffer that's big enough, but don't waste one that's
+         way too big.  */
+      if (size >= min_size && size < BUFF_SIZE_UPPER_BOUND (min_size))
        break;
     }
 
@@ -2197,7 +2211,7 @@ _cpp_extend_buff (pfile, buff, min_extra)
      _cpp_buff *buff;
      unsigned int min_extra;
 {
-  unsigned int size = min_extra + (buff->limit - buff->cur) * 2;
+  unsigned int size = EXTENDED_BUFF_SIZE (buff, min_extra);
 
   buff->next = _cpp_get_buff (pfile, size);
   memcpy (buff->next->base, buff->cur, buff->limit - buff->cur);
@@ -2219,16 +2233,14 @@ _cpp_free_buff (buff)
 }
 
 static int
-chunk_suitable (pool, chunk, size)
-     cpp_pool *pool;
+chunk_suitable (chunk, size)
      cpp_chunk *chunk;
      unsigned int size;
 {
   /* Being at least twice SIZE means we can use memcpy in
      _cpp_next_chunk rather than memmove.  Besides, it's a good idea
      anyway.  */
-  return (chunk && pool->locked != chunk
-         && (unsigned int) (chunk->limit - chunk->base) >= size * 2);
+  return (chunk && (unsigned int) (chunk->limit - chunk->base) >= size * 2);
 }
 
 /* Returns the end of the new pool.  PTR points to a char in the old
@@ -2243,7 +2255,7 @@ _cpp_next_chunk (pool, len, ptr)
 
   /* LEN is the minimum size we want in the new pool.  */
   len += POOL_ROOM (pool);
-  if (! chunk_suitable (pool, chunk, len))
+  if (! chunk_suitable (chunk, len))
     {
       chunk = new_chunk (POOL_SIZE (pool) * 2 + len);
 
@@ -2294,28 +2306,10 @@ _cpp_init_pool (pool, size, align, temp)
   pool->align = align;
   pool->first = new_chunk (size);
   pool->cur = pool->first;
-  pool->locked = 0;
-  pool->locks = 0;
   if (temp)
     pool->cur->next = pool->cur;
 }
 
-void
-_cpp_lock_pool (pool)
-     cpp_pool *pool;
-{
-  if (pool->locks++ == 0)
-    pool->locked = pool->cur;
-}
-
-void
-_cpp_unlock_pool (pool)
-     cpp_pool *pool;
-{
-  if (--pool->locks == 0)
-    pool->locked = 0;
-}
-
 void
 _cpp_free_pool (pool)
      cpp_pool *pool;
index fd38c08c9ae3bfb5e6d2602585a00de0436c1a98..ad4cfedfaa845877f35223b77404aebc5687e213 100644 (file)
@@ -54,14 +54,13 @@ struct macro_arg
 
 /* Macro expansion.  */
 
-static void lock_pools PARAMS ((cpp_reader *));
-static void unlock_pools PARAMS ((cpp_reader *));
 static int enter_macro_context PARAMS ((cpp_reader *, cpp_hashnode *));
 static const cpp_token *builtin_macro PARAMS ((cpp_reader *, cpp_hashnode *));
 static void push_token_context
   PARAMS ((cpp_reader *, cpp_macro *, const cpp_token *, unsigned int));
 static void push_ptoken_context
-  PARAMS ((cpp_reader *, cpp_macro *, const cpp_token **, unsigned int));
+  PARAMS ((cpp_reader *, cpp_macro *, _cpp_buff *,
+          const cpp_token **, unsigned int));
 static _cpp_buff *collect_args PARAMS ((cpp_reader *, const cpp_hashnode *));
 static cpp_context *next_context PARAMS ((cpp_reader *));
 static const cpp_token *padding_token
@@ -217,20 +216,6 @@ builtin_macro (pfile, node)
     }
 }
 
-static void
-lock_pools (pfile)
-     cpp_reader *pfile;
-{
-  _cpp_lock_pool (&pfile->argument_pool);
-}
-
-static void
-unlock_pools (pfile)
-     cpp_reader *pfile;
-{
-  _cpp_unlock_pool (&pfile->argument_pool);
-}
-
 /* Adds backslashes before all backslashes and double quotes appearing
    in strings.  Non-printable characters are converted to octal.  */
 static U_CHAR *
@@ -685,15 +670,8 @@ enter_macro_context (pfile, node)
     {
       cpp_macro *macro = node->value.macro;
 
-      if (!pfile->context->prev)
-       lock_pools (pfile);
-
       if (macro->fun_like && !funlike_invocation_p (pfile, node))
-       {
-         if (!pfile->context->prev)
-           unlock_pools (pfile);
-         return 0;
-       }
+       return 0;
 
       /* Disable the macro within its expansion.  */
       macro->disabled = 1;
@@ -718,12 +696,12 @@ replace_args (pfile, macro, args)
   const cpp_token *src, *limit;
   const cpp_token **dest, **first;
   macro_arg *arg;
+  _cpp_buff *buff;
 
   /* First, fully macro-expand arguments, calculating the number of
-     tokens in the final expansion as we go.  This ensures that the
-     possible recursive use of argument_pool is fine.  The ordering of
-     the if statements below is subtle; we must handle stringification
-     before pasting.  */
+     tokens in the final expansion as we go.  The ordering of the if
+     statements below is subtle; we must handle stringification before
+     pasting.  */
   total = macro->count;
   limit = macro->expansion + macro->count;
 
@@ -755,8 +733,8 @@ replace_args (pfile, macro, args)
 
   /* Now allocate space for the expansion, copy the tokens and replace
      the arguments.  */
-  first = (const cpp_token **) _cpp_pool_alloc (&pfile->argument_pool,
-                                               total * sizeof (cpp_token *));
+  buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *));
+  first = (const cpp_token **) buff->base;
   dest = first;
 
   for (src = macro->expansion; src < limit; src++)
@@ -841,7 +819,7 @@ replace_args (pfile, macro, args)
     if (args[i].expanded)
       free (args[i].expanded);
 
-  push_ptoken_context (pfile, macro, first, dest - first);
+  push_ptoken_context (pfile, macro, buff, first, dest - first);
 }
 
 /* Return a special padding token, with padding inherited from SOURCE.  */
@@ -879,9 +857,10 @@ next_context (pfile)
 
 /* Push a list of pointers to tokens.  */
 static void
-push_ptoken_context (pfile, macro, first, count)
+push_ptoken_context (pfile, macro, buff, first, count)
      cpp_reader *pfile;
      cpp_macro *macro;
+     _cpp_buff *buff;
      const cpp_token **first;
      unsigned int count;
 {
@@ -889,6 +868,7 @@ push_ptoken_context (pfile, macro, first, count)
 
   context->direct_p = false;
   context->macro = macro;
+  context->buff = buff;
   context->first.ptoken = first;
   context->last.ptoken = first + count;
 }
@@ -905,6 +885,7 @@ push_token_context (pfile, macro, first, count)
 
   context->direct_p = true;
   context->macro = macro;
+  context->buff = NULL;
   context->first.token = first;
   context->last.token = first + count;
 }
@@ -924,7 +905,7 @@ expand_arg (pfile, arg)
   arg->expanded = (const cpp_token **)
     xmalloc (capacity * sizeof (cpp_token *));
 
-  push_ptoken_context (pfile, NULL, arg->first, arg->count + 1);
+  push_ptoken_context (pfile, NULL, NULL, arg->first, arg->count + 1);
   for (;;)
     {
       const cpp_token *token;
@@ -944,22 +925,23 @@ expand_arg (pfile, arg)
       arg->expanded[arg->expanded_count++] = token;
     }
 
-  /* Avoid the unlock_pools test of _cpp_pop_context.  Change this to
-     call _cpp_pop_context once we remove pool locking.  */
-  pfile->context = pfile->context->prev;
+  _cpp_pop_context (pfile);
 }
 
 void
 _cpp_pop_context (pfile)
      cpp_reader *pfile;
 {
+  cpp_context *context = pfile->context;
+
   /* Re-enable a macro when leaving its expansion.  */
-  if (pfile->context->macro)
-    pfile->context->macro->disabled = 0;
+  if (context->macro)
+    context->macro->disabled = 0;
+
+  if (context->buff)
+    _cpp_release_buff (pfile, context->buff);
 
-  pfile->context = pfile->context->prev;
-  if (!pfile->context->prev && !pfile->state.parsing_args)
-    unlock_pools (pfile);
+  pfile->context = context->prev;
 }
 
 /* Eternal routine to get a token.  Also used nearly everywhere