JIT now supports multiple relocations per code template. This simplifies non-optimizing compiler backends
parent
581d017b46
commit
12a34d81f7
|
@ -93,24 +93,19 @@ CONSTANT: -1-offset 9
|
||||||
|
|
||||||
SYMBOL: sub-primitives
|
SYMBOL: sub-primitives
|
||||||
|
|
||||||
SYMBOL: jit-define-rc
|
SYMBOL: jit-relocations
|
||||||
SYMBOL: jit-define-rt
|
|
||||||
SYMBOL: jit-define-offset
|
|
||||||
|
|
||||||
: compute-offset ( -- offset )
|
: compute-offset ( rc -- offset )
|
||||||
building get length jit-define-rc get rc-absolute-cell = bootstrap-cell 4 ? - ;
|
[ building get length ] dip rc-absolute-cell = bootstrap-cell 4 ? - ;
|
||||||
|
|
||||||
: jit-rel ( rc rt -- )
|
: jit-rel ( rc rt -- )
|
||||||
jit-define-rt set
|
over compute-offset 3array jit-relocations get push-all ;
|
||||||
jit-define-rc set
|
|
||||||
compute-offset jit-define-offset set ;
|
|
||||||
|
|
||||||
: make-jit ( quot -- quad )
|
: make-jit ( quot -- jit-data )
|
||||||
[
|
[
|
||||||
|
V{ } clone jit-relocations set
|
||||||
call( -- )
|
call( -- )
|
||||||
jit-define-rc get
|
jit-relocations get >array
|
||||||
jit-define-rt get
|
|
||||||
jit-define-offset get 3array
|
|
||||||
] B{ } make prefix ;
|
] B{ } make prefix ;
|
||||||
|
|
||||||
: jit-define ( quot name -- )
|
: jit-define ( quot name -- )
|
||||||
|
@ -142,8 +137,7 @@ SYMBOL: jit-word-jump
|
||||||
SYMBOL: jit-word-call
|
SYMBOL: jit-word-call
|
||||||
SYMBOL: jit-push-immediate
|
SYMBOL: jit-push-immediate
|
||||||
SYMBOL: jit-if-word
|
SYMBOL: jit-if-word
|
||||||
SYMBOL: jit-if-1
|
SYMBOL: jit-if
|
||||||
SYMBOL: jit-if-2
|
|
||||||
SYMBOL: jit-dip-word
|
SYMBOL: jit-dip-word
|
||||||
SYMBOL: jit-dip
|
SYMBOL: jit-dip
|
||||||
SYMBOL: jit-2dip-word
|
SYMBOL: jit-2dip-word
|
||||||
|
@ -156,7 +150,6 @@ SYMBOL: jit-execute-call
|
||||||
SYMBOL: jit-epilog
|
SYMBOL: jit-epilog
|
||||||
SYMBOL: jit-return
|
SYMBOL: jit-return
|
||||||
SYMBOL: jit-profiling
|
SYMBOL: jit-profiling
|
||||||
SYMBOL: jit-save-stack
|
|
||||||
|
|
||||||
! PIC stubs
|
! PIC stubs
|
||||||
SYMBOL: pic-load
|
SYMBOL: pic-load
|
||||||
|
@ -188,13 +181,11 @@ SYMBOL: undefined-quot
|
||||||
{ jit-word-jump 26 }
|
{ jit-word-jump 26 }
|
||||||
{ jit-word-call 27 }
|
{ jit-word-call 27 }
|
||||||
{ jit-if-word 28 }
|
{ jit-if-word 28 }
|
||||||
{ jit-if-1 29 }
|
{ jit-if 29 }
|
||||||
{ jit-if-2 30 }
|
|
||||||
{ jit-epilog 33 }
|
{ jit-epilog 33 }
|
||||||
{ jit-return 34 }
|
{ jit-return 34 }
|
||||||
{ jit-profiling 35 }
|
{ jit-profiling 35 }
|
||||||
{ jit-push-immediate 36 }
|
{ jit-push-immediate 36 }
|
||||||
{ jit-save-stack 37 }
|
|
||||||
{ jit-dip-word 38 }
|
{ jit-dip-word 38 }
|
||||||
{ jit-dip 39 }
|
{ jit-dip 39 }
|
||||||
{ jit-2dip-word 40 }
|
{ jit-2dip-word 40 }
|
||||||
|
@ -539,8 +530,7 @@ M: quotation '
|
||||||
jit-word-call
|
jit-word-call
|
||||||
jit-push-immediate
|
jit-push-immediate
|
||||||
jit-if-word
|
jit-if-word
|
||||||
jit-if-1
|
jit-if
|
||||||
jit-if-2
|
|
||||||
jit-dip-word
|
jit-dip-word
|
||||||
jit-dip
|
jit-dip
|
||||||
jit-2dip-word
|
jit-2dip-word
|
||||||
|
@ -553,7 +543,6 @@ M: quotation '
|
||||||
jit-epilog
|
jit-epilog
|
||||||
jit-return
|
jit-return
|
||||||
jit-profiling
|
jit-profiling
|
||||||
jit-save-stack
|
|
||||||
pic-load
|
pic-load
|
||||||
pic-tag
|
pic-tag
|
||||||
pic-hi-tag
|
pic-hi-tag
|
||||||
|
|
|
@ -50,9 +50,6 @@ CONSTANT: rs-reg 14
|
||||||
0 6 LOAD32 rc-absolute-ppc-2/2 rt-stack-chain jit-rel
|
0 6 LOAD32 rc-absolute-ppc-2/2 rt-stack-chain jit-rel
|
||||||
7 6 0 LWZ
|
7 6 0 LWZ
|
||||||
1 7 0 STW
|
1 7 0 STW
|
||||||
] jit-save-stack jit-define
|
|
||||||
|
|
||||||
[
|
|
||||||
0 6 LOAD32 rc-absolute-ppc-2/2 rt-primitive jit-rel
|
0 6 LOAD32 rc-absolute-ppc-2/2 rt-primitive jit-rel
|
||||||
6 MTCTR
|
6 MTCTR
|
||||||
BCTR
|
BCTR
|
||||||
|
@ -68,11 +65,8 @@ CONSTANT: rs-reg 14
|
||||||
0 3 \ f tag-number CMPI
|
0 3 \ f tag-number CMPI
|
||||||
2 BEQ
|
2 BEQ
|
||||||
0 B rc-relative-ppc-3 rt-xt jit-rel
|
0 B rc-relative-ppc-3 rt-xt jit-rel
|
||||||
] jit-if-1 jit-define
|
|
||||||
|
|
||||||
[
|
|
||||||
0 B rc-relative-ppc-3 rt-xt jit-rel
|
0 B rc-relative-ppc-3 rt-xt jit-rel
|
||||||
] jit-if-2 jit-define
|
] jit-if jit-define
|
||||||
|
|
||||||
: jit->r ( -- )
|
: jit->r ( -- )
|
||||||
4 ds-reg 0 LWZ
|
4 ds-reg 0 LWZ
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2007 Slava Pestov.
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: bootstrap.image.private kernel namespaces system
|
USING: bootstrap.image.private kernel namespaces system
|
||||||
cpu.x86.assembler layouts vocabs parser compiler.constants ;
|
cpu.x86.assembler layouts vocabs parser compiler.constants ;
|
||||||
|
@ -26,9 +26,7 @@ IN: bootstrap.x86
|
||||||
temp0 0 [] MOV rc-absolute-cell rt-stack-chain jit-rel
|
temp0 0 [] MOV rc-absolute-cell rt-stack-chain jit-rel
|
||||||
! save stack pointer
|
! save stack pointer
|
||||||
temp0 [] stack-reg MOV
|
temp0 [] stack-reg MOV
|
||||||
] jit-save-stack jit-define
|
! call the primitive
|
||||||
|
|
||||||
[
|
|
||||||
0 JMP rc-relative rt-primitive jit-rel
|
0 JMP rc-relative rt-primitive jit-rel
|
||||||
] jit-primitive jit-define
|
] jit-primitive jit-define
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2007 Slava Pestov.
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: bootstrap.image.private kernel namespaces system
|
USING: bootstrap.image.private kernel namespaces system
|
||||||
cpu.x86.assembler layouts vocabs parser compiler.constants math ;
|
cpu.x86.assembler layouts vocabs parser compiler.constants math ;
|
||||||
|
@ -25,9 +25,6 @@ IN: bootstrap.x86
|
||||||
temp0 temp0 [] MOV
|
temp0 temp0 [] MOV
|
||||||
! save stack pointer
|
! save stack pointer
|
||||||
temp0 [] stack-reg MOV
|
temp0 [] stack-reg MOV
|
||||||
] jit-save-stack jit-define
|
|
||||||
|
|
||||||
[
|
|
||||||
! load XT
|
! load XT
|
||||||
temp1 0 MOV rc-absolute-cell rt-primitive jit-rel
|
temp1 0 MOV rc-absolute-cell rt-primitive jit-rel
|
||||||
! go
|
! go
|
||||||
|
|
|
@ -58,12 +58,9 @@ big-endian off
|
||||||
temp0 \ f tag-number CMP
|
temp0 \ f tag-number CMP
|
||||||
! jump to true branch if not equal
|
! jump to true branch if not equal
|
||||||
0 JNE rc-relative rt-xt jit-rel
|
0 JNE rc-relative rt-xt jit-rel
|
||||||
] jit-if-1 jit-define
|
|
||||||
|
|
||||||
[
|
|
||||||
! jump to false branch if equal
|
! jump to false branch if equal
|
||||||
0 JMP rc-relative rt-xt jit-rel
|
0 JMP rc-relative rt-xt jit-rel
|
||||||
] jit-if-2 jit-define
|
] jit-if jit-define
|
||||||
|
|
||||||
: jit->r ( -- )
|
: jit->r ( -- )
|
||||||
rs-reg bootstrap-cell ADD
|
rs-reg bootstrap-cell ADD
|
||||||
|
|
29
vm/jit.cpp
29
vm/jit.cpp
|
@ -23,24 +23,21 @@ jit::jit(cell type_, cell owner_)
|
||||||
if(stack_traces_p()) literal(owner.value());
|
if(stack_traces_p()) literal(owner.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
relocation_entry jit::rel_to_emit(cell code_template, bool *rel_p)
|
void jit::emit_relocation(cell code_template_)
|
||||||
{
|
{
|
||||||
array *quadruple = untag<array>(code_template);
|
gc_root<array> code_template(code_template_);
|
||||||
cell rel_class = array_nth(quadruple,1);
|
cell capacity = array_capacity(code_template.untagged());
|
||||||
cell rel_type = array_nth(quadruple,2);
|
for(cell i = 1; i < capacity; i += 3)
|
||||||
cell offset = array_nth(quadruple,3);
|
{
|
||||||
|
cell rel_class = array_nth(code_template.untagged(),i);
|
||||||
|
cell rel_type = array_nth(code_template.untagged(),i + 1);
|
||||||
|
cell offset = array_nth(code_template.untagged(),i + 2);
|
||||||
|
|
||||||
if(rel_class == F)
|
relocation_entry new_entry
|
||||||
{
|
= (untag_fixnum(rel_type) << 28)
|
||||||
*rel_p = false;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*rel_p = true;
|
|
||||||
return (untag_fixnum(rel_type) << 28)
|
|
||||||
| (untag_fixnum(rel_class) << 24)
|
| (untag_fixnum(rel_class) << 24)
|
||||||
| ((code.count + untag_fixnum(offset)));
|
| ((code.count + untag_fixnum(offset)));
|
||||||
|
relocation.append_bytes(&new_entry,sizeof(relocation_entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +46,7 @@ void jit::emit(cell code_template_)
|
||||||
{
|
{
|
||||||
gc_root<array> code_template(code_template_);
|
gc_root<array> code_template(code_template_);
|
||||||
|
|
||||||
bool rel_p;
|
emit_relocation(code_template.value());
|
||||||
relocation_entry rel = rel_to_emit(code_template.value(),&rel_p);
|
|
||||||
if(rel_p) relocation.append_bytes(&rel,sizeof(relocation_entry));
|
|
||||||
|
|
||||||
gc_root<byte_array> insns(array_nth(code_template.untagged(),0));
|
gc_root<byte_array> insns(array_nth(code_template.untagged(),0));
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct jit {
|
||||||
jit(cell jit_type, cell owner);
|
jit(cell jit_type, cell owner);
|
||||||
void compute_position(cell offset);
|
void compute_position(cell offset);
|
||||||
|
|
||||||
relocation_entry rel_to_emit(cell code_template, bool *rel_p);
|
void emit_relocation(cell code_template);
|
||||||
void emit(cell code_template);
|
void emit(cell code_template);
|
||||||
|
|
||||||
void literal(cell literal) { literals.add(literal); }
|
void literal(cell literal) { literals.add(literal); }
|
||||||
|
@ -35,7 +35,7 @@ struct jit {
|
||||||
void emit_subprimitive(cell word_) {
|
void emit_subprimitive(cell word_) {
|
||||||
gc_root<word> word(word_);
|
gc_root<word> word(word_);
|
||||||
gc_root<array> code_template(word->subprimitive);
|
gc_root<array> code_template(word->subprimitive);
|
||||||
if(array_nth(code_template.untagged(),1) != F) literal(T);
|
if(array_capacity(code_template.untagged()) > 1) literal(T);
|
||||||
emit(code_template.value());
|
emit(code_template.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,6 @@ void quotation_jit::iterate_quotation()
|
||||||
/* Primitive calls */
|
/* Primitive calls */
|
||||||
if(primitive_call_p(i))
|
if(primitive_call_p(i))
|
||||||
{
|
{
|
||||||
emit(userenv[JIT_SAVE_STACK]);
|
|
||||||
emit_with(userenv[JIT_PRIMITIVE],obj.value());
|
emit_with(userenv[JIT_PRIMITIVE],obj.value());
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
@ -187,8 +186,9 @@ void quotation_jit::iterate_quotation()
|
||||||
jit_compile(array_nth(elements.untagged(),i + 1),relocate);
|
jit_compile(array_nth(elements.untagged(),i + 1),relocate);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_with(userenv[JIT_IF_1],array_nth(elements.untagged(),i));
|
literal(array_nth(elements.untagged(),i));
|
||||||
emit_with(userenv[JIT_IF_2],array_nth(elements.untagged(),i + 1));
|
literal(array_nth(elements.untagged(),i + 1));
|
||||||
|
emit(userenv[JIT_IF]);
|
||||||
|
|
||||||
i += 2;
|
i += 2;
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,12 @@ enum special_object {
|
||||||
JIT_WORD_JUMP,
|
JIT_WORD_JUMP,
|
||||||
JIT_WORD_CALL,
|
JIT_WORD_CALL,
|
||||||
JIT_IF_WORD,
|
JIT_IF_WORD,
|
||||||
JIT_IF_1,
|
JIT_IF,
|
||||||
JIT_IF_2,
|
|
||||||
JIT_EPILOG = 33,
|
JIT_EPILOG = 33,
|
||||||
JIT_RETURN,
|
JIT_RETURN,
|
||||||
JIT_PROFILING,
|
JIT_PROFILING,
|
||||||
JIT_PUSH_IMMEDIATE,
|
JIT_PUSH_IMMEDIATE,
|
||||||
JIT_SAVE_STACK,
|
JIT_DIP_WORD = 38,
|
||||||
JIT_DIP_WORD,
|
|
||||||
JIT_DIP,
|
JIT_DIP,
|
||||||
JIT_2DIP_WORD,
|
JIT_2DIP_WORD,
|
||||||
JIT_2DIP,
|
JIT_2DIP,
|
||||||
|
|
Loading…
Reference in New Issue