2010-01-06 23:39:22 -05:00
|
|
|
! Copyright (C) 2009, 2010 Slava Pestov.
|
2009-09-08 22:56:28 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-07-02 15:44:12 -04:00
|
|
|
USING: accessors compiler.cfg.instructions compiler.cfg.registers
|
2009-09-08 22:56:28 -04:00
|
|
|
compiler.cfg.rpo cpu.architecture kernel sequences vectors ;
|
|
|
|
IN: compiler.cfg.save-contexts
|
|
|
|
|
|
|
|
! Insert context saves.
|
|
|
|
|
2010-07-02 15:44:12 -04:00
|
|
|
GENERIC: needs-save-context? ( insn -- ? )
|
|
|
|
|
|
|
|
M: ##unary-float-function needs-save-context? drop t ;
|
|
|
|
M: ##binary-float-function needs-save-context? drop t ;
|
|
|
|
M: gc-map-insn needs-save-context? drop t ;
|
|
|
|
M: insn needs-save-context? drop f ;
|
|
|
|
|
|
|
|
: bb-needs-save-context? ( insn -- ? )
|
|
|
|
instructions>> [ needs-save-context? ] any? ;
|
|
|
|
|
|
|
|
GENERIC: modifies-context? ( insn -- ? )
|
|
|
|
|
|
|
|
M: ##inc-d modifies-context? drop t ;
|
|
|
|
M: ##inc-r modifies-context? drop t ;
|
2010-07-13 07:40:14 -04:00
|
|
|
M: ##callback-inputs modifies-context? drop t ;
|
2010-07-02 15:44:12 -04:00
|
|
|
M: insn modifies-context? drop f ;
|
|
|
|
|
|
|
|
: save-context-offset ( bb -- n )
|
|
|
|
! ##save-context must be placed after instructions that
|
|
|
|
! modify the context, or instructions that read parameter
|
|
|
|
! registers.
|
|
|
|
instructions>> [ modifies-context? not ] find drop ;
|
2009-09-08 22:56:28 -04:00
|
|
|
|
|
|
|
: insert-save-context ( bb -- )
|
2010-07-02 15:44:12 -04:00
|
|
|
dup bb-needs-save-context? [
|
|
|
|
[
|
|
|
|
int-rep next-vreg-rep
|
|
|
|
int-rep next-vreg-rep
|
|
|
|
\ ##save-context new-insn
|
|
|
|
] dip
|
|
|
|
[ save-context-offset ] keep
|
|
|
|
[ insert-nth ] change-instructions drop
|
|
|
|
] [ drop ] if ;
|
2009-09-08 22:56:28 -04:00
|
|
|
|
|
|
|
: insert-save-contexts ( cfg -- cfg' )
|
|
|
|
dup [ insert-save-context ] each-basic-block ;
|