is reachable or not, taking empty trailing blocks into account.
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,
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))
{
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
};
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.
*/
@*/
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))
{
/* 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 */