Commit 1e013d2e by Neil Booth Committed by Neil Booth

cpphash.h (struct cpp_pool): Remove locks and locked.

	* 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
parent 0c055e34
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> 2001-09-26 DJ Delorie <dj@redhat.com>
* c-typeck.c (digest_init): Check for sizeless arrays. * c-typeck.c (digest_init): Check for sizeless arrays.
......
...@@ -66,10 +66,9 @@ struct cpp_chunk ...@@ -66,10 +66,9 @@ struct cpp_chunk
typedef struct cpp_pool cpp_pool; typedef struct cpp_pool cpp_pool;
struct cpp_pool struct cpp_pool
{ {
struct cpp_chunk *cur, *locked, *first; struct cpp_chunk *cur, *first;
unsigned char *pos; /* Current position. */ unsigned char *pos; /* Current position. */
unsigned int align; unsigned int align;
unsigned int locks;
}; };
/* A generic memory buffer. */ /* A generic memory buffer. */
...@@ -134,6 +133,10 @@ struct cpp_context ...@@ -134,6 +133,10 @@ struct cpp_context
union utoken first; union utoken first;
union utoken last; 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. */ /* For a macro context, these are the macro and its arguments. */
cpp_macro *macro; cpp_macro *macro;
...@@ -267,7 +270,6 @@ struct cpp_reader ...@@ -267,7 +270,6 @@ struct cpp_reader
cpp_pool ident_pool; /* For all identifiers, and permanent cpp_pool ident_pool; /* For all identifiers, and permanent
numbers and strings. */ numbers and strings. */
cpp_pool macro_pool; /* For macro definitions. Permanent. */ cpp_pool macro_pool; /* For macro definitions. Permanent. */
cpp_pool argument_pool; /* For macro arguments. Temporary. */
/* Memory buffers. */ /* Memory buffers. */
_cpp_buff *free_buffs; _cpp_buff *free_buffs;
...@@ -436,8 +438,6 @@ extern unsigned char *_cpp_pool_reserve PARAMS ((cpp_pool *, unsigned int)); ...@@ -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_pool_alloc PARAMS ((cpp_pool *, unsigned int));
extern unsigned char *_cpp_next_chunk PARAMS ((cpp_pool *, unsigned int, extern unsigned char *_cpp_next_chunk PARAMS ((cpp_pool *, unsigned int,
unsigned char **)); unsigned char **));
extern void _cpp_lock_pool PARAMS ((cpp_pool *));
extern void _cpp_unlock_pool PARAMS ((cpp_pool *));
/* In cppinit.c. */ /* In cppinit.c. */
extern bool _cpp_push_next_buffer PARAMS ((cpp_reader *)); extern bool _cpp_push_next_buffer PARAMS ((cpp_reader *));
......
...@@ -530,9 +530,6 @@ cpp_create_reader (table, lang) ...@@ -530,9 +530,6 @@ cpp_create_reader (table, lang)
/* Identifier pool initially 8K. Unaligned, permanent pool. */ /* Identifier pool initially 8K. Unaligned, permanent pool. */
_cpp_init_pool (&pfile->ident_pool, 8 * 1024, 1, 0); _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. */ /* Macro pool initially 8K. Aligned, permanent pool. */
_cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0); _cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0);
...@@ -590,7 +587,6 @@ cpp_destroy (pfile) ...@@ -590,7 +587,6 @@ cpp_destroy (pfile)
_cpp_free_pool (&pfile->ident_pool); _cpp_free_pool (&pfile->ident_pool);
_cpp_free_pool (&pfile->macro_pool); _cpp_free_pool (&pfile->macro_pool);
_cpp_free_pool (&pfile->argument_pool);
_cpp_free_buff (pfile->free_buffs); _cpp_free_buff (pfile->free_buffs);
for (run = &pfile->base_run; run; run = runn) for (run = &pfile->base_run; run; run = runn)
......
...@@ -105,7 +105,7 @@ static int maybe_read_ucs PARAMS ((cpp_reader *, const unsigned char **, ...@@ -105,7 +105,7 @@ static int maybe_read_ucs PARAMS ((cpp_reader *, const unsigned char **,
static tokenrun *next_tokenrun PARAMS ((tokenrun *)); static tokenrun *next_tokenrun PARAMS ((tokenrun *));
static cpp_chunk *new_chunk PARAMS ((unsigned int)); 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 unsigned int hex_digit_value PARAMS ((unsigned int));
static _cpp_buff *new_buff 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) ...@@ -2115,7 +2115,16 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen)
return result; 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 struct dummy
{ {
...@@ -2138,8 +2147,8 @@ new_buff (len) ...@@ -2138,8 +2147,8 @@ new_buff (len)
_cpp_buff *result; _cpp_buff *result;
char *base; char *base;
if (len < 4000) if (len < MIN_BUFF_SIZE)
len = 4000; len = MIN_BUFF_SIZE;
len = CPP_ALIGN (len, DEFAULT_ALIGNMENT); len = CPP_ALIGN (len, DEFAULT_ALIGNMENT);
base = xmalloc (len + sizeof (_cpp_buff)); base = xmalloc (len + sizeof (_cpp_buff));
...@@ -2175,10 +2184,15 @@ _cpp_get_buff (pfile, min_size) ...@@ -2175,10 +2184,15 @@ _cpp_get_buff (pfile, min_size)
for (p = &pfile->free_buffs;; p = &(*p)->next) 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); return new_buff (min_size);
result = (*p)->next; result = *p;
if ((unsigned int) (result->limit - result->base) > min_size) 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; break;
} }
...@@ -2197,7 +2211,7 @@ _cpp_extend_buff (pfile, buff, min_extra) ...@@ -2197,7 +2211,7 @@ _cpp_extend_buff (pfile, buff, min_extra)
_cpp_buff *buff; _cpp_buff *buff;
unsigned int min_extra; 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); buff->next = _cpp_get_buff (pfile, size);
memcpy (buff->next->base, buff->cur, buff->limit - buff->cur); memcpy (buff->next->base, buff->cur, buff->limit - buff->cur);
...@@ -2219,16 +2233,14 @@ _cpp_free_buff (buff) ...@@ -2219,16 +2233,14 @@ _cpp_free_buff (buff)
} }
static int static int
chunk_suitable (pool, chunk, size) chunk_suitable (chunk, size)
cpp_pool *pool;
cpp_chunk *chunk; cpp_chunk *chunk;
unsigned int size; unsigned int size;
{ {
/* Being at least twice SIZE means we can use memcpy in /* Being at least twice SIZE means we can use memcpy in
_cpp_next_chunk rather than memmove. Besides, it's a good idea _cpp_next_chunk rather than memmove. Besides, it's a good idea
anyway. */ anyway. */
return (chunk && pool->locked != chunk return (chunk && (unsigned int) (chunk->limit - chunk->base) >= size * 2);
&& (unsigned int) (chunk->limit - chunk->base) >= size * 2);
} }
/* Returns the end of the new pool. PTR points to a char in the old /* 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) ...@@ -2243,7 +2255,7 @@ _cpp_next_chunk (pool, len, ptr)
/* LEN is the minimum size we want in the new pool. */ /* LEN is the minimum size we want in the new pool. */
len += POOL_ROOM (pool); len += POOL_ROOM (pool);
if (! chunk_suitable (pool, chunk, len)) if (! chunk_suitable (chunk, len))
{ {
chunk = new_chunk (POOL_SIZE (pool) * 2 + len); chunk = new_chunk (POOL_SIZE (pool) * 2 + len);
...@@ -2294,29 +2306,11 @@ _cpp_init_pool (pool, size, align, temp) ...@@ -2294,29 +2306,11 @@ _cpp_init_pool (pool, size, align, temp)
pool->align = align; pool->align = align;
pool->first = new_chunk (size); pool->first = new_chunk (size);
pool->cur = pool->first; pool->cur = pool->first;
pool->locked = 0;
pool->locks = 0;
if (temp) if (temp)
pool->cur->next = pool->cur; pool->cur->next = pool->cur;
} }
void 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_free_pool (pool)
cpp_pool *pool; cpp_pool *pool;
{ {
......
...@@ -54,14 +54,13 @@ struct macro_arg ...@@ -54,14 +54,13 @@ struct macro_arg
/* Macro expansion. */ /* 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 int enter_macro_context PARAMS ((cpp_reader *, cpp_hashnode *));
static const cpp_token *builtin_macro PARAMS ((cpp_reader *, cpp_hashnode *)); static const cpp_token *builtin_macro PARAMS ((cpp_reader *, cpp_hashnode *));
static void push_token_context static void push_token_context
PARAMS ((cpp_reader *, cpp_macro *, const cpp_token *, unsigned int)); PARAMS ((cpp_reader *, cpp_macro *, const cpp_token *, unsigned int));
static void push_ptoken_context 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_buff *collect_args PARAMS ((cpp_reader *, const cpp_hashnode *));
static cpp_context *next_context PARAMS ((cpp_reader *)); static cpp_context *next_context PARAMS ((cpp_reader *));
static const cpp_token *padding_token static const cpp_token *padding_token
...@@ -217,20 +216,6 @@ builtin_macro (pfile, node) ...@@ -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 /* Adds backslashes before all backslashes and double quotes appearing
in strings. Non-printable characters are converted to octal. */ in strings. Non-printable characters are converted to octal. */
static U_CHAR * static U_CHAR *
...@@ -685,15 +670,8 @@ enter_macro_context (pfile, node) ...@@ -685,15 +670,8 @@ enter_macro_context (pfile, node)
{ {
cpp_macro *macro = node->value.macro; cpp_macro *macro = node->value.macro;
if (!pfile->context->prev)
lock_pools (pfile);
if (macro->fun_like && !funlike_invocation_p (pfile, node)) 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. */ /* Disable the macro within its expansion. */
macro->disabled = 1; macro->disabled = 1;
...@@ -718,12 +696,12 @@ replace_args (pfile, macro, args) ...@@ -718,12 +696,12 @@ replace_args (pfile, macro, args)
const cpp_token *src, *limit; const cpp_token *src, *limit;
const cpp_token **dest, **first; const cpp_token **dest, **first;
macro_arg *arg; macro_arg *arg;
_cpp_buff *buff;
/* First, fully macro-expand arguments, calculating the number of /* First, fully macro-expand arguments, calculating the number of
tokens in the final expansion as we go. This ensures that the tokens in the final expansion as we go. The ordering of the if
possible recursive use of argument_pool is fine. The ordering of statements below is subtle; we must handle stringification before
the if statements below is subtle; we must handle stringification pasting. */
before pasting. */
total = macro->count; total = macro->count;
limit = macro->expansion + macro->count; limit = macro->expansion + macro->count;
...@@ -755,8 +733,8 @@ replace_args (pfile, macro, args) ...@@ -755,8 +733,8 @@ replace_args (pfile, macro, args)
/* Now allocate space for the expansion, copy the tokens and replace /* Now allocate space for the expansion, copy the tokens and replace
the arguments. */ the arguments. */
first = (const cpp_token **) _cpp_pool_alloc (&pfile->argument_pool, buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *));
total * sizeof (cpp_token *)); first = (const cpp_token **) buff->base;
dest = first; dest = first;
for (src = macro->expansion; src < limit; src++) for (src = macro->expansion; src < limit; src++)
...@@ -841,7 +819,7 @@ replace_args (pfile, macro, args) ...@@ -841,7 +819,7 @@ replace_args (pfile, macro, args)
if (args[i].expanded) if (args[i].expanded)
free (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. */ /* Return a special padding token, with padding inherited from SOURCE. */
...@@ -879,9 +857,10 @@ next_context (pfile) ...@@ -879,9 +857,10 @@ next_context (pfile)
/* Push a list of pointers to tokens. */ /* Push a list of pointers to tokens. */
static void static void
push_ptoken_context (pfile, macro, first, count) push_ptoken_context (pfile, macro, buff, first, count)
cpp_reader *pfile; cpp_reader *pfile;
cpp_macro *macro; cpp_macro *macro;
_cpp_buff *buff;
const cpp_token **first; const cpp_token **first;
unsigned int count; unsigned int count;
{ {
...@@ -889,6 +868,7 @@ push_ptoken_context (pfile, macro, first, count) ...@@ -889,6 +868,7 @@ push_ptoken_context (pfile, macro, first, count)
context->direct_p = false; context->direct_p = false;
context->macro = macro; context->macro = macro;
context->buff = buff;
context->first.ptoken = first; context->first.ptoken = first;
context->last.ptoken = first + count; context->last.ptoken = first + count;
} }
...@@ -905,6 +885,7 @@ push_token_context (pfile, macro, first, count) ...@@ -905,6 +885,7 @@ push_token_context (pfile, macro, first, count)
context->direct_p = true; context->direct_p = true;
context->macro = macro; context->macro = macro;
context->buff = NULL;
context->first.token = first; context->first.token = first;
context->last.token = first + count; context->last.token = first + count;
} }
...@@ -924,7 +905,7 @@ expand_arg (pfile, arg) ...@@ -924,7 +905,7 @@ expand_arg (pfile, arg)
arg->expanded = (const cpp_token **) arg->expanded = (const cpp_token **)
xmalloc (capacity * sizeof (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 (;;) for (;;)
{ {
const cpp_token *token; const cpp_token *token;
...@@ -944,22 +925,23 @@ expand_arg (pfile, arg) ...@@ -944,22 +925,23 @@ expand_arg (pfile, arg)
arg->expanded[arg->expanded_count++] = token; arg->expanded[arg->expanded_count++] = token;
} }
/* Avoid the unlock_pools test of _cpp_pop_context. Change this to _cpp_pop_context (pfile);
call _cpp_pop_context once we remove pool locking. */
pfile->context = pfile->context->prev;
} }
void void
_cpp_pop_context (pfile) _cpp_pop_context (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_context *context = pfile->context;
/* Re-enable a macro when leaving its expansion. */ /* Re-enable a macro when leaving its expansion. */
if (pfile->context->macro) if (context->macro)
pfile->context->macro->disabled = 0; context->macro->disabled = 0;
if (context->buff)
_cpp_release_buff (pfile, context->buff);
pfile->context = pfile->context->prev; pfile->context = context->prev;
if (!pfile->context->prev && !pfile->state.parsing_args)
unlock_pools (pfile);
} }
/* Eternal routine to get a token. Also used nearly everywhere /* Eternal routine to get a token. Also used nearly everywhere
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment