compiler.cfg.scheduling: refactor to use split-insns and compiler.cfg.linear-scan.numbering + tests
parent
422c4b2051
commit
c777cb954a
|
@ -1,16 +1,16 @@
|
|||
USING: compiler.cfg.scheduling compiler.cfg.instructions
|
||||
vocabs.loader namespaces tools.test arrays kernel random
|
||||
words compiler.units ;
|
||||
USING: accessors compiler.cfg compiler.cfg.instructions
|
||||
compiler.cfg.linearization compiler.cfg.scheduling compiler.cfg.utilities
|
||||
vocabs.loader namespaces tools.test arrays kernel random sequences words ;
|
||||
IN: compiler.cfg.scheduling.tests
|
||||
|
||||
! Test split-3-ways
|
||||
! Test split-insns
|
||||
[
|
||||
{ }
|
||||
{ }
|
||||
{ T{ ##test-branch } }
|
||||
] [
|
||||
V{ T{ ##test-branch } }
|
||||
split-3-ways
|
||||
split-insns
|
||||
[ >array ] tri@
|
||||
] unit-test
|
||||
|
||||
|
@ -28,7 +28,7 @@ IN: compiler.cfg.scheduling.tests
|
|||
T{ ##mul }
|
||||
T{ ##test-branch }
|
||||
}
|
||||
split-3-ways
|
||||
split-insns
|
||||
[ >array ] tri@
|
||||
] unit-test
|
||||
|
||||
|
@ -43,6 +43,65 @@ IN: compiler.cfg.scheduling.tests
|
|||
T{ ##mul }
|
||||
T{ ##dispatch }
|
||||
}
|
||||
split-3-ways
|
||||
split-insns
|
||||
[ >array ] tri@
|
||||
] unit-test
|
||||
|
||||
! Instructions gets numbered as a side-effect
|
||||
{ t } [
|
||||
V{
|
||||
T{ ##inc-r }
|
||||
T{ ##inc-d }
|
||||
T{ ##load-tagged }
|
||||
T{ ##allot }
|
||||
T{ ##set-slot-imm }
|
||||
} insns>cfg schedule-instructions
|
||||
linearization-order [ instructions>> ] map concat [ insn#>> ] all?
|
||||
] unit-test
|
||||
|
||||
{
|
||||
{ T{ ##inc-r } T{ ##inc-d } }
|
||||
{
|
||||
T{ ##peek }
|
||||
T{ ##peek }
|
||||
T{ ##load-tagged }
|
||||
T{ ##allot }
|
||||
T{ ##set-slot-imm }
|
||||
T{ ##load-reference }
|
||||
T{ ##allot }
|
||||
T{ ##set-slot-imm }
|
||||
T{ ##set-slot-imm }
|
||||
T{ ##set-slot-imm }
|
||||
T{ ##replace-imm }
|
||||
T{ ##replace }
|
||||
T{ ##replace }
|
||||
T{ ##replace }
|
||||
T{ ##replace }
|
||||
T{ ##replace-imm }
|
||||
T{ ##replace }
|
||||
}
|
||||
{ T{ ##branch } }
|
||||
} [
|
||||
V{
|
||||
##inc-r
|
||||
##inc-d
|
||||
##peek
|
||||
##peek
|
||||
##load-tagged
|
||||
##allot
|
||||
##set-slot-imm
|
||||
##load-reference
|
||||
##allot
|
||||
##set-slot-imm
|
||||
##set-slot-imm
|
||||
##set-slot-imm
|
||||
##replace-imm
|
||||
##replace
|
||||
##replace
|
||||
##replace
|
||||
##replace
|
||||
##replace-imm
|
||||
##replace
|
||||
##branch
|
||||
} [ new ] map split-insns [ >array ] tri@
|
||||
] unit-test
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
! Copyright (C) 2009, 2010 Daniel Ehrenberg.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays assocs fry kernel locals make math
|
||||
namespaces sequences sets combinators.short-circuit
|
||||
compiler.cfg.def-use compiler.cfg.dependence
|
||||
compiler.cfg.instructions compiler.cfg.rpo cpu.architecture ;
|
||||
USING: accessors arrays assocs compiler.cfg.def-use compiler.cfg.dependence
|
||||
compiler.cfg.instructions compiler.cfg.linear-scan.numbering compiler.cfg.rpo
|
||||
cpu.architecture fry kernel make math namespaces sequences sets splitting ;
|
||||
IN: compiler.cfg.scheduling
|
||||
|
||||
! Instruction scheduling to reduce register pressure, from:
|
||||
|
@ -40,7 +39,7 @@ ERROR: bad-delete-at key assoc ;
|
|||
|
||||
: select-instruction ( -- insn/f )
|
||||
roots get [ f ] [
|
||||
[ score ] select
|
||||
[ score ] select
|
||||
[ insn>> ]
|
||||
[ set-parent-indices ]
|
||||
[ remove-node ] tri
|
||||
|
@ -67,34 +66,21 @@ conditional-branch-insn
|
|||
: final-insn-start ( insns -- n )
|
||||
[ final-insn? not ] find-last drop [ 1 + ] [ 0 ] if* ;
|
||||
|
||||
:: split-3-ways ( insns -- first middle last )
|
||||
insns initial-insn-end :> a
|
||||
insns final-insn-start :> b
|
||||
insns a head-slice
|
||||
a b insns <slice>
|
||||
insns b tail-slice ;
|
||||
: split-insns ( insns -- pre body post )
|
||||
dup [ initial-insn-end ] [ final-insn-start ] bi 2array split-indices
|
||||
first3 ;
|
||||
|
||||
: reorder ( insns -- insns' )
|
||||
split-3-ways [
|
||||
split-insns [
|
||||
build-dependence-graph
|
||||
build-fan-in-trees
|
||||
[ (reorder) ] V{ } make reverse
|
||||
] dip 3append ;
|
||||
|
||||
: number-insns ( insns -- )
|
||||
[ >>insn# drop ] each-index ;
|
||||
|
||||
: clear-numbers ( insns -- )
|
||||
[ f >>insn# drop ] each ;
|
||||
|
||||
: schedule-block ( bb -- )
|
||||
[
|
||||
[ number-insns ]
|
||||
[ reorder ]
|
||||
[ clear-numbers ] tri
|
||||
] change-instructions drop ;
|
||||
[ reorder ] change-instructions drop ;
|
||||
|
||||
: schedule-instructions ( cfg -- cfg' )
|
||||
dup [
|
||||
dup kill-block?>> [ drop ] [ schedule-block ] if
|
||||
] each-basic-block ;
|
||||
! TODO: stack effect should be ( cfg -- )
|
||||
: schedule-instructions ( cfg -- cfg' )
|
||||
dup number-instructions
|
||||
dup reverse-post-order [ kill-block?>> not ] filter [ schedule-block ] each ;
|
||||
|
|
Loading…
Reference in New Issue