From cb59f689a37fc39178b9ac5fa595c63b3d7eddc0 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Fri, 9 Jun 2017 20:36:50 +0200 Subject: [PATCH] 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 --- gcc/ChangeLog | 11 +++++++++++ gcc/builtin-attrs.def | 7 +++++++ gcc/builtins.def | 6 +++--- gcc/calls.c | 2 ++ gcc/cp/ChangeLog | 6 ++++++ gcc/cp/class.c | 2 +- gcc/cp/decl.c | 4 ++-- gcc/cp/except.c | 7 ++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/predict-14.c | 8 +++++--- gcc/testsuite/gcc.target/i386/umod-3.c | 5 ++--- gcc/tree-core.h | 3 +++ gcc/tree.c | 7 +++++-- 13 files changed, 56 insertions(+), 17 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7dec15309b0..866f3ab2c9f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2017-06-09 Jan Hubicka + + * 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 * predict.c (unlikely_executed_stmt_p): Cleanup. diff --git a/gcc/builtin-attrs.def b/gcc/builtin-attrs.def index 38fb1bb8810..53e67e62844 100644 --- a/gcc/builtin-attrs.def +++ b/gcc/builtin-attrs.def @@ -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) \ diff --git a/gcc/builtins.def b/gcc/builtins.def index 58d78dbbdee..1c887db7cb9 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -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) diff --git a/gcc/calls.c b/gcc/calls.c index 91a4466b00b..8a23b50fc66 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -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; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 38b04faf0e1..f1235a9de9b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-06-09 Jan Hubicka + + * 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 PR c/81006 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 227466ec913..66f42627715 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -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) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index b144426d56f..b0df3c9835c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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; } diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 1795e6f1664..ab7ab5db158 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -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 *); */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 382805c64e0..8a1c361fbed 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-09 Jan Hubicka + + * gcc.dg/predict-14.c: Avoid cold function detection. + * gcc.target/i386/umod-3.c: Likewise. + 2017-06-09 Tamar Christina * gcc.target/aarch64/lrint-matherr.h: New. diff --git a/gcc/testsuite/gcc.dg/predict-14.c b/gcc/testsuite/gcc.dg/predict-14.c index 18ede8f39c0..a1b283699ec 100644 --- a/gcc/testsuite/gcc.dg/predict-14.c +++ b/gcc/testsuite/gcc.dg/predict-14.c @@ -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; diff --git a/gcc/testsuite/gcc.target/i386/umod-3.c b/gcc/testsuite/gcc.target/i386/umod-3.c index 7123bc9f256..e1fb988263a 100644 --- a/gcc/testsuite/gcc.target/i386/umod-3.c +++ b/gcc/testsuite/gcc.target/i386/umod-3.c @@ -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); } diff --git a/gcc/tree-core.h b/gcc/tree-core.h index ea73477163d..34e5c17ab22 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -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. */ diff --git a/gcc/tree.c b/gcc/tree.c index a58f9aaa69e..3ba11be3261 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -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)