From patchwork Wed Jul 27 08:27:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 653198 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 3rzp610dWpz9t1p for ; Wed, 27 Jul 2016 18:28:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Qb2zBzQ0; 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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=bevlMy/maoVrVBFr5NiHFXIitOOUywyvtCcL+hYtRDj7k+0LCp OhZNqZF+aBHWYj0zzUf/yK3xjSWzKB4Ur4rLwp6Z1LtvzrReVKHuCQ1QHTyelYG9 zx6Y3rDbyYRWY5uKd52yz3HkXkd91WCvIc1/7fqyyRg3+CmolzsRUfoRc= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=/r1WygPaGxaN7HXVoyGt0AciKjE=; b=Qb2zBzQ0uhsYdGuyfaed ICsD36wnOn6YRw9HRROjm+GHs9YinHU8sJRC3UXQj5CTHwfGAHJ3nZKE6s56Yetb 3SKJzcpzkSr2pDhv6Gql758pWmQhRaJP37/3hcNlhrDJm6NU/8072QMlMAZQbVY3 fbXuTS7LBU+VMWWgJtWz0jM= Received: (qmail 79998 invoked by alias); 27 Jul 2016 08:27:54 -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 79988 invoked by uid 89); 27 Jul 2016 08:27:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=UD:c-common.c, ccommonc, c-common.c, 7176 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Wed, 27 Jul 2016 08:27:43 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id ACD9DAD26; Wed, 27 Jul 2016 08:27:39 +0000 (UTC) To: GCC Patches Cc: coolypf@qq.com, Jan Hubicka From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Introduce no_profile_instrument_function attribute (PR gcov-profile/68025) Message-ID: <00b28d6f-ab20-b9ff-becb-b4d82b2ff989@suse.cz> Date: Wed, 27 Jul 2016 10:27:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 X-IsSubscribed: yes Hi. As mentioned in the PR gcov-profile/68025, there's a request not to instrument some functions (e.g. a in linux kernel). Thus, I come with a new attribute no_profile_instrument_function which skips any profiling instrumentation. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Thoughts? Martin From be1a81dc949480c24c0e173085bdad193c0579ce Mon Sep 17 00:00:00 2001 From: marxin Date: Tue, 26 Jul 2016 15:03:29 +0200 Subject: [PATCH] Introduce no_profile_instrument_function attribute gcc/ChangeLog: 2016-07-26 Martin Liska PR gcov-profile/68025 * tree-profile.c (tree_profiling): Respect no_profile_instrument_function attribute. gcc/c-family/ChangeLog: 2016-07-26 Martin Liska PR gcov-profile/68025 * c-common.c (handle_no_profile_instrument_function_attribute): gcc/testsuite/ChangeLog: 2016-07-26 Martin Liska PR gcov-profile/68025 * gcc.dg/no_profile_instrument_function-attr-1.c: New test. --- gcc/c-family/c-common.c | 21 ++++++++++++++++++++ .../gcc.dg/no_profile_instrument_function-attr-1.c | 23 ++++++++++++++++++++++ gcc/tree-profile.c | 3 +++ 3 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 1c5974a..35b5e5d 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -353,6 +353,8 @@ static tree handle_tls_model_attribute (tree *, tree, tree, int, bool *); static tree handle_no_instrument_function_attribute (tree *, tree, tree, int, bool *); +static tree handle_no_profile_instrument_function_attribute (tree *, tree, + tree, int, bool *); static tree handle_malloc_attribute (tree *, tree, tree, int, bool *); static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *); static tree handle_no_limit_stack_attribute (tree *, tree, tree, int, @@ -717,6 +719,9 @@ const struct attribute_spec c_common_attribute_table[] = { "no_instrument_function", 0, 0, true, false, false, handle_no_instrument_function_attribute, false }, + { "no_profile_instrument_function", 0, 0, true, false, false, + handle_no_profile_instrument_function_attribute, + false }, { "malloc", 0, 0, true, false, false, handle_malloc_attribute, false }, { "returns_twice", 0, 0, true, false, false, @@ -8293,6 +8298,22 @@ handle_no_instrument_function_attribute (tree *node, tree name, return NULL_TREE; } +/* Handle a "no_profile_instrument_function" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_no_profile_instrument_function_attribute (tree *node, tree name, tree, + int, bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Handle a "malloc" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c new file mode 100644 index 0000000..c93d171 --- /dev/null +++ b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c @@ -0,0 +1,23 @@ +/* { dg-options "-O2 -fprofile-generate -fdump-tree-optimized" } */ + +__attribute__ ((no_profile_instrument_function)) +int foo() +{ + return 0; +} + +__attribute__ ((no_profile_instrument_function)) +int bar() +{ + return 1; +} + +int main () +{ + return foo (); +} + +/* { dg-final { scan-tree-dump-times "__gcov0\\.main.* = PROF_edge_counter" 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "__gcov_indirect_call_profiler_v2" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "__gcov_time_profiler" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "__gcov_init" 1 "optimized" } } */ diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c index 1f3a726..39fe15f 100644 --- a/gcc/tree-profile.c +++ b/gcc/tree-profile.c @@ -524,6 +524,9 @@ tree_profiling (void) if (DECL_SOURCE_LOCATION (node->decl) == BUILTINS_LOCATION) continue; + if (lookup_attribute ("no_profile_instrument_function", + DECL_ATTRIBUTES (node->decl))) + continue; /* Do not instrument extern inline functions when testing coverage. While this is not perfectly consistent (early inlined extern inlines will get acocunted), testsuite expects that. */ -- 2.9.2