compiler.cfg.*: replacing the peek/replace/kill-sets with slots

So instead of storing the info in variables, it is stored in slots on
the basic-block tuple which is much nicer.
char-rename
Björn Lindqvist 2016-08-29 12:07:47 +02:00
parent e8e1811542
commit 6c88577ee7
8 changed files with 43 additions and 48 deletions

View File

@ -36,6 +36,18 @@ HELP: basic-block
{ $slot "rs-height" } { $slot "rs-height" }
"The retainstacks height at the entry of the block. Used during cfg construction." "The retainstacks height at the entry of the block. Used during cfg construction."
} }
{
{ $slot "replaces" }
{ "Used by " { $vocab-link "compiler.cfg.stacks.local" } " for local stack analysis." }
}
{
{ $slot "peeks" }
{ "Used by " { $vocab-link "compiler.cfg.stacks.local" } " for local stack analysis." }
}
{
{ $slot "kills" }
{ "Used by " { $vocab-link "compiler.cfg.stacks.local" } " for local stack analysis." }
}
} }
} }
{ $notes "A basic-block is an " { $link identity-tuple } " becase it is used as a hash table key by the compiler." } ; { $notes "A basic-block is an " { $link identity-tuple } " becase it is used as a hash table key by the compiler." } ;

View File

@ -10,7 +10,10 @@ TUPLE: basic-block < identity-tuple
{ successors vector } { successors vector }
{ predecessors vector } { predecessors vector }
{ kill-block? boolean } { kill-block? boolean }
ds-height rs-height ; ds-height rs-height
replaces
peeks
kills ;
: <basic-block> ( -- bb ) : <basic-block> ( -- bb )
basic-block new basic-block new

View File

@ -55,10 +55,7 @@ IN: compiler.cfg.intrinsics.simd.tests
initial-height-state \ height-state pick set-at initial-height-state \ height-state pick set-at
HS{ } clone \ local-peek-set pick set-at HS{ } clone \ local-peek-set pick set-at
H{ } clone \ replaces pick set-at H{ } clone \ replaces pick set-at
H{ } <biassoc> \ locs>vregs pick set-at H{ } <biassoc> \ locs>vregs pick set-at ;
H{ } clone \ peek-sets pick set-at
H{ } clone \ replace-sets pick set-at
H{ } clone \ kill-sets pick set-at ;
: make-classes ( quot -- seq ) : make-classes ( quot -- seq )
{ } make [ class-of ] map ; inline { } make [ class-of ] map ; inline

View File

@ -1,19 +1,14 @@
! 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: assocs compiler.cfg.dataflow-analysis compiler.cfg.stacks.local USING: accessors compiler.cfg.dataflow-analysis kernel sequences sets ;
kernel namespaces sequences sets ;
IN: compiler.cfg.stacks.global IN: compiler.cfg.stacks.global
: peek-set ( bb -- assoc ) peek-sets get at ;
: replace-set ( bb -- assoc ) replace-sets get at ;
: kill-set ( bb -- assoc ) kill-sets get at ;
! Should exists somewhere else ! Should exists somewhere else
: refine ( sets -- set ) : refine ( sets -- set )
[ f ] [ [ ] [ intersect ] map-reduce ] if-empty ; [ f ] [ [ ] [ intersect ] map-reduce ] if-empty ;
: transfer-peeked-locs ( set bb -- set' ) : transfer-peeked-locs ( set bb -- set' )
[ replace-set diff ] [ peek-set union ] bi ; [ replaces>> diff ] [ peeks>> union ] bi ;
BACKWARD-ANALYSIS: anticip BACKWARD-ANALYSIS: anticip
@ -27,18 +22,18 @@ M: live join-sets 2drop combine ;
FORWARD-ANALYSIS: avail FORWARD-ANALYSIS: avail
M: avail transfer-set M: avail transfer-set ( in-set bb dfa -- out-set )
drop [ peek-set ] [ replace-set ] bi union union ; drop [ peeks>> ] [ replaces>> ] bi union union ;
M: avail join-sets 2drop refine ; M: avail join-sets 2drop refine ;
FORWARD-ANALYSIS: pending FORWARD-ANALYSIS: pending
M: pending transfer-set M: pending transfer-set
drop replace-set union ; drop replaces>> union ;
M: pending join-sets 2drop refine ; M: pending join-sets 2drop refine ;
BACKWARD-ANALYSIS: dead BACKWARD-ANALYSIS: dead
M: dead transfer-set M: dead transfer-set
drop [ kill-set ] [ replace-set ] bi union union ; drop [ kills>> ] [ replaces>> ] bi union union ;
M: dead join-sets 2drop refine ; M: dead join-sets 2drop refine ;

View File

@ -1,6 +1,6 @@
USING: assocs compiler.cfg compiler.cfg.instructions USING: assocs compiler.cfg compiler.cfg.instructions
compiler.cfg.registers compiler.cfg.stacks hash-sets hashtables compiler.cfg.registers compiler.cfg.stacks hash-sets hashtables
help.markup help.syntax math sequences ; help.markup help.syntax kernel math sequences ;
IN: compiler.cfg.stacks.local IN: compiler.cfg.stacks.local
HELP: emit-changes HELP: emit-changes
@ -9,7 +9,7 @@ HELP: emit-changes
HELP: end-local-analysis HELP: end-local-analysis
{ $values { "basic-block" basic-block } } { $values { "basic-block" basic-block } }
{ $description "Called to end the local analysis of a block. The word writes to the dynamic variables " { $link replace-sets } ", " { $link peek-sets } " and " { $link kill-sets } " what the blocks replaces, peeks and kill locations are." } ; { $description "Called to end the local analysis of a block. The word fills in the blocks slots " { $slot "replaces" } ", " { $slot "peeks" } " and " { $slot "kills" } " with what the blocks replaces, peeks and kill locations are." } ;
HELP: height-state HELP: height-state
{ $var-description "A two-tuple used to keep track of the heights of the data and retain stacks in a " { $link basic-block } " The idea is that if the stack change instructions are tracked, then multiple changes can be folded into one. The first item is the datastacks current height and queued up height change. The second item is the same for the retain stack." } ; { $var-description "A two-tuple used to keep track of the heights of the data and retain stacks in a " { $link basic-block } " The idea is that if the stack change instructions are tracked, then multiple changes can be folded into one. The first item is the datastacks current height and queued up height change. The second item is the same for the retain stack." } ;
@ -30,9 +30,6 @@ HELP: inc-stack
{ $values { "loc" loc } } { $values { "loc" loc } }
{ $description "Increases or decreases the data or retain stack depending on if loc is a " { $link ds-loc } " or " { $link rs-loc } " instance. An " { $link ##inc } " instruction will later be inserted." } ; { $description "Increases or decreases the data or retain stack depending on if loc is a " { $link ds-loc } " or " { $link rs-loc } " instance. An " { $link ##inc } " instruction will later be inserted." } ;
HELP: kill-sets
{ $var-description "A " { $link hashtable } " that maps from " { $link basic-block } " to the stack locations that are killed in that block. Stack locations are deemed killed when the stack height is decreased." } ;
HELP: loc>vreg HELP: loc>vreg
{ $values { "loc" loc } { "vreg" "virtual register" } } { $values { "loc" loc } { "vreg" "virtual register" } }
{ $description "Maps a stack location to a virtual register." } ; { $description "Maps a stack location to a virtual register." } ;
@ -63,9 +60,6 @@ HELP: replace-loc
{ $description "Registers that the absolute stack location " { $snippet "loc" } " should be overwritten with the contents of the virtual register." } { $description "Registers that the absolute stack location " { $snippet "loc" } " should be overwritten with the contents of the virtual register." }
{ $see-also replaces } ; { $see-also replaces } ;
HELP: replace-sets
{ $var-description "An " { $link assoc } " in which each key is a " { $link basic-block } " and each value a " { $link hash-set } " with locations that were replaced in that block." } ;
HELP: replaces HELP: replaces
{ $var-description "An " { $link assoc } " that maps from stack locations to virtual registers that were put on the stack during the local analysis phase. " { $link ds-push } " and similar words writes to it." } { $var-description "An " { $link assoc } " that maps from stack locations to virtual registers that were put on the stack during the local analysis phase. " { $link ds-push } " and similar words writes to it." }
{ $see-also replace-loc } ; { $see-also replace-loc } ;
@ -83,11 +77,11 @@ HELP: translate-local-loc
{ $see-also height-state } ; { $see-also height-state } ;
ARTICLE: "compiler.cfg.stacks.local" "Local stack analysis" ARTICLE: "compiler.cfg.stacks.local" "Local stack analysis"
"Local stack analysis. We build three sets for every basic block in the " { $link cfg } ":" "Local stack analysis. For each " { $link basic-block } " in the " { $link cfg } ", three sets containing stack locations are built:"
{ $list { $list
"peek-set: all stack locations that the block reads before writing" { { $slot "peeks" } " all stack locations that the block reads before writing" }
{ { $link replace-sets } " all stack locations that the block writes" } { { $slot "replaces" } " all stack locations that the block writes" }
{ { $link kill-sets } " all stack locations which become unavailable after the block ends because of the stack height being decremented" } { { $slot "kills" } " all stack locations which become unavailable after the block ends because of the stack height being decremented. For example, if the block contains " { $link drop } ", then D: 0 will be contained in kills because that stack location will not be live anymore." }
} }
"This is done while constructing the CFG." "This is done while constructing the CFG."
$nl $nl
@ -107,7 +101,7 @@ $nl
begin-local-analysis begin-local-analysis
end-local-analysis end-local-analysis
} }
"Temporary variables that keeps track of the blocks read and written stack locations:" "Temporary variables that keeps track of the block's read and written stack locations:"
{ $subsections { $subsections
local-peek-set local-peek-set
replaces replaces

View File

@ -1,7 +1,8 @@
USING: assocs compiler.cfg.instructions compiler.cfg.registers USING: accessors assocs compiler.cfg.instructions
compiler.cfg.stacks.local compiler.cfg.utilities compiler.test compiler.cfg.registers compiler.cfg.stacks.local
cpu.architecture kernel kernel.private make math namespaces compiler.cfg.utilities compiler.test cpu.architecture kernel
sequences.private slots.private tools.test ; kernel.private make math namespaces sequences.private slots.private
tools.test ;
QUALIFIED: sets QUALIFIED: sets
IN: compiler.cfg.stacks.local.tests IN: compiler.cfg.stacks.local.tests
@ -14,7 +15,7 @@ IN: compiler.cfg.stacks.local.tests
V{ } 137 insns>block V{ } 137 insns>block
[ 0 0 rot record-stack-heights ] [ 0 0 rot record-stack-heights ]
[ [ "eh" , end-local-analysis ] V{ } make drop ] [ [ "eh" , end-local-analysis ] V{ } make drop ]
[ [ peek-sets ] [ replace-sets ] [ kill-sets ] tri [ get at ] 2tri@ ] tri [ [ peeks>> ] [ replaces>> ] [ kills>> ] tri ] tri
] cfg-unit-test ] cfg-unit-test
{ {
@ -23,7 +24,7 @@ IN: compiler.cfg.stacks.local.tests
V{ } 137 insns>block V{ } 137 insns>block
[ 0 0 rot record-stack-heights ] [ 0 0 rot record-stack-heights ]
[ [ 3 D: 3 replace-loc "eh" , end-local-analysis ] V{ } make drop ] [ [ 3 D: 3 replace-loc "eh" , end-local-analysis ] V{ } make drop ]
[ replace-sets get at ] tri [ replaces>> ] tri
] cfg-unit-test ] cfg-unit-test
! kill-locations ! kill-locations

View File

@ -41,7 +41,7 @@ IN: compiler.cfg.stacks.local
[ [ <ds-loc> ] map ] [ [ <rs-loc> ] map ] bi* [ [ <ds-loc> ] map ] [ [ <rs-loc> ] map ] bi*
append >hash-set ; append >hash-set ;
SYMBOLS: height-state peek-sets replace-sets kill-sets locs>vregs ; SYMBOLS: height-state locs>vregs local-peek-set replaces ;
: inc-stack ( loc -- ) : inc-stack ( loc -- )
height-state get swap modify-height ; height-state get swap modify-height ;
@ -49,8 +49,6 @@ SYMBOLS: height-state peek-sets replace-sets kill-sets locs>vregs ;
: loc>vreg ( loc -- vreg ) locs>vregs get [ drop next-vreg ] cache ; : loc>vreg ( loc -- vreg ) locs>vregs get [ drop next-vreg ] cache ;
: vreg>loc ( vreg -- loc/f ) locs>vregs get value-at ; : vreg>loc ( vreg -- loc/f ) locs>vregs get value-at ;
SYMBOLS: local-peek-set replaces ;
: replaces>copy-insns ( replaces -- insns ) : replaces>copy-insns ( replaces -- insns )
[ [ loc>vreg ] dip ] assoc-map parallel-copy ; [ [ loc>vreg ] dip ] assoc-map parallel-copy ;
@ -83,10 +81,8 @@ SYMBOLS: local-peek-set replaces ;
[ [ loc>vreg ] dip = ] assoc-reject ; [ [ loc>vreg ] dip = ] assoc-reject ;
: end-local-analysis ( basic-block -- ) : end-local-analysis ( basic-block -- )
[ replaces get remove-redundant-replaces
replaces get remove-redundant-replaces [ height-state get emit-changes ] keep
[ height-state get emit-changes ] keys >hash-set >>replaces
[ keys >hash-set swap replace-sets get set-at ] bi local-peek-set get >>peeks
] dup compute-local-kill-set >>kills drop ;
[ [ local-peek-set get ] dip peek-sets get set-at ]
[ [ compute-local-kill-set ] keep kill-sets get set-at ] tri ;

View File

@ -8,9 +8,6 @@ IN: compiler.cfg.stacks
: begin-stack-analysis ( -- ) : begin-stack-analysis ( -- )
<bihash> locs>vregs set <bihash> locs>vregs set
H{ } clone peek-sets set
H{ } clone replace-sets set
H{ } clone kill-sets set
initial-height-state height-state set ; initial-height-state height-state set ;
: end-stack-analysis ( cfg -- ) : end-stack-analysis ( cfg -- )