compiler.cfg.scheduling: split-insns returns a 3-tuple instead of 3 items on the stack

db4
Björn Lindqvist 2014-11-08 19:01:00 +01:00 committed by Doug Coleman
parent c777cb954a
commit a1b20e451b
2 changed files with 58 additions and 53 deletions

View File

@ -1,24 +1,24 @@
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 ;
vocabs.loader namespaces tools.test arrays kernel random sequences sets words ;
IN: compiler.cfg.scheduling.tests
! Test split-insns
[
{ }
{ }
{ T{ ##test-branch } }
] [
V{ T{ ##test-branch } }
split-insns
[ >array ] tri@
] unit-test
{
{
V{ }
V{ }
V{ T{ ##test-branch } }
}
} [ V{ T{ ##test-branch } } split-insns ] unit-test
[
{ T{ ##inc-d } T{ ##inc-r } T{ ##callback-inputs } }
{ T{ ##add } T{ ##sub } T{ ##mul } }
{ T{ ##test-branch } }
] [
{
{
V{ T{ ##inc-d } T{ ##inc-r } T{ ##callback-inputs } }
V{ T{ ##add } T{ ##sub } T{ ##mul } }
V{ T{ ##test-branch } }
}
} [
V{
T{ ##inc-d }
T{ ##inc-r }
@ -27,24 +27,22 @@ IN: compiler.cfg.scheduling.tests
T{ ##sub }
T{ ##mul }
T{ ##test-branch }
}
split-insns
[ >array ] tri@
} split-insns
] unit-test
[
{ }
{ T{ ##add } T{ ##sub } T{ ##mul } }
{ T{ ##dispatch } }
{
V{ }
V{ T{ ##add } T{ ##sub } T{ ##mul } }
V{ T{ ##dispatch } }
}
] [
V{
T{ ##add }
T{ ##sub }
T{ ##mul }
T{ ##dispatch }
}
split-insns
[ >array ] tri@
} split-insns
] unit-test
! Instructions gets numbered as a side-effect
@ -59,29 +57,7 @@ IN: compiler.cfg.scheduling.tests
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 } }
} [
: test-1187 ( -- insns )
V{
##inc-r
##inc-d
@ -103,5 +79,35 @@ IN: compiler.cfg.scheduling.tests
##replace-imm
##replace
##branch
} [ new ] map split-insns [ >array ] tri@
} [ new ] map ;
{
{
V{ T{ ##inc-r } T{ ##inc-d } }
V{
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 }
}
V{ T{ ##branch } }
}
} [ test-1187 split-insns ] unit-test
! You should get the exact same instruction order each time.
{ 1 } [
10 [ test-1187 split-insns 1 swap nth ] replicate members length
] unit-test

View File

@ -25,7 +25,7 @@ ERROR: bad-delete-at key assoc ;
'[ [ precedes>> _ swap check-delete-at ] each ]
[ [ ready? ] filter roots get push-all ] bi ;
: score ( insn -- n )
: score ( node -- n )
[ parent-index>> ] [ registers>> neg ] [ insn>> insn#>> ] tri 3array ;
: pull-out-nth ( n seq -- elt )
@ -66,12 +66,11 @@ conditional-branch-insn
: final-insn-start ( insns -- n )
[ final-insn? not ] find-last drop [ 1 + ] [ 0 ] if* ;
: split-insns ( insns -- pre body post )
dup [ initial-insn-end ] [ final-insn-start ] bi 2array split-indices
first3 ;
: split-insns ( insns -- pre/body/post )
dup [ initial-insn-end ] [ final-insn-start ] bi 2array split-indices ;
: reorder ( insns -- insns' )
split-insns [
split-insns first3 [
build-dependence-graph
build-fan-in-trees
[ (reorder) ] V{ } make reverse