builtin-attrs.def (ATTR_NORETURN_NOTHROW_LEAF_COLD_LIST, [...]): New.
authorJan Hubicka <hubicka@ucw.cz>
Fri, 9 Jun 2017 18:36:50 +0000 (20:36 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Fri, 9 Jun 2017 18:36:50 +0000 (18:36 +0000)
* 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

13 files changed:
gcc/ChangeLog
gcc/builtin-attrs.def
gcc/builtins.def
gcc/calls.c
gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/decl.c
gcc/cp/except.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/predict-14.c
gcc/testsuite/gcc.target/i386/umod-3.c
gcc/tree-core.h
gcc/tree.c

index 7dec15309b02ff6168f445bd6cfb62974e966966..866f3ab2c9f5c02f3dfea5eab93b6336488ce871 100644 (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.
index 38fb1bb88102fb7b3877732afe051b1ec8c3fbc7..53e67e62844af99fa5f8460e771277b286294119 100644 (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)                                   \
index 58d78dbbdee58df77fb7bad904362327704403c5..1c887db7cb94b1077762458c8d2ba36f3e4c82e6 100644 (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)
index 91a4466b00bec4f514344b80aacbe0ca30aac8fe..8a23b50fc66661d8b53f0b2e3fe19a3a7ef9d156 100644 (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;
index 38b04faf0e1223f04b1d46f3ee33390bc8194c6a..f1235a9de9ba031c10da708c5048ef791eb1750b 100644 (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
index 227466ec913b34f206e79cf3ebebd452d92b28aa..66f42627715f891cc6b5d4ff2a5930e292a5dbbc 100644 (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)
index b144426d56fb872b13364025ffcc2a8edc345e97..b0df3c9835c21c65fd2a13daa2ce12ae29e69a7e 100644 (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;
 }
 \f
index 1795e6f1664fa0b376611483fa9ae2791f9cbc0b..ab7ab5db1586d6b9303c096c61d84cb593440759 100644 (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 *); */
index 382805c64e0ccc8c8d4cb1087a4422097c53c3a7..8a1c361fbedee002f66c0c474e171b98828eee5f 100644 (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.
index 18ede8f39c057fd7272345369267e1b35f504afd..a1b283699ec7d4d92dc96efba5162badb604a1a9 100644 (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;
index 7123bc9f2564f016a3390c57f27d0d9410bb7d46..e1fb988263a6363288506c659c9bb03a8336664c 100644 (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);
 }
index ea73477163d835b98e37b55a38f25d59087a4be3..34e5c17ab22a846f5ea21ac150a2b248bf4a07e6 100644 (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.  */
index a58f9aaa69ec4b0b5ad22d92a41935ceae36b1c4..3ba11be3261b41009ff2c310220a755c92bbb1d9 100644 (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)