From a1b20e451b5a707b2b88524e6635ff0ed0753f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Sat, 8 Nov 2014 19:01:00 +0100 Subject: [PATCH] compiler.cfg.scheduling: split-insns returns a 3-tuple instead of 3 items on the stack --- .../cfg/scheduling/scheduling-tests.factor | 102 +++++++++--------- .../compiler/cfg/scheduling/scheduling.factor | 9 +- 2 files changed, 58 insertions(+), 53 deletions(-) diff --git a/basis/compiler/cfg/scheduling/scheduling-tests.factor b/basis/compiler/cfg/scheduling/scheduling-tests.factor index 7c2b3ff510..d458e4c30e 100644 --- a/basis/compiler/cfg/scheduling/scheduling-tests.factor +++ b/basis/compiler/cfg/scheduling/scheduling-tests.factor @@ -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 diff --git a/basis/compiler/cfg/scheduling/scheduling.factor b/basis/compiler/cfg/scheduling/scheduling.factor index cf403726eb..e42e8fdf90 100644 --- a/basis/compiler/cfg/scheduling/scheduling.factor +++ b/basis/compiler/cfg/scheduling/scheduling.factor @@ -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