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
parent
e8e1811542
commit
6c88577ee7
|
@ -36,6 +36,18 @@ HELP: basic-block
|
|||
{ $slot "rs-height" }
|
||||
"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." } ;
|
||||
|
|
|
@ -10,7 +10,10 @@ TUPLE: basic-block < identity-tuple
|
|||
{ successors vector }
|
||||
{ predecessors vector }
|
||||
{ kill-block? boolean }
|
||||
ds-height rs-height ;
|
||||
ds-height rs-height
|
||||
replaces
|
||||
peeks
|
||||
kills ;
|
||||
|
||||
: <basic-block> ( -- bb )
|
||||
basic-block new
|
||||
|
|
|
@ -55,10 +55,7 @@ IN: compiler.cfg.intrinsics.simd.tests
|
|||
initial-height-state \ height-state pick set-at
|
||||
HS{ } clone \ local-peek-set pick set-at
|
||||
H{ } clone \ replaces 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 ;
|
||||
H{ } <biassoc> \ locs>vregs pick set-at ;
|
||||
|
||||
: make-classes ( quot -- seq )
|
||||
{ } make [ class-of ] map ; inline
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
! Copyright (C) 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: assocs compiler.cfg.dataflow-analysis compiler.cfg.stacks.local
|
||||
kernel namespaces sequences sets ;
|
||||
USING: accessors compiler.cfg.dataflow-analysis kernel sequences sets ;
|
||||
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
|
||||
: refine ( sets -- set )
|
||||
[ f ] [ [ ] [ intersect ] map-reduce ] if-empty ;
|
||||
|
||||
: transfer-peeked-locs ( set bb -- set' )
|
||||
[ replace-set diff ] [ peek-set union ] bi ;
|
||||
[ replaces>> diff ] [ peeks>> union ] bi ;
|
||||
|
||||
BACKWARD-ANALYSIS: anticip
|
||||
|
||||
|
@ -27,18 +22,18 @@ M: live join-sets 2drop combine ;
|
|||
|
||||
FORWARD-ANALYSIS: avail
|
||||
|
||||
M: avail transfer-set
|
||||
drop [ peek-set ] [ replace-set ] bi union union ;
|
||||
M: avail transfer-set ( in-set bb dfa -- out-set )
|
||||
drop [ peeks>> ] [ replaces>> ] bi union union ;
|
||||
M: avail join-sets 2drop refine ;
|
||||
|
||||
FORWARD-ANALYSIS: pending
|
||||
|
||||
M: pending transfer-set
|
||||
drop replace-set union ;
|
||||
drop replaces>> union ;
|
||||
M: pending join-sets 2drop refine ;
|
||||
|
||||
BACKWARD-ANALYSIS: dead
|
||||
|
||||
M: dead transfer-set
|
||||
drop [ kill-set ] [ replace-set ] bi union union ;
|
||||
drop [ kills>> ] [ replaces>> ] bi union union ;
|
||||
M: dead join-sets 2drop refine ;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
USING: assocs compiler.cfg compiler.cfg.instructions
|
||||
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
|
||||
|
||||
HELP: emit-changes
|
||||
|
@ -9,7 +9,7 @@ HELP: emit-changes
|
|||
|
||||
HELP: end-local-analysis
|
||||
{ $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
|
||||
{ $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 } }
|
||||
{ $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
|
||||
{ $values { "loc" loc } { "vreg" "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." }
|
||||
{ $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
|
||||
{ $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 } ;
|
||||
|
@ -83,11 +77,11 @@ HELP: translate-local-loc
|
|||
{ $see-also height-state } ;
|
||||
|
||||
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
|
||||
"peek-set: all stack locations that the block reads before writing"
|
||||
{ { $link replace-sets } " 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 "peeks" } " all stack locations that the block reads before writing" }
|
||||
{ { $slot "replaces" } " all stack locations that the block writes" }
|
||||
{ { $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."
|
||||
$nl
|
||||
|
@ -107,7 +101,7 @@ $nl
|
|||
begin-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
|
||||
local-peek-set
|
||||
replaces
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
USING: assocs compiler.cfg.instructions compiler.cfg.registers
|
||||
compiler.cfg.stacks.local compiler.cfg.utilities compiler.test
|
||||
cpu.architecture kernel kernel.private make math namespaces
|
||||
sequences.private slots.private tools.test ;
|
||||
USING: accessors assocs compiler.cfg.instructions
|
||||
compiler.cfg.registers compiler.cfg.stacks.local
|
||||
compiler.cfg.utilities compiler.test cpu.architecture kernel
|
||||
kernel.private make math namespaces sequences.private slots.private
|
||||
tools.test ;
|
||||
QUALIFIED: sets
|
||||
IN: compiler.cfg.stacks.local.tests
|
||||
|
||||
|
@ -14,7 +15,7 @@ IN: compiler.cfg.stacks.local.tests
|
|||
V{ } 137 insns>block
|
||||
[ 0 0 rot record-stack-heights ]
|
||||
[ [ "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
|
||||
|
||||
{
|
||||
|
@ -23,7 +24,7 @@ IN: compiler.cfg.stacks.local.tests
|
|||
V{ } 137 insns>block
|
||||
[ 0 0 rot record-stack-heights ]
|
||||
[ [ 3 D: 3 replace-loc "eh" , end-local-analysis ] V{ } make drop ]
|
||||
[ replace-sets get at ] tri
|
||||
[ replaces>> ] tri
|
||||
] cfg-unit-test
|
||||
|
||||
! kill-locations
|
||||
|
|
|
@ -41,7 +41,7 @@ IN: compiler.cfg.stacks.local
|
|||
[ [ <ds-loc> ] map ] [ [ <rs-loc> ] map ] bi*
|
||||
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 -- )
|
||||
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 ;
|
||||
: vreg>loc ( vreg -- loc/f ) locs>vregs get value-at ;
|
||||
|
||||
SYMBOLS: local-peek-set replaces ;
|
||||
|
||||
: replaces>copy-insns ( replaces -- insns )
|
||||
[ [ loc>vreg ] dip ] assoc-map parallel-copy ;
|
||||
|
||||
|
@ -83,10 +81,8 @@ SYMBOLS: local-peek-set replaces ;
|
|||
[ [ loc>vreg ] dip = ] assoc-reject ;
|
||||
|
||||
: end-local-analysis ( basic-block -- )
|
||||
[
|
||||
replaces get remove-redundant-replaces
|
||||
[ height-state get emit-changes ]
|
||||
[ keys >hash-set swap replace-sets get set-at ] bi
|
||||
]
|
||||
[ [ local-peek-set get ] dip peek-sets get set-at ]
|
||||
[ [ compute-local-kill-set ] keep kill-sets get set-at ] tri ;
|
||||
replaces get remove-redundant-replaces
|
||||
[ height-state get emit-changes ] keep
|
||||
keys >hash-set >>replaces
|
||||
local-peek-set get >>peeks
|
||||
dup compute-local-kill-set >>kills drop ;
|
||||
|
|
|
@ -8,9 +8,6 @@ IN: compiler.cfg.stacks
|
|||
|
||||
: begin-stack-analysis ( -- )
|
||||
<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 ;
|
||||
|
||||
: end-stack-analysis ( cfg -- )
|
||||
|
|
Loading…
Reference in New Issue