This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Speed-up get_identifier("main") (take 2)
- From: Roger Sayle <roger at eyesopen dot com>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 7 Aug 2003 07:38:26 -0600 (MDT)
- Subject: [PATCH] Speed-up get_identifier("main") (take 2)
On Wed, 6 Aug 2003, Zack Weinberg wrote:
> I like the general idea. I'm wondering if it makes sense to make
> get_identifier itself be this macro; the definition of get_identifier
> is functionally identical to the macro, and it would avoid having to
> change most of the uses of get_identifier. However, it might hurt
> code size. Could you experiment, please?
Ok here's the patch I came up with. The warts this time are that we
have to ensure the arguments to get_identifier are free from
side-effects, otherwise the behaviour changes. I'm sure we could
do something clever to avoid re-evaluation, but I suspect it would
be either non-portable or defeat the purpose of getting strlen,
a constant string literal.
The text size of cc1 increases from 4241925 to 4243589 (1664 bytes),
the size of cc1plus increases from 5173765 to 5180021 (6256 bytes)
and the text size of jc1 increases from 4343280 to 4347504 (4224 bytes).
I think I can decrease these a bit by judicious use of temporary
variables in a few places.
I also like the proposed __builtin_constant_p solution. Unfortunately,
GCC doesn't currently use __builtin_constant_p during stage1 and I'd be
completely unable to implement the necessary configure checks myself.
The following patch has been tested on i686-pc-linux-gnu with a complete
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.
Ok for mainline?
2003-08-07 Roger Sayle <roger@eyesopen.com>
* tree.h (get_identifier): Convert to macro implemented using
get_identifier_with_length and strlen.
* stringpool.c (get_identifier): Delete function.
* objc/objc-act.c (encode_method_prototype): Fix get_identifier
with side-effecting argument.
(build_ivar_list_initializer): Likewise.
(encode_method_def): Likewise.
java/
* parse.y (single_type_import_declaration): Fix get_identifier
with side-effecting argument.
(maybe_make_nested_class_name): Likewise.
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.433
diff -c -3 -p -r1.433 tree.h
*** tree.h 5 Aug 2003 14:11:43 -0000 1.433
--- tree.h 7 Aug 2003 12:45:20 -0000
*************** extern tree make_tree_vec (int);
*** 2048,2054 ****
/* Return the (unique) IDENTIFIER_NODE node for a given name.
The name is supplied as a char *. */
! extern tree get_identifier (const char *);
/* Identical to get_identifier, except that the length is assumed
known. */
--- 2048,2055 ----
/* Return the (unique) IDENTIFIER_NODE node for a given name.
The name is supplied as a char *. */
! #define get_identifier(X) \
! get_identifier_with_length (X, (unsigned int) strlen (X))
/* Identical to get_identifier, except that the length is assumed
known. */
Index: stringpool.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stringpool.c,v
retrieving revision 1.21
diff -c -3 -p -r1.21 stringpool.c
*** stringpool.c 6 Jul 2003 12:35:55 -0000 1.21
--- stringpool.c 7 Aug 2003 12:45:20 -0000
*************** ggc_alloc_string (const char *contents,
*** 91,113 ****
return obstack_finish (&string_stack);
}
! /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
If an identifier with that name has previously been referred to,
the same node is returned this time. */
-
- tree
- get_identifier (const char *text)
- {
- hashnode ht_node = ht_lookup (ident_hash,
- (const unsigned char *) text,
- strlen (text), HT_ALLOC);
-
- /* ht_node can't be NULL here. */
- return HT_IDENT_TO_GCC_IDENT (ht_node);
- }
-
- /* Identical to get_identifier, except that the length is assumed
- known. */
tree
get_identifier_with_length (const char *text, unsigned int length)
--- 91,99 ----
return obstack_finish (&string_stack);
}
! /* Return an IDENTIFIER_NODE whose name is LENGTH characters of TEXT.
If an identifier with that name has previously been referred to,
the same node is returned this time. */
tree
get_identifier_with_length (const char *text, unsigned int length)
Index: objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.185
diff -c -3 -p -r1.185 objc-act.c
*** objc/objc-act.c 25 Jul 2003 10:27:42 -0000 1.185
--- objc/objc-act.c 7 Aug 2003 12:45:21 -0000
*************** encode_method_prototype (method_decl, fu
*** 2752,2757 ****
--- 2752,2758 ----
HOST_WIDE_INT max_parm_end = 0;
char buf[40];
tree result;
+ char *str;
/* ONEWAY and BYCOPY, for remote object are the only method qualifiers. */
encode_type_qualifiers (TREE_PURPOSE (TREE_TYPE (method_decl)));
*************** encode_method_prototype (method_decl, fu
*** 2806,2812 ****
}
obstack_1grow (&util_obstack, '\0');
! result = get_identifier (obstack_finish (&util_obstack));
obstack_free (&util_obstack, util_firstobj);
return result;
}
--- 2807,2814 ----
}
obstack_1grow (&util_obstack, '\0');
! str = obstack_finish (&util_obstack);
! result = get_identifier (str);
obstack_free (&util_obstack, util_firstobj);
return result;
}
*************** build_ivar_list_initializer (type, field
*** 3732,3737 ****
--- 3734,3740 ----
tree field_decl;
{
tree initlist = NULL_TREE;
+ char *str;
do
{
*************** build_ivar_list_initializer (type, field
*** 3754,3764 ****
/* Null terminate string. */
obstack_1grow (&util_obstack, 0);
ivar
= tree_cons
(NULL_TREE,
! add_objc_string (get_identifier (obstack_finish (&util_obstack)),
! meth_var_types),
ivar);
obstack_free (&util_obstack, util_firstobj);
--- 3757,3767 ----
/* Null terminate string. */
obstack_1grow (&util_obstack, 0);
+ str = obstack_finish (&util_obstack);
ivar
= tree_cons
(NULL_TREE,
! add_objc_string (get_identifier (str), meth_var_types),
ivar);
obstack_free (&util_obstack, util_firstobj);
*************** encode_method_def (func_decl)
*** 7333,7338 ****
--- 7336,7342 ----
HOST_WIDE_INT max_parm_end = 0;
char buffer[40];
tree result;
+ char *str;
/* Return type. */
encode_type (TREE_TYPE (TREE_TYPE (func_decl)),
*************** encode_method_def (func_decl)
*** 7376,7382 ****
/* Null terminate string. */
obstack_1grow (&util_obstack, 0);
! result = get_identifier (obstack_finish (&util_obstack));
obstack_free (&util_obstack, util_firstobj);
return result;
}
--- 7380,7387 ----
/* Null terminate string. */
obstack_1grow (&util_obstack, 0);
! str = obstack_finish (&util_obstack);
! result = get_identifier (str);
obstack_free (&util_obstack, util_firstobj);
return result;
}
Index: java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.438
diff -c -3 -p -r1.438 parse.y
*** java/parse.y 5 Aug 2003 18:47:22 -0000 1.438
--- java/parse.y 7 Aug 2003 12:45:24 -0000
*************** single_type_import_declaration:
*** 734,740 ****
break;
last--;
}
! last_name = get_identifier (++last);
if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
{
tree err = find_name_in_single_imports (last_name);
--- 734,741 ----
break;
last--;
}
! last++;
! last_name = get_identifier (last);
if (IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name))
{
tree err = find_name_in_single_imports (last_name);
*************** static tree
*** 3681,3686 ****
--- 3682,3688 ----
maybe_make_nested_class_name (tree name)
{
tree id = NULL_TREE;
+ char *str;
if (CPC_INNER_P ())
{
*************** maybe_make_nested_class_name (tree name)
*** 3701,3707 ****
obstack_grow0 (&temporary_obstack,
IDENTIFIER_POINTER (name),
IDENTIFIER_LENGTH (name));
! id = get_identifier (obstack_finish (&temporary_obstack));
if (ctxp->package)
QUALIFIED_P (id) = 1;
}
--- 3703,3710 ----
obstack_grow0 (&temporary_obstack,
IDENTIFIER_POINTER (name),
IDENTIFIER_LENGTH (name));
! str = obstack_finish (&temporary_obstack);
! id = get_identifier (str);
if (ctxp->package)
QUALIFIED_P (id) = 1;
}
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833