1 // WebAssemblyInstrMemory.td-WebAssembly Memory codegen support -*- tablegen -*-
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief WebAssembly Memory operand code-gen constructs.
13 //===----------------------------------------------------------------------===//
17 // - WebAssemblyTargetLowering::isLegalAddressingMode
18 // - WebAssemblyTargetLowering having to do with atomics
19 // - Each has optional alignment and immediate byte offset.
21 // WebAssembly has i8/i16/i32/i64/f32/f64 memory types, but doesn't have i8/i16
22 // local types. These memory-only types instead zero- or sign-extend into local
23 // types when loading, and truncate when storing.
26 def LOAD_I32 : I<(outs I32:$dst), (ins I32:$addr),
27 [(set I32:$dst, (load I32:$addr))],
28 "i32.load $dst, $addr">;
29 def LOAD_I64 : I<(outs I64:$dst), (ins I32:$addr),
30 [(set I64:$dst, (load I32:$addr))],
31 "i64.load $dst, $addr">;
32 def LOAD_F32 : I<(outs F32:$dst), (ins I32:$addr),
33 [(set F32:$dst, (load I32:$addr))],
34 "f32.load $dst, $addr">;
35 def LOAD_F64 : I<(outs F64:$dst), (ins I32:$addr),
36 [(set F64:$dst, (load I32:$addr))],
37 "f64.load $dst, $addr">;
40 def LOAD8_S_I32 : I<(outs I32:$dst), (ins I32:$addr),
41 [(set I32:$dst, (sextloadi8 I32:$addr))],
42 "i32.load8_s $dst, $addr">;
43 def LOAD8_U_I32 : I<(outs I32:$dst), (ins I32:$addr),
44 [(set I32:$dst, (zextloadi8 I32:$addr))],
45 "i32.load8_u $dst, $addr">;
46 def LOAD16_S_I32 : I<(outs I32:$dst), (ins I32:$addr),
47 [(set I32:$dst, (sextloadi16 I32:$addr))],
48 "i32.load16_s $dst, $addr">;
49 def LOAD16_U_I32 : I<(outs I32:$dst), (ins I32:$addr),
50 [(set I32:$dst, (zextloadi16 I32:$addr))],
51 "i32.load16_u $dst, $addr">;
52 def LOAD8_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
53 [(set I64:$dst, (sextloadi8 I32:$addr))],
54 "i64.load8_s $dst, $addr">;
55 def LOAD8_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
56 [(set I64:$dst, (zextloadi8 I32:$addr))],
57 "i64.load8_u $dst, $addr">;
58 def LOAD16_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
59 [(set I64:$dst, (sextloadi16 I32:$addr))],
60 "i64.load16_s $dst, $addr">;
61 def LOAD16_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
62 [(set I64:$dst, (zextloadi16 I32:$addr))],
63 "i64.load16_u $dst, $addr">;
64 def LOAD32_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
65 [(set I64:$dst, (sextloadi32 I32:$addr))],
66 "i64.load32_s $dst, $addr">;
67 def LOAD32_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
68 [(set I64:$dst, (zextloadi32 I32:$addr))],
69 "i64.load32_u $dst, $addr">;
71 // "Don't care" extending load become zero-extending load.
72 def : Pat<(i32 (extloadi8 I32:$addr)), (LOAD8_U_I32 $addr)>;
73 def : Pat<(i32 (extloadi16 I32:$addr)), (LOAD16_U_I32 $addr)>;
74 def : Pat<(i64 (extloadi8 I32:$addr)), (LOAD8_U_I64 $addr)>;
75 def : Pat<(i64 (extloadi16 I32:$addr)), (LOAD16_U_I64 $addr)>;
76 def : Pat<(i64 (extloadi32 I32:$addr)), (LOAD32_U_I64 $addr)>;
79 // Note: WebAssembly inverts SelectionDAG's usual operand order.
80 def STORE_I32 : I<(outs), (ins I32:$addr, I32:$val),
81 [(store i32:$val, I32:$addr)],
82 "i32.store $addr, $val">;
83 def STORE_I64 : I<(outs), (ins I32:$addr, I64:$val),
84 [(store i64:$val, I32:$addr)],
85 "i64.store $addr, $val">;
86 def STORE_F32 : I<(outs), (ins I32:$addr, F32:$val),
87 [(store f32:$val, I32:$addr)],
88 "f32.store $addr, $val">;
89 def STORE_F64 : I<(outs), (ins I32:$addr, F64:$val),
90 [(store f64:$val, I32:$addr)],
91 "f64.store $addr, $val">;
94 def STORE8_I32 : I<(outs), (ins I32:$addr, I32:$val),
95 [(truncstorei8 I32:$val, I32:$addr)],
96 "i32.store8 $addr, $val">;
97 def STORE16_I32 : I<(outs), (ins I32:$addr, I32:$val),
98 [(truncstorei16 I32:$val, I32:$addr)],
99 "i32.store16 $addr, $val">;
100 def STORE8_I64 : I<(outs), (ins I32:$addr, I64:$val),
101 [(truncstorei8 I64:$val, I32:$addr)],
102 "i64.store8 $addr, $val">;
103 def STORE16_I64 : I<(outs), (ins I32:$addr, I64:$val),
104 [(truncstorei16 I64:$val, I32:$addr)],
105 "i64.store16 $addr, $val">;
106 def STORE32_I64 : I<(outs), (ins I32:$addr, I64:$val),
107 [(truncstorei32 I64:$val, I32:$addr)],
108 "i64.store32 $addr, $val">;
111 def memory_size_I32 : I<(outs I32:$dst), (ins),
112 [(set I32:$dst, (int_wasm_memory_size))],
113 "i32.memory_size $dst">,
114 Requires<[HasAddr32]>;
115 def memory_size_I64 : I<(outs I64:$dst), (ins),
116 [(set I64:$dst, (int_wasm_memory_size))],
117 "i64.memory_size $dst">,
118 Requires<[HasAddr64]>;
121 def grow_memory_I32 : I<(outs), (ins I32:$delta),
122 [(int_wasm_grow_memory I32:$delta)],
123 "i32.grow_memory $delta">,
124 Requires<[HasAddr32]>;
125 def grow_memory_I64 : I<(outs), (ins I64:$delta),
126 [(int_wasm_grow_memory I64:$delta)],
127 "i64.grow_memory $delta">,
128 Requires<[HasAddr64]>;