2009-07-09 00:07:06 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
2009-06-11 18:55:14 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-09 00:07:06 -04:00
|
|
|
USING: accessors arrays assocs combinators
|
|
|
|
combinators.short-circuit fry kernel locals
|
|
|
|
make math sequences
|
2009-07-22 04:08:28 -04:00
|
|
|
compiler.cfg.rpo
|
2009-07-13 00:00:33 -04:00
|
|
|
compiler.cfg.utilities
|
2009-07-09 00:07:06 -04:00
|
|
|
compiler.cfg.instructions
|
|
|
|
compiler.cfg.linear-scan.assignment
|
2009-07-22 04:08:28 -04:00
|
|
|
compiler.cfg.linear-scan.mapping
|
|
|
|
compiler.cfg.linear-scan.liveness ;
|
2009-06-11 18:55:14 -04:00
|
|
|
IN: compiler.cfg.linear-scan.resolve
|
|
|
|
|
2009-07-04 00:38:52 -04:00
|
|
|
: add-mapping ( from to reg-class -- )
|
|
|
|
over spill-slot? [
|
|
|
|
pick spill-slot?
|
|
|
|
[ memory->memory ]
|
|
|
|
[ register->memory ] if
|
2009-06-21 01:20:01 -04:00
|
|
|
] [
|
2009-07-04 00:38:52 -04:00
|
|
|
pick spill-slot?
|
|
|
|
[ memory->register ]
|
|
|
|
[ register->register ] if
|
2009-06-21 01:20:01 -04:00
|
|
|
] if ;
|
2009-06-11 18:55:14 -04:00
|
|
|
|
2009-07-04 00:38:52 -04:00
|
|
|
:: resolve-value-data-flow ( bb to vreg -- )
|
|
|
|
vreg bb vreg-at-end
|
|
|
|
vreg to vreg-at-start
|
|
|
|
2dup eq? [ 2drop ] [ vreg reg-class>> add-mapping ] if ;
|
2009-06-21 01:20:01 -04:00
|
|
|
|
|
|
|
: compute-mappings ( bb to -- mappings )
|
|
|
|
[
|
|
|
|
dup live-in keys
|
|
|
|
[ resolve-value-data-flow ] with with each
|
|
|
|
] { } make ;
|
|
|
|
|
2009-07-13 00:00:33 -04:00
|
|
|
: perform-mappings ( bb to mappings -- )
|
|
|
|
dup empty? [ 3drop ] [
|
|
|
|
mapping-instructions <simple-block>
|
|
|
|
insert-basic-block
|
2009-06-21 01:20:01 -04:00
|
|
|
] if ;
|
2009-06-11 18:55:14 -04:00
|
|
|
|
|
|
|
: resolve-edge-data-flow ( bb to -- )
|
2009-07-13 00:00:33 -04:00
|
|
|
2dup compute-mappings perform-mappings ;
|
2009-06-11 18:55:14 -04:00
|
|
|
|
|
|
|
: resolve-block-data-flow ( bb -- )
|
2009-06-21 01:20:01 -04:00
|
|
|
dup successors>> [ resolve-edge-data-flow ] with each ;
|
2009-06-11 18:55:14 -04:00
|
|
|
|
2009-07-22 04:08:28 -04:00
|
|
|
: resolve-data-flow ( cfg -- )
|
|
|
|
[ resolve-block-data-flow ] each-basic-block ;
|