USING: arrays compiler.cfg.alias-analysis compiler.cfg.instructions
compiler.cfg.registers compiler.cfg.debugger compiler.cfg.comparisons
-cpu.architecture tools.test ;
+cpu.architecture tools.test byte-arrays layouts literals alien ;
IN: compiler.cfg.alias-analysis.tests
! Redundant load elimination
T{ ##compare f 2 0 1 cc= }
} alias-analysis-step
] unit-test
+
+! Make sure that input to ##box-displaced-alien becomes heap-ac
+[
+ V{
+ T{ ##allot f 1 16 byte-array }
+ T{ ##load-reference f 2 10 }
+ T{ ##box-displaced-alien f 3 2 1 4 byte-array }
+ T{ ##slot-imm f 5 3 1 $[ alien type-number ] }
+ T{ ##compare f 6 5 1 cc= }
+ }
+] [
+ V{
+ T{ ##allot f 1 16 byte-array }
+ T{ ##load-reference f 2 10 }
+ T{ ##box-displaced-alien f 3 2 1 4 byte-array }
+ T{ ##slot-imm f 5 3 1 $[ alien type-number ] }
+ T{ ##compare f 6 5 1 cc= }
+ } alias-analysis-step
+] unit-test
#! object.
dup dst>> set-new-ac ;
+M: ##box-displaced-alien analyze-aliases*
+ [ call-next-method ]
+ [ base>> heap-ac get merge-acs ] bi ;
+
M: ##read analyze-aliases*
call-next-method
dup [ dst>> ] [ insn-slot# ] [ insn-object ] tri
: new-insn ( ... class -- insn ) f swap boa ; inline
-! Virtual CPU instructions, used by CFG and machine IRs
+! Virtual CPU instructions, used by CFG IR
TUPLE: insn ;
! Instructions which are referentially transparent; used for
temp: temp/int-rep
literal: rep vcc ;
-INSN: _test-vector-branch
-literal: label
-use: src1
-temp: temp/int-rep
-literal: rep vcc ;
-
PURE-INSN: ##add-vector
def: dst
use: src1 src2
] when ;
[ ] [ 2000 [ "hello" clone dup gc-root-messup first eq? t assert= ] times ] unit-test
+
+! Alias analysis bug
+[ t ] [
+ [
+ 10 10 <byte-array> [ <displaced-alien> underlying>> ] keep eq?
+ ] compile-call
+] unit-test
2drop alien \ f class-or <class-info>
] "outputs" set-word-prop
+\ <displaced-alien> [
+ [ interval>> 0 swap interval-contains? ] dip
+ class>> alien class-or alien ? <class-info>
+] "outputs" set-word-prop
+
{ <tuple> <tuple-boa> } [
[
literal>> dup array? [ first ] [ drop tuple ] if <class-info>
! Should actually be 0 23 2^ 1 - [a,b]
[ string-nth ] final-info first interval>> 0 23 2^ [a,b] =
] unit-test
+
+! Non-zero displacement for <displaced-alien> restricts the output type
+[ t ] [
+ [ { byte-array } declare <displaced-alien> ] final-classes
+ first byte-array alien class-or class=
+] unit-test
+
+[ V{ alien } ] [
+ [ { alien } declare <displaced-alien> ] final-classes
+] unit-test
+
+[ t ] [
+ [ { POSTPONE: f } declare <displaced-alien> ] final-classes
+ first \ f alien class-or class=
+] unit-test
+
+[ V{ alien } ] [
+ [ { byte-array } declare [ 10 bitand 2 + ] dip <displaced-alien> ] final-classes
+] unit-test