From 31f23c8eba38f1df062cd73369c957f8ae0ffb0b Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Wed, 24 Mar 2010 10:38:52 -0400 Subject: [PATCH] Scheduling uses sets where appropriate --- basis/compiler/cfg/dependence/dependence.factor | 14 ++++++-------- basis/compiler/cfg/scheduling/scheduling.factor | 10 +++++----- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/basis/compiler/cfg/dependence/dependence.factor b/basis/compiler/cfg/dependence/dependence.factor index 947e9e3bd1..d25f29cdbb 100644 --- a/basis/compiler/cfg/dependence/dependence.factor +++ b/basis/compiler/cfg/dependence/dependence.factor @@ -4,6 +4,7 @@ USING: accessors assocs combinators compiler.cfg.def-use compiler.cfg.instructions compiler.cfg.registers fry kernel locals namespaces sequences sets sorting math.vectors make math combinators.short-circuit vectors ; +FROM: namespaces => set ; IN: compiler.cfg.dependence ! Dependence graph construction @@ -32,15 +33,12 @@ M: node hashcode* nip number>> ; node-number counter >>number swap >>insn H{ } clone >>precedes - H{ } clone >>follows ; + V{ } clone >>follows ; : ready? ( node -- ? ) precedes>> assoc-empty? ; -: spin ( a b c -- c b a ) - [ 2nip ] [ drop nip ] [ 2drop ] 3tri ; - -: precedes ( first second how -- ) - spin precedes>> set-at ; +:: precedes ( first second how -- ) + how second first precedes>> set-at ; :: add-data-edges ( nodes -- ) ! This builds up def-use information on the fly, since @@ -107,12 +105,12 @@ M: object add-control-edge 2drop ; : set-follows ( nodes -- ) [ dup precedes>> keys [ - follows>> conjoin + follows>> push ] with each ] each ; : set-roots ( nodes -- ) - [ ready? ] filter V{ } like roots set ; + [ ready? ] V{ } filter-as roots set ; : build-dependence-graph ( instructions -- ) [ ] map { diff --git a/basis/compiler/cfg/scheduling/scheduling.factor b/basis/compiler/cfg/scheduling/scheduling.factor index 2f08ad96cf..816e333b9e 100644 --- a/basis/compiler/cfg/scheduling/scheduling.factor +++ b/basis/compiler/cfg/scheduling/scheduling.factor @@ -26,7 +26,7 @@ ERROR: bad-delete-at key assoc ; '[ _ >>parent-index drop ] each ; : remove-node ( node -- ) - [ follows>> keys ] keep + [ follows>> members ] keep '[ [ precedes>> _ swap check-delete-at ] each ] [ [ ready? ] filter roots get push-all ] bi ; @@ -84,12 +84,12 @@ t check-scheduling? set-global ERROR: definition-after-usage vreg old-bb new-bb ; :: check-usages ( new-bb old-bb -- ) - H{ } clone :> useds + HS{ } clone :> useds new-bb instructions>> split-3-ways drop nip [| insn | - insn uses-vregs [ useds conjoin ] each + insn uses-vregs [ useds adjoin ] each insn defs-vreg :> def-reg - def-reg useds key? + def-reg useds in? [ def-reg old-bb new-bb definition-after-usage ] when ] each ; @@ -132,7 +132,7 @@ ERROR: definition-after-usage vreg old-bb new-bb ; : schedule-instructions ( cfg -- cfg' ) dup [ - dup might-spill? + dup might-spill? [ schedule-block ] [ drop ] if ] each-basic-block ;