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
|
USING: accessors compiler.cfg compiler.cfg.instructions
|
||||||
vocabs.loader namespaces tools.test arrays kernel random
|
compiler.cfg.linearization compiler.cfg.scheduling compiler.cfg.utilities
|
||||||
words compiler.units ;
|
vocabs.loader namespaces tools.test arrays kernel random sequences words ;
|
||||||
IN: compiler.cfg.scheduling.tests
|
IN: compiler.cfg.scheduling.tests
|
||||||
|
|
||||||
! Test split-3-ways
|
! Test split-insns
|
||||||
[
|
[
|
||||||
{ }
|
{ }
|
||||||
{ }
|
{ }
|
||||||
{ T{ ##test-branch } }
|
{ T{ ##test-branch } }
|
||||||
] [
|
] [
|
||||||
V{ T{ ##test-branch } }
|
V{ T{ ##test-branch } }
|
||||||
split-3-ways
|
split-insns
|
||||||
[ >array ] tri@
|
[ >array ] tri@
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ IN: compiler.cfg.scheduling.tests
|
||||||
T{ ##mul }
|
T{ ##mul }
|
||||||
T{ ##test-branch }
|
T{ ##test-branch }
|
||||||
}
|
}
|
||||||
split-3-ways
|
split-insns
|
||||||
[ >array ] tri@
|
[ >array ] tri@
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
@ -43,6 +43,65 @@ IN: compiler.cfg.scheduling.tests
|
||||||
T{ ##mul }
|
T{ ##mul }
|
||||||
T{ ##dispatch }
|
T{ ##dispatch }
|
||||||
}
|
}
|
||||||
split-3-ways
|
split-insns
|
||||||
[ >array ] tri@
|
[ >array ] tri@
|
||||||
] unit-test
|
] 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.
|
! Copyright (C) 2009, 2010 Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays assocs fry kernel locals make math
|
USING: accessors arrays assocs compiler.cfg.def-use compiler.cfg.dependence
|
||||||
namespaces sequences sets combinators.short-circuit
|
compiler.cfg.instructions compiler.cfg.linear-scan.numbering compiler.cfg.rpo
|
||||||
compiler.cfg.def-use compiler.cfg.dependence
|
cpu.architecture fry kernel make math namespaces sequences sets splitting ;
|
||||||
compiler.cfg.instructions compiler.cfg.rpo cpu.architecture ;
|
|
||||||
IN: compiler.cfg.scheduling
|
IN: compiler.cfg.scheduling
|
||||||
|
|
||||||
! Instruction scheduling to reduce register pressure, from:
|
! Instruction scheduling to reduce register pressure, from:
|
||||||
|
@ -67,34 +66,21 @@ conditional-branch-insn
|
||||||
: final-insn-start ( insns -- n )
|
: final-insn-start ( insns -- n )
|
||||||
[ final-insn? not ] find-last drop [ 1 + ] [ 0 ] if* ;
|
[ final-insn? not ] find-last drop [ 1 + ] [ 0 ] if* ;
|
||||||
|
|
||||||
:: split-3-ways ( insns -- first middle last )
|
: split-insns ( insns -- pre body post )
|
||||||
insns initial-insn-end :> a
|
dup [ initial-insn-end ] [ final-insn-start ] bi 2array split-indices
|
||||||
insns final-insn-start :> b
|
first3 ;
|
||||||
insns a head-slice
|
|
||||||
a b insns <slice>
|
|
||||||
insns b tail-slice ;
|
|
||||||
|
|
||||||
: reorder ( insns -- insns' )
|
: reorder ( insns -- insns' )
|
||||||
split-3-ways [
|
split-insns [
|
||||||
build-dependence-graph
|
build-dependence-graph
|
||||||
build-fan-in-trees
|
build-fan-in-trees
|
||||||
[ (reorder) ] V{ } make reverse
|
[ (reorder) ] V{ } make reverse
|
||||||
] dip 3append ;
|
] dip 3append ;
|
||||||
|
|
||||||
: number-insns ( insns -- )
|
|
||||||
[ >>insn# drop ] each-index ;
|
|
||||||
|
|
||||||
: clear-numbers ( insns -- )
|
|
||||||
[ f >>insn# drop ] each ;
|
|
||||||
|
|
||||||
: schedule-block ( bb -- )
|
: schedule-block ( bb -- )
|
||||||
[
|
[ reorder ] change-instructions drop ;
|
||||||
[ number-insns ]
|
|
||||||
[ reorder ]
|
|
||||||
[ clear-numbers ] tri
|
|
||||||
] change-instructions drop ;
|
|
||||||
|
|
||||||
|
! TODO: stack effect should be ( cfg -- )
|
||||||
: schedule-instructions ( cfg -- cfg' )
|
: schedule-instructions ( cfg -- cfg' )
|
||||||
dup [
|
dup number-instructions
|
||||||
dup kill-block?>> [ drop ] [ schedule-block ] if
|
dup reverse-post-order [ kill-block?>> not ] filter [ schedule-block ] each ;
|
||||||
] each-basic-block ;
|
|
||||||
|
|
Loading…
Reference in New Issue