From 4e2a72cc6b48005a65e199feaae9957aa89ef991 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Wed, 26 May 2004 01:19:38 +0000 Subject: [PATCH] Add "jit_block_current_is_dead" to simplify testing if the last block is reachable or not, taking empty trailing blocks into account. --- ChangeLog | 5 +++++ dpas/dpas-parser.y | 3 +-- include/jit/jit-block.h | 1 + jit/jit-block.c | 36 ++++++++++++++++++++++++++++++++++++ jit/jit-insn.c | 24 ++---------------------- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 81b186a..f3b4dc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,11 @@ 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 * tools/.cvsignore, tools/Makefile.am, tools/gen-sel-parser.y, diff --git a/dpas/dpas-parser.y b/dpas/dpas-parser.y index 426b7a0..0242db4 100644 --- a/dpas/dpas-parser.y +++ b/dpas/dpas-parser.y @@ -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)) { diff --git a/include/jit/jit-block.h b/include/jit/jit-block.h index b4a5295..30aeca6 100644 --- a/include/jit/jit-block.h +++ b/include/jit/jit-block.h @@ -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 }; diff --git a/jit/jit-block.c b/jit/jit-block.c index ae9cb90..8123f98 100644 --- a/jit/jit-block.c +++ b/jit/jit-block.c @@ -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. */ diff --git a/jit/jit-insn.c b/jit/jit-insn.c index a103b3a..457c609 100644 --- a/jit/jit-insn.c +++ b/jit/jit-insn.c @@ -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 */ -- 2.47.3