Do no generate body blocks in the first place, when the body of a for- or while-loop...
authorChristoph Mallon <christoph.mallon@gmx.de>
Sat, 17 Nov 2007 21:52:13 +0000 (21:52 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sat, 17 Nov 2007 21:52:13 +0000 (21:52 +0000)
[r18468]

ast2firm.c

index a51f5c7..6726dc7 100644 (file)
@@ -1594,25 +1594,27 @@ static void while_statement_to_firm(while_statement_t *statement)
        ir_node *false_block = new_immBlock();
 
        /* the loop body */
-       ir_node *body_block = new_immBlock();
-
+       ir_node *body_block;
        if (statement->body != NULL) {
                ir_node *old_continue_label = continue_label;
                ir_node *old_break_label    = break_label;
                continue_label              = header_block;
                break_label                 = false_block;
 
+               body_block = new_immBlock();
                statement_to_firm(statement->body);
 
                assert(continue_label == header_block);
                assert(break_label    == false_block);
                continue_label = old_continue_label;
                break_label    = old_break_label;
-       }
 
-       if(get_cur_block() != NULL) {
-               ir_node *jmp = new_Jmp();
-               add_immBlock_pred(header_block, jmp);
+               if(get_cur_block() != NULL) {
+                       ir_node *jmp = new_Jmp();
+                       add_immBlock_pred(header_block, jmp);
+               }
+       } else {
+               body_block = header_block;
        }
 
        /* create the condition */
@@ -1709,25 +1711,27 @@ static void for_statement_to_firm(for_statement_t *statement)
        ir_node *const false_block = new_immBlock();
 
        /* the loop body */
-       ir_node *const body_block = new_immBlock();
-
+       ir_node * body_block;
        if (statement->body != NULL) {
                ir_node *const old_continue_label = continue_label;
                ir_node *const old_break_label    = break_label;
                continue_label = step_block;
                break_label    = false_block;
 
+               body_block = new_immBlock();
                statement_to_firm(statement->body);
 
                assert(continue_label == step_block);
                assert(break_label    == false_block);
                continue_label = old_continue_label;
                break_label    = old_break_label;
-       }
 
-       if (get_cur_block() != NULL) {
-               ir_node *const jmp = new_Jmp();
-               add_immBlock_pred(step_block, jmp);
+               if (get_cur_block() != NULL) {
+                       ir_node *const jmp = new_Jmp();
+                       add_immBlock_pred(step_block, jmp);
+               }
+       } else {
+               body_block = step_block;
        }
 
        /* create the condition */