diff --git a/basis/compiler/cfg/dependence/dependence.factor b/basis/compiler/cfg/dependence/dependence.factor index 73bb6f203d..3ba6a2b9b1 100644 --- a/basis/compiler/cfg/dependence/dependence.factor +++ b/basis/compiler/cfg/dependence/dependence.factor @@ -84,13 +84,12 @@ M: object add-control-edge 2drop ; : set-roots ( nodes -- ) [ ready? ] V{ } filter-as roots set ; -: build-dependence-graph ( instructions -- ) - [ ] map { +: build-dependence-graph ( nodes -- ) + { [ add-control-edges ] [ add-data-edges ] [ set-follows ] [ set-roots ] - [ nodes set ] } cleave ; ! Sethi-Ulmann numbering @@ -121,8 +120,7 @@ M: object add-control-edge 2drop ; ] if-empty ] [ drop ] if ; -: make-trees ( -- trees ) - nodes get +: make-trees ( nodes -- trees ) [ [ choose-parent ] each ] [ [ parent>> not ] filter ] bi ; @@ -146,8 +144,8 @@ ERROR: node-missing-children trees nodes ; : verify-trees ( trees -- trees ) verify-parents verify-children ; -: build-fan-in-trees ( -- ) - make-trees verify-trees [ +: build-fan-in-trees ( nodes -- ) + dup nodes set make-trees verify-trees [ -1/0. >>parent-index calculate-registers drop ] each ; diff --git a/basis/compiler/cfg/scheduling/scheduling-docs.factor b/basis/compiler/cfg/scheduling/scheduling-docs.factor index 5a61168c86..6571807260 100644 --- a/basis/compiler/cfg/scheduling/scheduling-docs.factor +++ b/basis/compiler/cfg/scheduling/scheduling-docs.factor @@ -1,10 +1,6 @@ USING: compiler.cfg compiler.cfg.height help.markup help.syntax sequences ; IN: compiler.cfg.scheduling -HELP: number-insns -{ $values { "insns" sequence } } -{ $description "Assigns a sequence number to the " { $slot "insn#" } " slot of each instruction in the sequence." } ; - HELP: schedule-instructions { $values { "cfg" cfg } { "cfg'" cfg } } { $description "Performs a instruction scheduling optimization pass over the CFG to attempt to reduce the number of spills. The step must be performed after " { $link normalize-height } " or else invalid peeks might be inserted into the CFG." } ; diff --git a/basis/compiler/cfg/scheduling/scheduling.factor b/basis/compiler/cfg/scheduling/scheduling.factor index e42e8fdf90..7079a178f0 100644 --- a/basis/compiler/cfg/scheduling/scheduling.factor +++ b/basis/compiler/cfg/scheduling/scheduling.factor @@ -66,15 +66,21 @@ conditional-branch-insn : final-insn-start ( insns -- n ) [ final-insn? not ] find-last drop [ 1 + ] [ 0 ] if* ; +! hack to get bootstrapping working +: split-indices-int ( seq indices -- pieces ) + over length suffix 0 swap [ dup swapd 2array ] map nip + [ first2 rot subseq ] with map ; + : split-insns ( insns -- pre/body/post ) - dup [ initial-insn-end ] [ final-insn-start ] bi 2array split-indices ; + dup [ initial-insn-end ] [ final-insn-start ] bi 2array split-indices-int ; + +: reorder-body ( body -- body' ) + [ ] map + [ build-dependence-graph ] [ build-fan-in-trees ] bi + [ (reorder) ] V{ } make reverse ; : reorder ( insns -- insns' ) - split-insns first3 [ - build-dependence-graph - build-fan-in-trees - [ (reorder) ] V{ } make reverse - ] dip 3append ; + split-insns first3 [ reorder-body ] dip 3append ; : schedule-block ( bb -- ) [ reorder ] change-instructions drop ;