This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Remove insert_default_attributes langhook.
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 3 Aug 2003 11:57:01 -0600 (MDT)
- Subject: [PATCH] Remove insert_default_attributes langhook.
This patch is the second part of my patch to remove the last few
functions from builtin-attrs.def. The first installment moved the
functionality to GCC builtins, this final installment cleans-up
all of the dead-code now that that insert_default_attributes is
no longer required.
This contains both of the clean-ups requested by Zack (the comment
describing DEF_FN_ATTR was actually already removed from the top of
builtin-attrs.def by the first patch) and Joseph Myers' suggested
removal of flag_noniso_default_format_attributes which is also
unused. But as you can see from the ChangeLog these were just the
tip of the iceberg of the fallout.
Whilst I appreciate Zack's concerns that there may be a nontrivial
start-up cost associated with GCC's builtins, predeclaring under
200 builtins is significantly more efficient than the code we've
just removed, which would do a sequential comparison against each
builtin in insert_default_attributes, which was called once for
every identifier declaration in a source file, which averages at
over 2000 declarations per compilation unit in a GCC bootstrap.
However, I do have plans to attempt to reduce the cost of building
predeclared builtins at start-up. The first and obvious step is to
time a "-fno-builtin" bootstrap of mainline to determine the cost/benefit
ratio of GCC's builtins. This can then form a baseline by which to
assess future builtins changes.
I'm pretty sure insert_default_attributes has no part in GCC's future.
Unless we have huge numbers of builtins to create at start-up, the
overhead of per-declaration processing (such as a second hash-table lookup
or even perfect hashing) on one of GCC's critical paths is just too
expensive. A better solution is to reduce the constant start-up
overhead, by using static trees or a scheme like PCH. This not only
helps "builtin functions", but also predeclared types, floating point
constants and all the other tree nodes that we create every cc1
invocation.
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-03 Roger Sayle <roger@eyesopen.com>
* c-common.c (flag_noniso_default_format_attributes): Delete.
(built_in_attribute): Don't define/undefine DEF_FN_ATTR.
(c_attrs_initialized): Delete.
(c_common_nodes_and_builtins): Don't test c_attrs_initialized,
always call c_init_attributes.
(c_init_attributes): Don't define/undefine DEF_FN_ATTR. Don't
set c_attrs_initialized when done.
(c_common_insert_default_attributes): Delete.
* c-common.h (flag_noniso_default_format_attributes): Delete.
(c_coomon_insert_default_attributes): Delete prototype.
* c-opts.c (set_std_c89, set_std_c99, set_std_cxx98): Dont set
flag_noniso_default_format_attributes.
* c-decl.c (c_insert_default_attributes): Delete.
* c-tree.h (c_insert_default_attributes): Delete prototype.
* attribs.c (decl_attributes): Don't call insert_default_attributes
langhook. Update function description comment.
* langhooks.h (lang_hooks): Remove insert_default_attributes field.
* langhooks-def.h (LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES): Delete.
* c-lang.c (LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES): Don't define.
* system.h: Poison LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES macro.
cp/
* decl.c (cxx_insert_default_attributes): Delete.
* cp-tree.h (cxx_insert_default_attributes): Don't prototype.
* cp-lang.c (LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES): Don't define.
objc/
* objc-lang.c (LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES): Don't define.
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.443
diff -c -3 -p -r1.443 c-common.c
*** c-common.c 3 Aug 2003 03:23:13 -0000 1.443
--- c-common.c 3 Aug 2003 13:58:15 -0000
*************** int flag_isoc99;
*** 372,382 ****
int flag_hosted = 1;
- /* Nonzero means add default format_arg attributes for functions not
- in ISO C. */
-
- int flag_noniso_default_format_attributes = 1;
-
/* Nonzero means warn when casting a function call to a type that does
not match the return type (e.g. (float)sqrt() or (anything*)malloc()
when there is no previous declaration of sqrt or malloc. */
--- 372,377 ----
*************** enum built_in_attribute
*** 2957,2976 ****
#define DEF_ATTR_INT(ENUM, VALUE) ENUM,
#define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
- #define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) /* No entry needed in enum. */
#include "builtin-attrs.def"
#undef DEF_ATTR_NULL_TREE
#undef DEF_ATTR_INT
#undef DEF_ATTR_IDENT
#undef DEF_ATTR_TREE_LIST
- #undef DEF_FN_ATTR
ATTR_LAST
};
static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
- static bool c_attrs_initialized = false;
-
static void c_init_attributes (void);
/* Build tree nodes and builtin functions common to both C and C++ language
--- 2952,2967 ----
*************** c_common_nodes_and_builtins (void)
*** 3348,3355 ****
#undef DEF_FUNCTION_TYPE_VAR_3
#undef DEF_POINTER_TYPE
! if (!c_attrs_initialized)
! c_init_attributes ();
#define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, \
BOTH_P, FALLBACK_P, NONANSI_P, ATTRS, IMPLICIT) \
--- 3339,3345 ----
#undef DEF_FUNCTION_TYPE_VAR_3
#undef DEF_POINTER_TYPE
! c_init_attributes ();
#define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, \
BOTH_P, FALLBACK_P, NONANSI_P, ATTRS, IMPLICIT) \
*************** c_init_attributes (void)
*** 4176,4196 ****
= tree_cons (built_in_attributes[(int) PURPOSE], \
built_in_attributes[(int) VALUE], \
built_in_attributes[(int) CHAIN]);
- #define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) /* No initialization needed. */
#include "builtin-attrs.def"
#undef DEF_ATTR_NULL_TREE
#undef DEF_ATTR_INT
#undef DEF_ATTR_IDENT
#undef DEF_ATTR_TREE_LIST
- #undef DEF_FN_ATTR
- c_attrs_initialized = true;
- }
-
- /* Depending on the name of DECL, apply default attributes to it. */
-
- void
- c_common_insert_default_attributes (tree decl ATTRIBUTE_UNUSED)
- {
}
/* Output a -Wshadow warning MSGCODE about NAME, and give the location
--- 4166,4176 ----
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.199
diff -c -3 -p -r1.199 c-common.h
*** c-common.h 1 Aug 2003 18:41:39 -0000 1.199
--- c-common.h 3 Aug 2003 13:58:15 -0000
*************** extern int flag_isoc99;
*** 549,559 ****
extern int flag_hosted;
- /* Nonzero means add default format_arg attributes for functions not
- in ISO C. */
-
- extern int flag_noniso_default_format_attributes;
-
/* Nonzero means warn when casting a function call to a type that does
not match the return type (e.g. (float)sqrt() or (anything*)malloc()
when there is no previous declaration of sqrt or malloc. */
--- 549,554 ----
*************** extern void check_function_format (int *
*** 893,899 ****
extern void set_Wformat (int);
extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
- extern void c_common_insert_default_attributes (tree);
extern int c_common_handle_option (size_t code, const char *arg, int value);
extern bool c_common_missing_argument (const char *opt, size_t code);
extern tree c_common_type_for_mode (enum machine_mode, int);
--- 888,893 ----
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.84
diff -c -3 -p -r1.84 c-opts.c
*** c-opts.c 1 Aug 2003 14:04:02 -0000 1.84
--- c-opts.c 3 Aug 2003 13:58:16 -0000
*************** set_std_c89 (int c94, int iso)
*** 1459,1465 ****
flag_no_asm = iso;
flag_no_gnu_keywords = iso;
flag_no_nonansi_builtin = iso;
- flag_noniso_default_format_attributes = !iso;
flag_isoc94 = c94;
flag_isoc99 = 0;
flag_writable_strings = 0;
--- 1459,1464 ----
*************** set_std_c99 (int iso)
*** 1472,1478 ****
cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
flag_no_asm = iso;
flag_no_nonansi_builtin = iso;
- flag_noniso_default_format_attributes = !iso;
flag_iso = iso;
flag_isoc99 = 1;
flag_isoc94 = 1;
--- 1471,1476 ----
*************** set_std_cxx98 (int iso)
*** 1486,1492 ****
cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
flag_no_gnu_keywords = iso;
flag_no_nonansi_builtin = iso;
- flag_noniso_default_format_attributes = !iso;
flag_iso = iso;
}
--- 1484,1489 ----
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.426
diff -c -3 -p -r1.426 c-decl.c
*** c-decl.c 1 Aug 2003 18:41:39 -0000 1.426
--- c-decl.c 3 Aug 2003 13:58:17 -0000
*************** builtin_function (const char *name, tree
*** 2370,2386 ****
return decl;
}
-
- /* Apply default attributes to a function, if a system function with default
- attributes. */
-
- void
- c_insert_default_attributes (tree decl)
- {
- if (!TREE_PUBLIC (decl))
- return;
- c_common_insert_default_attributes (decl);
- }
/* Called when a declaration is seen that contains no names to declare.
If its type is a reference to a structure, union or enum inherited
--- 2370,2375 ----
Index: c-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-tree.h,v
retrieving revision 1.126
diff -c -3 -p -r1.126 c-tree.h
*** c-tree.h 29 Jul 2003 23:58:07 -0000 1.126
--- c-tree.h 3 Aug 2003 13:58:17 -0000
*************** extern void insert_block (tree);
*** 186,192 ****
extern void set_block (tree);
extern tree pushdecl (tree);
- extern void c_insert_default_attributes (tree);
extern void c_init_decl_processing (void);
extern void c_dup_lang_specific_decl (tree);
extern void c_print_identifier (FILE *, tree, int);
--- 186,191 ----
Index: attribs.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/attribs.c,v
retrieving revision 1.26
diff -c -3 -p -r1.26 attribs.c
*** attribs.c 15 Jun 2003 13:43:30 -0000 1.26
--- attribs.c 3 Aug 2003 13:58:17 -0000
*************** init_attributes (void)
*** 134,144 ****
information, in the form of a bitwise OR of flags in enum attribute_flags
from tree.h. Depending on these flags, some attributes may be
returned to be applied at a later stage (for example, to apply
! a decl attribute to the declaration rather than to its type). If
! ATTR_FLAG_BUILT_IN is not set and *NODE is a DECL, then also consider
! whether there might be some default attributes to apply to this DECL;
! if so, decl_attributes will be called recursively with those attributes
! and ATTR_FLAG_BUILT_IN set. */
tree
decl_attributes (tree *node, tree attributes, int flags)
--- 134,140 ----
information, in the form of a bitwise OR of flags in enum attribute_flags
from tree.h. Depending on these flags, some attributes may be
returned to be applied at a later stage (for example, to apply
! a decl attribute to the declaration rather than to its type). */
tree
decl_attributes (tree *node, tree attributes, int flags)
*************** decl_attributes (tree *node, tree attrib
*** 150,159 ****
init_attributes ();
(*targetm.insert_attributes) (*node, &attributes);
-
- if (DECL_P (*node) && TREE_CODE (*node) == FUNCTION_DECL
- && !(flags & (int) ATTR_FLAG_BUILT_IN))
- (*lang_hooks.insert_default_attributes) (*node);
for (a = attributes; a; a = TREE_CHAIN (a))
{
--- 146,151 ----
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.67
diff -c -3 -p -r1.67 langhooks.h
*** langhooks.h 31 Jul 2003 19:26:16 -0000 1.67
--- langhooks.h 3 Aug 2003 13:58:18 -0000
*************** struct lang_hooks
*** 268,277 ****
error_mark_node). */
tree (*truthvalue_conversion) (tree);
- /* Possibly apply default attributes to a function (represented by
- a FUNCTION_DECL). */
- void (*insert_default_attributes) (tree);
-
/* Hook called by safe_from_p for language-specific tree codes. It is
up to the language front-end to install a hook if it has any such
codes that safe_from_p needs to know about. Since same_from_p will
--- 268,273 ----
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.58
diff -c -3 -p -r1.58 langhooks-def.h
*** langhooks-def.h 31 Jul 2003 19:26:16 -0000 1.58
--- langhooks-def.h 3 Aug 2003 13:58:18 -0000
*************** extern tree lhd_tree_inlining_convert_pa
*** 97,103 ****
#define LANG_HOOKS_FINISH_INCOMPLETE_DECL lhd_do_nothing_t
#define LANG_HOOKS_UNSAFE_FOR_REEVAL lhd_unsafe_for_reeval
#define LANG_HOOKS_STATICP lhd_staticp
- #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES lhd_do_nothing_t
#define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL lhd_do_nothing_t
#define LANG_HOOKS_UNSAVE_EXPR_NOW lhd_unsave_expr_now
#define LANG_HOOKS_MAYBE_BUILD_CLEANUP lhd_return_null_tree
--- 97,102 ----
*************** extern int lhd_tree_dump_type_quals (tre
*** 256,262 ****
LANG_HOOKS_EXPAND_CONSTANT, \
LANG_HOOKS_EXPAND_EXPR, \
LANG_HOOKS_TRUTHVALUE_CONVERSION, \
- LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES, \
LANG_HOOKS_SAFE_FROM_P, \
LANG_HOOKS_FINISH_INCOMPLETE_DECL, \
LANG_HOOKS_UNSAFE_FOR_REEVAL, \
--- 255,260 ----
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.111
diff -c -3 -p -r1.111 c-lang.c
*** c-lang.c 31 Jul 2003 19:26:16 -0000 1.111
--- c-lang.c 3 Aug 2003 13:58:18 -0000
*************** enum c_language_kind c_language = clk_c;
*** 61,68 ****
#define LANG_HOOKS_PARSE_FILE c_common_parse_file
#undef LANG_HOOKS_TRUTHVALUE_CONVERSION
#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion
- #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES
- #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES c_insert_default_attributes
#undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
#define LANG_HOOKS_FINISH_INCOMPLETE_DECL c_finish_incomplete_decl
#undef LANG_HOOKS_UNSAFE_FOR_REEVAL
--- 61,66 ----
Index: system.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/system.h,v
retrieving revision 1.167
diff -c -3 -p -r1.167 system.h
*** system.h 1 Aug 2003 21:51:13 -0000 1.167
--- system.h 3 Aug 2003 13:58:18 -0000
*************** typedef char _Bool;
*** 614,620 ****
/* Hooks that are no longer used. */
#pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE \
! LANG_HOOKS_MARK_TREE
/* Libiberty macros that are no longer used in GCC. */
#undef ANSI_PROTOTYPES
--- 614,620 ----
/* Hooks that are no longer used. */
#pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE \
! LANG_HOOKS_MARK_TREE LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES
/* Libiberty macros that are no longer used in GCC. */
#undef ANSI_PROTOTYPES
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1108
diff -c -3 -p -r1.1108 decl.c
*** cp/decl.c 2 Aug 2003 18:52:14 -0000 1.1108
--- cp/decl.c 3 Aug 2003 13:58:22 -0000
*************** push_throw_library_fn (tree name, tree t
*** 6642,6660 ****
TREE_NOTHROW (fn) = 0;
return fn;
}
-
- /* Apply default attributes to a function, if a system function with default
- attributes. */
-
- void
- cxx_insert_default_attributes (tree decl)
- {
- if (!DECL_EXTERN_C_FUNCTION_P (decl))
- return;
- if (!TREE_PUBLIC (decl))
- return;
- c_common_insert_default_attributes (decl);
- }
/* When we call finish_struct for an anonymous union, we create
default copy constructors and such. But, an anonymous union
--- 6642,6647 ----
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.896
diff -c -3 -p -r1.896 cp-tree.h
*** cp/cp-tree.h 2 Aug 2003 11:01:37 -0000 1.896
--- cp/cp-tree.h 3 Aug 2003 13:58:23 -0000
*************** extern tree pushdecl (tree);
*** 3638,3644 ****
extern void cxx_init_decl_processing (void);
enum cp_tree_node_structure_enum cp_tree_node_structure
(union lang_tree_node *);
- extern void cxx_insert_default_attributes (tree);
extern bool cxx_mark_addressable (tree);
extern void cxx_push_function_context (struct function *);
extern void cxx_pop_function_context (struct function *);
--- 3638,3643 ----
Index: cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.58
diff -c -3 -p -r1.58 cp-lang.c
*** cp/cp-lang.c 30 Jul 2003 17:27:13 -0000 1.58
--- cp/cp-lang.c 3 Aug 2003 13:58:23 -0000
*************** static bool cp_var_mod_type_p (tree);
*** 77,84 ****
#define LANG_HOOKS_MAYBE_BUILD_CLEANUP cxx_maybe_build_cleanup
#undef LANG_HOOKS_TRUTHVALUE_CONVERSION
#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion
- #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES
- #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES cxx_insert_default_attributes
#undef LANG_HOOKS_UNSAFE_FOR_REEVAL
#define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
--- 77,82 ----
Index: objc/objc-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-lang.c,v
retrieving revision 1.36
diff -c -3 -p -r1.36 objc-lang.c
*** objc/objc-lang.c 17 Jul 2003 21:52:50 -0000 1.36
--- objc/objc-lang.c 3 Aug 2003 13:58:23 -0000
*************** enum c_language_kind c_language = clk_ob
*** 61,68 ****
#define LANG_HOOKS_MARK_ADDRESSABLE c_mark_addressable
#undef LANG_HOOKS_TRUTHVALUE_CONVERSION
#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion
- #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES
- #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES c_insert_default_attributes
#undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
#define LANG_HOOKS_FINISH_INCOMPLETE_DECL c_finish_incomplete_decl
#undef LANG_HOOKS_UNSAFE_FOR_REEVAL
--- 61,66 ----
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