compiler.cfg.stacks.local: refactoring making stack-changes and height-changes take and return stuff instead of using variables and the make building
parent
e87be7b5c8
commit
1bd4525ac6
|
@ -1,4 +1,4 @@
|
||||||
USING: compiler.cfg.parallel-copy tools.test make arrays
|
USING: compiler.cfg.parallel-copy tools.test arrays
|
||||||
compiler.cfg.registers namespaces compiler.cfg.instructions
|
compiler.cfg.registers namespaces compiler.cfg.instructions
|
||||||
cpu.architecture ;
|
cpu.architecture ;
|
||||||
IN: compiler.cfg.parallel-copy.tests
|
IN: compiler.cfg.parallel-copy.tests
|
||||||
|
@ -6,8 +6,13 @@ IN: compiler.cfg.parallel-copy.tests
|
||||||
SYMBOL: temp
|
SYMBOL: temp
|
||||||
|
|
||||||
: test-parallel-copy ( mapping -- seq )
|
: test-parallel-copy ( mapping -- seq )
|
||||||
3 vreg-counter set-global
|
3 vreg-counter set-global parallel-copy ;
|
||||||
[ parallel-copy ] { } make ;
|
|
||||||
|
{
|
||||||
|
{ }
|
||||||
|
} [
|
||||||
|
H{ } test-parallel-copy
|
||||||
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: assocs compiler.cfg.instructions compiler.cfg.registers
|
USING: assocs compiler.cfg.instructions compiler.cfg.registers
|
||||||
compiler.cfg.ssa.destruction.leaders cpu.architecture deques
|
compiler.cfg.ssa.destruction.leaders cpu.architecture deques
|
||||||
dlists fry kernel locals namespaces sequences ;
|
dlists fry kernel locals make namespaces sequences ;
|
||||||
FROM: sets => conjoin ;
|
FROM: sets => conjoin ;
|
||||||
IN: compiler.cfg.parallel-copy
|
IN: compiler.cfg.parallel-copy
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ SYMBOLS: locs preds to-do ready ;
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
:: parallel-mapping ( mapping temp: ( src -- dst ) quot: ( dst src -- ) -- )
|
:: parallel-mapping ( mapping temp: ( src -- dst ) quot: ( dst src -- ) -- )
|
||||||
! mapping is a list of { dst src } pairs
|
|
||||||
[
|
[
|
||||||
mapping init
|
mapping init
|
||||||
to-do get [
|
to-do get [
|
||||||
|
@ -52,8 +51,8 @@ PRIVATE>
|
||||||
] slurp-deque
|
] slurp-deque
|
||||||
] with-scope ; inline
|
] with-scope ; inline
|
||||||
|
|
||||||
: parallel-copy ( mapping -- )
|
: parallel-copy ( mapping -- insns )
|
||||||
next-vreg '[ drop _ ] [ any-rep ##copy, ] parallel-mapping ;
|
[ next-vreg '[ drop _ ] [ any-rep ##copy, ] parallel-mapping ] { } make ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
@ -65,7 +64,8 @@ SYMBOL: temp-vregs
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: parallel-copy-rep ( mapping -- )
|
: parallel-copy-rep ( mapping -- insns )
|
||||||
! mapping is a list of { dst src } pairs
|
[
|
||||||
H{ } clone temp-vregs set
|
H{ } clone temp-vregs set
|
||||||
[ rep-of temp-vreg ] [ dup rep-of ##copy, ] parallel-mapping ;
|
[ rep-of temp-vreg ] [ dup rep-of ##copy, ] parallel-mapping
|
||||||
|
] { } make ;
|
||||||
|
|
|
@ -130,7 +130,7 @@ M: ##copy cleanup-insn
|
||||||
M: ##parallel-copy cleanup-insn
|
M: ##parallel-copy cleanup-insn
|
||||||
values>>
|
values>>
|
||||||
[ first2 leaders 2array ] map [ first2 eq? not ] filter
|
[ first2 leaders 2array ] map [ first2 eq? not ] filter
|
||||||
[ parallel-copy-rep ] unless-empty ;
|
[ parallel-copy-rep % ] unless-empty ;
|
||||||
|
|
||||||
M: ##tagged>integer cleanup-insn
|
M: ##tagged>integer cleanup-insn
|
||||||
dup useful-copy? [ , ] [ drop ] if ;
|
dup useful-copy? [ , ] [ drop ] if ;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2009 Slava Pestov.
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs combinators compiler.cfg
|
USING: accessors arrays assocs combinators compiler.cfg
|
||||||
compiler.cfg.instructions compiler.cfg.parallel-copy
|
compiler.cfg.instructions compiler.cfg.parallel-copy
|
||||||
compiler.cfg.registers compiler.cfg.stacks.height kernel make
|
compiler.cfg.registers compiler.cfg.stacks.height kernel make
|
||||||
math math.order namespaces sequences sets ;
|
math math.order namespaces sequences sets ;
|
||||||
|
@ -26,21 +26,17 @@ GENERIC: translate-local-loc ( loc -- loc' )
|
||||||
M: ds-loc translate-local-loc n>> current-height get d>> - <ds-loc> ;
|
M: ds-loc translate-local-loc n>> current-height get d>> - <ds-loc> ;
|
||||||
M: rs-loc translate-local-loc n>> current-height get r>> - <rs-loc> ;
|
M: rs-loc translate-local-loc n>> current-height get r>> - <rs-loc> ;
|
||||||
|
|
||||||
: emit-stack-changes ( -- )
|
: stack-changes ( replace-mapping -- insns )
|
||||||
replace-mapping get dup assoc-empty? [ drop ] [
|
[ [ loc>vreg ] dip ] assoc-map parallel-copy ;
|
||||||
[ [ loc>vreg ] dip ] assoc-map parallel-copy
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
: emit-height-changes ( -- )
|
: height-changes ( current-height -- insns )
|
||||||
current-height get
|
[ emit-d>> ] [ emit-r>> ] bi 2array
|
||||||
[ emit-d>> dup 0 = [ drop ] [ ##inc-d, ] if ]
|
{ ##inc-d ##inc-r } [ new swap >>n ] 2map [ n>> 0 = not ] filter ;
|
||||||
[ emit-r>> dup 0 = [ drop ] [ ##inc-r, ] if ] bi ;
|
|
||||||
|
|
||||||
: emit-changes ( -- )
|
: emit-changes ( -- )
|
||||||
! Insert height and stack changes prior to the last instruction
|
|
||||||
building get pop
|
building get pop
|
||||||
emit-stack-changes
|
replace-mapping get stack-changes %
|
||||||
emit-height-changes
|
current-height get height-changes %
|
||||||
, ;
|
, ;
|
||||||
|
|
||||||
! inc-d/inc-r: these emit ##inc-d/##inc-r to change the stack height later
|
! inc-d/inc-r: these emit ##inc-d/##inc-r to change the stack height later
|
||||||
|
|
Loading…
Reference in New Issue