2009-07-18 23:27:42 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2014-12-13 19:10:21 -05:00
|
|
|
USING: assocs combinators compiler.cfg.dataflow-analysis
|
2015-03-31 19:34:56 -04:00
|
|
|
compiler.cfg.stacks.local kernel namespaces ;
|
2009-07-23 21:54:38 -04:00
|
|
|
IN: compiler.cfg.stacks.global
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2015-03-31 19:34:56 -04:00
|
|
|
: peek-set ( bb -- assoc ) peek-sets get at ;
|
|
|
|
: replace-set ( bb -- assoc ) replace-sets get at ;
|
|
|
|
: kill-set ( bb -- assoc ) kill-sets get at ;
|
|
|
|
|
2009-08-03 08:08:28 -04:00
|
|
|
: transfer-peeked-locs ( assoc bb -- assoc' )
|
|
|
|
[ replace-set assoc-diff ] [ peek-set assoc-union ] bi ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-08-03 08:08:28 -04:00
|
|
|
! A stack location is anticipated at a location if every path from
|
|
|
|
! the location to an exit block will read the stack location
|
|
|
|
! before writing it.
|
|
|
|
BACKWARD-ANALYSIS: anticip
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-08-03 08:08:28 -04:00
|
|
|
M: anticip-analysis transfer-set drop transfer-peeked-locs ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-08-03 08:08:28 -04:00
|
|
|
! A stack location is live at a location if some path from
|
|
|
|
! the location to an exit block will read the stack location
|
|
|
|
! before writing it.
|
|
|
|
BACKWARD-ANALYSIS: live
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-08-03 08:08:28 -04:00
|
|
|
M: live-analysis transfer-set drop transfer-peeked-locs ;
|
|
|
|
|
2009-08-13 00:52:29 -04:00
|
|
|
M: live-analysis join-sets 2drop assoc-combine ;
|
2009-08-03 08:08:28 -04:00
|
|
|
|
|
|
|
! A stack location is available at a location if all paths from
|
|
|
|
! the entry block to the location load the location into a
|
|
|
|
! register.
|
2009-07-22 03:05:40 -04:00
|
|
|
FORWARD-ANALYSIS: avail
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-08-03 08:08:28 -04:00
|
|
|
M: avail-analysis transfer-set
|
|
|
|
drop [ peek-set assoc-union ] [ replace-set assoc-union ] bi ;
|
|
|
|
|
|
|
|
! A stack location is pending at a location if all paths from
|
|
|
|
! the entry block to the location write the location.
|
|
|
|
FORWARD-ANALYSIS: pending
|
|
|
|
|
|
|
|
M: pending-analysis transfer-set
|
|
|
|
drop replace-set assoc-union ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-08-03 08:08:28 -04:00
|
|
|
! A stack location is dead at a location if no paths from the
|
|
|
|
! location to the exit block read the location before writing it.
|
|
|
|
BACKWARD-ANALYSIS: dead
|
2009-07-18 23:27:42 -04:00
|
|
|
|
2009-08-03 08:08:28 -04:00
|
|
|
M: dead-analysis transfer-set
|
|
|
|
drop
|
|
|
|
[ kill-set assoc-union ]
|
|
|
|
[ replace-set assoc-union ] bi ;
|