From patchwork Fri Aug 6 17:41:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 61127 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 6B357B6F01 for ; Sat, 7 Aug 2010 03:42:14 +1000 (EST) Received: (qmail 27383 invoked by alias); 6 Aug 2010 17:42:11 -0000 Received: (qmail 27369 invoked by uid 22791); 6 Aug 2010 17:42:09 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 06 Aug 2010 17:42:02 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 4BEBACB0257; Fri, 6 Aug 2010 19:42:00 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sHVvGTVpL0T1; Fri, 6 Aug 2010 19:42:00 +0200 (CEST) Received: from adijon-256-1-25-207.w81-51.abo.wanadoo.fr (ADijon-256-1-25-207.w81-51.abo.wanadoo.fr [81.51.136.207]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id C2E88CB01E2; Fri, 6 Aug 2010 19:41:59 +0200 (CEST) From: Eric Botcazou To: Richard Henderson Subject: Re: [PATCH] Implement -fstack-usage option Date: Fri, 6 Aug 2010 19:41:55 +0200 User-Agent: KMail/1.9.9 Cc: gcc-patches@gcc.gnu.org References: <201008051742.05446.ebotcazou@adacore.com> <4C5B0D23.8010700@redhat.com> In-Reply-To: <4C5B0D23.8010700@redhat.com> MIME-Version: 1.0 Message-Id: <201008061941.55733.ebotcazou@adacore.com> 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 > Most of this looks fairly sane. Thanks. > This last line ought to add to the dynamic stack size instead. This makes sense indeed. > (And you're over-estimating by 1 minimal-stack-alignment-unit. ;-) I think that this is mitigated by not adding the word for the new return address slot; that's what I was trying to say in the comment. Here is a corrected version, attached. I've also added a testcase for this, as well as a generic one. * config/i386/i386.c (ix86_expand_prologue): Set stack usage info. testsuite/ * lib/gcc-dg.exp (cleanup-stack-usage): New procedure. * lib/scanasm.exp (scan-stack-usage): Likewise. (scan-stack-usage-not): Likewise. * gcc.dg/stack-usage-1.c: New test/ * gcc.target/i386/stack-usage-realign.c: Likewise. Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 162897) +++ config/i386/i386.c (working copy) @@ -9588,6 +9588,29 @@ ix86_expand_prologue (void) } allocate = frame.stack_pointer_offset - m->fs.sp_offset; + if (flag_stack_usage) + { + /* We start to count from ARG_POINTER. */ + HOST_WIDE_INT stack_size = frame.stack_pointer_offset; + + /* If it was realigned, take into account the fake frame. */ + if (stack_realign_drap) + { + if (ix86_static_chain_on_stack) + stack_size += UNITS_PER_WORD; + + if (!call_used_regs[REGNO (crtl->drap_reg)]) + stack_size += UNITS_PER_WORD; + + /* This over-estimates by 1 minimal-stack-alignment-unit but + mitigates that by counting in the new return address slot. */ + current_function_dynamic_stack_size + += crtl->stack_alignment_needed / BITS_PER_UNIT; + } + + current_function_static_stack_size = stack_size; + } + /* The stack has already been decremented by the instruction calling us so we need to probe unconditionally to preserve the protection area. */ if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK) Index: testsuite/lib/gcc-dg.exp =================================================================== --- testsuite/lib/gcc-dg.exp (revision 162897) +++ testsuite/lib/gcc-dg.exp (working copy) @@ -1,5 +1,5 @@ -# Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009 -# Free Software Foundation, Inc. +# Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009, +# 2010 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -460,6 +460,11 @@ proc cleanup-ipa-dump { suffix } { cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix" } +# Remove a stack usage file for the current test. +proc cleanup-stack-usage { args } { + cleanup-dump "su" +} + # Remove all dump files with the provided suffix. proc cleanup-dump { suffix } { # This assumes that we are three frames down from dg-test or some other Index: testsuite/lib/scanasm.exp =================================================================== --- testsuite/lib/scanasm.exp (revision 162897) +++ testsuite/lib/scanasm.exp (working copy) @@ -1,4 +1,5 @@ -# Copyright (C) 2000, 2002, 2003, 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 2000, 2002, 2003, 2007, 2008, 2010 +# Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -154,6 +155,28 @@ proc scan-file-not { output_file args } dg-scan "scan-file-not" 0 $testcase $output_file $args } +# Look for a pattern in the .su file produced by the compiler. See +# dg-scan for details. + +proc scan-stack-usage { args } { + upvar 2 name testcase + set testcase [lindex $testcase 0] + set output_file "[file rootname [file tail $testcase]].su" + + dg-scan "scan-file" 1 $testcase $output_file $args +} + +# Check that a pattern is not present in the .su file produced by the +# compiler. See dg-scan for details. + +proc scan-stack-usage-not { args } { + upvar 2 name testcase + set testcase [lindex $testcase 0] + set output_file "[file rootname [file tail $testcase]].su" + + dg-scan "scan-file-not" 0 $testcase $output_file $args +} + # Call pass if pattern is present given number of times, otherwise fail. proc scan-assembler-times { args } { if { [llength $args] < 2 } {