From patchwork Sat Aug 27 21:28:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 1105292 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 p7RLQf4o032290 for ; Sat, 27 Aug 2011 21:28:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751628Ab1H0V2z (ORCPT ); Sat, 27 Aug 2011 17:28:55 -0400 Received: from mail-pz0-f42.google.com ([209.85.210.42]:64681 "EHLO mail-pz0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751554Ab1H0V2y (ORCPT ); Sat, 27 Aug 2011 17:28:54 -0400 Received: by pzk37 with SMTP id 37so6220437pzk.1 for ; Sat, 27 Aug 2011 14:28:54 -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=lGJh2stBKzHqzGTkYWIBofaacM4RPAvZ5OBj4UfAwxk=; b=WtIc9dCYaUjJiMFTX6saOoZyIXooLX8Siy/l3FxkcjjIepV0RnA5JDTrivyXOlJ0uK MQ3ckK9/gqKo2NzyoMxrbZhgZFBZjrfguNBTuK0xNMgTXkBKB2R3pobgia9iC1pjggcD f/lLumunaFu2h0k7O/Btb1f1qEB9v1Vkf8I/I= Received: by 10.142.193.10 with SMTP id q10mr1461862wff.135.1314480534310; Sat, 27 Aug 2011 14:28:54 -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 m1sm9067187pbf.3.2011.08.27.14.28.52 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 27 Aug 2011 14:28:53 -0700 (PDT) Date: Sat, 27 Aug 2011 14:28:51 -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 3/3] Make 'linearize_return()' 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:28:55 +0000 (UTC) From: Linus Torvalds Date: Sat, 27 Aug 2011 11:43:24 -0700 Subject: [PATCH 3/3] Make 'linearize_return()' helper function Rather than do it in that huge 'linearize_statement()' function, split out the return generation case. Avoids one level of indentation, and makes for simpler and more straightforward functions. Signed-off-by: Linus Torvalds --- You'd think "return" is easily linearized, but it's actually not at all trivial. Inline functions and all that.. linearize.c | 48 ++++++++++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 22 deletions(-) diff --git a/linearize.c b/linearize.c index e48854755b1e..320972745d6d 100644 --- a/linearize.c +++ b/linearize.c @@ -1843,6 +1843,30 @@ static pseudo_t linearize_declaration(struct entrypoint *ep, struct statement *s return VOID; } +static pseudo_t linearize_return(struct entrypoint *ep, struct statement *stmt) +{ + struct expression *expr = stmt->expression; + struct basic_block *bb_return = get_bound_block(ep, stmt->ret_target); + struct basic_block *active; + pseudo_t src = linearize_expression(ep, expr); + active = ep->active; + if (active && src != &void_pseudo) { + struct instruction *phi_node = first_instruction(bb_return->insns); + pseudo_t phi; + if (!phi_node) { + phi_node = alloc_typed_instruction(OP_PHI, expr->ctype); + phi_node->target = alloc_pseudo(phi_node); + phi_node->bb = bb_return; + add_instruction(&bb_return->insns, phi_node); + } + phi = alloc_phi(active, src, type_size(expr->ctype)); + phi->ident = &return_ident; + use_pseudo(phi_node, phi, add_pseudo(&phi_node->phi_list, phi)); + } + add_goto(ep, bb_return); + return VOID; +} + static pseudo_t linearize_switch(struct entrypoint *ep, struct statement *stmt) { struct symbol *sym; @@ -1980,28 +2004,8 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt) case STMT_ASM: return linearize_asm_statement(ep, stmt); - case STMT_RETURN: { - struct expression *expr = stmt->expression; - struct basic_block *bb_return = get_bound_block(ep, stmt->ret_target); - struct basic_block *active; - pseudo_t src = linearize_expression(ep, expr); - active = ep->active; - if (active && src != &void_pseudo) { - struct instruction *phi_node = first_instruction(bb_return->insns); - pseudo_t phi; - if (!phi_node) { - phi_node = alloc_typed_instruction(OP_PHI, expr->ctype); - phi_node->target = alloc_pseudo(phi_node); - phi_node->bb = bb_return; - add_instruction(&bb_return->insns, phi_node); - } - phi = alloc_phi(active, src, type_size(expr->ctype)); - phi->ident = &return_ident; - use_pseudo(phi_node, phi, add_pseudo(&phi_node->phi_list, phi)); - } - add_goto(ep, bb_return); - return VOID; - } + case STMT_RETURN: + return linearize_return(ep, stmt); case STMT_CASE: { add_label(ep, stmt->case_label);