]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
Add "jit_block_current_is_dead" to simplify testing if the last block
authorRhys Weatherley <rweather@southern-storm.com.au>
Wed, 26 May 2004 01:19:38 +0000 (01:19 +0000)
committerRhys Weatherley <rweather@southern-storm.com.au>
Wed, 26 May 2004 01:19:38 +0000 (01:19 +0000)
is reachable or not, taking empty trailing blocks into account.

ChangeLog
dpas/dpas-parser.y
include/jit/jit-block.h
jit/jit-block.c
jit/jit-insn.c

index 81b186a23b1f6c7ee89eaafd68e47b0310f55135..f3b4dc50726524e4ab85d63b2e514fc1bb93d312 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        jitplus/jit-plus-function.cpp: add "jit_insn_new_block" to simplify
        creating a new block that doesn't have an explicit label.
 
+       * dpas/dpas-parser.y, include/jit/jit-block.h, jit/jit-block.c,
+       jit/jit-insn.c: add "jit_block_current_is_dead" to simplify
+       testing if the last block is reachable or not, taking empty
+       trailing blocks into account.
+
 2004-05-25  Rhys Weatherley  <rweather@southern-storm.com.au>
 
        * tools/.cvsignore, tools/Makefile.am, tools/gen-sel-parser.y,
index 426b7a045ba400ad52e434a2f28466d8a35375c5..0242db4369aac75230b1acbb228161195da37bee 100644 (file)
@@ -1787,8 +1787,7 @@ IfTail
                                jit_label_t label = jit_label_undefined;
 
                                /* Jump to the end of the "if" statement */
-                               if(!jit_block_ends_in_dead
-                                               (jit_block_previous(dpas_current_function(), 0)))
+                               if(!jit_block_current_is_dead(dpas_current_function()))
                                {
                                        if(!jit_insn_branch(dpas_current_function(), &label))
                                        {
index b4a5295e36ca2e026982624dcc4e170a35c86289..30aeca6946f43ce66da4ef136433451e56157158 100644 (file)
@@ -42,6 +42,7 @@ void *jit_block_get_meta(jit_block_t block, int type) JIT_NOTHROW;
 void jit_block_free_meta(jit_block_t block, int type) JIT_NOTHROW;
 int jit_block_is_reachable(jit_block_t block) JIT_NOTHROW;
 int jit_block_ends_in_dead(jit_block_t block) JIT_NOTHROW;
+int jit_block_current_is_dead(jit_function_t func) JIT_NOTHROW;
 
 #ifdef __cplusplus
 };
index ae9cb9049dcf88657b6b63c24cac627cde48ad2c..8123f98e8ed72cb293db8700827981c9a5d2d549 100644 (file)
@@ -369,6 +369,42 @@ int jit_block_ends_in_dead(jit_block_t block)
        return block->ends_in_dead;
 }
 
+/*@
+ * @deftypefun int jit_block_current_is_dead (jit_function_t func)
+ * Determine if the current point in the function is dead.  That is,
+ * there are no existing branches or fall-throughs to this point.
+ * This differs slightly from @code{jit_block_ends_in_dead} in that
+ * this can skip past zero-length blocks that may not appear to be
+ * dead to find the dead block at the head of a chain of empty blocks.
+ * @end deftypefun
+@*/
+int jit_block_current_is_dead(jit_function_t func)
+{
+       jit_block_t block = jit_block_previous(func, 0);
+       while(block != 0)
+       {
+               if(block->ends_in_dead)
+               {
+                       return 1;
+               }
+               else if(!(block->entered_via_top) &&
+                               !(block->entered_via_branch))
+               {
+                       return 1;
+               }
+               else if(block->entered_via_branch)
+               {
+                       break;
+               }
+               else if(block->first_insn <= block->last_insn)
+               {
+                       break;
+               }
+               block = block->prev;
+       }
+       return 0;
+}
+
 /*
  * Determine if a block is empty or is never entered.
  */
index a103b3a595fdda747ecd7ac96973cf76fb152350..457c609d64e9177085901378c9c843ff52374bd2 100644 (file)
@@ -6084,8 +6084,6 @@ int jit_insn_return_ptr
 @*/
 int jit_insn_default_return(jit_function_t func)
 {
-       jit_block_t current;
-
        /* Ensure that we have a builder for this function */
        if(!_jit_function_ensure_builder(func))
        {
@@ -6094,27 +6092,9 @@ int jit_insn_default_return(jit_function_t func)
 
        /* If the last block ends in an unconditional branch, or is dead,
           then we don't need to add a default return */
-       current = func->builder->current_block;
-       while(current != 0)
+       if(jit_block_current_is_dead(func))
        {
-               if(current->ends_in_dead)
-               {
-                       return 2;
-               }
-               else if(!(current->entered_via_top) &&
-                               !(current->entered_via_branch))
-               {
-                       return 2;
-               }
-               else if(current->entered_via_branch)
-               {
-                       break;
-               }
-               else if(current->first_insn <= current->last_insn)
-               {
-                       break;
-               }
-               current = current->prev;
+               return 2;
        }
 
        /* Add a simple "void" return to terminate the function */