2009-07-22 07:07:28 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
USING: kernel accessors assocs sequences sets
|
|
|
|
|
compiler.cfg.def-use compiler.cfg.dataflow-analysis
|
|
|
|
|
compiler.cfg.instructions ;
|
|
|
|
|
IN: compiler.cfg.liveness
|
|
|
|
|
|
|
|
|
|
! See http://en.wikipedia.org/wiki/Liveness_analysis
|
|
|
|
|
! Do not run after SSA construction
|
|
|
|
|
|
|
|
|
|
BACKWARD-ANALYSIS: live
|
|
|
|
|
|
2009-07-27 01:31:21 -04:00
|
|
|
GENERIC: insn-liveness ( live-set insn -- )
|
|
|
|
|
|
2009-07-22 07:07:28 -04:00
|
|
|
: transfer-liveness ( live-set instructions -- live-set' )
|
|
|
|
|
[ clone ] [ <reversed> ] bi* [
|
2009-07-27 01:31:21 -04:00
|
|
|
[ dup ##phi? [ drop ] [ uses-vregs [ over conjoin ] each ] if ]
|
2009-07-22 07:07:28 -04:00
|
|
|
[ defs-vregs [ over delete-at ] each ] bi
|
|
|
|
|
] each ;
|
|
|
|
|
|
|
|
|
|
: local-live-in ( instructions -- live-set )
|
2009-07-27 01:31:21 -04:00
|
|
|
[ H{ } ] dip transfer-liveness keys ;
|
2009-07-22 07:07:28 -04:00
|
|
|
|
|
|
|
|
M: live-analysis transfer-set
|
|
|
|
|
drop instructions>> transfer-liveness ;
|
|
|
|
|
|
|
|
|
|
M: live-analysis join-sets
|
|
|
|
|
drop assoc-combine ;
|