From patchwork Fri Jul 23 09:11:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Zhang X-Patchwork-Id: 59747 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 B31531007D1 for ; Fri, 23 Jul 2010 19:11:43 +1000 (EST) Received: (qmail 16376 invoked by alias); 23 Jul 2010 09:11:37 -0000 Received: (qmail 16360 invoked by uid 22791); 23 Jul 2010 09:11:35 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 23 Jul 2010 09:11:28 +0000 Received: (qmail 26525 invoked from network); 23 Jul 2010 09:11:25 -0000 Received: from unknown (HELO ?192.168.1.100?) (jie@127.0.0.2) by mail.codesourcery.com with ESMTPA; 23 Jul 2010 09:11:25 -0000 Message-ID: <4C495CBB.7010709@codesourcery.com> Date: Fri, 23 Jul 2010 17:11:23 +0800 From: Jie Zhang User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.7) Gecko/20100713 Lightning/1.0b2 Thunderbird/3.1.1 MIME-Version: 1.0 To: Mark Mitchell CC: GCC Patches Subject: Re: [PATCH] Fix "naked" attribute (PR target/44290) References: <4C483FEE.5040605@codesourcery.com> <4C48BF49.8060709@codesourcery.com> In-Reply-To: <4C48BF49.8060709@codesourcery.com> X-IsSubscribed: yes 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 On 07/23/2010 05:59 AM, Mark Mitchell wrote: > Jie Zhang wrote: > >> The "naked" attribute should imply "noinline" and "noclone". This patch >> implements this for all the 5 targets which currently support the >> "naked" attribute: ARM, AVR, MCORE, RX, SPU. > > I completely agree with the spirit of this patch. "naked" functions are > very weird things, and the compiler should be very cautious in doing > things with them. It shouldn't make copies of them (inline or clone) > because we really have no way of knowing what's in there, including (for > example) static data declared in assembly code. > > But, I think the implementation could be more architecture-independent. > I'm prepared to say that any architecture that supports the "naked" > attribute *must* implement it with the semantics on the architectures > you name above. That means that the ${arch}_insert_attributes functions > you have could be architecture-independent. Just put that code into the > architecture-independent attribute-processing function. > This is a good idea. The modified patch is attached. Is it OK now? Regards, PR target/44290 * attribs.c (decl_attributes): Insert "noinline" and "noclone" if "naked". * tree-sra.c (ipa_sra_preliminary_function_checks): Return false if ! tree_versionable_function_p. testsuite/ PR target/44290 * gcc.dg/pr44290-1.c: New test. * gcc.dg/pr44290-2.c: New test. Index: attribs.c =================================================================== --- attribs.c (revision 162396) +++ attribs.c (working copy) @@ -276,6 +276,19 @@ decl_attributes (tree *node, tree attrib TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr)); } + /* A "naked" function attribute implies "noinline" and "noclone" for + those targets that support it. */ + if (TREE_CODE (*node) == FUNCTION_DECL + && lookup_attribute_spec (get_identifier ("naked")) + && lookup_attribute ("naked", attributes) != NULL) + { + if (lookup_attribute ("noinline", attributes) == NULL) + attributes = tree_cons (get_identifier ("noinline"), NULL, attributes); + + if (lookup_attribute ("noclone", attributes) == NULL) + attributes = tree_cons (get_identifier ("noclone"), NULL, attributes); + } + targetm.insert_attributes (*node, &attributes); for (a = attributes; a; a = TREE_CHAIN (a)) Index: testsuite/gcc.dg/pr44290-1.c =================================================================== --- testsuite/gcc.dg/pr44290-1.c (revision 0) +++ testsuite/gcc.dg/pr44290-1.c (revision 0) @@ -0,0 +1,18 @@ +/* { dg-do compile { target arm*-*-* avr-*-* mcore-*-* rx-*-* spu-*-* } } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +static void __attribute__((naked)) +foo(void *from, void *to) +{ + asm volatile("dummy"::"r"(from), "r"(to)); +} + +unsigned int fie[2]; + +void fum(void *to) +{ + foo(fie, to); +} + +/* { dg-final { scan-tree-dump "foo \\\(void \\\* from, void \\\* to\\\)" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ Index: testsuite/gcc.dg/pr44290-2.c =================================================================== --- testsuite/gcc.dg/pr44290-2.c (revision 0) +++ testsuite/gcc.dg/pr44290-2.c (revision 0) @@ -0,0 +1,24 @@ +/* { dg-do compile { target arm*-*-* avr-*-* mcore-*-* rx-*-* spu-*-* } } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +static unsigned long __attribute__((naked)) +foo (unsigned long base) +{ + asm volatile ("dummy"); +} +unsigned long +bar (void) +{ + static int start, set; + + if (!set) + { + set = 1; + start = foo (0); + } + + return foo (start); +} + +/* { dg-final { scan-tree-dump "foo \\\(long unsigned int base\\\)" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ Index: tree-sra.c =================================================================== --- tree-sra.c (revision 162396) +++ tree-sra.c (working copy) @@ -4285,6 +4285,13 @@ modify_function (struct cgraph_node *nod static bool ipa_sra_preliminary_function_checks (struct cgraph_node *node) { + if (!tree_versionable_function_p (current_function_decl)) + { + if (dump_file) + fprintf (dump_file, "Function isn't allowed to be versioned.\n"); + return false; + } + if (!cgraph_node_can_be_local_p (node)) { if (dump_file)