From patchwork Mon Aug 19 15:24:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1149347 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-507271-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="F7+Yvv2P"; 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 46ByQs0LcYz9s3Z for ; Tue, 20 Aug 2019 01:24:51 +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=XDI7EBd/agKuIQ4NatKTGpbsAtXnh NbDp/4VJyGAob17Bza7/WiJ0+ZiVuAYaOJW55qlU5aLUto6Jq7UdyeSE/49kmpxL YbXfLTsaFGghf3XQjvDzOQNhkvfFh/5jD2cg3dWhTigj9QrgPPizdkt0B7f5urzQ fhzZJ+pAcxu6bA= 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=9JD5MDElAtrMtS40G6hVN5b67l4=; b=F7+ Yvv2PsS0WmDcIyKZ+NcKcz6EU6gLyaw3NNSkafiROdBOKbf1dt04CXcJ/bj9K7TE sWEXZI30dWg7RhxjvpZWxHKp48aFw3r4PKGrFm3GrlZANaTeZ3v7vLOZcVBZfnAO psO8J0H4I+4MLKA0wHH8DnUnK/orvLJiRNPll9QY= Received: (qmail 32793 invoked by alias); 19 Aug 2019 15:24:42 -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 32485 invoked by uid 89); 19 Aug 2019 15:24:23 -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= 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:24:22 +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 797B1344 for ; Mon, 19 Aug 2019 08:24:20 -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 217A73F718 for ; Mon, 19 Aug 2019 08:24:20 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [13/13] Add a pass_by_reference flag to function_arg_info References: Date: Mon, 19 Aug 2019 16:24:18 +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 flag that tells targets whether an argument has been converted to pass-by-reference form. This replaces assign_parm_data_one::passed_pointer in function.c. The flag is set automatically for places that call apply_pass_by_reference_rules. Places that apply pass-by-reference manually need to set it themselves. (After previous changes, no targets apply pass-by-reference manually. They all go through apply_pass_by_reference_rules.) 2019-08-19 Richard Sandiford gcc/ * calls.h (function_arg_info): Add a pass_by_reference field, defaulting to false. * calls.c (apply_pass_by_reference_rules): Set pass_by_reference when applying pass-by-reference semantics. (initialize_argument_information): Likewise. (emit_library_call_value_1): Likewise. * function.c (assign_parm_data_one): Remove passed_pointer field. (assign_parm_find_data_types): Don't set it. (assign_parm_find_stack_rtl, assign_parm_adjust_stack_rtl) (assign_parm_setup_reg, assign_parms, gimplify_parameters): Use arg.pass_by_reference instead of passed_pointer. Index: gcc/calls.h =================================================================== --- gcc/calls.h 2019-08-19 15:59:09.801778220 +0100 +++ gcc/calls.h 2019-08-19 15:59:21.817691272 +0100 @@ -34,21 +34,25 @@ #define GCC_CALLS_H class function_arg_info { public: - function_arg_info () : type (NULL_TREE), mode (VOIDmode), named (false) {} + function_arg_info () + : type (NULL_TREE), mode (VOIDmode), named (false), + pass_by_reference (false) + {} /* Initialize an argument of mode MODE, either before or after promotion. */ function_arg_info (machine_mode mode, bool named) - : type (NULL_TREE), mode (mode), named (named) + : type (NULL_TREE), mode (mode), named (named), pass_by_reference (false) {} /* Initialize an unpromoted argument of type TYPE. */ function_arg_info (tree type, bool named) - : type (type), mode (TYPE_MODE (type)), named (named) + : type (type), mode (TYPE_MODE (type)), named (named), + pass_by_reference (false) {} /* Initialize an argument with explicit properties. */ function_arg_info (tree type, machine_mode mode, bool named) - : type (type), mode (mode), named (named) + : type (type), mode (mode), named (named), pass_by_reference (false) {} /* Return true if the gimple-level type is an aggregate. */ @@ -100,6 +104,10 @@ #define GCC_CALLS_H treated as an unnamed variadic argument (i.e. one passed through "..."). See also TARGET_STRICT_ARGUMENT_NAMING. */ unsigned int named : 1; + + /* True if we have decided to pass the argument by reference, in which case + the function_arg_info describes a pointer to the original argument. */ + unsigned int pass_by_reference : 1; }; extern int flags_from_decl_or_type (const_tree); Index: gcc/calls.c =================================================================== --- gcc/calls.c 2019-08-19 15:59:18.145717843 +0100 +++ gcc/calls.c 2019-08-19 15:59:21.817691272 +0100 @@ -946,6 +946,7 @@ apply_pass_by_reference_rules (CUMULATIV { arg.type = build_pointer_type (arg.type); arg.mode = TYPE_MODE (arg.type); + arg.pass_by_reference = true; return true; } return false; @@ -2125,6 +2126,7 @@ initialize_argument_information (int num "argument must be passed" " by copying"); } + arg.pass_by_reference = true; } unsignedp = TYPE_UNSIGNED (type); @@ -4957,6 +4959,7 @@ emit_library_call_value_1 (int retval, r call_fusage); arg.mode = Pmode; + arg.pass_by_reference = true; val = force_operand (XEXP (slot, 0), NULL_RTX); } Index: gcc/function.c =================================================================== --- gcc/function.c 2019-08-19 15:59:14.297745685 +0100 +++ gcc/function.c 2019-08-19 15:59:21.821691241 +0100 @@ -2271,7 +2271,6 @@ struct assign_parm_data_one machine_mode passed_mode; struct locate_and_pad_arg_data locate; int partial; - BOOL_BITFIELD passed_pointer : 1; }; /* A subroutine of assign_parms. Initialize ALL. */ @@ -2453,7 +2452,6 @@ assign_parm_find_data_types (struct assi if (apply_pass_by_reference_rules (&all->args_so_far_v, data->arg)) { data->nominal_type = data->arg.type; - data->passed_pointer = true; data->passed_mode = data->nominal_mode = data->arg.mode; } @@ -2653,7 +2651,7 @@ assign_parm_find_stack_rtl (tree parm, s stack_parm = gen_rtx_PLUS (Pmode, stack_parm, offset_rtx); stack_parm = gen_rtx_MEM (data->arg.mode, stack_parm); - if (!data->passed_pointer) + if (!data->arg.pass_by_reference) { set_mem_attributes (stack_parm, parm, 1); /* set_mem_attributes could set MEM_SIZE to the passed mode's size, @@ -2812,7 +2810,7 @@ assign_parm_adjust_stack_rtl (struct ass pointers in their passed stack slots. */ else if (crtl->stack_protect_guard && (flag_stack_protect == 2 - || data->passed_pointer + || data->arg.pass_by_reference || POINTER_TYPE_P (data->nominal_type))) stack_parm = NULL; @@ -3125,7 +3123,7 @@ assign_parm_setup_reg (struct assign_par /* If this was an item that we received a pointer to, set rtl appropriately. */ - if (data->passed_pointer) + if (data->arg.pass_by_reference) { rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data->arg.type)), parmreg); set_mem_attributes (rtl, parm, 1); @@ -3295,7 +3293,7 @@ assign_parm_setup_reg (struct assign_par /* If we were passed a pointer but the actual value can safely live in a register, retrieve it and use it directly. */ - if (data->passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode) + if (data->arg.pass_by_reference && TYPE_MODE (TREE_TYPE (parm)) != BLKmode) { /* We can't use nominal_mode, because it will have been set to Pmode above. We must use the actual mode of the parm. */ @@ -3615,7 +3613,7 @@ assign_parms (tree fndecl) assign_parm_adjust_entry_rtl (&data); } /* Record permanently how this parm was passed. */ - if (data.passed_pointer) + if (data.arg.pass_by_reference) { rtx incoming_rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data.arg.type)), @@ -3629,7 +3627,7 @@ assign_parms (tree fndecl) if (assign_parm_setup_block_p (&data)) assign_parm_setup_block (&all, parm, &data); - else if (data.passed_pointer || use_register_for_decl (parm)) + else if (data.arg.pass_by_reference || use_register_for_decl (parm)) assign_parm_setup_reg (&all, parm, &data); else assign_parm_setup_stack (&all, parm, &data); @@ -3840,7 +3838,7 @@ gimplify_parameters (gimple_seq *cleanup gimplify_one_sizepos (&DECL_SIZE_UNIT (parm), &stmts); } - if (data.passed_pointer) + if (data.arg.pass_by_reference) { tree type = TREE_TYPE (data.arg.type); function_arg_info orig_arg (type, data.arg.named);