compiler.cfg.*: refactoring which removes spill-area-size and

spill-area-align from cfg

This makes the code for building the stack frame simpler.
db4
Björn Lindqvist 2015-11-02 18:40:13 +01:00
parent cfe4fec574
commit f692200547
14 changed files with 85 additions and 81 deletions

View File

@ -53,18 +53,14 @@ M: insn compute-stack-frame* drop f ;
dup calculate-spill-area-base >>spill-area-base dup calculate-spill-area-base >>spill-area-base
dup stack-frame-size >>total-size ; dup stack-frame-size >>total-size ;
: <stack-frame> ( cfg -- stack-frame ) : compute-stack-frame ( cfg -- stack-frame/f )
stack-frame new dup cfg>insns f [ compute-stack-frame* or ] reduce [
over spill-area-size>> >>spill-area-size stack-frame>>
swap spill-area-align>> >>spill-area-align
allot-area-size get >>allot-area-size allot-area-size get >>allot-area-size
allot-area-align get >>allot-area-align allot-area-align get >>allot-area-align
param-area-size get >>params param-area-size get >>params
finalize-stack-frame ; finalize-stack-frame
] [ drop f ] if ;
: compute-stack-frame ( cfg -- stack-frame/f )
dup cfg>insns f [ compute-stack-frame* or ] reduce
[ <stack-frame> ] [ drop f ] if ;
: build-stack-frame ( cfg -- ) : build-stack-frame ( cfg -- )
0 param-area-size set 0 param-area-size set

View File

@ -1,6 +1,6 @@
USING: compiler.cfg compiler.cfg.instructions compiler.cfg.rpo USING: compiler.cfg.instructions compiler.cfg.rpo
compiler.cfg.stack-frame compiler.tree help.markup help.syntax namespaces compiler.cfg.stack-frame compiler.tree help.markup help.syntax math
sequences vectors words ; namespaces sequences vectors words ;
IN: compiler.cfg IN: compiler.cfg
HELP: basic-block HELP: basic-block
@ -41,3 +41,7 @@ HELP: cfg-changed
{ $values { "cfg" cfg } } { $values { "cfg" cfg } }
{ $description "Resets all \"calculated\" slots in the cfg which forces them to be recalculated." } { $description "Resets all \"calculated\" slots in the cfg which forces them to be recalculated." }
{ $see-also predecessors-changed } ; { $see-also predecessors-changed } ;
HELP: spill-offset
{ $values { "n" integer } { "offset" integer } }
{ $description "Offset in the current " { $link stack-frame } " to byte at index 'n' in the spill area." } ;

View File

@ -11,7 +11,10 @@ IN: compiler.cfg.tests
{ {
[ word>> ] [ word>> ]
[ label>> ] [ label>> ]
[
stack-frame>>
[ spill-area-size>> ] [ spill-area-size>> ]
[ spill-area-align>> cell = ] [ spill-area-align>> cell = ] bi
]
} cleave } cleave
] unit-test ] unit-test

View File

@ -1,6 +1,7 @@
! Copyright (C) 2008, 2010 Slava Pestov. ! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel layouts math namespaces vectors ; USING: accessors compiler.cfg.stack-frame kernel layouts math
namespaces vectors ;
IN: compiler.cfg IN: compiler.cfg
TUPLE: basic-block < identity-tuple TUPLE: basic-block < identity-tuple
@ -20,8 +21,6 @@ TUPLE: cfg
{ entry basic-block } { entry basic-block }
word word
label label
{ spill-area-size integer }
{ spill-area-align integer }
stack-frame stack-frame
frame-pointer? frame-pointer?
post-order linear-order post-order linear-order
@ -32,8 +31,7 @@ TUPLE: cfg
swap >>entry swap >>entry
swap >>label swap >>label
swap >>word swap >>word
0 >>spill-area-size stack-frame new cell >>spill-area-align >>stack-frame ;
cell >>spill-area-align ;
: cfg-changed ( cfg -- ) : cfg-changed ( cfg -- )
f >>post-order f >>post-order
@ -46,3 +44,9 @@ TUPLE: cfg
: with-cfg ( ..a cfg quot: ( ..a cfg -- ..b ) -- ..b ) : with-cfg ( ..a cfg quot: ( ..a cfg -- ..b ) -- ..b )
[ dup cfg ] dip with-variable ; inline [ dup cfg ] dip with-variable ; inline
: local-allot-offset ( n -- offset )
cfg get stack-frame>> allot-area-base>> + ;
: spill-offset ( n -- offset )
cfg get stack-frame>> spill-area-base>> + ;

View File

@ -27,7 +27,8 @@ HELP: assign-spill-slot
{ "rep" representation } { "rep" representation }
{ "spill-slot" spill-slot } { "spill-slot" spill-slot }
} }
{ $description "Assigns a spill slot for the vreg." } ; { $description "Assigns a spill slot for the vreg. The stack frames spill area align is updated so that it is at least as large as the vregs size. Then a " { $link spill-slot } " is assigned for the vreg/rep-size combination if one hasn't already been assigned and is put on the stack." }
{ $see-also next-spill-slot } ;
HELP: deactivate-intervals HELP: deactivate-intervals
{ $values { "n" integer } } { $values { "n" integer } }

View File

@ -2,8 +2,9 @@ USING: accessors assocs combinators.extras compiler.cfg
compiler.cfg.instructions compiler.cfg.linear-scan.allocation compiler.cfg.instructions compiler.cfg.linear-scan.allocation
compiler.cfg.linear-scan.allocation.state compiler.cfg.linear-scan.allocation.state
compiler.cfg.linear-scan.live-intervals compiler.cfg.registers compiler.cfg.linear-scan.live-intervals compiler.cfg.registers
compiler.cfg.utilities cpu.architecture cpu.x86.assembler.operands fry compiler.cfg.stack-frame compiler.cfg.utilities cpu.architecture
heaps kernel layouts literals namespaces sequences system tools.test ; cpu.x86.assembler.operands fry heaps kernel layouts literals
namespaces sequences system tools.test ;
IN: compiler.cfg.linear-scan.allocation.state.tests IN: compiler.cfg.linear-scan.allocation.state.tests
! active-intervals-for ! active-intervals-for
@ -91,10 +92,24 @@ ${
{ t } [ { t } [
H{ } clone spill-slots set H{ } clone spill-slots set
f f <basic-block> <cfg> cfg set { } insns>cfg cfg set
55 int-rep assign-spill-slot spill-slots get values first eq? 55 int-rep assign-spill-slot spill-slots get values first eq?
] unit-test ] unit-test
{
H{
{ { 55 8 } T{ spill-slot } }
{ { 44 8 } T{ spill-slot { n 8 } } }
}
} [
H{ } clone spill-slots set
{ } insns>cfg cfg set
{ { 55 int-rep } { 44 int-rep } { 55 int-rep } } [
assign-spill-slot drop
] assoc-each
spill-slots get
] unit-test
! check-handled ! check-handled
{ } [ { } [
40 progress set 40 progress set
@ -107,7 +122,7 @@ ${
! align-spill-area ! align-spill-area
${ cell } [ ${ cell } [
3 { } insns>cfg [ align-spill-area ] keep 3 { } insns>cfg stack-frame>> [ align-spill-area ] keep
spill-area-align>> spill-area-align>>
] unit-test ] unit-test
@ -128,11 +143,14 @@ ${ cell } [
! next-spill-slot ! next-spill-slot
{ {
T{ cfg { spill-area-size 16 } }
T{ spill-slot f 0 } T{ spill-slot f 0 }
T{ spill-slot f 8 } T{ spill-slot f 8 }
T{ stack-frame
{ spill-area-size 16 }
{ spill-area-align 8 }
}
} [ } [
T{ cfg { spill-area-size 0 } } dup '[ 8 _ next-spill-slot ] twice { } insns>cfg stack-frame>> [ '[ 8 _ next-spill-slot ] twice ] keep
] unit-test ] unit-test
! >unhandled-min-heap ! >unhandled-min-heap

View File

@ -113,19 +113,19 @@ ERROR: register-already-used live-interval ;
: reg-class-assoc ( quot -- assoc ) : reg-class-assoc ( quot -- assoc )
[ reg-classes ] dip { } map>assoc ; inline [ reg-classes ] dip { } map>assoc ; inline
: next-spill-slot ( size cfg -- spill-slot ) : align-spill-area ( align stack-frame -- )
[ swap [ align dup ] [ + ] bi ] change-spill-area-size drop <spill-slot> ;
: align-spill-area ( align cfg -- )
[ max ] change-spill-area-align drop ; [ max ] change-spill-area-align drop ;
: next-spill-slot ( size stack-frame -- spill-slot )
[ swap [ align dup ] [ + ] bi ] change-spill-area-size drop <spill-slot> ;
SYMBOL: spill-slots SYMBOL: spill-slots
: assign-spill-slot ( coalesced-vreg rep -- spill-slot ) : assign-spill-slot ( coalesced-vreg rep -- spill-slot )
rep-size rep-size spill-slots get [
[ cfg get align-spill-area ] nip cfg get stack-frame>>
[ spill-slots get [ nip cfg get next-spill-slot ] 2cache ] [ align-spill-area ] [ next-spill-slot ] 2bi
bi ; ] 2cache ;
: lookup-spill-slot ( coalesced-vreg rep -- spill-slot ) : lookup-spill-slot ( coalesced-vreg rep -- spill-slot )
rep-size 2array spill-slots get ?at [ ] [ bad-vreg ] if ; rep-size 2array spill-slots get ?at [ ] [ bad-vreg ] if ;

View File

@ -28,17 +28,14 @@ check-allocation? on
check-numbering? on check-numbering? on
! Live interval calculation ! Live interval calculation
: test-live-intervals ( -- )
! A value is defined and never used; make sure it has the right ! A value is defined and never used; make sure it has the right
! live range ! live range
V{ {
T{ ##load-integer f 1 0 } T{ ##load-integer f 1 0 }
T{ ##replace-imm f D: 0 "hi" } T{ ##replace-imm f D: 0 "hi" }
T{ ##branch } T{ ##branch }
} 0 test-bb } insns>cfg
: test-live-intervals ( -- )
0 get block>cfg
[ cfg set ] [ number-instructions ] [ compute-live-intervals ] tri [ cfg set ] [ number-instructions ] [ compute-live-intervals ] tri
drop ; drop ;
@ -57,8 +54,7 @@ V{
] unit-test ] unit-test
! Live interval splitting ! Live interval splitting
{ } insns>cfg [ stack-frame>> 4 >>spill-area-align drop ] keep cfg set
cfg new 0 >>spill-area-size 4 >>spill-area-align cfg set
H{ } spill-slots set H{ } spill-slots set
H{ H{

View File

@ -1,8 +1,6 @@
USING: compiler.cfg.linear-scan.resolve tools.test kernel namespaces USING: accessors compiler.cfg compiler.cfg.instructions
accessors compiler.cfg.linear-scan.resolve compiler.cfg.utilities
compiler.cfg cpu.architecture kernel make namespaces sequences tools.test ;
compiler.cfg.instructions cpu.architecture make sequences
compiler.cfg.linear-scan.allocation.state ;
IN: compiler.cfg.linear-scan.resolve.tests IN: compiler.cfg.linear-scan.resolve.tests
{ {
@ -106,7 +104,7 @@ IN: compiler.cfg.linear-scan.resolve.tests
mapping-instructions mapping-instructions
] unit-test ] unit-test
cfg new 8 >>spill-area-size cfg set { } insns>cfg [ stack-frame>> 8 >>spill-area-size drop ] [ cfg set ] bi
init-resolve init-resolve
{ t } [ { t } [

View File

@ -29,7 +29,7 @@ SYMBOL: temp-spills
: temp-spill ( rep -- spill-slot ) : temp-spill ( rep -- spill-slot )
rep-size temp-spills get rep-size temp-spills get
[ cfg get next-spill-slot ] cache ; [ cfg get stack-frame>> next-spill-slot ] cache ;
SYMBOL: temp-locations SYMBOL: temp-locations

View File

@ -27,10 +27,6 @@ HELP: (stack-frame-size)
{ $values { "stack-frame" stack-frame } { "n" integer } } { $values { "stack-frame" stack-frame } { "n" integer } }
{ $description "Base stack frame size, without padding and alignment. If the size is zero, then no " { $link ##epilogue } " and " { $link ##prologue } " needs to be emitted for the word." } ; { $description "Base stack frame size, without padding and alignment. If the size is zero, then no " { $link ##epilogue } " and " { $link ##prologue } " needs to be emitted for the word." } ;
HELP: spill-offset
{ $values { "n" integer } { "offset" integer } }
{ $description "Offset in the current " { $link stack-frame } " to byte at index 'n' in the spill area." } ;
ARTICLE: "compiler.cfg.stack-frame" "Stack frames" ARTICLE: "compiler.cfg.stack-frame" "Stack frames"
"This vocab contains definitions for constructing stack frames." ; "This vocab contains definitions for constructing stack frames." ;

View File

@ -1,6 +1,6 @@
! Copyright (C) 2009, 2010 Slava Pestov. ! Copyright (C) 2009, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors compiler.cfg kernel math namespaces ; USING: accessors kernel math namespaces ;
IN: compiler.cfg.stack-frame IN: compiler.cfg.stack-frame
TUPLE: stack-frame TUPLE: stack-frame
@ -9,16 +9,9 @@ TUPLE: stack-frame
{ allot-area-align integer } { allot-area-align integer }
{ spill-area-size integer } { spill-area-size integer }
{ spill-area-align integer } { spill-area-align integer }
{ total-size integer } { total-size integer }
{ allot-area-base integer } { allot-area-base integer }
{ spill-area-base integer } ; { spill-area-base integer } ;
: local-allot-offset ( n -- offset )
cfg get stack-frame>> allot-area-base>> + ;
: spill-offset ( n -- offset )
cfg get stack-frame>> spill-area-base>> + ;
: (stack-frame-size) ( stack-frame -- n ) : (stack-frame-size) ( stack-frame -- n )
[ spill-area-base>> ] [ spill-area-size>> ] bi + ; [ spill-area-base>> ] [ spill-area-size>> ] bi + ;

View File

@ -5,7 +5,7 @@ classes.algebra byte-arrays make math math.order math.ranges
system namespaces locals layouts words alien alien.accessors system namespaces locals layouts words alien alien.accessors
alien.c-types alien.complex alien.data alien.libraries alien.c-types alien.complex alien.data alien.libraries
literals cpu.architecture cpu.ppc.assembler literals cpu.architecture cpu.ppc.assembler
compiler.cfg.registers compiler.cfg.instructions compiler.cfg compiler.cfg.registers compiler.cfg.instructions
compiler.cfg.comparisons compiler.codegen.fixup compiler.cfg.comparisons compiler.codegen.fixup
compiler.cfg.intrinsics compiler.cfg.stack-frame compiler.cfg.intrinsics compiler.cfg.stack-frame
compiler.cfg.build-stack-frame compiler.units compiler.constants compiler.cfg.build-stack-frame compiler.units compiler.constants

View File

@ -1,20 +1,15 @@
! Copyright (C) 2005, 2010 Slava Pestov. ! Copyright (C) 2005, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs alien alien.c-types arrays strings USING: accessors alien arrays assocs byte-arrays classes.algebra
cpu.x86.assembler cpu.x86.assembler.private cpu.x86.assembler.operands combinators compiler compiler.cfg compiler.cfg.comparisons
cpu.x86.features cpu.x86.features.private cpu.architecture kernel compiler.cfg.instructions compiler.cfg.intrinsics
kernel.private math memory namespaces make sequences words system compiler.cfg.registers compiler.cfg.stack-frame
layouts combinators math.order math.vectors fry locals compiler.constants compiler.codegen.gc-maps compiler.codegen.labels
byte-arrays io macros quotations classes.algebra compiler compiler.codegen.relocation compiler.constants compiler.units
compiler.units init vm vocabs cpu.architecture cpu.x86.assembler cpu.x86.assembler.operands
compiler.cfg.registers cpu.x86.assembler.private cpu.x86.features cpu.x86.features.private
compiler.cfg.instructions fry io kernel layouts locals make math math.order memory namespaces
compiler.cfg.intrinsics sequences system vm vocabs ;
compiler.cfg.comparisons
compiler.cfg.stack-frame
compiler.codegen.gc-maps
compiler.codegen.labels
compiler.codegen.relocation ;
QUALIFIED-WITH: alien.c-types c QUALIFIED-WITH: alien.c-types c
FROM: math => float ; FROM: math => float ;
IN: cpu.x86 IN: cpu.x86