compiler.cfg.ssa.destruction.interference: fix a bug and add unit tests
parent
7ec288b013
commit
87e13db946
|
@ -0,0 +1,52 @@
|
||||||
|
USING: accessors compiler.cfg compiler.cfg.debugger
|
||||||
|
compiler.cfg.def-use compiler.cfg.dominance
|
||||||
|
compiler.cfg.instructions compiler.cfg.liveness.ssa
|
||||||
|
compiler.cfg.registers compiler.cfg.predecessors
|
||||||
|
compiler.cfg.ssa.destruction.interference
|
||||||
|
compiler.cfg.ssa.destruction.live-ranges cpu.architecture
|
||||||
|
kernel namespaces tools.test ;
|
||||||
|
IN: compiler.cfg.ssa.destruction.interference.tests
|
||||||
|
|
||||||
|
: test-interference ( -- )
|
||||||
|
cfg new 0 get >>entry
|
||||||
|
compute-ssa-live-sets
|
||||||
|
compute-predecessors
|
||||||
|
dup compute-def-use
|
||||||
|
dup compute-dominance
|
||||||
|
compute-live-ranges ;
|
||||||
|
|
||||||
|
V{
|
||||||
|
T{ ##peek f V int-regs 0 D 0 }
|
||||||
|
T{ ##peek f V int-regs 2 D 0 }
|
||||||
|
T{ ##copy f V int-regs 1 V int-regs 0 }
|
||||||
|
T{ ##copy f V int-regs 3 V int-regs 2 }
|
||||||
|
T{ ##branch }
|
||||||
|
} 0 test-bb
|
||||||
|
|
||||||
|
V{
|
||||||
|
T{ ##peek f V int-regs 4 D 0 }
|
||||||
|
T{ ##peek f V int-regs 5 D 0 }
|
||||||
|
T{ ##replace f V int-regs 3 D 0 }
|
||||||
|
T{ ##peek f V int-regs 6 D 0 }
|
||||||
|
T{ ##replace f V int-regs 5 D 0 }
|
||||||
|
T{ ##return }
|
||||||
|
} 1 test-bb
|
||||||
|
|
||||||
|
0 1 edge
|
||||||
|
|
||||||
|
[ ] [ test-interference ] unit-test
|
||||||
|
|
||||||
|
[ f ] [ V int-regs 0 V int-regs 1 interferes? ] unit-test
|
||||||
|
[ f ] [ V int-regs 1 V int-regs 0 interferes? ] unit-test
|
||||||
|
[ f ] [ V int-regs 2 V int-regs 3 interferes? ] unit-test
|
||||||
|
[ f ] [ V int-regs 3 V int-regs 2 interferes? ] unit-test
|
||||||
|
[ t ] [ V int-regs 0 V int-regs 2 interferes? ] unit-test
|
||||||
|
[ t ] [ V int-regs 2 V int-regs 0 interferes? ] unit-test
|
||||||
|
[ f ] [ V int-regs 1 V int-regs 3 interferes? ] unit-test
|
||||||
|
[ f ] [ V int-regs 3 V int-regs 1 interferes? ] unit-test
|
||||||
|
[ t ] [ V int-regs 3 V int-regs 4 interferes? ] unit-test
|
||||||
|
[ t ] [ V int-regs 4 V int-regs 3 interferes? ] unit-test
|
||||||
|
[ t ] [ V int-regs 3 V int-regs 5 interferes? ] unit-test
|
||||||
|
[ t ] [ V int-regs 5 V int-regs 3 interferes? ] unit-test
|
||||||
|
[ f ] [ V int-regs 3 V int-regs 6 interferes? ] unit-test
|
||||||
|
[ f ] [ V int-regs 6 V int-regs 3 interferes? ] unit-test
|
|
@ -7,19 +7,22 @@ IN: compiler.cfg.ssa.destruction.interference
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: kill-after-def? ( vreg1 vreg2 bb -- ? )
|
:: kill-after-def? ( vreg1 vreg2 bb -- ? )
|
||||||
! If first register is used after second one is defined, they interfere.
|
! If first register is used after second one is defined, they interfere.
|
||||||
! If they are used in the same instruction, no interference. If the
|
! If they are used in the same instruction, no interference. If the
|
||||||
! instruction is a def-is-use-insn, then there will be a use at +1
|
! instruction is a def-is-use-insn, then there will be a use at +1
|
||||||
! (instructions are 2 apart) and so outputs will interfere with
|
! (instructions are 2 apart) and so outputs will interfere with
|
||||||
! inputs.
|
! inputs.
|
||||||
[ kill-index ] [ def-index ] bi-curry bi* > ;
|
vreg1 bb kill-index
|
||||||
|
vreg2 bb def-index > ;
|
||||||
|
|
||||||
: interferes-same-block? ( vreg1 vreg2 bb1 bb2 -- ? )
|
:: interferes-same-block? ( vreg1 vreg2 bb1 bb2 -- ? )
|
||||||
! If both are defined in the same basic block, they interfere if their
|
! If both are defined in the same basic block, they interfere if their
|
||||||
! local live ranges intersect.
|
! local live ranges intersect.
|
||||||
drop
|
vreg1 bb1 def-index
|
||||||
{ [ kill-after-def? ] [ swapd kill-after-def? ] } 3|| ;
|
vreg2 bb1 def-index <
|
||||||
|
[ vreg1 vreg2 ] [ vreg2 vreg1 ] if
|
||||||
|
bb1 kill-after-def? ;
|
||||||
|
|
||||||
: interferes-first-dominates? ( vreg1 vreg2 bb1 bb2 -- ? )
|
: interferes-first-dominates? ( vreg1 vreg2 bb1 bb2 -- ? )
|
||||||
! If vreg1 dominates vreg2, then they interfere if vreg2's definition
|
! If vreg1 dominates vreg2, then they interfere if vreg2's definition
|
||||||
|
|
Loading…
Reference in New Issue