From patchwork Fri Jun 9 16:53:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 774071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wkpJv3rh9z9s9Y for ; Sat, 10 Jun 2017 02:53:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LDwcyjov"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=kuSWzybZlxLnCaoAMyduSvBOquQJil07N8D2EhB4lQ00vClgWDrN9 gBX1VmNclD7jZekVeiOkhqHPyXhEZAWoMJwwfzwOwFQdXKoeivefuPQqNwz1de64 gIb1YTrb7hT6nyw8JsASatPTbr4rB2f6SUZ9VIYRYpPpzBO+Cwnbzg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=TEF6pr2kWPUzz2MuleLCDO18rvA=; b=LDwcyjovN8pZmoIqlAeP S6B0d51NPgxGxX7kaasvD8WuBtkXql0oxcurg96bR7BG6+l3hLY9OkzSfxA2Z0ke TYo4z7N02660MP1OUkYlAD1+LiF5+soJ1b5EKcCq2rVtzcEldUjmYkpaWszhrg60 fqFQNG9Yzk1muXLIqYA1yxI= Received: (qmail 105863 invoked by alias); 9 Jun 2017 16:53:19 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 102821 invoked by uid 89); 9 Jun 2017 16:53:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Category, testers, terminations X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Jun 2017 16:53:14 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 1211A548051; Fri, 9 Jun 2017 18:53:15 +0200 (CEST) Date: Fri, 9 Jun 2017 18:53:15 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Mark abort, trap, unreachable and C++ EH and terminations as cold Message-ID: <20170609165315.GA77879@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Hi, this patch marks the obvious candidates for cold attribute and enables cold auto-detection on some common coding patterns. I have bootstrapped/regtested x86_64-linux and plan to commit it at weekend once performance testers pick up this weeks changes if there are no complains. Honza * 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. Index: builtin-attrs.def =================================================================== --- builtin-attrs.def (revision 249057) +++ builtin-attrs.def (working copy) @@ -136,6 +136,8 @@ DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHRO 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_N 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_ 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: builtins.def =================================================================== --- builtins.def (revision 249057) +++ builtins.def (working copy) @@ -775,7 +775,7 @@ DEF_GCC_BUILTIN (BUILT_IN_UMULL_O 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_SAVEREG 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: calls.c =================================================================== --- calls.c (revision 249057) +++ calls.c (working copy) @@ -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: cp/class.c =================================================================== --- cp/class.c (revision 249057) +++ cp/class.c (working copy) @@ -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: cp/decl.c =================================================================== --- cp/decl.c (revision 249057) +++ cp/decl.c (working copy) @@ -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 pa 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; } Index: cp/except.c =================================================================== --- cp/except.c (revision 249057) +++ cp/except.c (working copy) @@ -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: testsuite/gcc.dg/predict-14.c =================================================================== --- testsuite/gcc.dg/predict-14.c (revision 249057) +++ testsuite/gcc.dg/predict-14.c (working copy) @@ -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: testsuite/gcc.target/i386/umod-3.c =================================================================== --- testsuite/gcc.target/i386/umod-3.c (revision 249057) +++ testsuite/gcc.target/i386/umod-3.c (working copy) @@ -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: tree-core.h =================================================================== --- tree-core.h (revision 249057) +++ tree-core.h (working copy) @@ -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: tree.c =================================================================== --- tree.c (revision 249057) +++ tree.c (working copy) @@ -10625,6 +10625,9 @@ set_call_expr_flags (tree decl, int flag 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)