From patchwork Thu Jun 10 21:40:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 55263 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 10F391007D1 for ; Fri, 11 Jun 2010 07:37:16 +1000 (EST) Received: (qmail 23054 invoked by alias); 10 Jun 2010 21:37:14 -0000 Received: (qmail 23045 invoked by uid 22791); 10 Jun 2010 21:37:13 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI X-Spam-Check-By: sourceware.org Received: from cantor.suse.de (HELO mx1.suse.de) (195.135.220.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 10 Jun 2010 21:37:08 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id E4CEF74609; Thu, 10 Jun 2010 23:37:05 +0200 (CEST) Date: Thu, 10 Jun 2010 23:40:06 +0200 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Richard Guenther , Jakub Jelinek Subject: [PATCH, PR 43905] Make IPA-SRA clone functions it modifies Message-ID: <20100610214006.GB3309@alvy.suse.cz> Mail-Followup-To: GCC Patches , Jan Hubicka , Richard Guenther , Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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 Hi, the patch below is basically a different fix to PR 43141 which fixes the still-opened PR 43905 and a number of issues that that first attempt caused (e.g. wrong sharing of parameter chain list and some debug info problems). After trying quite hard to move the body of a function from the old declaration to a new one and all necessary fixing up so that nothing breaks, I gave up and resorted to simple cloning. Fortunately the pass management works in a way that setting the cfun and current_function_decl to the new function is enough to make the subsequent passes work on the correct function. It is a bit of a hack, but I can't think of any substantial improvement. The patch also does not deal with same_body aliases. I hope it is not necessary. And that is what the patch does. I have bootstrapped and tested it on x86_64-linux with no problems. Is it OK for trunk and for 4.5 after a while? Thanks, Martin 2010-06-10 Martin Jambor PR tree-optimization/43905 * tree-sra.c (create_abstract_origin): Removed. (modify_function): Version the call graph node instead of creating abstract origins and dealing with same_body aliases. * testsuite/g++.dg/torture/pr43905.C Index: mine/gcc/tree-sra.c =================================================================== --- mine.orig/gcc/tree-sra.c +++ mine/gcc/tree-sra.c @@ -4224,43 +4224,38 @@ convert_callers (struct cgraph_node *nod return; } -/* Create an abstract origin declaration for OLD_DECL and make it an abstract - origin of the provided decl so that there are preserved parameters for debug - information. */ - -static void -create_abstract_origin (tree old_decl) -{ - if (!DECL_ABSTRACT_ORIGIN (old_decl)) - { - tree new_decl = copy_node (old_decl); - - DECL_ABSTRACT (new_decl) = 1; - SET_DECL_ASSEMBLER_NAME (new_decl, NULL_TREE); - SET_DECL_RTL (new_decl, NULL); - DECL_STRUCT_FUNCTION (new_decl) = NULL; - DECL_ARTIFICIAL (old_decl) = 1; - DECL_ABSTRACT_ORIGIN (old_decl) = new_decl; - } -} - /* Perform all the modification required in IPA-SRA for NODE to have parameters as given in ADJUSTMENTS. */ static void modify_function (struct cgraph_node *node, ipa_parm_adjustment_vec adjustments) { - struct cgraph_node *alias; - for (alias = node->same_body; alias; alias = alias->next) - ipa_modify_formal_parameters (alias->decl, adjustments, "ISRA"); - /* current_function_decl must be handled last, after same_body aliases, - as following functions will use what it computed. */ - create_abstract_origin (current_function_decl); + struct cgraph_node *new_node; + struct cgraph_edge *cs; + VEC (cgraph_edge_p, heap) * redirect_callers; + int node_callers; + + node_callers = 0; + for (cs = node->callers; cs != NULL; cs = cs->next_caller) + node_callers++; + redirect_callers = VEC_alloc (cgraph_edge_p, heap, node_callers); + for (cs = node->callers; cs != NULL; cs = cs->next_caller) + VEC_quick_push (cgraph_edge_p, redirect_callers, cs); + + rebuild_cgraph_edges (); + pop_cfun (); + current_function_decl = NULL_TREE; + + new_node = cgraph_function_versioning (node, redirect_callers, NULL, NULL, + NULL, NULL, "isra"); + current_function_decl = new_node->decl; + push_cfun (DECL_STRUCT_FUNCTION (new_node->decl)); + ipa_modify_formal_parameters (current_function_decl, adjustments, "ISRA"); ipa_sra_modify_function_body (adjustments); sra_ipa_reset_debug_stmts (adjustments); - convert_callers (node, adjustments); - cgraph_make_node_local (node); + convert_callers (new_node, adjustments); + cgraph_make_node_local (new_node); return; } Index: mine/gcc/testsuite/g++.dg/torture/pr43905.C =================================================================== --- /dev/null +++ mine/gcc/testsuite/g++.dg/torture/pr43905.C @@ -0,0 +1,13 @@ +extern void sf ( __const char *); +struct Matrix{ + int operator[](int n){ + sf ( __PRETTY_FUNCTION__); + } + int operator[](int n)const{ + sf ( __PRETTY_FUNCTION__); + } +}; +void calcmy(Matrix const &b, Matrix &c, int k){ + b[k]; + c[k]; +}