2009-07-18 23:27:42 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
USING: namespaces assocs accessors sequences kernel math locals fry
|
|
|
|
|
compiler.cfg.instructions compiler.cfg.rpo compiler.cfg.registers ;
|
|
|
|
|
IN: compiler.cfg.dcn.height
|
|
|
|
|
|
|
|
|
|
! Compute block in-height and out-height sets. These are relative to the
|
|
|
|
|
! stack height from the start of the procedure.
|
|
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
|
|
SYMBOLS: in-ds-heights out-ds-heights in-rs-heights out-rs-heights ;
|
|
|
|
|
|
|
|
|
|
GENERIC: ds-height-change ( insn -- n )
|
|
|
|
|
|
|
|
|
|
M: insn ds-height-change drop 0 ;
|
|
|
|
|
|
|
|
|
|
M: ##inc-d ds-height-change n>> ;
|
|
|
|
|
|
2009-07-19 00:08:53 -04:00
|
|
|
M: ##call ds-height-change height>> ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-07-19 20:45:23 -04:00
|
|
|
: alien-node-height ( node -- n )
|
2009-07-19 00:08:53 -04:00
|
|
|
params>> [ out-d>> length ] [ in-d>> length ] bi - ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-07-19 00:08:53 -04:00
|
|
|
M: ##alien-invoke ds-height-change alien-node-height ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-07-19 00:08:53 -04:00
|
|
|
M: ##alien-indirect ds-height-change alien-node-height ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
|
|
|
|
GENERIC: rs-height-change ( insn -- n )
|
|
|
|
|
|
|
|
|
|
M: insn rs-height-change drop 0 ;
|
|
|
|
|
|
|
|
|
|
M: ##inc-r rs-height-change n>> ;
|
|
|
|
|
|
|
|
|
|
:: compute-in-height ( bb in out -- )
|
|
|
|
|
bb predecessors>> [ out at ] map-find drop 0 or
|
|
|
|
|
bb in set-at ;
|
|
|
|
|
|
|
|
|
|
:: compute-out-height ( bb in out quot -- )
|
|
|
|
|
bb instructions>>
|
|
|
|
|
bb in at
|
|
|
|
|
[ quot call + ] reduce
|
|
|
|
|
bb out set-at ; inline
|
|
|
|
|
|
|
|
|
|
:: compute-height ( bb in out quot -- )
|
|
|
|
|
bb in get out get
|
|
|
|
|
[ compute-in-height ]
|
|
|
|
|
[ quot compute-out-height ] 3bi ; inline
|
|
|
|
|
|
|
|
|
|
: compute-ds-height ( bb -- )
|
|
|
|
|
in-ds-heights out-ds-heights [ ds-height-change ] compute-height ;
|
|
|
|
|
|
|
|
|
|
: compute-rs-height ( bb -- )
|
|
|
|
|
in-rs-heights out-rs-heights [ rs-height-change ] compute-height ;
|
|
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
|
|
: compute-heights ( cfg -- )
|
|
|
|
|
H{ } clone in-ds-heights set
|
|
|
|
|
H{ } clone out-ds-heights set
|
|
|
|
|
H{ } clone in-rs-heights set
|
|
|
|
|
H{ } clone out-rs-heights set
|
|
|
|
|
[
|
|
|
|
|
[ compute-rs-height ]
|
|
|
|
|
[ compute-ds-height ] bi
|
|
|
|
|
] each-basic-block ;
|
|
|
|
|
|
2009-07-21 23:24:50 -04:00
|
|
|
GENERIC# translate-loc 1 ( loc bb -- loc' )
|
|
|
|
|
|
|
|
|
|
M: ds-loc translate-loc [ n>> ] [ in-ds-heights get at ] bi* - <ds-loc> ;
|
|
|
|
|
M: rs-loc translate-loc [ n>> ] [ in-rs-heights get at ] bi* - <rs-loc> ;
|
|
|
|
|
|
2009-07-21 02:24:19 -04:00
|
|
|
: translate-locs ( assoc bb -- assoc' )
|
|
|
|
|
'[ [ _ translate-loc ] dip ] assoc-map ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-07-21 23:24:50 -04:00
|
|
|
GENERIC# untranslate-loc 1 ( loc bb -- loc' )
|
|
|
|
|
|
|
|
|
|
M: ds-loc untranslate-loc [ n>> ] [ in-ds-heights get at ] bi* + <ds-loc> ;
|
|
|
|
|
M: rs-loc untranslate-loc [ n>> ] [ in-rs-heights get at ] bi* + <rs-loc> ;
|
|
|
|
|
|
2009-07-21 02:24:19 -04:00
|
|
|
: untranslate-locs ( assoc bb -- assoc' )
|
|
|
|
|
'[ [ _ untranslate-loc ] dip ] assoc-map ;
|