builtin-attrs.def (ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST, [...]): New.

* builtin-attrs.def (ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST,
	ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST,
	ATTR_TMPURE_NORETURN_NOTHROW_LEAF_COLD_LIST): New.
	* builtins.def (abort, trap, unreachable): Declare cold.
	* calls.c (flags_from_decl_or_type): Lookup ECF_COLD.
	* tree-core.h (ECF_COLD): New.
	* tree.c (set_call_expr_flags): Handle ECF_COLD.
	(build_common_builtin_nodes): Mark unreachable and abort as cold.

	* class.c (build_vtbl_initializer): Mark dvirt_fn as cold.
	* decl.c (cxx_init_decl_processing, push_throw_library_fn): Likewise.
	(excpet.c): Mark terminate as cold.

	* gcc.dg/predict-14.c: Avoid cold function detection.
	* gcc.target/i386/umod-3.c: Likewise.

From-SVN: r249070
This commit is contained in:
Jan Hubicka 2017-06-09 20:36:50 +02:00 committed by Jan Hubicka
parent d225aa745d
commit cb59f689a3
13 changed files with 56 additions and 17 deletions

View File

@ -1,3 +1,14 @@
2017-06-09 Jan Hubicka <hubicka@ucw.cz>
* builtin-attrs.def (ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST,
ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST,
ATTR_TMPURE_NORETURN_NOTHROW_LEAF_COLD_LIST): New.
* builtins.def (abort, trap, unreachable): Declare cold.
* calls.c (flags_from_decl_or_type): Lookup ECF_COLD.
* tree-core.h (ECF_COLD): New.
* tree.c (set_call_expr_flags): Handle ECF_COLD.
(build_common_builtin_nodes): Mark unreachable and abort as cold.
2017-06-09 Jan Hubicka <hubicka@ucw.cz>
* predict.c (unlikely_executed_stmt_p): Cleanup.

View File

@ -136,6 +136,8 @@ DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN, \
ATTR_NULL, ATTR_NOTHROW_LIST)
DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LEAF_LIST, ATTR_NORETURN,\
ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST, ATTR_COLD,\
ATTR_NULL, ATTR_NORETURN_NOTHROW_LEAF_LIST)
DEF_ATTR_TREE_LIST (ATTR_RT_NOTHROW_LEAF_LIST, ATTR_RETURNS_TWICE,\
ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
DEF_ATTR_TREE_LIST (ATTR_COLD_NOTHROW_LEAF_LIST, ATTR_COLD,\
@ -144,6 +146,8 @@ DEF_ATTR_TREE_LIST (ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST, ATTR_COLD,\
ATTR_NULL, ATTR_NORETURN_NOTHROW_LEAF_LIST)
DEF_ATTR_TREE_LIST (ATTR_CONST_NORETURN_NOTHROW_LEAF_LIST, ATTR_CONST,\
ATTR_NULL, ATTR_NORETURN_NOTHROW_LEAF_LIST)
DEF_ATTR_TREE_LIST (ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST, ATTR_COLD,\
ATTR_NULL, ATTR_CONST_NORETURN_NOTHROW_LEAF_LIST)
DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC, \
ATTR_NULL, ATTR_NOTHROW_LIST)
DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LEAF_LIST, ATTR_MALLOC, \
@ -387,6 +391,9 @@ DEF_ATTR_TREE_LIST (ATTR_TMPURE_NOTHROW_LEAF_LIST,
ATTR_TM_TMPURE, ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
DEF_ATTR_TREE_LIST (ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST,
ATTR_TM_TMPURE, ATTR_NULL, ATTR_NORETURN_NOTHROW_LEAF_LIST)
DEF_ATTR_TREE_LIST (ATTR_TMPURE_NORETURN_NOTHROW_LEAF_COLD_LIST,
ATTR_COLD, ATTR_NULL,
ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
/* Construct a tree for a format_arg attribute. */
#define DEF_FORMAT_ARG_ATTRIBUTE(FA) \

View File

@ -775,7 +775,7 @@ DEF_GCC_BUILTIN (BUILT_IN_UMULL_OVERFLOW, "umull_overflow", BT_FN_BOOL_UL
DEF_GCC_BUILTIN (BUILT_IN_UMULLL_OVERFLOW, "umulll_overflow", BT_FN_BOOL_ULONGLONG_ULONGLONG_ULONGLONGPTR, ATTR_NOTHROW_NONNULL_LEAF_LIST)
/* Category: miscellaneous builtins. */
DEF_LIB_BUILTIN (BUILT_IN_ABORT, "abort", BT_FN_VOID, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_LIST)
DEF_LIB_BUILTIN (BUILT_IN_ABORT, "abort", BT_FN_VOID, ATTR_TMPURE_NORETURN_NOTHROW_LEAF_COLD_LIST)
DEF_LIB_BUILTIN (BUILT_IN_ABS, "abs", BT_FN_INT_INT, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_GCC_BUILTIN (BUILT_IN_AGGREGATE_INCOMING_ADDRESS, "aggregate_incoming_address", BT_FN_PTR_VAR, ATTR_LEAF_LIST)
DEF_EXT_LIB_BUILTIN (BUILT_IN_ALLOCA, "alloca", BT_FN_PTR_SIZE, ATTR_ALLOCA_SIZE_1_NOTHROW_LEAF_LIST)
@ -881,8 +881,8 @@ DEF_GCC_BUILTIN (BUILT_IN_SAVEREGS, "saveregs", BT_FN_PTR_VAR, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_SETJMP, "setjmp", BT_FN_INT_PTR, ATTR_RT_NOTHROW_LEAF_LIST)
DEF_EXT_LIB_BUILTIN (BUILT_IN_STRFMON, "strfmon", BT_FN_SSIZE_STRING_SIZE_CONST_STRING_VAR, ATTR_FORMAT_STRFMON_NOTHROW_3_4)
DEF_LIB_BUILTIN (BUILT_IN_STRFTIME, "strftime", BT_FN_SIZE_STRING_SIZE_CONST_STRING_CONST_TM_PTR, ATTR_FORMAT_STRFTIME_NOTHROW_3_0)
DEF_GCC_BUILTIN (BUILT_IN_TRAP, "trap", BT_FN_VOID, ATTR_NORETURN_NOTHROW_LEAF_LIST)
DEF_GCC_BUILTIN (BUILT_IN_UNREACHABLE, "unreachable", BT_FN_VOID, ATTR_CONST_NORETURN_NOTHROW_LEAF_LIST)
DEF_GCC_BUILTIN (BUILT_IN_TRAP, "trap", BT_FN_VOID, ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST)
DEF_GCC_BUILTIN (BUILT_IN_UNREACHABLE, "unreachable", BT_FN_VOID, ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST)
DEF_GCC_BUILTIN (BUILT_IN_UNWIND_INIT, "unwind_init", BT_FN_VOID, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_UPDATE_SETJMP_BUF, "update_setjmp_buf", BT_FN_VOID_PTR, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_VA_COPY, "va_copy", BT_FN_VOID_VALIST_REF_VALIST_ARG, ATTR_NOTHROW_LEAF_LIST)

View File

@ -821,6 +821,8 @@ flags_from_decl_or_type (const_tree exp)
flags |= ECF_NOVOPS;
if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp)))
flags |= ECF_LEAF;
if (lookup_attribute ("cold", DECL_ATTRIBUTES (exp)))
flags |= ECF_COLD;
if (TREE_NOTHROW (exp))
flags |= ECF_NOTHROW;

View File

@ -1,3 +1,9 @@
2017-06-09 Jan Hubicka <hubicka@ucw.cz>
* class.c (build_vtbl_initializer): Mark dvirt_fn as cold.
* decl.c (cxx_init_decl_processing, push_throw_library_fn): Likewise.
(excpet.c): Mark terminate as cold.
2017-06-08 Jakub Jelinek <jakub@redhat.com>
PR c/81006

View File

@ -9727,7 +9727,7 @@ build_vtbl_initializer (tree binfo,
dvirt_fn = push_library_fn
(name,
build_function_type_list (void_type_node, NULL_TREE),
NULL_TREE, ECF_NORETURN);
NULL_TREE, ECF_NORETURN | ECF_COLD);
}
fn = dvirt_fn;
if (!TARGET_VTABLE_USES_DESCRIPTORS)

View File

@ -4269,7 +4269,7 @@ cxx_init_decl_processing (void)
abort_fndecl
= build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
ECF_NORETURN | ECF_NOTHROW);
ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
/* Perform other language dependent initializations. */
init_class_processing ();
@ -4550,7 +4550,7 @@ push_void_library_fn (tree name, tree parmtypes, int ecf_flags)
tree
push_throw_library_fn (tree name, tree type)
{
tree fn = push_library_fn (name, type, NULL_TREE, ECF_NORETURN);
tree fn = push_library_fn (name, type, NULL_TREE, ECF_NORETURN | ECF_COLD);
return fn;
}

View File

@ -54,9 +54,10 @@ init_exception_processing (void)
push_namespace (std_identifier);
tmp = build_function_type_list (void_type_node, NULL_TREE);
terminate_fn = build_cp_library_fn_ptr ("terminate", tmp,
ECF_NOTHROW | ECF_NORETURN);
TREE_THIS_VOLATILE (terminate_fn) = 1;
TREE_NOTHROW (terminate_fn) = 1;
ECF_NOTHROW | ECF_NORETURN
| ECF_COLD);
gcc_checking_assert (TREE_THIS_VOLATILE (terminate_fn)
&& TREE_NOTHROW (terminate_fn));
pop_namespace ();
/* void __cxa_call_unexpected(void *); */

View File

@ -1,3 +1,8 @@
2017-06-09 Jan Hubicka <hubicka@ucw.cz>
* gcc.dg/predict-14.c: Avoid cold function detection.
* gcc.target/i386/umod-3.c: Likewise.
2017-06-09 Tamar Christina <tamar.christina@arm.com>
* gcc.target/aarch64/lrint-matherr.h: New.

View File

@ -1,16 +1,18 @@
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
void test(void) __attribute__ ((noreturn));
int main(int argc, char **argv)
{
switch (argc)
{
case 1:
__builtin_abort();
test();
case 4:
__builtin_abort();
test();
default:
__builtin_abort();
test();
}
return 10;

View File

@ -1,7 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-O2 -mtune=atom" } */
extern void abort (void);
extern void exit (int);
unsigned char cx = 7;
@ -11,8 +10,8 @@ main ()
{
unsigned char cy;
cy = cx / 6; if (cy != 1) abort ();
cy = cx % 6; if (cy != 1) abort ();
cy = cx / 6; if (cy != 1) exit (1);
cy = cx % 6; if (cy != 1) exit (1);
exit(0);
}

View File

@ -93,6 +93,9 @@ struct die_struct;
/* Nonzero if this is an indirect call by descriptor. */
#define ECF_BY_DESCRIPTOR (1 << 14)
/* Nonzero if this is a cold function. */
#define ECF_COLD (1 << 15)
/* Call argument flags. */
/* Nonzero if the argument is not dereferenced recursively, thus only
directly reachable memory is read or written. */

View File

@ -10625,6 +10625,9 @@ set_call_expr_flags (tree decl, int flags)
if (flags & ECF_LEAF)
DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
NULL, DECL_ATTRIBUTES (decl));
if (flags & ECF_COLD)
DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
NULL, DECL_ATTRIBUTES (decl));
if (flags & ECF_RET1)
DECL_ATTRIBUTES (decl)
= tree_cons (get_identifier ("fn spec"),
@ -10674,11 +10677,11 @@ build_common_builtin_nodes (void)
BUILT_IN_UNREACHABLE,
"__builtin_unreachable",
ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
| ECF_CONST);
| ECF_CONST | ECF_COLD);
if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
"abort",
ECF_LEAF | ECF_NORETURN | ECF_CONST);
ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
}
if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)