From patchwork Sat Feb 9 02:57:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshit Chopra X-Patchwork-Id: 219361 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]) by ozlabs.org (Postfix) with SMTP id C5EDF2C008C for ; Sat, 9 Feb 2013 13:57:44 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1360983465; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:To:Subject:User-Agent:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:From: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=g2eBsTUUzNPReBJEY0zm 4QnCaV4=; b=mIqLXrV4Tompexq6JCu0XmaH7Q6m13u6glQKREyeq5SIqGd/nE0q NZEfNBvDchHPHHDur0XeCdAt8YEZ9OZEK2LqONWHUDXIzfjCVWx5s5EF5RFxYVjN jBv0KzrPbD39YTzoNFWbRiFzXheW007YBBU5+G+tO8UqiGiaRmSRGYo= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:X-Received:Received:Received:Received:Date:To:Subject:User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:From:X-Gm-Message-State:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=SzOJRRF6FsPp7ztVLy8PIQG+d/Hqp/1A6GSY958I+Ga8FOCf4qh4EH8S7VvWzx LntmJ1WGeuhVqjw2wvdQqkmc0LsX3gn3pJ0iTgxsdmIHobR6zHNh2f0fMC6jloqs Ttx0/PWXpOL3jY3YBFrQgzBcwN8cIUn4n9bzTOGyHYuJ8=; Received: (qmail 5340 invoked by alias); 9 Feb 2013 02:57:40 -0000 Received: (qmail 5329 invoked by uid 22791); 9 Feb 2013 02:57:39 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-we0-f201.google.com (HELO mail-we0-f201.google.com) (74.125.82.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 09 Feb 2013 02:57:33 +0000 Received: by mail-we0-f201.google.com with SMTP id d7so294313wer.2 for ; Fri, 08 Feb 2013 18:57:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:date:to:subject:user-agent:mime-version:content-type :content-transfer-encoding:message-id:from:x-gm-message-state; bh=Ef/rTIhn9rHndDh/mJtkEqFhl1V3Gspy1jIKwP19qK4=; b=k0DXwthf9+U3Iv7nIVdKF7hF2VtjXaFoJecoiNykAzLKfGs+rfamwJxQ+KqiMRi2SG doQhqKWmuFmLml+UjuPtkfo+C9UsfDjM4nak90+YUUj5t4OZLDWnsPeFy+p3WR0BvFvf VXOdONZEd7zYtiKl297JHXref46j75d+meNhtkU02OQzyvgteFHZgsWPbWrxRkiYreNE 3Tqq74Cbcv15tMkG8lgjkJ5B0ogrAUprjtp4TPU/a2Or91KisyvEPDf2KnZ69Hfjvm/8 WbcEVz0hfWtHPqMH+PqQ4fi0aUPYJ+Ty/ZvMahtX6Rz79635PdamPYAyD8K5/n0C8hAn SGkA== X-Received: by 10.14.220.131 with SMTP id o3mr7613047eep.3.1360378652138; Fri, 08 Feb 2013 18:57:32 -0800 (PST) Received: from corp2gmr1-2.eem.corp.google.com (corp2gmr1-2.eem.corp.google.com [172.25.138.117]) by gmr-mx.google.com with ESMTPS id 6si4960193eej.0.2013.02.08.18.57.32 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Fri, 08 Feb 2013 18:57:32 -0800 (PST) Received: from hchopra.mtv.corp.google.com (hchopra.mtv.corp.google.com [172.17.133.27]) by corp2gmr1-2.eem.corp.google.com (Postfix) with ESMTP id 9B8A81E41B6; Fri, 8 Feb 2013 18:57:31 -0800 (PST) Received: by hchopra.mtv.corp.google.com (Postfix, from userid 48577) id D6FCD121033; Fri, 8 Feb 2013 18:57:30 -0800 (PST) Date: Fri, 08 Feb 2013 18:57:30 -0800 To: gcc-patches@gcc.gnu.org, davidxl@google.com, reply@codereview.appspotmail.com Subject: [google] Port revisions for -mpatch-functions-for-instrumentation option back to google-main. (issue7301068) User-Agent: Heirloom mailx 12.5 6/20/10 MIME-Version: 1.0 Message-Id: <20130209025730.D6FCD121033@hchopra.mtv.corp.google.com> From: harshit@google.com (Harshit Chopra) X-Gm-Message-State: ALoCoQlUDLaLTHa1TNt529RdVVOKcCkcHHCWgXa1/S2W5o6Ac7hFDzv7T18wt39yBBXsvflqgdy1jnU+yDS1wEyw0VrYCL0mz9PEb52lulCcyuq1My2inVEo3yULKGbmHtavsZYIMSx4D2lDER/2xel5tf9L7vIutkmNw3y5PdYMjcTtJhwcs23sM8eKxcOtnZKEvIPHhgHB 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 2013-02-08 Harshit Chopra Porting revisions r183548, r183888, r186118, r192231, r193381. --- This patch is available for review at http://codereview.appspot.com/7301068 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index ab416ff..04b973f 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -396,6 +396,13 @@ static tree ignore_attribute (tree *, tree, tree, int, bool *); static tree handle_no_split_stack_attribute (tree *, tree, tree, int, bool *); static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *); +static tree handle_always_patch_for_instrumentation_attribute (tree *, tree, + tree, int, + bool *); +static tree handle_never_patch_for_instrumentation_attribute (tree *, tree, + tree, int, + bool *); + static void check_function_nonnull (tree, int, tree *); static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT); static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT); @@ -804,6 +811,13 @@ const struct attribute_spec c_common_attribute_table[] = The name contains space to prevent its usage in source code. */ { "fn spec", 1, 1, false, true, true, handle_fnspec_attribute, false }, + { "always_patch_for_instrumentation", 0, 0, true, false, false, + handle_always_patch_for_instrumentation_attribute, + false }, + { "never_patch_for_instrumentation", 0, 0, true, false, false, + handle_never_patch_for_instrumentation_attribute, + false }, + { NULL, 0, 0, false, false, false, NULL, false } }; @@ -9158,6 +9172,48 @@ handle_no_thread_safety_analysis_attribute (tree *node, tree name, return NULL_TREE; } +/* Handle a "always_patch_for_instrumentation" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_always_patch_for_instrumentation_attribute (tree *node, tree name, + tree ARG_UNUSED (args), + int ARG_UNUSED (flags), + bool *no_add_attrs) +{ + if (TREE_CODE (*node) == FUNCTION_DECL) + { + /* Disable inlining if forced instrumentation. */ + DECL_UNINLINABLE (*node) = 1; + } + else + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + return NULL_TREE; +} + + +/* Handle a "never_patch_for_instrumentation" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_never_patch_for_instrumentation_attribute (tree *node, tree name, + tree ARG_UNUSED (args), + int ARG_UNUSED (flags), + bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + return NULL_TREE; +} + + + /* Check for valid arguments being passed to a function with FNTYPE. There are NARGS arguments in the array ARGARRAY. */ void diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 6972ae6..4e0d770 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -10968,6 +10968,13 @@ ix86_expand_epilogue (int style) returns. */ static bool patch_current_function_p = false; +static inline bool +has_attribute (const char* attribute_name) +{ + return lookup_attribute (attribute_name, + DECL_ATTRIBUTES (current_function_decl)) != NULL; +} + /* Return true if we patch the current function. By default a function is patched if it has loops or if the number of insns is greater than patch_functions_min_instructions (number of insns roughly translates @@ -10983,6 +10990,13 @@ check_should_patch_current_function (void) int num_loops = 0; int min_functions_instructions; + /* If a function has an attribute forcing patching on or off, do as it + indicates. */ + if (has_attribute ("always_patch_for_instrumentation")) + return true; + else if (has_attribute ("never_patch_for_instrumentation")) + return false; + /* Patch the function if it has at least a loop. */ if (!patch_functions_ignore_loops) { diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-force-no-patching.c b/gcc/testsuite/gcc.target/i386/patch-functions-force-no-patching.c new file mode 100644 index 0000000..cad6f2d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/patch-functions-force-no-patching.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-mpatch-functions-for-instrumentation -mno-patch-functions-main-always" } */ + +/* Even complicated functions shouldn't get patched if they have the + never_patch_for_instrumentation attribute. */ + +/* { dg-final { scan-assembler-not ".byte\t0xeb,0x09(.*).byte\t0x90" } } */ +/* { dg-final { scan-assembler-not "ret(.*).byte\t0x90(.*).byte\t0x90" } } */ + +__attribute__ ((never_patch_for_instrumentation)) +int foo () { + volatile unsigned x = 0; + volatile unsigned y = 1; + x += y; + x *= y; + while (++x) + foo (); + return y; +} + + +int main () +{ + int x = 0; + return 0; +} diff --git a/gcc/testsuite/gcc.target/i386/patch-functions-force-patching.c b/gcc/testsuite/gcc.target/i386/patch-functions-force-patching.c new file mode 100644 index 0000000..86ad159 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/patch-functions-force-patching.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-O3 -mpatch-functions-for-instrumentation -mno-patch-functions-main-always" } */ + +/* Functions which have the always_patch attribute should be patched no matter + what. Check that there are nop-bytes at the beginning and end of the + function. We add -O3 so that the compiler will try to inline foo (but it + will be blocked by the attribute). */ + +/* { dg-final { scan-assembler ".byte\t0xeb,0x09(.*).byte\t0x90" } } */ +/* { dg-final { scan-assembler "ret(.*).byte\t0x90(.*).byte\t0x90" } } */ + +__attribute__ ((always_patch_for_instrumentation)) +static int foo () { + return 3; +} + +int main () { + volatile int x = foo (); +}