From 355d89e8e814a941c1e87a75c3a2af20cf38e131 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 27 Jul 2010 12:40:31 -0400 Subject: [PATCH] compiler.cfg: now that kill-blocks cannot contain instructions that define vregs we can skip them all --- basis/compiler/cfg/copy-prop/copy-prop.factor | 4 +-- basis/compiler/cfg/def-use/def-use.factor | 10 +++---- .../linear-scan/assignment/assignment.factor | 28 ++++++++++--------- .../live-intervals/live-intervals.factor | 26 +++++++++-------- .../cfg/linear-scan/resolve/resolve.factor | 4 ++- .../coalescing/coalescing.factor | 8 +++--- .../cfg/save-contexts/save-contexts.factor | 8 ++++-- .../cfg/ssa/destruction/destruction.factor | 5 +--- .../live-ranges/live-ranges.factor | 11 ++++---- 9 files changed, 55 insertions(+), 49 deletions(-) diff --git a/basis/compiler/cfg/copy-prop/copy-prop.factor b/basis/compiler/cfg/copy-prop/copy-prop.factor index 29498affc2..e4de7d9880 100644 --- a/basis/compiler/cfg/copy-prop/copy-prop.factor +++ b/basis/compiler/cfg/copy-prop/copy-prop.factor @@ -53,8 +53,8 @@ M: insn visit-insn drop ; : (collect-copies) ( cfg -- ) [ phis get clear-assoc - instructions>> [ visit-insn ] each - ] each-basic-block ; + [ visit-insn ] each + ] simple-analysis ; : collect-copies ( cfg -- ) H{ } clone copies set diff --git a/basis/compiler/cfg/def-use/def-use.factor b/basis/compiler/cfg/def-use/def-use.factor index 99e87b277b..04443db45d 100644 --- a/basis/compiler/cfg/def-use/def-use.factor +++ b/basis/compiler/cfg/def-use/def-use.factor @@ -4,7 +4,7 @@ USING: accessors assocs arrays classes combinators compiler.units fry generalizations sequences.generalizations generic kernel locals namespaces quotations sequences sets slots words compiler.cfg.instructions compiler.cfg.instructions.syntax -compiler.cfg.rpo ; +compiler.cfg.rpo compiler.cfg ; FROM: namespaces => set ; FROM: sets => members ; IN: compiler.cfg.def-use @@ -91,17 +91,17 @@ SYMBOLS: defs insns ; : compute-defs ( cfg -- ) H{ } clone [ '[ - dup instructions>> [ + [ basic-block get ] dip [ _ set-def-of ] with each - ] each-basic-block + ] simple-analysis ] keep defs set ; : compute-insns ( cfg -- ) H{ } clone [ '[ - instructions>> [ + [ dup _ set-def-of ] each - ] each-basic-block + ] simple-analysis ] keep insns set ; diff --git a/basis/compiler/cfg/linear-scan/assignment/assignment.factor b/basis/compiler/cfg/linear-scan/assignment/assignment.factor index cab4438ec9..ef02b890f7 100644 --- a/basis/compiler/cfg/linear-scan/assignment/assignment.factor +++ b/basis/compiler/cfg/linear-scan/assignment/assignment.factor @@ -158,20 +158,22 @@ M: insn assign-registers-in-insn drop ; } cleave ; :: assign-registers-in-block ( bb -- ) - bb [ - [ - bb begin-block + bb kill-block?>> [ + bb [ [ - { - [ insn#>> 1 - prepare-insn ] - [ insn#>> prepare-insn ] - [ assign-registers-in-insn ] - [ , ] - } cleave - ] each - bb compute-live-out - ] V{ } make - ] change-instructions drop ; + bb begin-block + [ + { + [ insn#>> 1 - prepare-insn ] + [ insn#>> prepare-insn ] + [ assign-registers-in-insn ] + [ , ] + } cleave + ] each + bb compute-live-out + ] V{ } make + ] change-instructions drop + ] unless ; : assign-registers ( live-intervals cfg -- ) [ init-assignment ] dip diff --git a/basis/compiler/cfg/linear-scan/live-intervals/live-intervals.factor b/basis/compiler/cfg/linear-scan/live-intervals/live-intervals.factor index fbe0cd4507..41545981c2 100644 --- a/basis/compiler/cfg/linear-scan/live-intervals/live-intervals.factor +++ b/basis/compiler/cfg/linear-scan/live-intervals/live-intervals.factor @@ -171,18 +171,20 @@ M: clobber-insn compute-sync-points* M: insn compute-sync-points* drop ; : compute-live-intervals-step ( bb -- ) - { - [ block-from from set ] - [ block-to to set ] - [ handle-live-out ] - [ - instructions>> [ - [ compute-live-intervals* ] - [ compute-sync-points* ] - bi - ] each - ] - } cleave ; + dup kill-block?>> [ drop ] [ + { + [ block-from from set ] + [ block-to to set ] + [ handle-live-out ] + [ + instructions>> [ + [ compute-live-intervals* ] + [ compute-sync-points* ] + bi + ] each + ] + } cleave + ] if ; : init-live-intervals ( -- ) H{ } clone live-intervals set diff --git a/basis/compiler/cfg/linear-scan/resolve/resolve.factor b/basis/compiler/cfg/linear-scan/resolve/resolve.factor index 9d3c91ca18..564c2978f5 100644 --- a/basis/compiler/cfg/linear-scan/resolve/resolve.factor +++ b/basis/compiler/cfg/linear-scan/resolve/resolve.factor @@ -99,7 +99,9 @@ SYMBOL: temp 2dup compute-mappings perform-mappings ; : resolve-block-data-flow ( bb -- ) - dup successors>> [ resolve-edge-data-flow ] with each ; + dup kill-block?>> [ drop ] [ + dup successors>> [ resolve-edge-data-flow ] with each + ] if ; : resolve-data-flow ( cfg -- ) needs-predecessors diff --git a/basis/compiler/cfg/representations/coalescing/coalescing.factor b/basis/compiler/cfg/representations/coalescing/coalescing.factor index 6e31e82201..2caa485045 100644 --- a/basis/compiler/cfg/representations/coalescing/coalescing.factor +++ b/basis/compiler/cfg/representations/coalescing/coalescing.factor @@ -11,10 +11,10 @@ SYMBOL: components : init-components ( cfg components -- ) '[ - instructions>> [ + [ defs-vregs [ _ add-atom ] each ] each - ] each-basic-block ; + ] simple-analysis ; GENERIC# visit-insn 1 ( insn disjoint-set -- ) @@ -28,10 +28,10 @@ M: insn visit-insn 2drop ; : merge-components ( cfg components -- ) '[ - instructions>> [ + [ _ visit-insn ] each - ] each-basic-block ; + ] simple-analysis ; : compute-components ( cfg -- ) diff --git a/basis/compiler/cfg/save-contexts/save-contexts.factor b/basis/compiler/cfg/save-contexts/save-contexts.factor index 57691f1a4e..3e42c51bc5 100644 --- a/basis/compiler/cfg/save-contexts/save-contexts.factor +++ b/basis/compiler/cfg/save-contexts/save-contexts.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2009, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors compiler.cfg.instructions compiler.cfg.registers -compiler.cfg.rpo cpu.architecture kernel sequences vectors ; +compiler.cfg.rpo cpu.architecture kernel sequences vectors +combinators.short-circuit ; IN: compiler.cfg.save-contexts ! Insert context saves. @@ -14,7 +15,10 @@ M: gc-map-insn needs-save-context? drop t ; M: insn needs-save-context? drop f ; : bb-needs-save-context? ( insn -- ? ) - instructions>> [ needs-save-context? ] any? ; + { + [ kill-block?>> not ] + [ instructions>> [ needs-save-context? ] any? ] + } 1&& ; GENERIC: modifies-context? ( insn -- ? ) diff --git a/basis/compiler/cfg/ssa/destruction/destruction.factor b/basis/compiler/cfg/ssa/destruction/destruction.factor index bd5a84afc7..197093e5ae 100644 --- a/basis/compiler/cfg/ssa/destruction/destruction.factor +++ b/basis/compiler/cfg/ssa/destruction/destruction.factor @@ -103,12 +103,9 @@ M: ##phi prepare-insn [ dst>> ] [ inputs>> values ] bi [ maybe-eliminate-copy ] with each ; -: prepare-block ( bb -- ) - instructions>> [ prepare-insn ] each ; - : prepare-coalescing ( cfg -- ) init-coalescing - [ prepare-block ] each-basic-block ; + [ [ prepare-insn ] each ] simple-analysis ; : process-copies ( -- ) copies get [ maybe-eliminate-copy ] assoc-each ; diff --git a/basis/compiler/cfg/ssa/interference/live-ranges/live-ranges.factor b/basis/compiler/cfg/ssa/interference/live-ranges/live-ranges.factor index d301b14996..ffbbf8739f 100644 --- a/basis/compiler/cfg/ssa/interference/live-ranges/live-ranges.factor +++ b/basis/compiler/cfg/ssa/interference/live-ranges/live-ranges.factor @@ -38,13 +38,12 @@ M: insn record-insn SYMBOLS: def-indices kill-indices ; -: compute-local-live-ranges ( bb -- ) +: compute-local-live-ranges ( insns -- ) H{ } clone local-def-indices set H{ } clone local-kill-indices set - [ instructions>> [ swap record-insn ] each-index ] - [ [ local-def-indices get ] dip def-indices get set-at ] - [ [ local-kill-indices get ] dip kill-indices get set-at ] - tri ; + [ swap record-insn ] each-index + local-def-indices get basic-block get def-indices get set-at + local-kill-indices get basic-block get kill-indices get set-at ; PRIVATE> @@ -53,7 +52,7 @@ PRIVATE> H{ } clone def-indices set H{ } clone kill-indices set - [ compute-local-live-ranges ] each-basic-block ; + [ compute-local-live-ranges ] simple-analysis ; : def-index ( vreg bb -- n ) def-indices get at at ;