From patchwork Mon Aug 19 15:21:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1149344 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-507268-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="No80TwoI"; dkim-atps=neutral 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 46ByMb6LJJz9s3Z for ; Tue, 20 Aug 2019 01:22:03 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=i5+vmVqF1aRt44DgFM1bf8ovh5XL8 R3iI2t4Y6ABYoU0uwvjEzw4rHU42tdhx18LDtFWLFhyrDbttuR4mXsRLBRyrAeiZ xFW2z0f++jE9Qis27fDovflLQn8QEv2XO2P43IcUpG7OySBmXZ8ElsclvPoJo9Et xvSTreCrT/0UQ0= 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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=zFzdKEBw8sPZblTgJAuIBWIOha0=; b=No8 0TwoIv7hXg95a3MQptOauleunUNqF6VkDmorioxklgsZsBq3DcnnybSXn3rwe8U3 ogWThN14fQ9bbLZgwwS10/oixd9rCKa/1lljFyy3ZdvfqqDs8OpLi7+RCsijEVZ2 VSs5laXnlO77rPDk5rgse/LgPiOwn+mrX2qLjw6s= Received: (qmail 25683 invoked by alias); 19 Aug 2019 15:21:56 -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 25672 invoked by uid 89); 19 Aug 2019 15:21:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=patched X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Aug 2019 15:21:54 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 55E8E344 for ; Mon, 19 Aug 2019 08:21:53 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.99.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F21063F718 for ; Mon, 19 Aug 2019 08:21:52 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [10/13] Add a apply_pass_by_reference_rules helper References: Date: Mon, 19 Aug 2019 16:21:51 +0100 In-Reply-To: (Richard Sandiford's message of "Mon, 19 Aug 2019 16:11:12 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes This patch adds a helper routine that applies pass-by-reference semantics to an existing function_arg_info. The c6x part means that c6x_function_arg and c6x_function_arg_advance see the same "named" value as pass_by_reference did, rather than pass_by_reference seeing "true" and the others seeing "false". This doesn't matter because the c6x port doesn't care about namedness. The rs6000.c patch removes an assignment to "type", but the only later code to use it was the patched promote_mode line. (The reason for patching these places despite the above is that often target code gets used as a basis for new targets or changes to existing ones.) 2019-08-19 Richard Sandiford gcc/ * calls.h (apply_pass_by_reference_rules): Declare. * calls.c (apply_pass_by_reference_rules): New function. * config/c6x/c6x.c (c6x_call_saved_register_used): Use it. * config/rs6000/rs6000-call.c (rs6000_parm_needs_stack): Likewise. * config/s390/s390.c (s390_call_saved_register_used): Likewise. * function.c (assign_parm_find_data_types): Likewise. * var-tracking.c (prepare_call_arguments): Likewise. Index: gcc/calls.h =================================================================== --- gcc/calls.h 2019-08-19 15:59:04.261818304 +0100 +++ gcc/calls.h 2019-08-19 15:59:09.801778220 +0100 @@ -118,6 +118,8 @@ extern void fixup_tail_calls (void); extern bool pass_by_reference (CUMULATIVE_ARGS *, function_arg_info); extern bool pass_va_arg_by_reference (tree); +extern bool apply_pass_by_reference_rules (CUMULATIVE_ARGS *, + function_arg_info &); extern bool reference_callee_copied (CUMULATIVE_ARGS *, const function_arg_info &); extern void maybe_warn_alloc_args_overflow (tree, tree, tree[2], int[2]); Index: gcc/calls.c =================================================================== --- gcc/calls.c 2019-08-19 15:59:04.261818304 +0100 +++ gcc/calls.c 2019-08-19 15:59:09.801778220 +0100 @@ -935,6 +935,22 @@ pass_va_arg_by_reference (tree type) return pass_by_reference (NULL, function_arg_info (type, /*named=*/false)); } +/* Decide whether ARG, which occurs in the state described by CA, + should be passed by reference. Return true if so and update + ARG accordingly. */ + +bool +apply_pass_by_reference_rules (CUMULATIVE_ARGS *ca, function_arg_info &arg) +{ + if (pass_by_reference (ca, arg)) + { + arg.type = build_pointer_type (arg.type); + arg.mode = TYPE_MODE (arg.type); + return true; + } + return false; +} + /* Return true if ARG, which is passed by reference, should be callee copied instead of caller copied. */ Index: gcc/config/c6x/c6x.c =================================================================== --- gcc/config/c6x/c6x.c 2019-08-19 15:58:58.001863604 +0100 +++ gcc/config/c6x/c6x.c 2019-08-19 15:59:09.805778189 +0100 @@ -1088,8 +1088,6 @@ c6x_call_saved_register_used (tree call_ cumulative_args_t cum; HARD_REG_SET call_saved_regset; tree parameter; - machine_mode mode; - tree type; rtx parm_rtx; int i; @@ -1107,19 +1105,9 @@ c6x_call_saved_register_used (tree call_ if (TREE_CODE (parameter) == ERROR_MARK) return true; - type = TREE_TYPE (parameter); - gcc_assert (type); + function_arg_info arg (TREE_TYPE (parameter), /*named=*/true); + apply_pass_by_reference_rules (&cum_v, arg); - mode = TYPE_MODE (type); - gcc_assert (mode); - - if (pass_by_reference (&cum_v, function_arg_info (type, /*named=*/true))) - { - mode = Pmode; - type = build_pointer_type (type); - } - - function_arg_info arg (type, mode, /*named=*/false); parm_rtx = c6x_function_arg (cum, arg); c6x_function_arg_advance (cum, arg); Index: gcc/config/rs6000/rs6000-call.c =================================================================== --- gcc/config/rs6000/rs6000-call.c 2019-08-19 15:59:04.285818131 +0100 +++ gcc/config/rs6000/rs6000-call.c 2019-08-19 15:59:09.805778189 +0100 @@ -2170,7 +2170,6 @@ rs6000_pass_by_reference (cumulative_arg static bool rs6000_parm_needs_stack (cumulative_args_t args_so_far, tree type) { - machine_mode mode; int unsignedp; rtx entry_parm; @@ -2193,16 +2192,14 @@ rs6000_parm_needs_stack (cumulative_args type = TREE_TYPE (first_field (type)); /* See if this arg was passed by invisible reference. */ - if (pass_by_reference (get_cumulative_args (args_so_far), - function_arg_info (type, /*named=*/true))) - type = build_pointer_type (type); + function_arg_info arg (type, /*named=*/true); + apply_pass_by_reference_rules (get_cumulative_args (args_so_far), arg); /* Find mode as it is passed by the ABI. */ unsignedp = TYPE_UNSIGNED (type); - mode = promote_mode (type, TYPE_MODE (type), &unsignedp); + arg.mode = promote_mode (arg.type, arg.mode, &unsignedp); /* If we must pass in stack, we need a stack. */ - function_arg_info arg (type, mode, /*named=*/true); if (rs6000_must_pass_in_stack (arg)) return true; Index: gcc/config/s390/s390.c =================================================================== --- gcc/config/s390/s390.c 2019-08-19 15:58:50.337919057 +0100 +++ gcc/config/s390/s390.c 2019-08-19 15:59:09.809778162 +0100 @@ -13309,8 +13309,6 @@ s390_call_saved_register_used (tree call CUMULATIVE_ARGS cum_v; cumulative_args_t cum; tree parameter; - machine_mode mode; - tree type; rtx parm_rtx; int reg, i; @@ -13327,22 +13325,12 @@ s390_call_saved_register_used (tree call if (TREE_CODE (parameter) == ERROR_MARK) return true; - type = TREE_TYPE (parameter); - gcc_assert (type); - - mode = TYPE_MODE (type); - gcc_assert (mode); - /* We assume that in the target function all parameters are named. This only has an impact on vector argument register usage none of which is call-saved. */ - if (pass_by_reference (&cum_v, function_arg_info (type, /*named=*/true))) - { - mode = Pmode; - type = build_pointer_type (type); - } + function_arg_info arg (TREE_TYPE (parameter), /*named=*/true); + apply_pass_by_reference_rules (&cum_v, arg); - function_arg_info arg (type, mode, /*named=*/true); parm_rtx = s390_function_arg (cum, arg); s390_function_arg_advance (cum, arg); Index: gcc/function.c =================================================================== --- gcc/function.c 2019-08-19 15:59:04.289818104 +0100 +++ gcc/function.c 2019-08-19 15:59:09.809778162 +0100 @@ -2456,11 +2456,11 @@ assign_parm_find_data_types (struct assi /* See if this arg was passed by invisible reference. */ { function_arg_info arg (passed_type, passed_mode, data->named_arg); - if (pass_by_reference (&all->args_so_far_v, arg)) + if (apply_pass_by_reference_rules (&all->args_so_far_v, arg)) { - passed_type = nominal_type = build_pointer_type (passed_type); + passed_type = nominal_type = arg.type; data->passed_pointer = true; - passed_mode = nominal_mode = TYPE_MODE (nominal_type); + passed_mode = nominal_mode = arg.mode; } } Index: gcc/var-tracking.c =================================================================== --- gcc/var-tracking.c 2019-08-19 15:58:50.345918999 +0100 +++ gcc/var-tracking.c 2019-08-19 15:59:09.813778131 +0100 @@ -6426,28 +6426,24 @@ prepare_call_arguments (basic_block bb, } if (t && t != void_list_node) { - tree argtype = TREE_VALUE (t); rtx reg; - function_arg_info orig_arg (argtype, /*named=*/true); - if (pass_by_reference (&args_so_far_v, orig_arg)) - argtype = build_pointer_type (argtype); - machine_mode mode = TYPE_MODE (argtype); - function_arg_info arg (argtype, /*named=*/true); + function_arg_info arg (TREE_VALUE (t), /*named=*/true); + apply_pass_by_reference_rules (&args_so_far_v, arg); reg = targetm.calls.function_arg (args_so_far, arg); - if (TREE_CODE (argtype) == REFERENCE_TYPE - && INTEGRAL_TYPE_P (TREE_TYPE (argtype)) + if (TREE_CODE (arg.type) == REFERENCE_TYPE + && INTEGRAL_TYPE_P (TREE_TYPE (arg.type)) && reg && REG_P (reg) - && GET_MODE (reg) == mode - && (GET_MODE_CLASS (mode) == MODE_INT - || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT) + && GET_MODE (reg) == arg.mode + && (GET_MODE_CLASS (arg.mode) == MODE_INT + || GET_MODE_CLASS (arg.mode) == MODE_PARTIAL_INT) && REG_P (x) && REGNO (x) == REGNO (reg) - && GET_MODE (x) == mode + && GET_MODE (x) == arg.mode && item) { machine_mode indmode - = TYPE_MODE (TREE_TYPE (argtype)); + = TYPE_MODE (TREE_TYPE (arg.type)); rtx mem = gen_rtx_MEM (indmode, x); cselib_val *val = cselib_lookup (mem, indmode, 0, VOIDmode); if (val && cselib_preserved_value_p (val))