compiler.cfg.stacks.vacant: more docs and removed usage of byte-arrays

db4
Björn Lindqvist 2014-08-25 18:55:27 +02:00 committed by Doug Coleman
parent ab5e629243
commit ecead801c1
3 changed files with 31 additions and 16 deletions

View File

@ -1,4 +1,4 @@
USING: help.markup help.syntax sequences strings ;
USING: compiler.cfg.instructions help.markup help.syntax sequences strings ;
IN: compiler.cfg.stacks.vacant
ARTICLE: "compiler.cfg.stacks.vacant" "Uninitialized/overinitialized stack location analysis"
@ -12,4 +12,21 @@ ARTICLE: "compiler.cfg.stacks.vacant" "Uninitialized/overinitialized stack locat
}
"The GC check runs before stack locations 0 and 1 have been initialized, and so the GC needs to scrub them so that they don't get traced. This is achieved by computing uninitialized locations with a dataflow analysis, and recording the information in GC maps. The scrub_contexts() method on vm/gc.cpp reads this information from GC maps and performs the scrubbing." ;
HELP: initial-state
{ $description "Initially the stack bottom is at 0 for both the data and retain stacks and no replaces have been registered." } ;
HELP: vacant>bit-pattern
{ $values
{ "vacant" "sequence of uninitialized stack locations" }
{ "bit-pattern" "sequence of 1:s and 0:s" }
}
{ $description "Converts a sequence of uninitialized stack locations to the pattern of 1:s and 0:s that can be put in the " { $slot "scrub-d" } " and " { $slot "scrub-r" } " slots of a " { $link gc-map } "." }
{ $examples
{ $example
"USING: compiler.cfg.stacks.vacant prettyprint ;"
"{ 0 1 3 } vacant>bit-pattern ."
"{ 0 0 1 0 }"
}
} ;
ABOUT: "compiler.cfg.stacks.vacant"

View File

@ -1,7 +1,7 @@
USING: accessors arrays assocs compiler.cfg
compiler.cfg.dataflow-analysis.private compiler.cfg.instructions
compiler.cfg.registers compiler.cfg.stacks.vacant kernel math sequences
sorting tools.test vectors ;
compiler.cfg.linearization compiler.cfg.registers compiler.cfg.stacks.vacant
kernel math sequences sorting tools.test vectors ;
IN: compiler.cfg.stacks.vacant.tests
! Utils
@ -72,7 +72,7 @@ IN: compiler.cfg.stacks.vacant.tests
! [
! V{
! T{ ##replace { src 10 } { loc D -1 } }
! T{ ##alien-invoke { gc-map T{ gc-map { scrub-d B{ } } } } }
! T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
! T{ ##peek { dst 0 } { loc D -1 } }
! } create-cfg
! compute-vacant-sets
@ -82,7 +82,7 @@ IN: compiler.cfg.stacks.vacant.tests
{ { -1 { -1 } } } [
V{
T{ ##replace { src 10 } { loc D 0 } }
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d B{ } } } } }
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
T{ ##inc-d f -1 }
T{ ##peek { dst 0 } { loc D -1 } }
} create-cfg output-stack-map first
@ -92,14 +92,14 @@ IN: compiler.cfg.stacks.vacant.tests
! [
! V{
! T{ ##inc-d f 1 }
! T{ ##alien-invoke { gc-map T{ gc-map { scrub-d B{ } } } } }
! T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
! T{ ##peek { dst 0 } { loc D 0 } }
! } create-cfg
! compute-vacant-sets
! ] [ vacant-peek? ] must-fail-with
! visit-insn should set the gc info.
{ B{ 0 0 } B{ } } [
{ { 0 0 } { } } [
{ { 2 { } } { 0 { } } }
T{ ##alien-invoke { gc-map T{ gc-map } } }
[ visit-insn drop ] keep gc-map>> [ scrub-d>> ] [ scrub-r>> ] bi
@ -213,7 +213,7 @@ IN: compiler.cfg.stacks.vacant.tests
T{ ##inc-d f -3 }
T{ ##peek { dst 0 } { loc D -3 } }
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d B{ } } } } }
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
}
}
} [ over create-block ] assoc-map dup

View File

@ -1,4 +1,4 @@
USING: accessors arrays byte-arrays compiler.cfg.dataflow-analysis
USING: accessors arrays compiler.cfg.dataflow-analysis
compiler.cfg.instructions compiler.cfg.registers fry kernel math math.order
sequences sets ;
IN: compiler.cfg.stacks.vacant
@ -20,19 +20,17 @@ IN: compiler.cfg.stacks.vacant
: stack>vacant ( stack -- seq )
first2 [ 0 max iota ] dip diff ;
: vacant>byte-array ( seq -- ba )
[ B{ } ] [
: vacant>bit-pattern ( vacant -- bit-pattern )
[ { } ] [
dup supremum 1 + 1 <array>
[ '[ _ 0 -rot set-nth ] each ] keep >byte-array
[ '[ _ 0 -rot set-nth ] each ] keep
] if-empty ;
! Operations on the analysis state
: state>gc-map ( state -- pair )
[ stack>vacant vacant>byte-array ] map ;
[ stack>vacant vacant>bit-pattern ] map ;
! Stack bottom is 0 for d and r and no replaces.
: initial-state ( -- state )
{ { 0 { } } { 0 { } } } ;
CONSTANT: initial-state { { 0 { } } { 0 { } } }
: insn>gc-map ( insn -- pair )
gc-map>> [ scrub-d>> ] [ scrub-r>> ] bi 2array ;