From patchwork Tue Apr 3 21:18:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 150548 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 6B2CEB6FE3 for ; Wed, 4 Apr 2012 07:19:01 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1334092742; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=FZNmCNd iEmtrvPk15G9r0uztLyU=; b=r0gxn9EQmQWC2HqhEF5A0GPzKgr9c4MbzfvxRs9 tyliom8CwwAzDBcgfHNJwHsSe9eOkW2CGUtKTo41g+CAsLlxCnvk3nDOOIYFVutB poZBbbouL6E8YjHelx1c4pT3e3toP1Yvt75RJegtaHXmekxAvtoNuxvknbrACtQF ZLHk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=NEPd/3n41SWTNl5s8J6uOQ+Zi1E0/q/TJiQJdAQAqH5A1PG0eJXeKODldZO01E gKTpFtgOLKercOKF8Ex7Qgigpdyy5dCUIvbxOgI8waBFvLA0tlGLR3P4/MagLU6Q ro5eGamNr84nm2jtUbsiaRH0U3CwMa3gWhUfDl9SHsFRA=; Received: (qmail 28720 invoked by alias); 3 Apr 2012 21:18:55 -0000 Received: (qmail 28535 invoked by uid 22791); 3 Apr 2012 21:18:52 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 03 Apr 2012 21:18:31 +0000 Received: from [192.168.178.22] (port-92-204-114-63.dynamic.qsc.de [92.204.114.63]) by mx02.qsc.de (Postfix) with ESMTP id 931F21E532; Tue, 3 Apr 2012 23:18:28 +0200 (CEST) Message-ID: <4F7B6924.7010003@net-b.de> Date: Tue, 03 Apr 2012 23:18:28 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120312 Thunderbird/11.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PRs 52751/40973 - don't set TREE_PUBLIC for PRIVATE module procs/vars 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 Dear all, the attached patch only sets TREE_PUBLIC for module variables and module procedures which have neither the PRIVATE attribute nor a C-binding label. Seemingly, only NAG f95 does this for module variables and none of my compilers does this for module procedures. The main effect of this patch is a code size reduction as the compiler might (even without -fwhole-program -flto) optimize unused variables/procedures away. Additionally, the compiler might inline code which it otherwise wouldn't do (due to the code size increase) or do optimizations based on the value of the module variables (though, GCC has room for improvement for optimizing static variables.) Note: For C-binding variables without binding label ("bind(C, name='')"), I don't use DECL_COMMON. That should be okay as DECL_COMMON is only used to make sure that a variable can be initialized from either C or Fortran. But without binding name, that's not possible from C, hence, that's fine. Build and regtested on x86-64-linux. (And currently regtesting again - after a minor modification.) OK for the trunk? Tobias 2012-04-03 Tobias Burnus PR fortran/52751 * trans-decl.c (gfc_finish_var_decl): Don't set TREE_PUBLIC for PRIVATE module variables without C-binding label. PR fortran/40973 * trans-decl.c (build_function_decl): Ditto for procedures. 2012-04-03 Tobias Burnus PR fortran/40973 PR fortran/52751 * gfortran.dg/public_private_module_2.f90: New. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 8a1dd2e..23cf052 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -539,7 +539,7 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym) if (sym->attr.cray_pointee) return; - if(sym->attr.is_bind_c == 1) + if(sym->attr.is_bind_c == 1 && sym->binding_label) { /* We need to put variables that are bind(c) into the common segment of the object file, because this is what C would do. @@ -565,7 +565,8 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym) /* TODO: Don't set sym->module for result or dummy variables. */ gcc_assert (current_function_decl == NULL_TREE || sym->result == sym); /* This is the declaration of a module variable. */ - TREE_PUBLIC (decl) = 1; + if (sym->attr.access != ACCESS_PRIVATE) + TREE_PUBLIC (decl) = 1; TREE_STATIC (decl) = 1; } @@ -1842,7 +1857,8 @@ build_function_decl (gfc_symbol * sym, bool global) DECL_EXTERNAL (fndecl) = 0; if (!current_function_decl - && !sym->attr.entry_master && !sym->attr.is_main_program) + && !sym->attr.entry_master && !sym->attr.is_main_program + && (sym->attr.access != ACCESS_PRIVATE || sym->binding_label)) TREE_PUBLIC (fndecl) = 1; attributes = add_attributes_to_decl (attr, NULL_TREE); --- /dev/null 2012-03-22 21:06:43.387787737 +0100 +++ gcc/gcc/testsuite/gfortran.dg/public_private_module_2.f90 2012-04-03 23:02:59.000000000 +0200 @@ -0,0 +1,70 @@ +! { dg-do compile } +! { dg-options "-O2" } +! +! PR fortran/52751 (top, "module mod") +! PR fortran/40973 (bottom, "module m" +! +! Ensure that (only) those module variables and procedures which are PRIVATE +! and have no C-binding label are optimized away. +! + module mod + integer :: aa + integer, private :: iii + integer, private, bind(C) :: jj ! { dg-warning "PRIVATE but has been given the binding label" } + integer, private, bind(C,name='lll') :: kk ! { dg-warning "PRIVATE but has been given the binding label" } + integer, private, bind(C,name='') :: mmmm + integer, bind(C) :: nnn + integer, bind(C,name='oo') :: pp + integer, bind(C,name='') :: qq + end module mod + + ! { dg-final { scan-assembler "__mod_MOD_aa" } } + ! { dg-final { scan-assembler-not "iii" } } + ! { dg-final { scan-assembler "jj" } } + ! { dg-final { scan-assembler "lll" } } + ! { dg-final { scan-assembler-not "kk" } } + ! { dg-final { scan-assembler-not "mmmm" } } + ! { dg-final { scan-assembler "nnn" } } + ! { dg-final { scan-assembler "oo" } } + ! { dg-final { scan-assembler "__mod_MOD_qq" } } + +MODULE M + PRIVATE :: two, three, four, six + PUBLIC :: one, seven, eight, ten +CONTAINS + SUBROUTINE one(a) + integer :: a + a = two() + END SUBROUTINE one + integer FUNCTION two() + two = 42 + END FUNCTION two + integer FUNCTION three() bind(C) ! { dg-warning "PRIVATE but has been given the binding label" } + three = 43 + END FUNCTION three + integer FUNCTION four() bind(C, name='five') ! { dg-warning "PRIVATE but has been given the binding label" } + four = 44 + END FUNCTION four + integer FUNCTION six() bind(C, name='') + six = 46 + END FUNCTION six + integer FUNCTION seven() bind(C) + seven = 46 + END FUNCTION seven + integer FUNCTION eight() bind(C, name='nine') + eight = 48 + END FUNCTION eight + integer FUNCTION ten() bind(C, name='') + ten = 48 + END FUNCTION ten +END MODULE + +! { dg-final { scan-assembler "__m_MOD_one" } } +! { dg-final { scan-assembler-not "two" } } +! { dg-final { scan-assembler "three" } } +! { dg-final { scan-assembler-not "four" } } +! { dg-final { scan-assembler "five" } } +! { dg-final { scan-assembler-not "six" } } +! { dg-final { scan-assembler "seven" } } +! { dg-final { scan-assembler "nine" } } +! { dg-final { scan-assembler "__m_MOD_ten" } }