Handle a jump to a jump by cloning the block, in the same way we optimize jumps to returns

db4
Slava Pestov 2008-11-03 21:02:34 -06:00
parent b4d3473d5e
commit efcb916e35
1 changed files with 5 additions and 4 deletions

View File

@ -20,16 +20,17 @@ M: insn linearize-insn , drop ;
#! don't need to branch.
[ number>> ] bi@ 1- = ; inline
: branch-to-return? ( successor -- ? )
#! A branch to a block containing just a return is cloned.
: branch-to-branch? ( successor -- ? )
#! A branch to a block containing just a jump return is cloned.
instructions>> dup length 2 = [
[ first ##epilogue? ] [ second ##return? ] bi and
[ first ##epilogue? ]
[ second [ ##return? ] [ ##jump? ] bi or ] bi and
] [ drop f ] if ;
: emit-branch ( basic-block successor -- )
{
{ [ 2dup useless-branch? ] [ 2drop ] }
{ [ dup branch-to-return? ] [ nip linearize-insns ] }
{ [ dup branch-to-branch? ] [ nip linearize-insns ] }
[ nip number>> _branch ]
} cond ;