2009-07-18 23:27:42 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-22 03:05:40 -04:00
|
|
|
USING: assocs kernel combinators compiler.cfg.dataflow-analysis
|
2009-07-23 21:54:38 -04:00
|
|
|
compiler.cfg.stacks.local ;
|
|
|
|
IN: compiler.cfg.stacks.global
|
2009-07-18 23:27:42 -04:00
|
|
|
|
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 ;
|
|
|
|
|
|
|
|
M: live-analysis join-sets drop assoc-combine ;
|
|
|
|
|
|
|
|
! 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 ;
|
2009-07-18 23:27:42 -04:00
|
|
|
|
|
|
|
! Main word
|
2009-07-23 21:54:38 -04:00
|
|
|
: compute-global-sets ( cfg -- cfg' )
|
2009-07-18 23:27:42 -04:00
|
|
|
{
|
2009-08-03 08:08:28 -04:00
|
|
|
[ compute-anticip-sets ]
|
|
|
|
[ compute-live-sets ]
|
|
|
|
[ compute-pending-sets ]
|
|
|
|
[ compute-dead-sets ]
|
2009-07-18 23:27:42 -04:00
|
|
|
[ compute-avail-sets ]
|
2009-07-23 21:54:38 -04:00
|
|
|
[ ]
|
2009-07-18 23:27:42 -04:00
|
|
|
} cleave ;
|