From patchwork Sat Aug 27 21:27:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 1105272 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7RLQf4k032290 for ; Sat, 27 Aug 2011 21:27:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751666Ab1H0V1X (ORCPT ); Sat, 27 Aug 2011 17:27:23 -0400 Received: from mail-pz0-f42.google.com ([209.85.210.42]:60269 "EHLO mail-pz0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751608Ab1H0V1W (ORCPT ); Sat, 27 Aug 2011 17:27:22 -0400 Received: by pzk37 with SMTP id 37so6219152pzk.1 for ; Sat, 27 Aug 2011 14:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:date:from:x-x-sender:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=y9uHXKvqnCUH44WrkXErLtDa2jK0LmQ6Edw/u/Ed0rI=; b=da8wN0UHCtA33554bUQSjl3tKXOG19vLlN38jALgKoh2DetFpO+TRH4DKpopkqv+Js n+0kr6frKo+UYuOYwQCXP2B9fCvvhoMvOLnR+Z0mxwbB0U+Jm8Ts4/QfTUte6hB1gdlc 2HwVXKQaAW56p/IwN1geoMit1zfoH2A/Czf4A= Received: by 10.143.92.20 with SMTP id u20mr1352123wfl.206.1314480442228; Sat, 27 Aug 2011 14:27:22 -0700 (PDT) Received: from [192.168.1.87] (c-24-22-0-219.hsd1.or.comcast.net. [24.22.0.219]) by mx.google.com with ESMTPS id y5sm9019882pbq.12.2011.08.27.14.27.20 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 27 Aug 2011 14:27:21 -0700 (PDT) Date: Sat, 27 Aug 2011 14:27:19 -0700 (PDT) From: Linus Torvalds X-X-Sender: torvalds@i5.linux-foundation.org To: Sparse Mailing-list , Christopher Li , Josh Triplett cc: Pekka Enberg , Jeff Garzik Subject: [PATCH 1/3] Make 'linearize_iterator()' helper function In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (LFD 1266 2009-07-14) MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 27 Aug 2011 21:27:23 +0000 (UTC) From: Linus Torvalds Date: Sat, 27 Aug 2011 11:30:31 -0700 Subject: [PATCH 1/3] Make 'linearize_iterator()' helper function Rather than do it in that huge 'linearize_statement()' function, split out the iterator case. Avoids one level of indentation, and makes for simpler and more straightforward functions. Signed-off-by: Linus Torvalds --- linearize.c | 85 +++++++++++++++++++++++++++++++--------------------------- 1 files changed, 45 insertions(+), 40 deletions(-) diff --git a/linearize.c b/linearize.c index 1899978c1d08..2decd5300859 100644 --- a/linearize.c +++ b/linearize.c @@ -1843,6 +1843,49 @@ static pseudo_t linearize_declaration(struct entrypoint *ep, struct statement *s return VOID; } +static pseudo_t linearize_iterator(struct entrypoint *ep, struct statement *stmt) +{ + struct statement *pre_statement = stmt->iterator_pre_statement; + struct expression *pre_condition = stmt->iterator_pre_condition; + struct statement *statement = stmt->iterator_statement; + struct statement *post_statement = stmt->iterator_post_statement; + struct expression *post_condition = stmt->iterator_post_condition; + struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end; + + concat_symbol_list(stmt->iterator_syms, &ep->syms); + linearize_statement(ep, pre_statement); + + loop_body = loop_top = alloc_basic_block(ep, stmt->pos); + loop_continue = alloc_basic_block(ep, stmt->pos); + loop_end = alloc_basic_block(ep, stmt->pos); + + /* An empty post-condition means that it's the same as the pre-condition */ + if (!post_condition) { + loop_top = alloc_basic_block(ep, stmt->pos); + set_activeblock(ep, loop_top); + } + + if (pre_condition) + linearize_cond_branch(ep, pre_condition, loop_body, loop_end); + + bind_label(stmt->iterator_continue, loop_continue, stmt->pos); + bind_label(stmt->iterator_break, loop_end, stmt->pos); + + set_activeblock(ep, loop_body); + linearize_statement(ep, statement); + add_goto(ep, loop_continue); + + set_activeblock(ep, loop_continue); + linearize_statement(ep, post_statement); + if (!post_condition) + add_goto(ep, loop_top); + else + linearize_cond_branch(ep, post_condition, loop_top, loop_end); + set_activeblock(ep, loop_end); + + return VOID; +} + pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt) { struct basic_block *bb; @@ -2049,46 +2092,8 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt) break; } - case STMT_ITERATOR: { - struct statement *pre_statement = stmt->iterator_pre_statement; - struct expression *pre_condition = stmt->iterator_pre_condition; - struct statement *statement = stmt->iterator_statement; - struct statement *post_statement = stmt->iterator_post_statement; - struct expression *post_condition = stmt->iterator_post_condition; - struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end; - - concat_symbol_list(stmt->iterator_syms, &ep->syms); - linearize_statement(ep, pre_statement); - - loop_body = loop_top = alloc_basic_block(ep, stmt->pos); - loop_continue = alloc_basic_block(ep, stmt->pos); - loop_end = alloc_basic_block(ep, stmt->pos); - - /* An empty post-condition means that it's the same as the pre-condition */ - if (!post_condition) { - loop_top = alloc_basic_block(ep, stmt->pos); - set_activeblock(ep, loop_top); - } - - if (pre_condition) - linearize_cond_branch(ep, pre_condition, loop_body, loop_end); - - bind_label(stmt->iterator_continue, loop_continue, stmt->pos); - bind_label(stmt->iterator_break, loop_end, stmt->pos); - - set_activeblock(ep, loop_body); - linearize_statement(ep, statement); - add_goto(ep, loop_continue); - - set_activeblock(ep, loop_continue); - linearize_statement(ep, post_statement); - if (!post_condition) - add_goto(ep, loop_top); - else - linearize_cond_branch(ep, post_condition, loop_top, loop_end); - set_activeblock(ep, loop_end); - break; - } + case STMT_ITERATOR: + return linearize_iterator(ep, stmt); default: break;