1 ; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
3 %externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
5 @externref_table = local_unnamed_addr addrspace(1) global [0 x %externref] undef
7 declare void @llvm.wasm.table.set.externref(ptr addrspace(1), i32, %externref) nounwind
9 define void @set_externref_table(%externref %g, i32 %i) {
10 ; CHECK-LABEL: set_externref_table:
11 ; CHECK-NEXT: .functype set_externref_table (externref, i32) -> ()
12 ; CHECK-NEXT: local.get 1
13 ; CHECK-NEXT: local.get 0
14 ; CHECK-NEXT: table.set externref_table
15 ; CHECK-NEXT: end_function
17 ;; this generates a table.set of @externref_table
18 call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %i, %externref %g)
22 define void @set_externref_table_const(%externref %g) {
23 ; CHECK-LABEL: set_externref_table_const:
24 ; CHECK-NEXT: .functype set_externref_table_const (externref) -> ()
25 ; CHECK-NEXT: i32.const 0
26 ; CHECK-NEXT: local.get 0
27 ; CHECK-NEXT: table.set externref_table
28 ; CHECK-NEXT: end_function
29 call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 0, %externref %g)
33 define void @set_externref_table_with_offset(%externref %g, i32 %i) {
34 ; CHECK-LABEL: set_externref_table_with_offset:
35 ; CHECK-NEXT: .functype set_externref_table_with_offset (externref, i32) -> ()
36 ; CHECK-NEXT: local.get 1
37 ; CHECK-NEXT: i32.const 2
39 ; CHECK-NEXT: local.get 0
40 ; CHECK-NEXT: table.set externref_table
41 ; CHECK-NEXT: end_function
42 %off = add nsw i32 %i, 2
43 call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
47 define void @set_externref_table_with_var_offset(%externref %g, i32 %i, i32 %j) {
48 ; CHECK-LABEL: set_externref_table_with_var_offset:
49 ; CHECK-NEXT: .functype set_externref_table_with_var_offset (externref, i32, i32) -> ()
50 ; CHECK-NEXT: local.get 1
51 ; CHECK-NEXT: local.get 2
53 ; CHECK-NEXT: local.get 0
54 ; CHECK-NEXT: table.set externref_table
55 ; CHECK-NEXT: end_function
56 %off = add nsw i32 %i, %j
57 call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
61 declare i32 @set_offset()
63 define void @set_externref_table_with_var_offset2(%externref %g, i32 %i) {
64 ; CHECK-LABEL: set_externref_table_with_var_offset2:
65 ; CHECK-NEXT: .functype set_externref_table_with_var_offset2 (externref, i32) -> ()
66 ; CHECK-NEXT: local.get 1
67 ; CHECK-NEXT: call set_offset
69 ; CHECK-NEXT: local.get 0
70 ; CHECK-NEXT: table.set externref_table
71 ; CHECK-NEXT: end_function
72 %j = call i32 @set_offset()
73 %off = add nsw i32 %i, %j
74 call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %off, %externref %g)
78 declare i32 @get_table_slot() local_unnamed_addr
80 define void @set_externref_table_with_id_from_call(%externref %g) {
81 ; CHECK-LABEL: set_externref_table_with_id_from_call:
82 ; CHECK-NEXT: .functype set_externref_table_with_id_from_call (externref) -> ()
83 ; CHECK-NEXT: call get_table_slot
84 ; CHECK-NEXT: local.get 0
85 ; CHECK-NEXT: table.set externref_table
86 ; CHECK-NEXT: end_function
87 %id = call i32 @get_table_slot()
88 call void @llvm.wasm.table.set.externref(ptr addrspace(1) @externref_table, i32 %id, %externref %g)
92 ; CHECK: .tabletype externref_table, externref
93 ; CHECK-LABEL: externref_table: