From 820207c5b07b1efa7e4db1346794e0ee2fb276a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Tue, 28 Jul 2015 20:39:51 +0200 Subject: [PATCH] compiler.cfg.ssa.destruction.coalescing: simpler code for setting up the initial leader-map and class-element-map --- .../coalescing/coalescing-tests.factor | 59 +++++++++++++++++-- .../destruction/coalescing/coalescing.factor | 35 ++++++----- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/basis/compiler/cfg/ssa/destruction/coalescing/coalescing-tests.factor b/basis/compiler/cfg/ssa/destruction/coalescing/coalescing-tests.factor index 4eecdb0061..309cda82c1 100644 --- a/basis/compiler/cfg/ssa/destruction/coalescing/coalescing-tests.factor +++ b/basis/compiler/cfg/ssa/destruction/coalescing/coalescing-tests.factor @@ -1,15 +1,64 @@ USING: assocs compiler.cfg.def-use compiler.cfg.instructions -compiler.cfg.ssa.destruction.coalescing compiler.cfg.ssa.destruction.leaders -cpu.architecture grouping kernel make namespaces random sequences tools.test ; +compiler.cfg.ssa.destruction.coalescing +compiler.cfg.ssa.destruction.leaders compiler.cfg.ssa.interference +compiler.cfg.utilities cpu.architecture grouping kernel make +namespaces random sequences tools.test ; QUALIFIED: sets IN: compiler.cfg.ssa.destruction.coalescing.tests -! init-coalescing +! initial-class-elements { - H{ { 123 123 } { 77 77 } } + H{ + { + 77 + { T{ vreg-info { vreg 77 } { value 77 } { bb "bb2" } } } + } + { + 123 + { + T{ vreg-info + { vreg 123 } + { value 123 } + { bb "bb1" } + } + } + } + } } [ H{ { 123 "bb1" } { 77 "bb2" } } defs set - init-coalescing + initial-class-elements +] unit-test + +! initial-leaders +{ + H{ { 65 65 } { 99 99 } { 62 62 } { 303 303 } } +} [ + { + T{ ##load-vector + { dst 62 } + { val B{ 0 0 0 0 0 0 0 64 0 0 0 0 0 0 52 64 } } + { rep double-2-rep } + } + T{ ##add-vector + { dst 65 } + { src1 62 } + { src2 63 } + { rep double-2-rep } + } + T{ ##allot + { dst 99 } + { size 24 } + { temp 303 } + } + } insns>cfg initial-leaders +] unit-test + +! init-coalescing +{ + H{ { 118 118 } } +} [ + { T{ ##phi { dst 118 } { inputs H{ { 4 120 } { 2 119 } } } } } insns>cfg + dup compute-defs init-coalescing leader-map get ] unit-test diff --git a/basis/compiler/cfg/ssa/destruction/coalescing/coalescing.factor b/basis/compiler/cfg/ssa/destruction/coalescing/coalescing.factor index 11aeb9afad..90e0049f93 100644 --- a/basis/compiler/cfg/ssa/destruction/coalescing/coalescing.factor +++ b/basis/compiler/cfg/ssa/destruction/coalescing/coalescing.factor @@ -14,14 +14,6 @@ SYMBOL: class-element-map : value-of ( vreg -- value ) dup insn-of dup ##tagged>integer? [ nip src>> ] [ drop ] if ; -: init-coalescing ( -- ) - defs get - [ keys unique leader-map set ] - [ - [ [ dup dup value-of ] dip 1array ] assoc-map - class-element-map set - ] bi ; - : coalesce-elements ( merged follower leader -- ) class-element-map get [ delete-at ] [ set-at ] bi-curry bi* ; @@ -50,15 +42,12 @@ M: insn coalesce-insn drop ; M: alien-call-insn coalesce-insn drop ; M: vreg-insn coalesce-insn - [ temp-vregs [ leader-map get conjoin ] each ] - [ - [ defs-vregs ] [ uses-vregs ] bi - 2dup [ empty? not ] both? [ - [ first ] bi@ - 2dup [ rep-of reg-class-of ] bi@ eq? - [ 2array , ] [ 2drop ] if - ] [ 2drop ] if - ] bi ; + [ defs-vregs ] [ uses-vregs ] bi + 2dup [ empty? not ] both? [ + [ first ] bi@ + 2dup [ rep-of reg-class-of ] bi@ eq? + [ 2array , ] [ 2drop ] if + ] [ 2drop ] if ; M: ##copy coalesce-insn [ dst>> ] [ src>> ] bi 2array , ; @@ -73,7 +62,17 @@ M: ##phi coalesce-insn [ dst>> ] [ inputs>> values ] bi zip-scalar natural-sort t try-eliminate-copies ; +: initial-leaders ( cfg -- leaders ) + cfg>insns [ [ defs-vregs ] [ temp-vregs ] bi append ] map concat unique ; + +: initial-class-elements ( -- class-elements ) + defs get [ [ dup dup value-of ] dip 1array ] assoc-map ; + +: init-coalescing ( cfg -- ) + initial-leaders leader-map set + initial-class-elements class-element-map set ; + : coalesce-cfg ( cfg -- ) - init-coalescing + dup init-coalescing cfg>insns-rpo [ [ coalesce-insn ] each ] V{ } make f try-eliminate-copies ;