blob: 700a196fa29c94bb7b069ae1d3fe68625b248f47 [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
Dan Gohman9c54d3b2015-11-25 18:13:18 +000015// TODO:
JF Bastien73ff6af2015-08-31 22:24:11 +000016// - 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
Dan Gohmanfb3e0592015-11-25 19:36:19 +000025let Defs = [ARGUMENTS] in {
26
JF Bastien73ff6af2015-08-31 22:24:11 +000027// Basic load.
JF Bastien6126d2b2015-10-16 18:24:42 +000028def LOAD_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000029 [(set I32:$dst, (load I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000030 "i32.load\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000031def LOAD_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000032 [(set I64:$dst, (load I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000033 "i64.load\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000034def LOAD_F32 : I<(outs F32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000035 [(set F32:$dst, (load I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000036 "f32.load\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000037def LOAD_F64 : I<(outs F64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000038 [(set F64:$dst, (load I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000039 "f64.load\t$dst, $addr">;
JF Bastien73ff6af2015-08-31 22:24:11 +000040
41// Extending load.
JF Bastien6126d2b2015-10-16 18:24:42 +000042def LOAD8_S_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000043 [(set I32:$dst, (sextloadi8 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000044 "i32.load8_s\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000045def LOAD8_U_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000046 [(set I32:$dst, (zextloadi8 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000047 "i32.load8_u\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000048def LOAD16_S_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000049 [(set I32:$dst, (sextloadi16 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000050 "i32.load16_s\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000051def LOAD16_U_I32 : I<(outs I32:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000052 [(set I32:$dst, (zextloadi16 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000053 "i32.load16_u\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000054def LOAD8_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000055 [(set I64:$dst, (sextloadi8 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000056 "i64.load8_s\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000057def LOAD8_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000058 [(set I64:$dst, (zextloadi8 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000059 "i64.load8_u\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000060def LOAD16_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000061 [(set I64:$dst, (sextloadi16 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000062 "i64.load16_s\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000063def LOAD16_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000064 [(set I64:$dst, (zextloadi16 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000065 "i64.load16_u\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000066def LOAD32_S_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000067 [(set I64:$dst, (sextloadi32 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000068 "i64.load32_s\t$dst, $addr">;
JF Bastien6126d2b2015-10-16 18:24:42 +000069def LOAD32_U_I64 : I<(outs I64:$dst), (ins I32:$addr),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000070 [(set I64:$dst, (zextloadi32 I32:$addr))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000071 "i64.load32_u\t$dst, $addr">;
JF Bastien73ff6af2015-08-31 22:24:11 +000072
Dan Gohmanfb3e0592015-11-25 19:36:19 +000073} // Defs = [ARGUMENTS]
74
JF Bastien73ff6af2015-08-31 22:24:11 +000075// "Don't care" extending load become zero-extending load.
JF Bastien6126d2b2015-10-16 18:24:42 +000076def : Pat<(i32 (extloadi8 I32:$addr)), (LOAD8_U_I32 $addr)>;
77def : Pat<(i32 (extloadi16 I32:$addr)), (LOAD16_U_I32 $addr)>;
78def : Pat<(i64 (extloadi8 I32:$addr)), (LOAD8_U_I64 $addr)>;
79def : Pat<(i64 (extloadi16 I32:$addr)), (LOAD16_U_I64 $addr)>;
80def : Pat<(i64 (extloadi32 I32:$addr)), (LOAD32_U_I64 $addr)>;
JF Bastien73ff6af2015-08-31 22:24:11 +000081
Dan Gohmanfb3e0592015-11-25 19:36:19 +000082let Defs = [ARGUMENTS] in {
83
JF Bastien73ff6af2015-08-31 22:24:11 +000084// Basic store.
Dan Gohman7054ac12015-11-23 21:16:35 +000085// Note that we split the patterns out of the instruction definitions because
86// WebAssembly's stores return their operand value, and tablegen doesn't like
87// instruction definition patterns that don't reference all of the output
88// operands.
JF Bastien73ff6af2015-08-31 22:24:11 +000089// Note: WebAssembly inverts SelectionDAG's usual operand order.
Dan Gohman7054ac12015-11-23 21:16:35 +000090def STORE_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
91 "i32.store\t$dst, $addr, $val">;
92def STORE_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
93 "i64.store\t$dst, $addr, $val">;
94def STORE_F32 : I<(outs F32:$dst), (ins I32:$addr, F32:$val), [],
95 "f32.store\t$dst, $addr, $val">;
96def STORE_F64 : I<(outs F64:$dst), (ins I32:$addr, F64:$val), [],
97 "f64.store\t$dst, $addr, $val">;
98
Dan Gohmanfb3e0592015-11-25 19:36:19 +000099} // Defs = [ARGUMENTS]
100
Dan Gohman7054ac12015-11-23 21:16:35 +0000101def : Pat<(store I32:$val, I32:$addr), (STORE_I32 I32:$addr, I32:$val)>;
102def : Pat<(store I64:$val, I32:$addr), (STORE_I64 I32:$addr, I64:$val)>;
103def : Pat<(store F32:$val, I32:$addr), (STORE_F32 I32:$addr, F32:$val)>;
104def : Pat<(store F64:$val, I32:$addr), (STORE_F64 I32:$addr, F64:$val)>;
JF Bastien73ff6af2015-08-31 22:24:11 +0000105
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000106let Defs = [ARGUMENTS] in {
107
JF Bastien73ff6af2015-08-31 22:24:11 +0000108// Truncating store.
Dan Gohman7054ac12015-11-23 21:16:35 +0000109def STORE8_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
110 "i32.store8\t$dst, $addr, $val">;
111def STORE16_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
112 "i32.store16\t$dst, $addr, $val">;
113def STORE8_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
114 "i64.store8\t$dst, $addr, $val">;
115def STORE16_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
116 "i64.store16\t$dst, $addr, $val">;
117def STORE32_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
118 "i64.store32\t$dst, $addr, $val">;
119
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000120} // Defs = [ARGUMENTS]
121
Dan Gohman7054ac12015-11-23 21:16:35 +0000122def : Pat<(truncstorei8 I32:$val, I32:$addr),
123 (STORE8_I32 I32:$addr, I32:$val)>;
124def : Pat<(truncstorei16 I32:$val, I32:$addr),
125 (STORE16_I32 I32:$addr, I32:$val)>;
126def : Pat<(truncstorei8 I64:$val, I32:$addr),
127 (STORE8_I64 I32:$addr, I64:$val)>;
128def : Pat<(truncstorei16 I64:$val, I32:$addr),
129 (STORE16_I64 I32:$addr, I64:$val)>;
130def : Pat<(truncstorei32 I64:$val, I32:$addr),
131 (STORE32_I64 I32:$addr, I64:$val)>;
JF Bastien73ff6af2015-08-31 22:24:11 +0000132
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000133let Defs = [ARGUMENTS] in {
134
Dan Gohman72f16922015-10-02 19:21:15 +0000135// Memory size.
Dan Gohmanf4333242015-11-13 20:19:11 +0000136def MEMORY_SIZE_I32 : I<(outs I32:$dst), (ins),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000137 [(set I32:$dst, (int_wasm_memory_size))],
Dan Gohman192dddc2015-11-23 22:37:29 +0000138 "memory_size\t$dst">,
Dan Gohman72f16922015-10-02 19:21:15 +0000139 Requires<[HasAddr32]>;
Dan Gohmanf4333242015-11-13 20:19:11 +0000140def MEMORY_SIZE_I64 : I<(outs I64:$dst), (ins),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000141 [(set I64:$dst, (int_wasm_memory_size))],
Dan Gohman192dddc2015-11-23 22:37:29 +0000142 "memory_size\t$dst">,
Dan Gohman72f16922015-10-02 19:21:15 +0000143 Requires<[HasAddr64]>;
Dan Gohmanbaba8c62015-10-02 20:10:26 +0000144
Dan Gohmand7ffb912015-11-05 20:16:59 +0000145// Grow memory.
Dan Gohmanf4333242015-11-13 20:19:11 +0000146def GROW_MEMORY_I32 : I<(outs), (ins I32:$delta),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000147 [(int_wasm_grow_memory I32:$delta)],
Dan Gohman192dddc2015-11-23 22:37:29 +0000148 "grow_memory\t$delta">,
Dan Gohmand7ffb912015-11-05 20:16:59 +0000149 Requires<[HasAddr32]>;
Dan Gohmanf4333242015-11-13 20:19:11 +0000150def GROW_MEMORY_I64 : I<(outs), (ins I64:$delta),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000151 [(int_wasm_grow_memory I64:$delta)],
Dan Gohman192dddc2015-11-23 22:37:29 +0000152 "grow_memory\t$delta">,
Dan Gohmand7ffb912015-11-05 20:16:59 +0000153 Requires<[HasAddr64]>;
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000154
155} // Defs = [ARGUMENTS]