]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Move the output block of a loop to after the loop, otherwise IR dumps looks just...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 4 May 2012 08:01:38 +0000 (10:01 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 4 May 2012 08:01:38 +0000 (10:01 +0200)
ast.c

diff --git a/ast.c b/ast.c
index c96594752168de3399d7987a5909f1c652ab95b6..e7962156f6775372401b7d450225b925f136cf1f 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -939,6 +939,9 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
     ir_block *bincrement, *end_bincrement;
     ir_block *bout, *bin;
 
+    /* let's at least move the outgoing block to the end */
+    size_t    bout_id;
+
     /* 'break' and 'continue' need to be able to find the right blocks */
     ir_block *bcontinue = NULL;
     ir_block *bbreak    = NULL;
@@ -1014,6 +1017,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         bpostcond = end_bpostcond = NULL;
     }
 
+    bout_id = func->ir_func->blocks_count;
     bout = ir_function_create_block(func->ir_func, ast_function_label(func, "after_loop"));
     if (!bout)
         return false;
@@ -1135,5 +1139,13 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
             return false;
     }
 
+    /* Move 'bout' to the end */
+    if (!ir_function_blocks_remove(func->ir_func, bout_id) ||
+        !ir_function_blocks_add(func->ir_func, bout))
+    {
+        ir_block_delete(bout);
+        return false;
+    }
+
     return true;
 }