compiler.cfg.linear-scan.allocation: refactoring to simplify the (allocate-registers) recursion

db4
Björn Lindqvist 2014-12-14 18:55:59 +01:00
parent 52c6009aeb
commit fab478482e
1 changed files with 8 additions and 18 deletions

View File

@ -48,34 +48,24 @@ IN: compiler.cfg.linear-scan.allocation
GENERIC: handle ( obj -- ) GENERIC: handle ( obj -- )
M: live-interval-state handle M: live-interval-state handle
[ start>> deactivate-intervals ] [ start>> [ deactivate-intervals ] [ activate-intervals ] bi ]
[ start>> activate-intervals ] [ assign-register ] bi ;
[ assign-register ]
tri ;
: handle-sync-point ( sync-point -- ) : handle-sync-point ( sync-point -- )
active-intervals get values active-intervals get values
[ [ spill-at-sync-point ] with filter! drop ] with each ; [ [ spill-at-sync-point ] with filter! drop ] with each ;
M: sync-point handle ( sync-point -- ) M: sync-point handle ( sync-point -- )
[ n>> deactivate-intervals ] [ n>> [ deactivate-intervals ] [ activate-intervals ] bi ]
[ n>> activate-intervals ] [ handle-sync-point ] bi ;
[ handle-sync-point ]
tri ;
: smallest-heap ( heap1 heap2 -- heap ) : live-interval-or-sync-point ( intervals sync-points -- live-interval )
[ [ heap-peek nip ] bi@ <= ] most ; 2array [ heap-empty? not ] filter [ heap-peek nip ] infimum-by
heap-pop drop ;
:: (allocate-registers-step) ( unhandled-intervals unhandled-sync-points -- )
{
{ [ unhandled-intervals heap-empty? ] [ unhandled-sync-points ] }
{ [ unhandled-sync-points heap-empty? ] [ unhandled-intervals ] }
[ unhandled-intervals unhandled-sync-points smallest-heap ]
} cond heap-pop drop handle ;
: (allocate-registers) ( unhandled-intervals unhandled-sync-points -- ) : (allocate-registers) ( unhandled-intervals unhandled-sync-points -- )
2dup [ heap-empty? ] both? [ 2drop ] [ 2dup [ heap-empty? ] both? [ 2drop ] [
[ (allocate-registers-step) ] [ live-interval-or-sync-point handle ]
[ (allocate-registers) ] [ (allocate-registers) ]
2bi 2bi
] if ; ] if ;