blob: f7180a04d42e060c0a7d143a3381613ff1cf36e0 [file] [log] [blame]
JF Bastien5ca0bac2015-07-10 18:23:10 +00001// WebAssemblyInstrMemory.td-WebAssembly Memory codegen support -*- tablegen -*-
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief WebAssembly Memory operand code-gen constructs.
12///
13//===----------------------------------------------------------------------===//
14
JF Bastien73ff6af2015-08-31 22:24:11 +000015// FIXME:
16// - HasAddr64
17// - WebAssemblyTargetLowering::isLegalAddressingMode
18// - WebAssemblyTargetLowering having to do with atomics
19// - Each has optional alignment and immediate byte offset.
20
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.
24
25// Basic load.
JF Bastien6126d2b2015-10-16 18:24:42 +000026def LOAD_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000027 [(set I32:$dst, (load I32:$addr))],
28 "i32.load $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000029def LOAD_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000030 [(set I64:$dst, (load I32:$addr))],
31 "i64.load $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000032def LOAD_F32 : I<(outs F32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000033 [(set F32:$dst, (load I32:$addr))],
34 "f32.load $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000035def LOAD_F64 : I<(outs F64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000036 [(set F64:$dst, (load I32:$addr))],
37 "f64.load $dst, $addr">;
JF Bastien73ff6af2015-08-31 22:24:11 +000038
39// Extending load.
JF Bastien6126d2b2015-10-16 18:24:42 +000040def LOAD8_S_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000041 [(set I32:$dst, (sextloadi8 I32:$addr))],
42 "i32.load8_s $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000043def LOAD8_U_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000044 [(set I32:$dst, (zextloadi8 I32:$addr))],
45 "i32.load8_u $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000046def LOAD16_S_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000047 [(set I32:$dst, (sextloadi16 I32:$addr))],
48 "i32.load16_s $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000049def LOAD16_U_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000050 [(set I32:$dst, (zextloadi16 I32:$addr))],
51 "i32.load16_u $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000052def LOAD8_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000053 [(set I64:$dst, (sextloadi8 I32:$addr))],
54 "i64.load8_s $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000055def LOAD8_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000056 [(set I64:$dst, (zextloadi8 I32:$addr))],
57 "i64.load8_u $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000058def LOAD16_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000059 [(set I64:$dst, (sextloadi16 I32:$addr))],
60 "i64.load16_s $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000061def LOAD16_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000062 [(set I64:$dst, (zextloadi16 I32:$addr))],
63 "i64.load16_u $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000064def LOAD32_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000065 [(set I64:$dst, (sextloadi32 I32:$addr))],
66 "i64.load32_s $dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000067def LOAD32_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000068 [(set I64:$dst, (zextloadi32 I32:$addr))],
69 "i64.load32_u $dst, $addr">;
JF Bastien73ff6af2015-08-31 22:24:11 +000070
71// "Don't care" extending load become zero-extending load.
JF Bastien6126d2b2015-10-16 18:24:42 +000072def : Pat<(i32 (extloadi8 I32:$addr)), (LOAD8_U_I32 $addr)>;
73def : Pat<(i32 (extloadi16 I32:$addr)), (LOAD16_U_I32 $addr)>;
74def : Pat<(i64 (extloadi8 I32:$addr)), (LOAD8_U_I64 $addr)>;
75def : Pat<(i64 (extloadi16 I32:$addr)), (LOAD16_U_I64 $addr)>;
76def : Pat<(i64 (extloadi32 I32:$addr)), (LOAD32_U_I64 $addr)>;
JF Bastien73ff6af2015-08-31 22:24:11 +000077
78// Basic store.
79// Note: WebAssembly inverts SelectionDAG's usual operand order.
JF Bastien6126d2b2015-10-16 18:24:42 +000080def STORE_I32 : I<(outs), (ins I32:$addr, I32:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000081 [(store i32:$val, I32:$addr)],
82 "i32.store $addr, $val">;
JF Bastien6126d2b2015-10-16 18:24:42 +000083def STORE_I64 : I<(outs), (ins I32:$addr, I64:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000084 [(store i64:$val, I32:$addr)],
85 "i64.store $addr, $val">;
JF Bastien6126d2b2015-10-16 18:24:42 +000086def STORE_F32 : I<(outs), (ins I32:$addr, F32:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000087 [(store f32:$val, I32:$addr)],
88 "i64.store $addr, $val">;
JF Bastien6126d2b2015-10-16 18:24:42 +000089def STORE_F64 : I<(outs), (ins I32:$addr, F64:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000090 [(store f64:$val, I32:$addr)],
91 "i64.store $addr, $val">;
JF Bastien73ff6af2015-08-31 22:24:11 +000092
93// Truncating store.
JF Bastien6126d2b2015-10-16 18:24:42 +000094def STORE8_I32 : I<(outs), (ins I32:$addr, I32:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000095 [(truncstorei8 I32:$val, I32:$addr)],
96 "i32.store8 $addr, $val">;
JF Bastien6126d2b2015-10-16 18:24:42 +000097def STORE16_I32 : I<(outs), (ins I32:$addr, I32:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000098 [(truncstorei16 I32:$val, I32:$addr)],
99 "i32.store16 $addr, $val">;
JF Bastien6126d2b2015-10-16 18:24:42 +0000100def STORE8_I64 : I<(outs), (ins I32:$addr, I64:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000101 [(truncstorei8 I64:$val, I32:$addr)],
102 "i64.store8 $addr, $val">;
JF Bastien6126d2b2015-10-16 18:24:42 +0000103def STORE16_I64 : I<(outs), (ins I32:$addr, I64:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000104 [(truncstorei16 I64:$val, I32:$addr)],
105 "i64.store16 $addr, $val">;
JF Bastien6126d2b2015-10-16 18:24:42 +0000106def STORE32_I64 : I<(outs), (ins I32:$addr, I64:$val),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000107 [(truncstorei32 I64:$val, I32:$addr)],
108 "i64.store32 $addr, $val">;
JF Bastien73ff6af2015-08-31 22:24:11 +0000109
Dan Gohman72f16922015-10-02 19:21:15 +0000110// Memory size.
111def memory_size_I32 : I<(outs I32:$dst), (ins),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000112 [(set I32:$dst, (int_wasm_memory_size))],
113 "i32.memory_size $dst">,
Dan Gohman72f16922015-10-02 19:21:15 +0000114 Requires<[HasAddr32]>;
115def memory_size_I64 : I<(outs I64:$dst), (ins),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000116 [(set I64:$dst, (int_wasm_memory_size))],
117 "i64.memory_size $dst">,
Dan Gohman72f16922015-10-02 19:21:15 +0000118 Requires<[HasAddr64]>;
Dan Gohmanbaba8c62015-10-02 20:10:26 +0000119
Dan Gohmand7ffb912015-11-05 20:16:59 +0000120// Grow memory.
121def grow_memory_I32 : I<(outs), (ins I32:$delta),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000122 [(int_wasm_grow_memory I32:$delta)],
123 "i32.grow_memory $delta">,
Dan Gohmand7ffb912015-11-05 20:16:59 +0000124 Requires<[HasAddr32]>;
125def grow_memory_I64 : I<(outs), (ins I64:$delta),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000126 [(int_wasm_grow_memory I64:$delta)],
127 "i64.grow_memory $delta">,
Dan Gohmand7ffb912015-11-05 20:16:59 +0000128 Requires<[HasAddr64]>;