From patchwork Mon Aug 16 20:57:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61841 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 28BC3B6F01 for ; Tue, 17 Aug 2010 06:57:42 +1000 (EST) Received: (qmail 20351 invoked by alias); 16 Aug 2010 20:57:41 -0000 Received: (qmail 20342 invoked by uid 22791); 16 Aug 2010 20:57:40 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 16 Aug 2010 20:57:35 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7GKvRYo022090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 16 Aug 2010 16:57:27 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7GKvQXX027318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 16 Aug 2010 16:57:27 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o7GKvgWi032598; Mon, 16 Aug 2010 22:57:42 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o7GKvghC032597; Mon, 16 Aug 2010 22:57:42 +0200 Date: Mon, 16 Aug 2010 22:57:42 +0200 From: Jakub Jelinek To: Nathan Froyd Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up sorting of block fragments (take 2) Message-ID: <20100816205742.GD702@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek References: <20100816204227.GA702@tyan-ft48-01.lab.bos.redhat.com> <20100816204759.GK25394@codesourcery.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100816204759.GK25394@codesourcery.com> User-Agent: Mutt/1.5.20 (2009-12-10) 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 On Mon, Aug 16, 2010 at 01:47:59PM -0700, Nathan Froyd wrote: > On Mon, Aug 16, 2010 at 10:42:27PM +0200, Jakub Jelinek wrote: > > * function.c (block_fragments_nreverse, blocks_nreverse_all): New > > functions. > > (reorder_blocks): Use blocks_nreverse_all instead of blocks_nreverse. > > (reorder_blocks_1): Assert BLOCK_FRAGMENT_ORIGIN is NULL. Don't > > call block_nreverse here. > > > > +/* Reverse the order of elements in the fragment chain T of blocks, > > + and return the new head of the chain (old last element). */ > > + > > +static tree > > +block_fragments_nreverse (tree t) > > +{ > > + tree prev = 0, decl, next; > > Can we use `block' instead of `decl' here and in blocks_nreverse_all? Sure, good idea. That decl in there came from blocks_nreverse, patch below adjusts that function too. 2010-08-16 Jakub Jelinek * function.c (block_fragments_nreverse, blocks_nreverse_all): New functions. (reorder_blocks): Use blocks_nreverse_all instead of blocks_nreverse. (reorder_blocks_1): Assert BLOCK_FRAGMENT_ORIGIN is NULL. Don't call block_nreverse here. (blocks_nreverse): Rename decl temporary to block. Jakub --- gcc/function.c.jj 2010-02-26 16:58:08.000000000 +0100 +++ gcc/function.c 2010-03-21 17:41:29.000000000 +0100 @@ -3953,6 +3953,46 @@ generate_setjmp_warnings (void) } +/* Reverse the order of elements in the fragment chain T of blocks, + and return the new head of the chain (old last element). */ + +static tree +block_fragments_nreverse (tree t) +{ + tree prev = 0, block, next; + for (block = t; block; block = next) + { + next = BLOCK_FRAGMENT_CHAIN (block); + BLOCK_FRAGMENT_CHAIN (block) = prev; + prev = block; + } + return prev; +} + +/* Reverse the order of elements in the chain T of blocks, + and return the new head of the chain (old last element). + Also do the same on subblocks and reverse the order of elements + in BLOCK_FRAGMENT_CHAIN as well. */ + +static tree +blocks_nreverse_all (tree t) +{ + tree prev = 0, block, next; + for (block = t; block; block = next) + { + next = BLOCK_CHAIN (block); + BLOCK_CHAIN (block) = prev; + BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block)); + if (BLOCK_FRAGMENT_CHAIN (block) + && BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE) + BLOCK_FRAGMENT_CHAIN (block) + = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (block)); + prev = block; + } + return prev; +} + + /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END}, and create duplicate blocks. */ /* ??? Need an option to either create block fragments or to create @@ -3979,7 +4019,7 @@ reorder_blocks (void) /* Recreate the block tree from the note nesting. */ reorder_blocks_1 (get_insns (), block, &block_stack); - BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block)); + BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block)); VEC_free (tree, heap, block_stack); } @@ -4011,9 +4051,8 @@ reorder_blocks_1 (rtx insns, tree curren tree block = NOTE_BLOCK (insn); tree origin; - origin = (BLOCK_FRAGMENT_ORIGIN (block) - ? BLOCK_FRAGMENT_ORIGIN (block) - : block); + gcc_assert (BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE); + origin = block; /* If we have seen this block before, that means it now spans multiple address regions. Create a new fragment. */ @@ -4050,8 +4089,6 @@ reorder_blocks_1 (rtx insns, tree curren else if (NOTE_KIND (insn) == NOTE_INSN_BLOCK_END) { NOTE_BLOCK (insn) = VEC_pop (tree, *p_block_stack); - BLOCK_SUBBLOCKS (current_block) - = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); current_block = BLOCK_SUPERCONTEXT (current_block); } } @@ -4064,12 +4101,12 @@ reorder_blocks_1 (rtx insns, tree curren tree blocks_nreverse (tree t) { - tree prev = 0, decl, next; - for (decl = t; decl; decl = next) + tree prev = 0, block, next; + for (block = t; block; block = next) { - next = BLOCK_CHAIN (decl); - BLOCK_CHAIN (decl) = prev; - prev = decl; + next = BLOCK_CHAIN (block); + BLOCK_CHAIN (block) = prev; + prev = block; } return prev; }