From patchwork Mon Aug 16 20:42:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61837 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 DE212B70D0 for ; Tue, 17 Aug 2010 06:42:24 +1000 (EST) Received: (qmail 9617 invoked by alias); 16 Aug 2010 20:42:22 -0000 Received: (qmail 9605 invoked by uid 22791); 16 Aug 2010 20:42:20 -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:42:14 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7GKgDls014906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 16 Aug 2010 16:42:13 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7GKgCSo006923 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 16 Aug 2010 16:42:12 -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 o7GKgRK9032543 for ; Mon, 16 Aug 2010 22:42:27 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o7GKgRq9032541 for gcc-patches@gcc.gnu.org; Mon, 16 Aug 2010 22:42:27 +0200 Date: Mon, 16 Aug 2010 22:42:27 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up sorting of block fragments Message-ID: <20100816204227.GA702@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline 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 Hi! This is just a small snippet from the "make .debug_loc smaller" patch which was deferred because of questions whether it doesn't make debug info quality worse. This snippet makes sure that block fragments in DW_AT_ranges go, at least within the same section, with ascending PCs, compared to weirdo order GCC has been emitting up to now (lowest PC fragment first, then highest PC fragment and following fragments with decreasing PC). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 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. Jakub --- gcc/function.c.jj 2010-02-26 16:58:08.000000000 +0100 +++ gcc/function.c 2010-03-21 17:41:29.000000000 +0100 @@ -3808,6 +3808,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, decl, next; + for (decl = t; decl; decl = next) + { + next = BLOCK_FRAGMENT_CHAIN (decl); + BLOCK_FRAGMENT_CHAIN (decl) = prev; + prev = decl; + } + 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, decl, next; + for (decl = t; decl; decl = next) + { + next = BLOCK_CHAIN (decl); + BLOCK_CHAIN (decl) = prev; + BLOCK_SUBBLOCKS (decl) = blocks_nreverse_all (BLOCK_SUBBLOCKS (decl)); + if (BLOCK_FRAGMENT_CHAIN (decl) + && BLOCK_FRAGMENT_ORIGIN (decl) == NULL_TREE) + BLOCK_FRAGMENT_CHAIN (decl) + = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (decl)); + prev = decl; + } + 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 @@ -3834,7 +3874,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); } @@ -3866,9 +3906,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. */ @@ -3905,8 +3944,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); } }