Add an index_type field to Table.

This parallels the `index_type` field in `Heap`.
This commit is contained in:
Dan Gohman
2018-08-28 13:57:34 -07:00
parent 0d24641f21
commit 8e2d01a675
9 changed files with 192 additions and 5 deletions

View File

@@ -8,7 +8,7 @@ target x86_64
function %test0(i64 vmctx, i64) -> i64 {
gv0 = vmctx+12
gv1 = vmctx+14
table0 = dynamic gv0, min 20, bound gv1, element_size 4
table0 = dynamic gv0, min 20, bound gv1, element_size 4, index_type i64
ebb0(v0: i64, v1: i64):
v2 = table_addr.i64 table0, v1, +3

View File

@@ -0,0 +1,68 @@
test legalizer
target x86_64
; Test legalization for various forms of table addresses.
function %table_addrs(i32, i64, i64 vmctx) {
gv0 = vmctx+72
gv1 = vmctx+80
gv2 = vmctx+88
gv3 = deref(gv2): i32
table0 = dynamic gv0, min 0x1_0000, bound gv3, element_size 1, index_type i32
table1 = dynamic gv0, bound gv3, element_size 16, index_type i32
table2 = dynamic gv0, min 0x1_0000, bound gv1, element_size 1, index_type i64
table3 = dynamic gv0, bound gv1, element_size 16, index_type i64
; check: table0 = dynamic gv0, min 0x0001_0000, bound gv3, element_size 1, index_type i32
; check: table1 = dynamic gv0, min 0, bound gv3, element_size 16, index_type i32
; check: table2 = dynamic gv0, min 0x0001_0000, bound gv1, element_size 1, index_type i64
; check: table3 = dynamic gv0, min 0, bound gv1, element_size 16, index_type i64
ebb0(v0: i32, v1: i64, v3: i64):
v4 = table_addr.i64 table0, v0, +0
; check: v12 = iadd_imm v3, 88
; check: v13 = load.i32 notrap aligned v12
; check: v8 = iadd_imm v13, 0
; check: v9 = icmp uge v0, v8
; check: brz v9, ebb1
; check: trap table_oob
; check: ebb1:
; check: v10 = uextend.i64 v0
; check: v11 = iadd_imm.i64 v3, 72
; check: v4 = iadd v11, v10
v5 = table_addr.i64 table1, v0, +0
; check: v19 = iadd_imm.i64 v3, 88
; check: v20 = load.i32 notrap aligned v19
; check: v14 = iadd_imm v20, 0
; check: v15 = icmp.i32 uge v0, v14
; check: brz v15, ebb2
; check: trap table_oob
; check: ebb2:
; check: v16 = uextend.i64 v0
; check: v17 = iadd_imm.i64 v3, 72
; check: v18 = ishl_imm v16, 4
; check: v5 = iadd v17, v18
v6 = table_addr.i64 table2, v1, +0
; check: v21 = iadd_imm.i64 v3, 80
; check: v22 = icmp.i64 uge v1, v21
; check: brz v22, ebb3
; check: trap table_oob
; check: ebb3:
; check: v23 = iadd_imm.i64 v3, 72
; check: v6 = iadd v23, v1
v7 = table_addr.i64 table3, v1, +0
; check: v24 = iadd_imm.i64 v3, 80
; check: v25 = icmp.i64 uge v1, v24
; check: brz v25, ebb4
; check: trap table_oob
; check: ebb4:
; check: v26 = iadd_imm.i64 v3, 72
; check: v27 = ishl_imm.i64 v1, 4
; check: v7 = iadd v26, v27
return
}

View File

@@ -0,0 +1,46 @@
test verifier
target x86_64
function %table_base_type(i64 vmctx) {
gv0 = vmctx+0
gv1 = deref(gv0): i32
table0 = dynamic gv1, element_size 1, bound gv1, index_type i32 ; error: table base has type i32, which is not the pointer type i64
ebb0(v0: i64):
return
}
function %invalid_base(i64 vmctx) {
gv0 = vmctx+0
table0 = dynamic gv1, bound gv0, element_size 1, index_type i64 ; error: invalid base global value gv1
ebb0(v0: i64):
return
}
function %invalid_bound(i64 vmctx) {
gv0 = vmctx+0
table0 = dynamic gv0, bound gv1, element_size 1, index_type i64 ; error: invalid bound global value gv1
ebb0(v0: i64):
return
}
function %table_bound_type(i64 vmctx) {
gv0 = vmctx+0
gv1 = deref(gv0): i16
table0 = dynamic gv0, bound gv1, element_size 1, index_type i32 ; error: table index type i32 differs from the type of its bound, i16
ebb0(v0: i64):
return
}
function %table_addr_index_type(i64 vmctx, i64) {
gv0 = vmctx+0
gv1 = deref(gv0): i32
table0 = dynamic gv0, element_size 1, bound gv1, index_type i32
ebb0(v0: i64, v1: i64):
v2 = table_addr.i64 table0, v1, +0; error: index type i64 differs from table index type i32
return
}