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