2009-06-30 23:11:15 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: kernel accessors sequences math combinators combinators.short-circuit
|
2009-07-12 23:22:46 -04:00
|
|
|
classes vectors compiler.cfg compiler.cfg.instructions compiler.cfg.rpo
|
|
|
|
compiler.cfg.utilities ;
|
2009-06-30 23:11:15 -04:00
|
|
|
IN: compiler.cfg.useless-conditionals
|
|
|
|
|
|
|
|
: delete-conditional? ( bb -- ? )
|
|
|
|
{
|
2009-09-08 18:04:26 -04:00
|
|
|
[
|
|
|
|
instructions>> last class {
|
|
|
|
##compare-branch
|
|
|
|
##compare-imm-branch
|
|
|
|
##compare-float-ordered-branch
|
|
|
|
##compare-float-unordered-branch
|
|
|
|
} memq?
|
|
|
|
]
|
2009-06-30 23:11:15 -04:00
|
|
|
[ successors>> first2 [ skip-empty-blocks ] bi@ eq? ]
|
|
|
|
} 1&& ;
|
|
|
|
|
|
|
|
: delete-conditional ( bb -- )
|
|
|
|
[ first skip-empty-blocks 1vector ] change-successors
|
|
|
|
instructions>> [ pop* ] [ [ \ ##branch new-insn ] dip push ] bi ;
|
|
|
|
|
|
|
|
: delete-useless-conditionals ( cfg -- cfg' )
|
|
|
|
dup [
|
|
|
|
dup delete-conditional? [ delete-conditional ] [ drop ] if
|
|
|
|
] each-basic-block
|
2009-08-08 21:02:56 -04:00
|
|
|
|
|
|
|
cfg-changed predecessors-changed ;
|