1 ; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
3 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
5 @funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
7 declare void @llvm.wasm.table.set.funcref(ptr addrspace(1), i32, %funcref) nounwind
9 define void @set_funcref_table(%funcref %g, i32 %i) {
10 ; CHECK-LABEL: set_funcref_table:
11 ; CHECK-NEXT: .functype set_funcref_table (funcref, i32) -> ()
12 ; CHECK-NEXT: local.get 1
13 ; CHECK-NEXT: local.get 0
14 ; CHECK-NEXT: table.set funcref_table
15 ; CHECK-NEXT: end_function
17 ;; this generates a table.set of @funcref_table
18 call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %i, %funcref %g)
22 define void @set_funcref_table_const(%funcref %g) {
23 ; CHECK-LABEL: set_funcref_table_const:
24 ; CHECK-NEXT: .functype set_funcref_table_const (funcref) -> ()
25 ; CHECK-NEXT: i32.const 0
26 ; CHECK-NEXT: local.get 0
27 ; CHECK-NEXT: table.set funcref_table
28 ; CHECK-NEXT: end_function
29 call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 0, %funcref %g)
33 define void @set_funcref_table_with_offset(%funcref %g, i32 %i) {
34 ; CHECK-LABEL: set_funcref_table_with_offset:
35 ; CHECK-NEXT: .functype set_funcref_table_with_offset (funcref, i32) -> ()
36 ; CHECK-NEXT: local.get 1
37 ; CHECK-NEXT: i32.const 2
39 ; CHECK-NEXT: local.get 0
40 ; CHECK-NEXT: table.set funcref_table
41 ; CHECK-NEXT: end_function
42 %off = add nsw i32 %i, 2
43 call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
47 define void @set_funcref_table_with_var_offset(%funcref %g, i32 %i, i32 %j) {
48 ; CHECK-LABEL: set_funcref_table_with_var_offset:
49 ; CHECK-NEXT: .functype set_funcref_table_with_var_offset (funcref, 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 funcref_table
55 ; CHECK-NEXT: end_function
56 %off = add nsw i32 %i, %j
57 call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
61 declare i32 @set_offset()
63 define void @set_funcref_table_with_var_offset2(%funcref %g, i32 %i) {
64 ; CHECK-LABEL: set_funcref_table_with_var_offset2:
65 ; CHECK-NEXT: .functype set_funcref_table_with_var_offset2 (funcref, i32) -> ()
66 ; CHECK-NEXT: local.get 1
67 ; CHECK-NEXT: call set_offset
69 ; CHECK-NEXT: local.get 0
70 ; CHECK-NEXT: table.set funcref_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.funcref(ptr addrspace(1) @funcref_table, i32 %off, %funcref %g)
78 ; CHECK: .tabletype funcref_table, funcref
79 ; CHECK-LABEL: funcref_table: