From patchwork Thu Jan 21 10:36:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Bruel X-Patchwork-Id: 571118 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 469DC140C0A for ; Thu, 21 Jan 2016 21:37:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=vBhXIfKC; 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=rlPbT8Tn5KkkrM2gZR37HNONqRdBj7zMjFqt/5iSITuINitGqy cD0hVgpsoJGoyCvUt9/zhrYMl4JYyhLFe4pnPTM3GFmXGsfBVGy/H9R9Yp5WJ1l1 /hC/FS2AVwo1OQPLLmT8Gvi4rl1rhLFNQGJC+UNk+yAG+rPFgbJlQdEZ8= 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=XUhe4/lF7zbPQNGpI/vEsakNEVU=; b=vBhXIfKClg/asglZcNLg dYulFHQzwzJbA7AHUMQ86eR9tD8zHkPgzY/F0nU+b+TVe7ooxgFvo227nTkJmfmK 9xeRnKFUErZmDHLXhFFj03ORfN9eWW9wMF6oVgAPtSoxARfiqa/lIpGtZKwln4N+ UoDXHjz0jKv0ZbWl9wVRcfg= Received: (qmail 83011 invoked by alias); 21 Jan 2016 10:37:07 -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 83002 invoked by uid 89); 21 Jan 2016 10:37:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.9 required=5.0 tests=BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=awkward, H*r:Thu, cached, fndecl X-HELO: mx07-00178001.pphosted.com Received: from mx08-00178001.pphosted.com (HELO mx07-00178001.pphosted.com) (91.207.212.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 21 Jan 2016 10:37:05 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.15.0.59/8.15.0.59) with SMTP id u0LAMbh8031747; Thu, 21 Jan 2016 11:36:58 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 20fdmheqy0-1 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 21 Jan 2016 11:36:58 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0756D31; Thu, 21 Jan 2016 10:36:09 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas5.st.com [10.75.90.71]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4B347164F; Thu, 21 Jan 2016 10:36:56 +0000 (GMT) Received: from [164.129.122.197] (164.129.122.197) by webmail-eu.st.com (10.75.90.13) with Microsoft SMTP Server (TLS) id 8.3.406.0; Thu, 21 Jan 2016 11:36:55 +0100 To: , , CC: From: Christian Bruel Subject: [PATCH][ARM] Fix PR target/69245 Rewrite arm_set_current_function X-No-Archive: yes Message-ID: <56A0B4C7.5090609@st.com> Date: Thu, 21 Jan 2016 11:36:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-01-21_05:, , signatures=0 X-IsSubscribed: yes The current arm_set_current_function was both awkward and buggy. For instance using partially set TARGET_OPTION set from pragma_parse, while restore_target_globalsnor arm_option_params_internal was not reset. Another issue is that in some paths, target_reinit was not called due to old cached target_option_current_node value. for instance with foo{} #pragma GCC target ... foo was called with global_options set from old GCC target (which was wrong) and correct rtl values. This is a reimplementation of the function. Hoping to be easier to read (and maintain). Solves the current issues seen so far. regtested for arm-linux-gnueabi -mfpu=vfp, -mfpu=neon,-mfpu=neon-fp-armv8 2016-01-20 Christian Bruel PR target/69245 * config/arm/arm-c.c (arm_pragma_target_parse): Add comments. Move arm_reset_previous_fndecl and set_target_option_current_node in the conditional part. * config/arm/arm.c (arm_set_current_function): Refactor to better support #pragma target and attribute mix. 2016-01-20 Christian Bruel PR target/69245 * gcc.target/arm/pr69245.c: New test. Index: gcc/config/arm/arm-c.c =================================================================== --- gcc/config/arm/arm-c.c (revision 232669) +++ gcc/config/arm/arm-c.c (working copy) @@ -221,9 +221,6 @@ arm_pragma_target_parse (tree args, tree pop_targe } } - target_option_current_node = cur_tree; - arm_reset_previous_fndecl (); - /* Figure out the previous mode. */ prev_opt = TREE_TARGET_OPTION (prev_tree); cur_opt = TREE_TARGET_OPTION (cur_tree); @@ -261,8 +255,13 @@ arm_pragma_target_parse (tree args, tree pop_targe arm_cpu_builtins (parse_in); cpp_opts->warn_unused_macros = saved_warn_unused_macros; + + /* Make sure that target_reinit is called for next function, since + TREE_TARGET_OPTION might change with the #pragma even if there are + no target attribute attached to the function. */ + target_option_current_node = cur_tree; + arm_reset_previous_fndecl (); } return true; Index: gcc/config/arm/arm.c =================================================================== --- gcc/config/arm/arm.c (revision 232669) +++ gcc/config/arm/arm.c (working copy) @@ -29768,35 +29768,28 @@ arm_set_current_function (tree fndecl) tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); - arm_previous_fndecl = fndecl; + /* if no attribute, use the mode set by the current pragma target. */ + if (! new_tree) + new_tree = target_option_current_node; + if (old_tree == new_tree) return; - if (new_tree && new_tree != target_option_default_node) - { - cl_target_option_restore (&global_options, - TREE_TARGET_OPTION (new_tree)); + arm_previous_fndecl = fndecl; - if (TREE_TARGET_GLOBALS (new_tree)) - restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); - else - TREE_TARGET_GLOBALS (new_tree) - = save_target_globals_default_opts (); - } + /* First set the target options. */ + cl_target_option_restore (&global_options, TREE_TARGET_OPTION (new_tree)); - else if (old_tree && old_tree != target_option_default_node) + /* If we have a previous state, use it. */ + if (TREE_TARGET_GLOBALS (new_tree)) + restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); + else if (new_tree == target_option_default_node) + restore_target_globals (&default_target_globals); + else { - new_tree = target_option_current_node; - - cl_target_option_restore (&global_options, - TREE_TARGET_OPTION (new_tree)); - if (TREE_TARGET_GLOBALS (new_tree)) - restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); - else if (new_tree == target_option_default_node) - restore_target_globals (&default_target_globals); - else - TREE_TARGET_GLOBALS (new_tree) - = save_target_globals_default_opts (); + /* now target_reinit can save the state for later. */ + TREE_TARGET_GLOBALS (new_tree) + = save_target_globals_default_opts (); } arm_option_params_internal (); Index: gcc/testsuite/gcc.target/arm/pr69245.c =================================================================== --- gcc/testsuite/gcc.target/arm/pr69245.c (revision 0) +++ gcc/testsuite/gcc.target/arm/pr69245.c (working copy) @@ -0,0 +1,24 @@ +/* PR target/69245 */ +/* Test that pop_options restores the vfp fpu mode. */ +/* { dg-do compile } */ +/* { dg-require-effective-target arm_fp_ok } */ +/* { dg-add-options arm_fp } */ + +#pragma GCC target "fpu=vfp" + +#pragma GCC push_options +#pragma GCC target "fpu=neon" +int a, c, d; +float b; +static int fn1 () +{ + return 0; +} +#pragma GCC pop_options + +void fn2 () +{ + d = b * c + a; +} + +/* { dg-final { scan-assembler-times "\.fpu vfp" 1 } } */