compiler.cfg.build-stack-frame: refactoring which removes the

frame-required? variable
db4
Björn Lindqvist 2015-07-21 11:27:14 +02:00
parent 80ea6b8997
commit d24733e703
3 changed files with 48 additions and 42 deletions

View File

@ -1,23 +1,25 @@
USING: assocs compiler.cfg compiler.cfg.stack-frame help.markup help.syntax ; USING: assocs compiler.cfg compiler.cfg.instructions compiler.cfg.stack-frame
help.markup help.syntax kernel ;
IN: compiler.cfg.build-stack-frame IN: compiler.cfg.build-stack-frame
ARTICLE: "compiler.cfg.build-stack-frame" "Computing stack frame size and layout" HELP: compute-stack-frame
"The " { $vocab-link "compiler.cfg.build-stack-frame" } " vocab builds stack frames for cfg:s." ; { $values { "cfg" cfg } { "stack-frame/f" stack-frame } }
{ $description "Initializes a stack frame for a cfg, if it needs one." }
{ $see-also compute-stack-frame* } ;
HELP: compute-stack-frame*
{ $values { "insn" insn } { "?" boolean } }
{ $description "Computes required stack frame size for the instruction. If a stack frame is needed, then " { $link t } " is returned." } ;
HELP: param-area-size HELP: param-area-size
{ $var-description "Temporary variable used when building stack frames to calculate the parameter area size." } { $var-description "Temporary variable used when building stack frames to calculate the parameter area size." }
{ $see-also build-stack-frame } ; { $see-also build-stack-frame } ;
HELP: frame-required?
{ $var-description "Whether the word being compiled requires a stack frame or not. Most words does, but very simple words does not." } ;
HELP: compute-stack-frame
{ $values { "cfg" cfg } { "stack-frame/f" stack-frame } }
{ $description "Initializes a stack frame for a cfg, if it needs one." }
{ $see-also frame-required? } ;
HELP: finalize-stack-frame HELP: finalize-stack-frame
{ $values { "stack-frame" stack-frame } } { $values { "stack-frame" stack-frame } }
{ $description "Calculates and stores the " { $slot "allot-area-base" } ", " { $slot "spill-area-base" } " and " { $slot "total-size" } " slots of a stack frame." } ; { $description "Calculates and stores the " { $slot "allot-area-base" } ", " { $slot "spill-area-base" } " and " { $slot "total-size" } " slots of a stack frame." } ;
ARTICLE: "compiler.cfg.build-stack-frame" "Computing stack frame size and layout"
"The " { $vocab-link "compiler.cfg.build-stack-frame" } " vocab builds stack frames for cfg:s." ;
ABOUT: "compiler.cfg.build-stack-frame" ABOUT: "compiler.cfg.build-stack-frame"

View File

@ -1,6 +1,7 @@
USING: accessors compiler.cfg compiler.cfg.build-stack-frame USING: accessors compiler.cfg.build-stack-frame
compiler.cfg.stack-frame cpu.x86 kernel math namespaces slots.syntax compiler.cfg.instructions compiler.cfg.linearization
tools.test ; compiler.cfg.stack-frame compiler.cfg.utilities cpu.x86 kernel math
sequences slots.syntax tools.test ;
IN: compiler.cfg.build-stack-frame.tests IN: compiler.cfg.build-stack-frame.tests
{ {
@ -25,6 +26,17 @@ IN: compiler.cfg.build-stack-frame.tests
] unit-test ] unit-test
{ f } [ { f } [
t frame-required? set { } insns>cfg dup build-stack-frame stack-frame>>
f f <basic-block> <cfg> dup build-stack-frame stack-frame>> ] unit-test
{ t } [
{ T{ ##call-gc } } insns>cfg dup build-stack-frame
stack-frame>> stack-frame?
] unit-test
{ 0 } [
{
T{ ##call-gc }
T{ ##local-allot { dst 1 } { size 32 } { align 8 } }
} insns>cfg dup build-stack-frame cfg>insns last offset>>
] unit-test ] unit-test

View File

@ -1,31 +1,25 @@
! 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 compiler.cfg.instructions compiler.cfg.rpo USING: accessors compiler.cfg.instructions compiler.cfg.linearization
compiler.cfg.stack-frame cpu.architecture kernel layouts locals compiler.cfg.rpo compiler.cfg.stack-frame cpu.architecture kernel layouts
math math.order namespaces sequences ; locals math math.order namespaces sequences ;
IN: compiler.cfg.build-stack-frame IN: compiler.cfg.build-stack-frame
SYMBOLS: param-area-size allot-area-size allot-area-align SYMBOLS: param-area-size allot-area-size allot-area-align ;
frame-required? ;
: frame-required ( -- ) frame-required? on ; GENERIC: compute-stack-frame* ( insn -- ? )
GENERIC: compute-stack-frame* ( insn -- ) M:: ##local-allot compute-stack-frame* ( insn -- ? )
M:: ##local-allot compute-stack-frame* ( insn -- )
frame-required
insn size>> :> s insn size>> :> s
insn align>> :> a insn align>> :> a
allot-area-align [ a max ] change allot-area-align [ a max ] change
allot-area-size [ a align [ insn offset<< ] [ s + ] bi ] change ; allot-area-size [ a align [ insn offset<< ] [ s + ] bi ] change t ;
M: alien-call-insn compute-stack-frame* M: alien-call-insn compute-stack-frame*
frame-required stack-size>> param-area-size [ max ] change t ;
stack-size>> param-area-size [ max ] change ;
: vm-frame-required ( -- ) : vm-frame-required ( -- ? )
frame-required vm-stack-space param-area-size [ max ] change t ;
vm-stack-space param-area-size [ max ] change ;
M: ##call-gc compute-stack-frame* drop vm-frame-required ; M: ##call-gc compute-stack-frame* drop vm-frame-required ;
M: ##box compute-stack-frame* drop vm-frame-required ; M: ##box compute-stack-frame* drop vm-frame-required ;
@ -34,17 +28,17 @@ M: ##box-long-long compute-stack-frame* drop vm-frame-required ;
M: ##callback-inputs compute-stack-frame* drop vm-frame-required ; M: ##callback-inputs compute-stack-frame* drop vm-frame-required ;
M: ##callback-outputs compute-stack-frame* drop vm-frame-required ; M: ##callback-outputs compute-stack-frame* drop vm-frame-required ;
M: ##call compute-stack-frame* drop frame-required ; M: ##call compute-stack-frame* drop t ;
M: ##spill compute-stack-frame* drop frame-required ; M: ##spill compute-stack-frame* drop t ;
M: ##reload compute-stack-frame* drop frame-required ; M: ##reload compute-stack-frame* drop t ;
M: ##float>integer compute-stack-frame* M: ##float>integer compute-stack-frame*
drop integer-float-needs-stack-frame? [ frame-required ] when ; drop integer-float-needs-stack-frame? ;
M: ##integer>float compute-stack-frame* M: ##integer>float compute-stack-frame*
drop integer-float-needs-stack-frame? [ frame-required ] when ; drop integer-float-needs-stack-frame? ;
M: insn compute-stack-frame* drop ; M: insn compute-stack-frame* drop f ;
: calculate-allot-area-base ( stack-frame -- n ) : calculate-allot-area-base ( stack-frame -- n )
[ params>> ] [ allot-area-align>> ] bi align ; [ params>> ] [ allot-area-align>> ] bi align ;
@ -69,12 +63,10 @@ M: insn compute-stack-frame* drop ;
finalize-stack-frame ; finalize-stack-frame ;
: compute-stack-frame ( cfg -- stack-frame/f ) : compute-stack-frame ( cfg -- stack-frame/f )
[ [ instructions>> [ compute-stack-frame* ] each ] each-basic-block ] dup cfg>insns [ compute-stack-frame* ] map [ ] any?
[ frame-required? get [ <stack-frame> ] [ drop f ] if ] [ <stack-frame> ] [ drop f ] if ;
bi ;
: build-stack-frame ( cfg -- ) : build-stack-frame ( cfg -- )
f frame-required? set
0 param-area-size set 0 param-area-size set
0 allot-area-size set 0 allot-area-size set
cell allot-area-align set cell allot-area-align set