factor/basis/compiler/cfg/instructions/instructions.factor

133 lines
3.6 KiB
Factor
Raw Normal View History

2008-09-10 23:11:03 -04:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2008-10-17 16:35:04 -04:00
USING: assocs accessors arrays kernel sequences namespaces words
2008-09-15 05:22:12 -04:00
math compiler.cfg.registers compiler.cfg.instructions.syntax ;
2008-09-15 02:54:48 -04:00
IN: compiler.cfg.instructions
2008-09-10 23:11:03 -04:00
! Virtual CPU instructions, used by CFG and machine IRs
2008-10-17 16:35:04 -04:00
TUPLE: ##cond-branch < insn { src vreg } ;
TUPLE: ##unary < insn { dst vreg } { src vreg } ;
TUPLE: ##nullary < insn { dst vreg } ;
2008-09-10 23:11:03 -04:00
! Stack operations
2008-09-17 01:46:38 -04:00
INSN: ##load-literal < ##nullary obj ;
2008-10-17 16:35:04 -04:00
INSN: ##peek < ##nullary { loc loc } ;
INSN: ##replace { src vreg } { loc loc } ;
INSN: ##inc-d { n integer } ;
INSN: ##inc-r { n integer } ;
2008-09-10 23:11:03 -04:00
! Subroutine calls
2008-10-07 17:13:29 -04:00
TUPLE: stack-frame
{ params integer }
{ return integer }
2008-10-19 02:10:21 -04:00
{ total-size integer }
spill-counts ;
2008-10-07 17:13:29 -04:00
INSN: ##stack-frame stack-frame ;
: ##simple-stack-frame ( -- ) T{ stack-frame } ##stack-frame ;
2008-09-17 01:46:38 -04:00
INSN: ##call word ;
INSN: ##jump word ;
2008-10-07 17:13:29 -04:00
INSN: ##return ;
2008-09-17 01:46:38 -04:00
INSN: ##intrinsic quot defs-vregs uses-vregs ;
2008-09-10 23:11:03 -04:00
! Jump tables
2008-09-17 19:52:11 -04:00
INSN: ##dispatch src temp ;
2008-10-17 16:35:04 -04:00
INSN: ##dispatch-label label ;
2008-09-10 23:11:03 -04:00
! Boxing and unboxing
2008-09-17 01:46:38 -04:00
INSN: ##copy < ##unary ;
INSN: ##copy-float < ##unary ;
INSN: ##unbox-float < ##unary ;
INSN: ##unbox-f < ##unary ;
INSN: ##unbox-alien < ##unary ;
INSN: ##unbox-byte-array < ##unary ;
INSN: ##unbox-any-c-ptr < ##unary ;
2008-10-17 16:35:04 -04:00
INSN: ##box-float < ##unary { temp vreg } ;
INSN: ##box-alien < ##unary { temp vreg } ;
2008-09-17 01:46:38 -04:00
2008-09-17 19:52:11 -04:00
! Memory allocation
2008-10-17 16:35:04 -04:00
INSN: ##allot < ##nullary size type tag { temp vreg } ;
INSN: ##write-barrier { src vreg } card# table ;
2008-09-17 01:46:38 -04:00
INSN: ##gc ;
2008-09-10 23:11:03 -04:00
! FFI
2008-09-17 01:46:38 -04:00
INSN: ##alien-invoke params ;
INSN: ##alien-indirect params ;
INSN: ##alien-callback params ;
2008-10-13 00:32:14 -04:00
INSN: ##callback-return params ;
2008-09-10 23:11:03 -04:00
2008-09-15 02:54:48 -04:00
GENERIC: defs-vregs ( insn -- seq )
2008-09-10 23:11:03 -04:00
GENERIC: uses-vregs ( insn -- seq )
2008-10-17 16:35:04 -04:00
M: ##nullary defs-vregs dst>> 1array ;
M: ##unary defs-vregs dst>> 1array ;
2008-10-10 04:16:26 -04:00
M: ##write-barrier defs-vregs
2008-10-17 16:35:04 -04:00
[ card#>> ] [ table>> ] bi 2array ;
2008-09-17 19:52:11 -04:00
: allot-defs-vregs ( insn -- seq )
2008-10-17 16:35:04 -04:00
[ dst>> ] [ temp>> ] bi 2array ;
2008-09-17 19:52:11 -04:00
M: ##box-float defs-vregs allot-defs-vregs ;
M: ##box-alien defs-vregs allot-defs-vregs ;
M: ##allot defs-vregs allot-defs-vregs ;
2008-10-17 16:35:04 -04:00
M: ##dispatch defs-vregs temp>> 1array ;
2008-09-15 02:54:48 -04:00
M: insn defs-vregs drop f ;
2008-10-17 16:35:04 -04:00
M: ##replace uses-vregs src>> 1array ;
M: ##unary uses-vregs src>> 1array ;
M: ##write-barrier uses-vregs src>> 1array ;
M: ##dispatch uses-vregs src>> 1array ;
2008-09-15 03:59:24 -04:00
M: insn uses-vregs drop f ;
2008-09-15 02:54:48 -04:00
2008-09-17 01:46:38 -04:00
: intrinsic-vregs ( assoc -- seq' )
2008-10-17 21:03:59 -04:00
[ nip dup vreg? swap and ] { } assoc>map sift ;
2008-09-11 03:05:22 -04:00
2008-09-17 01:46:38 -04:00
: intrinsic-defs-vregs ( insn -- seq )
defs-vregs>> intrinsic-vregs ;
: intrinsic-uses-vregs ( insn -- seq )
uses-vregs>> intrinsic-vregs ;
2008-09-11 03:05:22 -04:00
2008-09-17 01:46:38 -04:00
M: ##intrinsic defs-vregs intrinsic-defs-vregs ;
M: ##intrinsic uses-vregs intrinsic-uses-vregs ;
2008-09-11 03:05:22 -04:00
2008-09-17 01:46:38 -04:00
! Instructions used by CFG IR only.
INSN: ##prologue ;
INSN: ##epilogue ;
2008-09-15 02:54:48 -04:00
2008-09-17 01:46:38 -04:00
INSN: ##branch ;
INSN: ##branch-f < ##cond-branch ;
INSN: ##branch-t < ##cond-branch ;
INSN: ##if-intrinsic quot defs-vregs uses-vregs ;
2008-09-15 02:54:48 -04:00
2008-10-17 16:35:04 -04:00
M: ##cond-branch uses-vregs src>> 1array ;
2008-09-15 02:54:48 -04:00
2008-09-17 01:46:38 -04:00
M: ##if-intrinsic defs-vregs intrinsic-defs-vregs ;
M: ##if-intrinsic uses-vregs intrinsic-uses-vregs ;
2008-09-11 03:05:22 -04:00
! Instructions used by machine IR only.
2008-10-07 17:13:29 -04:00
INSN: _prologue stack-frame ;
INSN: _epilogue stack-frame ;
2008-09-11 03:05:22 -04:00
2008-09-17 01:46:38 -04:00
INSN: _label id ;
2008-09-11 03:05:22 -04:00
2008-10-17 16:35:04 -04:00
TUPLE: _cond-branch < insn { src vreg } label ;
2008-09-11 03:05:22 -04:00
INSN: _branch label ;
INSN: _branch-f < _cond-branch ;
INSN: _branch-t < _cond-branch ;
2008-09-17 01:46:38 -04:00
INSN: _if-intrinsic label quot defs-vregs uses-vregs ;
2008-09-11 03:05:22 -04:00
2008-10-17 16:35:04 -04:00
M: _cond-branch uses-vregs src>> 1array ;
2008-09-17 01:46:38 -04:00
M: _if-intrinsic defs-vregs intrinsic-defs-vregs ;
M: _if-intrinsic uses-vregs intrinsic-uses-vregs ;
2008-09-15 03:59:24 -04:00
2008-10-19 02:10:21 -04:00
! These instructions operate on machine registers and not
! virtual registers
INSN: _spill src class n ;
INSN: _reload dst class n ;
INSN: _spill-counts counts ;