]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/build-stack-frame/build-stack-frame.factor
compiler.cfg.linear-scan: cleanups
[factor.git] / basis / compiler / cfg / build-stack-frame / build-stack-frame.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces accessors math.order assocs kernel sequences
4 combinators make classes words cpu.architecture layouts
5 compiler.cfg.instructions compiler.cfg.registers
6 compiler.cfg.stack-frame ;
7 IN: compiler.cfg.build-stack-frame
8
9 SYMBOL: frame-required?
10
11 GENERIC: compute-stack-frame* ( insn -- )
12
13 : request-stack-frame ( stack-frame -- )
14     frame-required? on
15     stack-frame [ max-stack-frame ] change ;
16
17 UNION: stack-frame-insn
18     ##alien-invoke
19     ##alien-indirect
20     ##alien-assembly
21     ##alien-callback ;
22
23 M: stack-frame-insn compute-stack-frame*
24     stack-frame>> request-stack-frame ;
25
26 M: ##call compute-stack-frame* drop frame-required? on ;
27
28 M: ##call-gc compute-stack-frame*
29     drop
30     frame-required? on
31     stack-frame new t >>calls-vm? request-stack-frame ;
32
33 M: _spill-area-size compute-stack-frame*
34     n>> stack-frame get (>>spill-area-size) ;
35
36 M: insn compute-stack-frame*
37     class frame-required? word-prop [
38         frame-required? on
39     ] when ;
40
41 ! PowerPC backend sets frame-required? for ##integer>float!
42 \ ##spill t frame-required? set-word-prop
43 \ ##unary-float-function t frame-required? set-word-prop
44 \ ##binary-float-function t frame-required? set-word-prop
45
46 : compute-stack-frame ( insns -- )
47     frame-required? off
48     stack-frame new stack-frame set
49     [ compute-stack-frame* ] each
50     stack-frame get dup stack-frame-size >>total-size drop ;
51
52 GENERIC: insert-pro/epilogues* ( insn -- )
53
54 M: ##prologue insert-pro/epilogues*
55     drop frame-required? get [ stack-frame get _prologue ] when ;
56
57 M: ##epilogue insert-pro/epilogues*
58     drop frame-required? get [ stack-frame get _epilogue ] when ;
59
60 M: insn insert-pro/epilogues* , ;
61
62 : insert-pro/epilogues ( insns -- insns )
63     [ [ insert-pro/epilogues* ] each ] { } make ;
64
65 : build-stack-frame ( mr -- mr )
66     [
67         [
68             [ compute-stack-frame ]
69             [ insert-pro/epilogues ]
70             bi
71         ] change-instructions
72     ] with-scope ;