blob: 3b6c6cb933efc729d3729c2ff89d561f11830a03 [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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000028 "i32.load\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000031 "i64.load\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000034 "f32.load\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000037 "f64.load\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000042 "i32.load8_s\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000045 "i32.load8_u\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000048 "i32.load16_s\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000051 "i32.load16_u\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000054 "i64.load8_s\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000057 "i64.load8_u\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000060 "i64.load16_s\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000063 "i64.load16_u\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000066 "i64.load32_s\t$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))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000069 "i64.load32_u\t$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.
Dan Gohman7054ac12015-11-23 21:16:35 +000079// Note that we split the patterns out of the instruction definitions because
80// WebAssembly's stores return their operand value, and tablegen doesn't like
81// instruction definition patterns that don't reference all of the output
82// operands.
JF Bastien73ff6af2015-08-31 22:24:11 +000083// Note: WebAssembly inverts SelectionDAG's usual operand order.
Dan Gohman7054ac12015-11-23 21:16:35 +000084def STORE_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
85 "i32.store\t$dst, $addr, $val">;
86def STORE_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
87 "i64.store\t$dst, $addr, $val">;
88def STORE_F32 : I<(outs F32:$dst), (ins I32:$addr, F32:$val), [],
89 "f32.store\t$dst, $addr, $val">;
90def STORE_F64 : I<(outs F64:$dst), (ins I32:$addr, F64:$val), [],
91 "f64.store\t$dst, $addr, $val">;
92
93def : Pat<(store I32:$val, I32:$addr), (STORE_I32 I32:$addr, I32:$val)>;
94def : Pat<(store I64:$val, I32:$addr), (STORE_I64 I32:$addr, I64:$val)>;
95def : Pat<(store F32:$val, I32:$addr), (STORE_F32 I32:$addr, F32:$val)>;
96def : Pat<(store F64:$val, I32:$addr), (STORE_F64 I32:$addr, F64:$val)>;
JF Bastien73ff6af2015-08-31 22:24:11 +000097
98// Truncating store.
Dan Gohman7054ac12015-11-23 21:16:35 +000099def STORE8_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
100 "i32.store8\t$dst, $addr, $val">;
101def STORE16_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
102 "i32.store16\t$dst, $addr, $val">;
103def STORE8_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
104 "i64.store8\t$dst, $addr, $val">;
105def STORE16_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
106 "i64.store16\t$dst, $addr, $val">;
107def STORE32_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
108 "i64.store32\t$dst, $addr, $val">;
109
110def : Pat<(truncstorei8 I32:$val, I32:$addr),
111 (STORE8_I32 I32:$addr, I32:$val)>;
112def : Pat<(truncstorei16 I32:$val, I32:$addr),
113 (STORE16_I32 I32:$addr, I32:$val)>;
114def : Pat<(truncstorei8 I64:$val, I32:$addr),
115 (STORE8_I64 I32:$addr, I64:$val)>;
116def : Pat<(truncstorei16 I64:$val, I32:$addr),
117 (STORE16_I64 I32:$addr, I64:$val)>;
118def : Pat<(truncstorei32 I64:$val, I32:$addr),
119 (STORE32_I64 I32:$addr, I64:$val)>;
JF Bastien73ff6af2015-08-31 22:24:11 +0000120
Dan Gohman72f16922015-10-02 19:21:15 +0000121// Memory size.
Dan Gohmanf4333242015-11-13 20:19:11 +0000122def MEMORY_SIZE_I32 : I<(outs I32:$dst), (ins),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000123 [(set I32:$dst, (int_wasm_memory_size))],
Dan Gohman192dddc2015-11-23 22:37:29 +0000124 "memory_size\t$dst">,
Dan Gohman72f16922015-10-02 19:21:15 +0000125 Requires<[HasAddr32]>;
Dan Gohmanf4333242015-11-13 20:19:11 +0000126def MEMORY_SIZE_I64 : I<(outs I64:$dst), (ins),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000127 [(set I64:$dst, (int_wasm_memory_size))],
Dan Gohman192dddc2015-11-23 22:37:29 +0000128 "memory_size\t$dst">,
Dan Gohman72f16922015-10-02 19:21:15 +0000129 Requires<[HasAddr64]>;
Dan Gohmanbaba8c62015-10-02 20:10:26 +0000130
Dan Gohmand7ffb912015-11-05 20:16:59 +0000131// Grow memory.
Dan Gohmanf4333242015-11-13 20:19:11 +0000132def GROW_MEMORY_I32 : I<(outs), (ins I32:$delta),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000133 [(int_wasm_grow_memory I32:$delta)],
Dan Gohman192dddc2015-11-23 22:37:29 +0000134 "grow_memory\t$delta">,
Dan Gohmand7ffb912015-11-05 20:16:59 +0000135 Requires<[HasAddr32]>;
Dan Gohmanf4333242015-11-13 20:19:11 +0000136def GROW_MEMORY_I64 : I<(outs), (ins I64:$delta),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000137 [(int_wasm_grow_memory I64:$delta)],
Dan Gohman192dddc2015-11-23 22:37:29 +0000138 "grow_memory\t$delta">,
Dan Gohmand7ffb912015-11-05 20:16:59 +0000139 Requires<[HasAddr64]>;