From patchwork Mon Nov 11 14:33:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 290315 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2A1AD2C00AD for ; Tue, 12 Nov 2013 01:36:46 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:subject:to:date:from:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=pnWOc81EmlbllWed 6kwdEaEJQtoCwa0tGSfJtqyKJk46yx/C4ezMTcnkBU+RbgR04UD/uTJw4mgTWakG 2opM8Rm2+zu6v6eSXmkGneNtbkNOdasGjuxljW3KZAL6Sysmpw1kN7qpiS1A9xL8 +p9G2AL6IPQefMIQKZ1yh/c5srw= 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 :message-id:subject:to:date:from:mime-version:content-type :content-transfer-encoding; s=default; bh=NAhCACIIYZjucOI1l08c36 UrZs0=; b=FL/SBmqXl1B+nsMEQm4GLrf7H1eM/d+moAXs1dW7OPpVMvkzK8+yNw selQ2KezGBMCTATCFHpEQV7b12DvcD6FtsJJ4kMLsgZlB9GZdkrp8fNbqyQA01BW 5pUMCDGmw9T4QOi4C9fRC/jkvuEVSE3y0LnuSL3U1cc5BUAwA/ES4= Received: (qmail 22572 invoked by alias); 11 Nov 2013 14:36:03 -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 22548 invoked by uid 89); 11 Nov 2013 14:36:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, MSGID_FROM_MTA_HEADER, RDNS_NONE, SPF_PASS autolearn=no version=3.3.2 X-HELO: e06smtp17.uk.ibm.com Received: from Unknown (HELO e06smtp17.uk.ibm.com) (195.75.94.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 11 Nov 2013 14:34:59 +0000 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Nov 2013 14:34:49 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 11 Nov 2013 14:34:47 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 599F72190068 for ; Mon, 11 Nov 2013 14:34:47 +0000 (GMT) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rABEXJgP60686578 for ; Mon, 11 Nov 2013 14:33:19 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rABEXVw5018043 for ; Mon, 11 Nov 2013 07:33:31 -0700 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with SMTP id rABEXTs3017904 for ; Mon, 11 Nov 2013 07:33:29 -0700 Message-Id: <201311111433.rABEXTs3017904@d06av02.portsmouth.uk.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Mon, 11 Nov 2013 15:33:29 +0100 Subject: [PATCH] Avoid duplicate calls to REG_PARM_STACK_SPACE To: gcc-patches@gcc.gnu.org Date: Mon, 11 Nov 2013 15:33:29 +0100 (CET) From: "Ulrich Weigand" MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13111114-0542-0000-0000-00000706BEF2 Hello, this is another tweak to the middle-end to help support the new powerpc64le-linux ABI. In the new ABI, we make a distinction between functions that pass all arguments solely in registers, and those that do not. Only when calling one the latter type (or a varags routine) does the caller need to provide REG_PARM_STACK_SPACE; in the former case, this can be omitted to save stack space. This leads to a definition of REG_PARM_STACK_SPACE that is a lot more complex than usual, which means it would be helpful if the middle-end were to evaluate it sparingly (e.g. once per function definition / call). The middle-end already does cache REG_PARM_STACK_SPACE results, however, this cache it not consistently used. In particular, the locate_and_pad_parm routine will re-evaluate the macro every time it is called, even though all callers of the routine already have a cached copy. This patch adds a new argument to locate_and_pad_parm which is used instead of evaluating REG_PARM_STACK_SPACE, and updates the callers to pass in the correct value. There should be no change in generated code on any platform. Tested on powerpc64-linux and powerpc64le-linux. OK for mainline? Bye, Ulrich 2013-11-11 Ulrich Weigand Alan Modra ChangeLog: * function.c (assign_parms): Use all.reg_parm_stack_space instead of re-evaluating REG_PARM_STACK_SPACE target macro. (locate_and_pad_parm): New parameter REG_PARM_STACK_SPACE. Use it instead of evaluating target macro REG_PARM_STACK_SPACE every time. (assign_parm_find_entry_rtl): Update call. * calls.c (initialize_argument_information): Update call. (emit_library_call_value_1): Likewise. * expr.h (locate_and_pad_parm): Update prototype. Index: gcc/gcc/expr.h =================================================================== --- gcc.orig/gcc/expr.h +++ gcc/gcc/expr.h @@ -521,8 +521,8 @@ extern rtx expand_divmod (int, enum tree rtx, int); #endif -extern void locate_and_pad_parm (enum machine_mode, tree, int, int, tree, - struct args_size *, +extern void locate_and_pad_parm (enum machine_mode, tree, int, int, int, + tree, struct args_size *, struct locate_and_pad_arg_data *); /* Return the CODE_LABEL rtx for a LABEL_DECL, creating it if necessary. */ Index: gcc/gcc/calls.c =================================================================== --- gcc.orig/gcc/calls.c +++ gcc/gcc/calls.c @@ -1326,6 +1326,7 @@ initialize_argument_information (int num #else args[i].reg != 0, #endif + reg_parm_stack_space, args[i].pass_on_stack ? 0 : args[i].partial, fndecl, args_size, &args[i].locate); #ifdef BLOCK_REG_PADDING @@ -3736,7 +3737,8 @@ emit_library_call_value_1 (int retval, r #else argvec[count].reg != 0, #endif - 0, NULL_TREE, &args_size, &argvec[count].locate); + reg_parm_stack_space, 0, + NULL_TREE, &args_size, &argvec[count].locate); if (argvec[count].reg == 0 || argvec[count].partial != 0 || reg_parm_stack_space > 0) @@ -3823,7 +3825,7 @@ emit_library_call_value_1 (int retval, r #else argvec[count].reg != 0, #endif - argvec[count].partial, + reg_parm_stack_space, argvec[count].partial, NULL_TREE, &args_size, &argvec[count].locate); args_size.constant += argvec[count].locate.size.constant; gcc_assert (!argvec[count].locate.size.var); Index: gcc/gcc/function.c =================================================================== --- gcc.orig/gcc/function.c +++ gcc/gcc/function.c @@ -2523,6 +2523,7 @@ assign_parm_find_entry_rtl (struct assig } locate_and_pad_parm (data->promoted_mode, data->passed_type, in_regs, + all->reg_parm_stack_space, entry_parm ? data->partial : 0, current_function_decl, &all->stack_args_size, &data->locate); @@ -3511,11 +3512,7 @@ assign_parms (tree fndecl) /* Adjust function incoming argument size for alignment and minimum length. */ -#ifdef REG_PARM_STACK_SPACE - crtl->args.size = MAX (crtl->args.size, - REG_PARM_STACK_SPACE (fndecl)); -#endif - + crtl->args.size = MAX (crtl->args.size, all.reg_parm_stack_space); crtl->args.size = CEIL_ROUND (crtl->args.size, PARM_BOUNDARY / BITS_PER_UNIT); @@ -3719,6 +3716,9 @@ gimplify_parameters (void) IN_REGS is nonzero if the argument will be passed in registers. It will never be set if REG_PARM_STACK_SPACE is not defined. + REG_PARM_STACK_SPACE is the number of bytes of stack space reserved + for arguments which are passed in registers. + FNDECL is the function in which the argument was defined. There are two types of rounding that are done. The first, controlled by @@ -3739,19 +3739,16 @@ gimplify_parameters (void) void locate_and_pad_parm (enum machine_mode passed_mode, tree type, int in_regs, - int partial, tree fndecl ATTRIBUTE_UNUSED, + int reg_parm_stack_space, int partial, + tree fndecl ATTRIBUTE_UNUSED, struct args_size *initial_offset_ptr, struct locate_and_pad_arg_data *locate) { tree sizetree; enum direction where_pad; unsigned int boundary, round_boundary; - int reg_parm_stack_space = 0; int part_size_in_regs; -#ifdef REG_PARM_STACK_SPACE - reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl); - /* If we have found a stack parm before we reach the end of the area reserved for registers, skip that area. */ if (! in_regs) @@ -3769,7 +3766,6 @@ locate_and_pad_parm (enum machine_mode p initial_offset_ptr->constant = reg_parm_stack_space; } } -#endif /* REG_PARM_STACK_SPACE */ part_size_in_regs = (reg_parm_stack_space == 0 ? partial : 0); @@ -3832,11 +3828,7 @@ locate_and_pad_parm (enum machine_mode p locate->slot_offset.constant += part_size_in_regs; - if (!in_regs -#ifdef REG_PARM_STACK_SPACE - || REG_PARM_STACK_SPACE (fndecl) > 0 -#endif - ) + if (!in_regs || reg_parm_stack_space > 0) pad_to_arg_alignment (&locate->slot_offset, boundary, &locate->alignment_pad); @@ -3856,11 +3848,7 @@ locate_and_pad_parm (enum machine_mode p pad_below (&locate->offset, passed_mode, sizetree); #else /* !ARGS_GROW_DOWNWARD */ - if (!in_regs -#ifdef REG_PARM_STACK_SPACE - || REG_PARM_STACK_SPACE (fndecl) > 0 -#endif - ) + if (!in_regs || reg_parm_stack_space > 0) pad_to_arg_alignment (initial_offset_ptr, boundary, &locate->alignment_pad); locate->slot_offset = *initial_offset_ptr;