From: Rhys Weatherley Date: Thu, 20 May 2004 09:53:37 +0000 (+0000) Subject: Treat dead blocks as empty when peepholing branches to the next block. X-Git-Tag: r.0.0.4~99 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=00351eaf603151ab3d36c0c514482da646e84a9b;p=francis%2Flibjit.git Treat dead blocks as empty when peepholing branches to the next block. --- diff --git a/ChangeLog b/ChangeLog index 871c03b..d1d964b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,9 @@ branches to branches before live variable analysis, so that the back ends don't need to worry about jump threading. + * jit/jit-block.c, jit/jit-live.c: treat dead blocks as empty + when peepholing branches to the next block. + 2004-05-15 Rhys Weatherley * tools/gen-apply.c: fix a macro generation bug for Win32 systems. diff --git a/jit/jit-block.c b/jit/jit-block.c index 8ef0a89..abc5b13 100644 --- a/jit/jit-block.c +++ b/jit/jit-block.c @@ -383,6 +383,25 @@ int jit_block_ends_in_dead(jit_block_t block) return block->ends_in_dead; } +/* + * Determine if a block is empty or is never entered. + */ +static int block_is_empty_or_dead(jit_block_t block) +{ + if(block->first_insn > block->last_insn) + { + return 1; + } + else if(!(block->entered_via_top) && !(block->entered_via_branch)) + { + return 1; + } + else + { + return 0; + } +} + /* * Determine if the next block after "block" has "label". */ @@ -396,29 +415,33 @@ static int block_branches_to_next(jit_block_t block, jit_label_t label) { return 1; } - if(block->first_insn < block->last_insn) - { - /* This block contains more than one instruction, so the - first cannot be an unconditional branch */ - break; - } - else if(block->first_insn == block->last_insn) + if(!block_is_empty_or_dead(block)) { - insn = block->func->builder->insns[block->first_insn]; - if(insn->opcode == JIT_OP_BR) + if(block->first_insn < block->last_insn) { - /* If the instruction branches to its next block, - then it is equivalent to an empty block. If it - does not, then we have to stop scanning here */ - if(!block_branches_to_next(block, (jit_label_t)(insn->dest))) - { - return 0; - } + /* This block contains more than one instruction, so the + first cannot be an unconditional branch */ + break; } else { - /* The block does not contain an unconditional branch */ - break; + insn = block->func->builder->insns[block->first_insn]; + if(insn->opcode == JIT_OP_BR) + { + /* If the instruction branches to its next block, + then it is equivalent to an empty block. If it + does not, then we have to stop scanning here */ + if(!block_branches_to_next + (block, (jit_label_t)(insn->dest))) + { + return 0; + } + } + else + { + /* The block does not contain an unconditional branch */ + break; + } } } block = block->next; @@ -449,7 +472,7 @@ void _jit_block_peephole_branch(jit_block_t block) while(label != block->label && count > 0) { new_block = jit_block_from_label(block->func, label); - while(new_block != 0 && new_block->first_insn > new_block->last_insn) + while(new_block != 0 && block_is_empty_or_dead(new_block)) { /* Skip past empty blocks */ new_block = new_block->next; diff --git a/jit/jit-live.c b/jit/jit-live.c index 5193313..6ee52b2 100644 --- a/jit/jit-live.c +++ b/jit/jit-live.c @@ -199,8 +199,19 @@ void _jit_function_compute_liveness(jit_function_t func) jit_block_t block = func->builder->first_block; while(block != 0) { + /* If the block is never entered, then replace it with empty */ + if(!(block->entered_via_top) && !(block->entered_via_branch)) + { + block->last_insn = block->first_insn - 1; + } + + /* Perform peephole optimization on branches to branches */ _jit_block_peephole_branch(block); + + /* Compute the liveness flags for the block */ compute_liveness_for_block(block); + + /* Move on to the next block in the function */ block = block->next; } }