Put GC checks in the right place when linearizing, and generate _dispatch-labels
parent
76d74c16af
commit
743550f19c
|
@ -21,6 +21,7 @@ M: ##compare-imm defs-vregs dst/tmp-vregs ;
|
||||||
M: ##compare-float defs-vregs dst/tmp-vregs ;
|
M: ##compare-float defs-vregs dst/tmp-vregs ;
|
||||||
M: ##fixnum-mul defs-vregs [ temp1>> ] [ temp2>> ] bi 2array ;
|
M: ##fixnum-mul defs-vregs [ temp1>> ] [ temp2>> ] bi 2array ;
|
||||||
M: ##fixnum-mul-tail defs-vregs [ temp1>> ] [ temp2>> ] bi 2array ;
|
M: ##fixnum-mul-tail defs-vregs [ temp1>> ] [ temp2>> ] bi 2array ;
|
||||||
|
M: _dispatch defs-vregs temp>> 1array ;
|
||||||
M: insn defs-vregs drop f ;
|
M: insn defs-vregs drop f ;
|
||||||
|
|
||||||
M: ##unary uses-vregs src>> 1array ;
|
M: ##unary uses-vregs src>> 1array ;
|
||||||
|
@ -42,6 +43,7 @@ M: ##fixnum-overflow uses-vregs [ src1>> ] [ src2>> ] bi 2array ;
|
||||||
M: ##phi uses-vregs inputs>> ;
|
M: ##phi uses-vregs inputs>> ;
|
||||||
M: _conditional-branch uses-vregs [ src1>> ] [ src2>> ] bi 2array ;
|
M: _conditional-branch uses-vregs [ src1>> ] [ src2>> ] bi 2array ;
|
||||||
M: _compare-imm-branch uses-vregs src1>> 1array ;
|
M: _compare-imm-branch uses-vregs src1>> 1array ;
|
||||||
|
M: _dispatch uses-vregs src>> 1array ;
|
||||||
M: insn uses-vregs drop f ;
|
M: insn uses-vregs drop f ;
|
||||||
|
|
||||||
! Instructions that use vregs
|
! Instructions that use vregs
|
||||||
|
@ -54,4 +56,5 @@ UNION: vreg-insn
|
||||||
##conditional-branch
|
##conditional-branch
|
||||||
##compare-imm-branch
|
##compare-imm-branch
|
||||||
_conditional-branch
|
_conditional-branch
|
||||||
_compare-imm-branch ;
|
_compare-imm-branch
|
||||||
|
_dispatch ;
|
||||||
|
|
|
@ -231,6 +231,9 @@ INSN: _gc live-in ;
|
||||||
|
|
||||||
INSN: _branch label ;
|
INSN: _branch label ;
|
||||||
|
|
||||||
|
INSN: _dispatch src temp ;
|
||||||
|
INSN: _dispatch-label label ;
|
||||||
|
|
||||||
TUPLE: _conditional-branch < insn label { src1 vreg } { src2 vreg } cc ;
|
TUPLE: _conditional-branch < insn label { src1 vreg } { src2 vreg } cc ;
|
||||||
|
|
||||||
INSN: _compare-branch < _conditional-branch ;
|
INSN: _compare-branch < _conditional-branch ;
|
||||||
|
|
|
@ -12,8 +12,38 @@ IN: compiler.cfg.linearization
|
||||||
! Convert CFG IR to machine IR.
|
! Convert CFG IR to machine IR.
|
||||||
GENERIC: linearize-insn ( basic-block insn -- )
|
GENERIC: linearize-insn ( basic-block insn -- )
|
||||||
|
|
||||||
: linearize-insns ( basic-block -- )
|
: linearize-insns ( bb insns -- )
|
||||||
dup instructions>> [ linearize-insn ] with each ; inline
|
[ linearize-insn ] with each ;
|
||||||
|
|
||||||
|
: gc? ( bb -- ? )
|
||||||
|
instructions>> [ ##allocation? ] any? ;
|
||||||
|
|
||||||
|
: object-pointer-regs ( basic-block -- vregs )
|
||||||
|
live-out keys [ reg-class>> int-regs eq? ] filter ;
|
||||||
|
|
||||||
|
: gc-check-position ( insns -- n )
|
||||||
|
#! We want to insert the GC check before the final branch in a basic block.
|
||||||
|
#! If there is a ##epilogue or ##loop-entry we want to insert it before that too.
|
||||||
|
dup length
|
||||||
|
dup 2 >= [
|
||||||
|
2 - swap nth [ ##loop-entry? ] [ ##epilogue? ] bi or
|
||||||
|
2 1 ?
|
||||||
|
] [ 2drop 1 ] if ;
|
||||||
|
|
||||||
|
: linearize-basic-block/gc ( bb -- )
|
||||||
|
dup instructions>> dup gc-check-position
|
||||||
|
[ head* linearize-insns ]
|
||||||
|
[ 2drop object-pointer-regs _gc ]
|
||||||
|
[ tail* linearize-insns ]
|
||||||
|
3tri ;
|
||||||
|
|
||||||
|
: linearize-basic-block ( bb -- )
|
||||||
|
[ number>> _label ]
|
||||||
|
[
|
||||||
|
dup gc?
|
||||||
|
[ linearize-basic-block/gc ]
|
||||||
|
[ dup instructions>> linearize-insns ] if
|
||||||
|
] bi ;
|
||||||
|
|
||||||
M: insn linearize-insn , drop ;
|
M: insn linearize-insn , drop ;
|
||||||
|
|
||||||
|
@ -32,7 +62,7 @@ M: insn linearize-insn , drop ;
|
||||||
: emit-branch ( basic-block successor -- )
|
: emit-branch ( basic-block successor -- )
|
||||||
{
|
{
|
||||||
{ [ 2dup useless-branch? ] [ 2drop ] }
|
{ [ 2dup useless-branch? ] [ 2drop ] }
|
||||||
{ [ dup branch-to-branch? ] [ nip linearize-insns ] }
|
{ [ dup branch-to-branch? ] [ nip linearize-basic-block ] }
|
||||||
[ nip number>> _branch ]
|
[ nip number>> _branch ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
@ -57,17 +87,11 @@ M: ##compare-imm-branch linearize-insn
|
||||||
M: ##compare-float-branch linearize-insn
|
M: ##compare-float-branch linearize-insn
|
||||||
binary-conditional _compare-float-branch emit-branch ;
|
binary-conditional _compare-float-branch emit-branch ;
|
||||||
|
|
||||||
: gc? ( bb -- ? )
|
M: ##dispatch linearize-insn
|
||||||
instructions>> [ ##allocation? ] any? ;
|
swap
|
||||||
|
[ [ src>> ] [ temp>> ] bi _dispatch ]
|
||||||
: object-pointer-regs ( basic-block -- vregs )
|
[ successors>> [ number>> _dispatch-label ] each ]
|
||||||
live-in keys [ reg-class>> int-regs eq? ] filter ;
|
bi* ;
|
||||||
|
|
||||||
: linearize-basic-block ( bb -- )
|
|
||||||
[ number>> _label ]
|
|
||||||
[ dup gc? [ object-pointer-regs _gc ] [ drop ] if ]
|
|
||||||
[ linearize-insns ]
|
|
||||||
tri ;
|
|
||||||
|
|
||||||
: linearize-basic-blocks ( rpo -- insns )
|
: linearize-basic-blocks ( rpo -- insns )
|
||||||
[ [ linearize-basic-block ] each ] { } make ;
|
[ [ linearize-basic-block ] each ] { } make ;
|
||||||
|
|
Loading…
Reference in New Issue