From patchwork Tue Nov 25 00:01:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 414181 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1350A140170 for ; Tue, 25 Nov 2014 11:01:18 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=LmNEdbsY7F/UztVmu1Age7TheLUxLpMet9fdkuEqj95 Hj6rnZ7VdgTAVXIioo+kn+6kqHAMGe12NsVsyRLgmxiZoSXsVm0ZHrpeRkt5uVI5 Gf2rNKHadwLpZWB3TyYKqkw6h5oE0UxS14TAbO7AH1WwkED596BFxucEopy7YdnI = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=bPSRURUshM8t/6gFoV1xPZmt8vw=; b=d1FH/T1FEUQlHn6H6 irKgGVw0OwB27EQKmea8xd3HyQms7JvZWjA1nujyDffwauCT9Vj4eFC5+HHTxUz9 GnqlNJ01RXo9FyzXcWIIeA6nsRUgqdvfUWc7asKa6SLkzC4OI7tHLyeZXY+oYPU0 j6MoPLzXpryv1jXiXJuKFIe4pw= Received: (qmail 3809 invoked by alias); 25 Nov 2014 00:01:11 -0000 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 Received: (qmail 3796 invoked by uid 89); 25 Nov 2014 00:01:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Nov 2014 00:01:08 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-03.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Xt3Z3-00000F-9n from Tom_deVries@mentor.com ; Mon, 24 Nov 2014 16:01:05 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-03.mgc.mentorg.com (137.202.0.108) with Microsoft SMTP Server id 14.3.181.6; Tue, 25 Nov 2014 00:01:03 +0000 Message-ID: <5473C6BD.6080108@mentor.com> Date: Tue, 25 Nov 2014 01:01:01 +0100 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Richard Biener CC: GCC Patches Subject: [PATCH] Add verify_sese Richard, I ran into a problem with my oacc kernels directive patch series where tail-merge added another entry into a region that was previously single-entry-single-exit. That resulted in hitting this assert in calc_dfs_tree: ... /* This aborts e.g. when there is _no_ path from ENTRY to EXIT at all. */ gcc_assert (di->nodes == (unsigned int) n_basic_blocks_for_fn (cfun) - 1); ... during a call to move_sese_region_to_fn. This patch makes sure that we abort earlier, with a clearer message of what is actually wrong. Bootstrapped and reg-tested on x86_64. OK for trunk/stage3? Thanks, - Tom 2014-11-23 Tom de Vries * tree-cfg.c (verify_sese): New function. (move_sese_region_to_fn): Call verify_sese. * tree-cfg.h (verify_sese): Declare. --- gcc/tree-cfg.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/tree-cfg.h | 1 + 2 files changed, 56 insertions(+) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index e78554f..db9f6c2 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -6870,6 +6870,58 @@ fixup_loop_arrays_after_move (struct function *fn1, struct function *fn2, fixup_loop_arrays_after_move (fn1, fn2, loop); } +DEBUG_FUNCTION void +verify_sese (basic_block entry, basic_block exit, vec *bbs_p) +{ + basic_block bb; + edge_iterator ei; + edge e; + bitmap bbs = BITMAP_ALLOC (NULL); + int i; + + gcc_assert (entry != NULL); + gcc_assert (entry != exit); + gcc_assert (bbs_p != NULL); + + gcc_assert (bbs_p->length () > 0); + + FOR_EACH_VEC_ELT (*bbs_p, i, bb) + bitmap_set_bit (bbs, bb->index); + + gcc_assert (bitmap_bit_p (bbs, entry->index)); + gcc_assert (exit == NULL || bitmap_bit_p (bbs, exit->index)); + + FOR_EACH_VEC_ELT (*bbs_p, i, bb) + { + if (bb == entry) + { + gcc_assert (single_pred_p (entry)); + gcc_assert (!bitmap_bit_p (bbs, single_pred (entry)->index)); + } + else + for (ei = ei_start (bb->preds); !ei_end_p (ei); ei_next (&ei)) + { + e = ei_edge (ei); + gcc_assert (bitmap_bit_p (bbs, e->src->index)); + } + + if (bb == exit) + { + gcc_assert (single_succ_p (exit)); + gcc_assert (!bitmap_bit_p (bbs, single_succ (exit)->index)); + } + else + for (ei = ei_start (bb->succs); !ei_end_p (ei); ei_next (&ei)) + { + e = ei_edge (ei); + gcc_assert (bitmap_bit_p (bbs, e->dest->index)); + } + } + + BITMAP_FREE (bbs); +} + + /* Move a single-entry, single-exit region delimited by ENTRY_BB and EXIT_BB to function DEST_CFUN. The whole region is replaced by a single basic block in the original CFG and the new basic block is @@ -6918,6 +6970,9 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb, bbs.create (0); bbs.safe_push (entry_bb); gather_blocks_in_sese_region (entry_bb, exit_bb, &bbs); +#ifdef ENABLE_CHECKING + verify_sese (entry_bb, exit_bb, &bbs); +#endif /* The blocks that used to be dominated by something in BBS will now be dominated by the new block. */ diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h index 626e973..d35e5ba 100644 --- a/gcc/tree-cfg.h +++ b/gcc/tree-cfg.h @@ -73,6 +73,7 @@ extern bool gimple_duplicate_sese_tail (edge, edge, basic_block *, unsigned, basic_block *); extern void gather_blocks_in_sese_region (basic_block entry, basic_block exit, vec *bbs_p); +extern void verify_sese (basic_block, basic_block, vec *); extern basic_block move_sese_region_to_fn (struct function *, basic_block, basic_block, tree); extern void dump_function_to_file (tree, FILE *, int); -- 1.9.1