[PATCH 3/3] Make 'linearize_return()' helper function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
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 <torvalds@xxxxxxxxxxxxxxxxxxxx>
---

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);
-- 
1.7.6.409.ge7a85.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux