M: expr simplify* drop f ;
-: simplify ( expr -- simplified? vn )
+: simplify ( expr -- vn )
dup simplify* {
- { [ dup not ] [ drop expr>vn f ] }
- { [ dup expr? ] [ expr>vn nip t ] }
- { [ dup integer? ] [ nip t ] }
- } cond swap ;
+ { [ dup not ] [ drop expr>vn ] }
+ { [ dup expr? ] [ expr>vn nip ] }
+ { [ dup integer? ] [ nip ] }
+ } cond ;
-: number-values ( insn -- simplified? )
- [ >expr simplify ] [ dst>> set-vn ] bi ;
+: number-values ( insn -- )
+ [ >expr simplify ] [ dst>> ] bi set-vn ;
[
{
T{ ##load-reference f V int-regs 0 0.0 }
- T{ ##load-reference f V int-regs 1 0.0 }
+ T{ ##copy f V int-regs 1 V int-regs 0 }
T{ ##replace f V int-regs 0 D 0 }
- T{ ##replace f V int-regs 0 D 1 }
+ T{ ##replace f V int-regs 1 D 1 }
}
] [
{
[
{
T{ ##load-reference f V int-regs 0 t }
- T{ ##load-reference f V int-regs 1 t }
+ T{ ##copy f V int-regs 1 V int-regs 0 }
T{ ##replace f V int-regs 0 D 0 }
- T{ ##replace f V int-regs 0 D 1 }
+ T{ ##replace f V int-regs 1 D 1 }
}
] [
{
} value-numbering-step
] unit-test
-! Copy propagation
-[
- {
- T{ ##peek f V int-regs 45 D 1 }
- T{ ##copy f V int-regs 48 V int-regs 45 }
- T{ ##compare-imm-branch f V int-regs 45 7 cc/= }
- }
-] [
- {
- T{ ##peek f V int-regs 45 D 1 }
- T{ ##copy f V int-regs 48 V int-regs 45 }
- T{ ##compare-imm-branch f V int-regs 48 7 cc/= }
- } value-numbering-step
-] unit-test
-
! Compare propagation
[
{
T{ ##load-reference f V int-regs 1 + }
T{ ##peek f V int-regs 2 D 0 }
T{ ##compare f V int-regs 4 V int-regs 2 V int-regs 1 cc> }
- T{ ##compare f V int-regs 6 V int-regs 2 V int-regs 1 cc> }
- T{ ##replace f V int-regs 4 D 0 }
+ T{ ##copy f V int-regs 6 V int-regs 4 }
+ T{ ##replace f V int-regs 6 D 0 }
}
] [
{
T{ ##peek f V int-regs 0 D 0 }
T{ ##peek f V int-regs 1 D 1 }
T{ ##load-immediate f V int-regs 2 0 }
- T{ ##add-imm f V int-regs 3 V int-regs 0 0 }
- T{ ##replace f V int-regs 0 D 0 }
+ T{ ##copy f V int-regs 3 V int-regs 0 }
+ T{ ##replace f V int-regs 3 D 0 }
}
] [
{
T{ ##peek f V int-regs 0 D 0 }
T{ ##peek f V int-regs 1 D 1 }
T{ ##load-immediate f V int-regs 2 0 }
- T{ ##add-imm f V int-regs 3 V int-regs 0 0 }
- T{ ##replace f V int-regs 0 D 0 }
+ T{ ##copy f V int-regs 3 V int-regs 0 }
+ T{ ##replace f V int-regs 3 D 0 }
}
] [
{
T{ ##peek f V int-regs 0 D 0 }
T{ ##peek f V int-regs 1 D 1 }
T{ ##load-immediate f V int-regs 2 0 }
- T{ ##or-imm f V int-regs 3 V int-regs 0 0 }
- T{ ##replace f V int-regs 0 D 0 }
+ T{ ##copy f V int-regs 3 V int-regs 0 }
+ T{ ##replace f V int-regs 3 D 0 }
}
] [
{
T{ ##peek f V int-regs 0 D 0 }
T{ ##peek f V int-regs 1 D 1 }
T{ ##load-immediate f V int-regs 2 0 }
- T{ ##xor-imm f V int-regs 3 V int-regs 0 0 }
- T{ ##replace f V int-regs 0 D 0 }
+ T{ ##copy f V int-regs 3 V int-regs 0 }
+ T{ ##replace f V int-regs 3 D 0 }
}
] [
{
{
T{ ##peek f V int-regs 0 D 0 }
T{ ##load-immediate f V int-regs 1 1 }
- T{ ##shl-imm f V int-regs 2 V int-regs 0 0 }
- T{ ##replace f V int-regs 0 D 0 }
+ T{ ##copy f V int-regs 2 V int-regs 0 }
+ T{ ##replace f V int-regs 2 D 0 }
}
] [
{
IN: compiler.cfg.value-numbering
! Local value numbering. Predecessors must be recomputed after this
-: >copy ( insn -- ##copy )
- dst>> dup vreg>vn vn>vreg \ ##copy new-insn ;
+: >copy ( insn -- insn/##copy )
+ dup dst>> dup vreg>vn vn>vreg
+ 2dup eq? [ 2drop ] [ \ ##copy new-insn nip ] if ;
: rewrite-loop ( insn -- insn' )
dup rewrite [ rewrite-loop ] [ ] ?if ;
M: ##flushable process-instruction
dup rewrite
[ process-instruction ]
- [ dup number-values [ >copy ] when ] ?if ;
+ [ dup number-values >copy ] ?if ;
M: insn process-instruction
dup rewrite
USING: compiler.cfg.write-barrier compiler.cfg.instructions
compiler.cfg.registers compiler.cfg.debugger cpu.architecture
-arrays tools.test vectors compiler.cfg kernel accessors ;
+arrays tools.test vectors compiler.cfg kernel accessors
+compiler.cfg.utilities ;
IN: compiler.cfg.write-barrier.tests
: test-write-barrier ( insns -- insns )
- write-barriers-step ;
+ <simple-block> dup write-barriers-step instructions>> ;
[
- {
+ V{
T{ ##peek f V int-regs 4 D 0 f }
- T{ ##copy f V int-regs 6 V int-regs 4 f }
T{ ##allot f V int-regs 7 24 array V int-regs 8 f }
T{ ##load-immediate f V int-regs 9 8 f }
T{ ##set-slot-imm f V int-regs 9 V int-regs 7 1 3 f }
- T{ ##set-slot-imm f V int-regs 6 V int-regs 7 2 3 f }
+ T{ ##set-slot-imm f V int-regs 4 V int-regs 7 2 3 f }
T{ ##replace f V int-regs 7 D 0 f }
+ T{ ##branch }
}
] [
{
T{ ##peek f V int-regs 4 D 0 }
- T{ ##copy f V int-regs 6 V int-regs 4 }
T{ ##allot f V int-regs 7 24 array V int-regs 8 }
T{ ##load-immediate f V int-regs 9 8 }
T{ ##set-slot-imm f V int-regs 9 V int-regs 7 1 3 }
T{ ##write-barrier f V int-regs 7 V int-regs 10 V int-regs 11 }
- T{ ##set-slot-imm f V int-regs 6 V int-regs 7 2 3 }
+ T{ ##set-slot-imm f V int-regs 4 V int-regs 7 2 3 }
T{ ##write-barrier f V int-regs 7 V int-regs 12 V int-regs 13 }
T{ ##replace f V int-regs 7 D 0 }
} test-write-barrier
] unit-test
[
- {
+ V{
T{ ##load-immediate f V int-regs 4 24 }
T{ ##peek f V int-regs 5 D -1 }
T{ ##peek f V int-regs 6 D -2 }
T{ ##set-slot-imm f V int-regs 5 V int-regs 6 3 2 }
T{ ##write-barrier f V int-regs 6 V int-regs 7 V int-regs 8 }
+ T{ ##branch }
}
] [
{
] unit-test
[
- {
+ V{
T{ ##peek f V int-regs 19 D -3 }
T{ ##peek f V int-regs 22 D -2 }
- T{ ##copy f V int-regs 23 V int-regs 19 }
- T{ ##set-slot-imm f V int-regs 22 V int-regs 23 3 2 }
- T{ ##write-barrier f V int-regs 23 V int-regs 24 V int-regs 25 }
- T{ ##copy f V int-regs 26 V int-regs 19 }
+ T{ ##set-slot-imm f V int-regs 22 V int-regs 19 3 2 }
+ T{ ##write-barrier f V int-regs 19 V int-regs 24 V int-regs 25 }
T{ ##peek f V int-regs 28 D -1 }
- T{ ##copy f V int-regs 29 V int-regs 19 }
- T{ ##set-slot-imm f V int-regs 28 V int-regs 29 4 2 }
+ T{ ##set-slot-imm f V int-regs 28 V int-regs 19 4 2 }
+ T{ ##branch }
}
] [
{
T{ ##peek f V int-regs 19 D -3 }
T{ ##peek f V int-regs 22 D -2 }
- T{ ##copy f V int-regs 23 V int-regs 19 }
- T{ ##set-slot-imm f V int-regs 22 V int-regs 23 3 2 }
- T{ ##write-barrier f V int-regs 23 V int-regs 24 V int-regs 25 }
- T{ ##copy f V int-regs 26 V int-regs 19 }
+ T{ ##set-slot-imm f V int-regs 22 V int-regs 19 3 2 }
+ T{ ##write-barrier f V int-regs 19 V int-regs 24 V int-regs 25 }
T{ ##peek f V int-regs 28 D -1 }
- T{ ##copy f V int-regs 29 V int-regs 19 }
- T{ ##set-slot-imm f V int-regs 28 V int-regs 29 4 2 }
- T{ ##write-barrier f V int-regs 29 V int-regs 30 V int-regs 3 }
+ T{ ##set-slot-imm f V int-regs 28 V int-regs 19 4 2 }
+ T{ ##write-barrier f V int-regs 19 V int-regs 30 V int-regs 3 }
} test-write-barrier
] unit-test