blob: a0d526b8a2e03a2374ff1dd39b239dee414561e7 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//==- WebAssemblyMCTargetDesc.h - WebAssembly Target Descriptions -*- C++ -*-=//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Dan Gohman10e730a2015-06-29 23:51:55 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// This file provides WebAssembly-specific target descriptions.
Dan Gohman10e730a2015-06-29 23:51:55 +000011///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
15#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
16
Thomas Lively3f34e1b82019-03-29 00:14:01 +000017#include "../WebAssemblySubtarget.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000018#include "llvm/BinaryFormat/Wasm.h"
Dan Gohmana11fb232016-01-12 03:09:16 +000019#include "llvm/MC/MCInstrDesc.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000020#include "llvm/Support/DataTypes.h"
Derek Schuff669300d2017-10-10 17:31:43 +000021#include <memory>
Dan Gohman10e730a2015-06-29 23:51:55 +000022
23namespace llvm {
24
Dan Gohman10e730a2015-06-29 23:51:55 +000025class MCAsmBackend;
26class MCCodeEmitter;
27class MCContext;
28class MCInstrInfo;
Peter Collingbournedcd7d6c2018-05-21 19:20:29 +000029class MCObjectTargetWriter;
Dan Gohman10e730a2015-06-29 23:51:55 +000030class MCSubtargetInfo;
Dan Gohman3acb1872016-10-24 23:27:49 +000031class MVT;
Dan Gohman10e730a2015-06-29 23:51:55 +000032class Target;
33class Triple;
Dan Gohman53828fd2015-11-23 16:50:18 +000034class raw_pwrite_stream;
Dan Gohman10e730a2015-06-29 23:51:55 +000035
Sam Clegg9d24fb72017-06-16 23:59:10 +000036MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
Dan Gohman53828fd2015-11-23 16:50:18 +000037
Dan Gohmancceedf72016-01-08 00:43:54 +000038MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
Dan Gohman10e730a2015-06-29 23:51:55 +000039
Peter Collingbournedcd7d6c2018-05-21 19:20:29 +000040std::unique_ptr<MCObjectTargetWriter>
Peter Collingbournedcd7d6c2018-05-21 19:20:29 +000041createWebAssemblyWasmObjectWriter(bool Is64Bit);
Dan Gohman18eafb62017-02-22 01:23:18 +000042
Dan Gohmana11fb232016-01-12 03:09:16 +000043namespace WebAssembly {
44enum OperandType {
45 /// Basic block label in a branch construct.
46 OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
Dan Gohman4fc4e422016-10-24 19:49:43 +000047 /// Local index.
48 OPERAND_LOCAL,
Dan Gohmanb89f2d32017-02-02 19:29:44 +000049 /// Global index.
50 OPERAND_GLOBAL,
Dan Gohman5a68ec72016-10-05 21:24:08 +000051 /// 32-bit integer immediates.
52 OPERAND_I32IMM,
53 /// 64-bit integer immediates.
54 OPERAND_I64IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000055 /// 32-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000056 OPERAND_F32IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000057 /// 64-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000058 OPERAND_F64IMM,
Thomas Lively22442922018-08-21 21:03:18 +000059 /// 8-bit vector lane immediate
60 OPERAND_VEC_I8IMM,
61 /// 16-bit vector lane immediate
62 OPERAND_VEC_I16IMM,
63 /// 32-bit vector lane immediate
64 OPERAND_VEC_I32IMM,
65 /// 64-bit vector lane immediate
66 OPERAND_VEC_I64IMM,
Dan Gohman00d734d2016-12-23 03:23:52 +000067 /// 32-bit unsigned function indices.
68 OPERAND_FUNCTION32,
69 /// 32-bit unsigned memory offsets.
70 OPERAND_OFFSET32,
Dan Gohmanbb372242016-01-26 03:39:31 +000071 /// p2align immediate for load and store address alignment.
Dan Gohman2726b882016-10-06 22:29:32 +000072 OPERAND_P2ALIGN,
73 /// signature immediate for block/loop.
Dan Gohmand934cb82017-02-24 23:18:00 +000074 OPERAND_SIGNATURE,
75 /// type signature immediate for call_indirect.
76 OPERAND_TYPEINDEX,
Heejin Ahnda419bd2018-11-14 02:46:21 +000077 /// Event index.
78 OPERAND_EVENT,
Wouter van Oortmerssen820c6262019-01-03 23:01:30 +000079 /// A list of branch targets for br_list.
80 OPERAND_BRLIST,
Dan Gohmana11fb232016-01-12 03:09:16 +000081};
82} // end namespace WebAssembly
83
84namespace WebAssemblyII {
Nicholas Wilsone408a892018-08-03 14:33:37 +000085
86/// Target Operand Flag enum.
87enum TOF {
88 MO_NO_FLAG = 0,
89
Sam Clegg2a7cac92019-04-04 17:43:50 +000090 // On a symbol operand this indicates that the immediate is a wasm global
91 // index. The value of the wasm global will be set to the symbol address at
92 // runtime. This adds a level of indirection similar to the GOT on native
93 // platforms.
Sam Cleggef4c66c2019-04-03 00:17:29 +000094 MO_GOT,
Sam Clegg2a7cac92019-04-04 17:43:50 +000095
96 // On a symbol operand this indicates that the immediate is the symbol
97 // address relative the __memory_base wasm global.
98 // Only applicable to data symbols.
99 MO_MEMORY_BASE_REL,
100
101 // On a symbol operand this indicates that the immediate is the symbol
102 // address relative the __table_base wasm global.
103 // Only applicable to function symbols.
104 MO_TABLE_BASE_REL,
Nicholas Wilsone408a892018-08-03 14:33:37 +0000105};
Sam Clegg492f7522019-03-26 19:46:15 +0000106
Dan Gohmana11fb232016-01-12 03:09:16 +0000107} // end namespace WebAssemblyII
108
Dan Gohman10e730a2015-06-29 23:51:55 +0000109} // end namespace llvm
110
111// Defines symbolic names for WebAssembly registers. This defines a mapping from
112// register name to register number.
113//
JF Bastien5ca0bac2015-07-10 18:23:10 +0000114#define GET_REGINFO_ENUM
115#include "WebAssemblyGenRegisterInfo.inc"
116
JF Bastienb9073fb2015-07-22 21:28:15 +0000117// Defines symbolic names for the WebAssembly instructions.
118//
119#define GET_INSTRINFO_ENUM
120#include "WebAssemblyGenInstrInfo.inc"
121
Dan Gohmanbb372242016-01-26 03:39:31 +0000122namespace llvm {
123namespace WebAssembly {
124
Wouter van Oortmerssend8ddf832019-07-12 22:08:25 +0000125/// This is used to indicate block signatures.
126enum class ExprType : unsigned {
127 Void = 0x40,
128 I32 = 0x7F,
129 I64 = 0x7E,
130 F32 = 0x7D,
131 F64 = 0x7C,
132 V128 = 0x7B,
133 ExceptRef = 0x68,
134 Invalid = 0x00
135};
136
137/// Instruction opcodes emitted via means other than CodeGen.
138static const unsigned Nop = 0x01;
139static const unsigned End = 0x0b;
140
141wasm::ValType toValType(const MVT &Ty);
142
Dan Gohmanbb372242016-01-26 03:39:31 +0000143/// Return the default p2align value for a load or store with the given opcode.
Wouter van Oortmerssend8ddf832019-07-12 22:08:25 +0000144inline unsigned GetDefaultP2AlignAny(unsigned Opc) {
145 switch (Opc) {
Dan Gohmanbb372242016-01-26 03:39:31 +0000146 case WebAssembly::LOAD8_S_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000147 case WebAssembly::LOAD8_S_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000148 case WebAssembly::LOAD8_U_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000149 case WebAssembly::LOAD8_U_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000150 case WebAssembly::LOAD8_S_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000151 case WebAssembly::LOAD8_S_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000152 case WebAssembly::LOAD8_U_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000153 case WebAssembly::LOAD8_U_I64_S:
Derek Schuff885dc592017-10-05 21:18:42 +0000154 case WebAssembly::ATOMIC_LOAD8_U_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000155 case WebAssembly::ATOMIC_LOAD8_U_I32_S:
Derek Schuff885dc592017-10-05 21:18:42 +0000156 case WebAssembly::ATOMIC_LOAD8_U_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000157 case WebAssembly::ATOMIC_LOAD8_U_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000158 case WebAssembly::STORE8_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000159 case WebAssembly::STORE8_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000160 case WebAssembly::STORE8_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000161 case WebAssembly::STORE8_I64_S:
Heejin Ahn402b4902018-07-02 21:22:59 +0000162 case WebAssembly::ATOMIC_STORE8_I32:
Heejin Ahn80d9f172018-07-05 21:27:09 +0000163 case WebAssembly::ATOMIC_STORE8_I32_S:
Heejin Ahn402b4902018-07-02 21:22:59 +0000164 case WebAssembly::ATOMIC_STORE8_I64:
Heejin Ahn80d9f172018-07-05 21:27:09 +0000165 case WebAssembly::ATOMIC_STORE8_I64_S:
Heejin Ahnfed73822018-07-09 22:30:51 +0000166 case WebAssembly::ATOMIC_RMW8_U_ADD_I32:
167 case WebAssembly::ATOMIC_RMW8_U_ADD_I32_S:
168 case WebAssembly::ATOMIC_RMW8_U_ADD_I64:
169 case WebAssembly::ATOMIC_RMW8_U_ADD_I64_S:
170 case WebAssembly::ATOMIC_RMW8_U_SUB_I32:
171 case WebAssembly::ATOMIC_RMW8_U_SUB_I32_S:
172 case WebAssembly::ATOMIC_RMW8_U_SUB_I64:
173 case WebAssembly::ATOMIC_RMW8_U_SUB_I64_S:
174 case WebAssembly::ATOMIC_RMW8_U_AND_I32:
175 case WebAssembly::ATOMIC_RMW8_U_AND_I32_S:
176 case WebAssembly::ATOMIC_RMW8_U_AND_I64:
177 case WebAssembly::ATOMIC_RMW8_U_AND_I64_S:
178 case WebAssembly::ATOMIC_RMW8_U_OR_I32:
179 case WebAssembly::ATOMIC_RMW8_U_OR_I32_S:
180 case WebAssembly::ATOMIC_RMW8_U_OR_I64:
181 case WebAssembly::ATOMIC_RMW8_U_OR_I64_S:
182 case WebAssembly::ATOMIC_RMW8_U_XOR_I32:
183 case WebAssembly::ATOMIC_RMW8_U_XOR_I32_S:
184 case WebAssembly::ATOMIC_RMW8_U_XOR_I64:
185 case WebAssembly::ATOMIC_RMW8_U_XOR_I64_S:
186 case WebAssembly::ATOMIC_RMW8_U_XCHG_I32:
187 case WebAssembly::ATOMIC_RMW8_U_XCHG_I32_S:
188 case WebAssembly::ATOMIC_RMW8_U_XCHG_I64:
189 case WebAssembly::ATOMIC_RMW8_U_XCHG_I64_S:
Heejin Ahnb3724b72018-08-01 19:40:28 +0000190 case WebAssembly::ATOMIC_RMW8_U_CMPXCHG_I32:
191 case WebAssembly::ATOMIC_RMW8_U_CMPXCHG_I32_S:
192 case WebAssembly::ATOMIC_RMW8_U_CMPXCHG_I64:
193 case WebAssembly::ATOMIC_RMW8_U_CMPXCHG_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000194 return 0;
195 case WebAssembly::LOAD16_S_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000196 case WebAssembly::LOAD16_S_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000197 case WebAssembly::LOAD16_U_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000198 case WebAssembly::LOAD16_U_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000199 case WebAssembly::LOAD16_S_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000200 case WebAssembly::LOAD16_S_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000201 case WebAssembly::LOAD16_U_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000202 case WebAssembly::LOAD16_U_I64_S:
Derek Schuff885dc592017-10-05 21:18:42 +0000203 case WebAssembly::ATOMIC_LOAD16_U_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000204 case WebAssembly::ATOMIC_LOAD16_U_I32_S:
Derek Schuff885dc592017-10-05 21:18:42 +0000205 case WebAssembly::ATOMIC_LOAD16_U_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000206 case WebAssembly::ATOMIC_LOAD16_U_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000207 case WebAssembly::STORE16_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000208 case WebAssembly::STORE16_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000209 case WebAssembly::STORE16_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000210 case WebAssembly::STORE16_I64_S:
Heejin Ahn402b4902018-07-02 21:22:59 +0000211 case WebAssembly::ATOMIC_STORE16_I32:
Heejin Ahn80d9f172018-07-05 21:27:09 +0000212 case WebAssembly::ATOMIC_STORE16_I32_S:
Heejin Ahn402b4902018-07-02 21:22:59 +0000213 case WebAssembly::ATOMIC_STORE16_I64:
Heejin Ahn80d9f172018-07-05 21:27:09 +0000214 case WebAssembly::ATOMIC_STORE16_I64_S:
Heejin Ahnfed73822018-07-09 22:30:51 +0000215 case WebAssembly::ATOMIC_RMW16_U_ADD_I32:
216 case WebAssembly::ATOMIC_RMW16_U_ADD_I32_S:
217 case WebAssembly::ATOMIC_RMW16_U_ADD_I64:
218 case WebAssembly::ATOMIC_RMW16_U_ADD_I64_S:
219 case WebAssembly::ATOMIC_RMW16_U_SUB_I32:
220 case WebAssembly::ATOMIC_RMW16_U_SUB_I32_S:
221 case WebAssembly::ATOMIC_RMW16_U_SUB_I64:
222 case WebAssembly::ATOMIC_RMW16_U_SUB_I64_S:
223 case WebAssembly::ATOMIC_RMW16_U_AND_I32:
224 case WebAssembly::ATOMIC_RMW16_U_AND_I32_S:
225 case WebAssembly::ATOMIC_RMW16_U_AND_I64:
226 case WebAssembly::ATOMIC_RMW16_U_AND_I64_S:
227 case WebAssembly::ATOMIC_RMW16_U_OR_I32:
228 case WebAssembly::ATOMIC_RMW16_U_OR_I32_S:
229 case WebAssembly::ATOMIC_RMW16_U_OR_I64:
230 case WebAssembly::ATOMIC_RMW16_U_OR_I64_S:
231 case WebAssembly::ATOMIC_RMW16_U_XOR_I32:
232 case WebAssembly::ATOMIC_RMW16_U_XOR_I32_S:
233 case WebAssembly::ATOMIC_RMW16_U_XOR_I64:
234 case WebAssembly::ATOMIC_RMW16_U_XOR_I64_S:
235 case WebAssembly::ATOMIC_RMW16_U_XCHG_I32:
236 case WebAssembly::ATOMIC_RMW16_U_XCHG_I32_S:
237 case WebAssembly::ATOMIC_RMW16_U_XCHG_I64:
238 case WebAssembly::ATOMIC_RMW16_U_XCHG_I64_S:
Heejin Ahnb3724b72018-08-01 19:40:28 +0000239 case WebAssembly::ATOMIC_RMW16_U_CMPXCHG_I32:
240 case WebAssembly::ATOMIC_RMW16_U_CMPXCHG_I32_S:
241 case WebAssembly::ATOMIC_RMW16_U_CMPXCHG_I64:
242 case WebAssembly::ATOMIC_RMW16_U_CMPXCHG_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000243 return 1;
244 case WebAssembly::LOAD_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000245 case WebAssembly::LOAD_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000246 case WebAssembly::LOAD_F32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000247 case WebAssembly::LOAD_F32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000248 case WebAssembly::STORE_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000249 case WebAssembly::STORE_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000250 case WebAssembly::STORE_F32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000251 case WebAssembly::STORE_F32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000252 case WebAssembly::LOAD32_S_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000253 case WebAssembly::LOAD32_S_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000254 case WebAssembly::LOAD32_U_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000255 case WebAssembly::LOAD32_U_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000256 case WebAssembly::STORE32_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000257 case WebAssembly::STORE32_I64_S:
Derek Schuff18ba1922017-08-30 18:07:45 +0000258 case WebAssembly::ATOMIC_LOAD_I32:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000259 case WebAssembly::ATOMIC_LOAD_I32_S:
Derek Schuff885dc592017-10-05 21:18:42 +0000260 case WebAssembly::ATOMIC_LOAD32_U_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000261 case WebAssembly::ATOMIC_LOAD32_U_I64_S:
Heejin Ahn402b4902018-07-02 21:22:59 +0000262 case WebAssembly::ATOMIC_STORE_I32:
Heejin Ahn80d9f172018-07-05 21:27:09 +0000263 case WebAssembly::ATOMIC_STORE_I32_S:
Heejin Ahn402b4902018-07-02 21:22:59 +0000264 case WebAssembly::ATOMIC_STORE32_I64:
Heejin Ahn80d9f172018-07-05 21:27:09 +0000265 case WebAssembly::ATOMIC_STORE32_I64_S:
Heejin Ahnfed73822018-07-09 22:30:51 +0000266 case WebAssembly::ATOMIC_RMW_ADD_I32:
267 case WebAssembly::ATOMIC_RMW_ADD_I32_S:
268 case WebAssembly::ATOMIC_RMW32_U_ADD_I64:
269 case WebAssembly::ATOMIC_RMW32_U_ADD_I64_S:
270 case WebAssembly::ATOMIC_RMW_SUB_I32:
271 case WebAssembly::ATOMIC_RMW_SUB_I32_S:
272 case WebAssembly::ATOMIC_RMW32_U_SUB_I64:
273 case WebAssembly::ATOMIC_RMW32_U_SUB_I64_S:
274 case WebAssembly::ATOMIC_RMW_AND_I32:
275 case WebAssembly::ATOMIC_RMW_AND_I32_S:
276 case WebAssembly::ATOMIC_RMW32_U_AND_I64:
277 case WebAssembly::ATOMIC_RMW32_U_AND_I64_S:
278 case WebAssembly::ATOMIC_RMW_OR_I32:
279 case WebAssembly::ATOMIC_RMW_OR_I32_S:
280 case WebAssembly::ATOMIC_RMW32_U_OR_I64:
281 case WebAssembly::ATOMIC_RMW32_U_OR_I64_S:
282 case WebAssembly::ATOMIC_RMW_XOR_I32:
283 case WebAssembly::ATOMIC_RMW_XOR_I32_S:
284 case WebAssembly::ATOMIC_RMW32_U_XOR_I64:
285 case WebAssembly::ATOMIC_RMW32_U_XOR_I64_S:
286 case WebAssembly::ATOMIC_RMW_XCHG_I32:
287 case WebAssembly::ATOMIC_RMW_XCHG_I32_S:
288 case WebAssembly::ATOMIC_RMW32_U_XCHG_I64:
289 case WebAssembly::ATOMIC_RMW32_U_XCHG_I64_S:
Heejin Ahnb3724b72018-08-01 19:40:28 +0000290 case WebAssembly::ATOMIC_RMW_CMPXCHG_I32:
291 case WebAssembly::ATOMIC_RMW_CMPXCHG_I32_S:
292 case WebAssembly::ATOMIC_RMW32_U_CMPXCHG_I64:
293 case WebAssembly::ATOMIC_RMW32_U_CMPXCHG_I64_S:
Heejin Ahn4128cb02018-08-02 21:44:24 +0000294 case WebAssembly::ATOMIC_NOTIFY:
295 case WebAssembly::ATOMIC_NOTIFY_S:
296 case WebAssembly::ATOMIC_WAIT_I32:
297 case WebAssembly::ATOMIC_WAIT_I32_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000298 return 2;
299 case WebAssembly::LOAD_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000300 case WebAssembly::LOAD_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000301 case WebAssembly::LOAD_F64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000302 case WebAssembly::LOAD_F64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000303 case WebAssembly::STORE_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000304 case WebAssembly::STORE_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000305 case WebAssembly::STORE_F64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000306 case WebAssembly::STORE_F64_S:
Derek Schuff885dc592017-10-05 21:18:42 +0000307 case WebAssembly::ATOMIC_LOAD_I64:
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000308 case WebAssembly::ATOMIC_LOAD_I64_S:
Heejin Ahn402b4902018-07-02 21:22:59 +0000309 case WebAssembly::ATOMIC_STORE_I64:
Heejin Ahn80d9f172018-07-05 21:27:09 +0000310 case WebAssembly::ATOMIC_STORE_I64_S:
Heejin Ahnfed73822018-07-09 22:30:51 +0000311 case WebAssembly::ATOMIC_RMW_ADD_I64:
312 case WebAssembly::ATOMIC_RMW_ADD_I64_S:
313 case WebAssembly::ATOMIC_RMW_SUB_I64:
314 case WebAssembly::ATOMIC_RMW_SUB_I64_S:
315 case WebAssembly::ATOMIC_RMW_AND_I64:
316 case WebAssembly::ATOMIC_RMW_AND_I64_S:
317 case WebAssembly::ATOMIC_RMW_OR_I64:
318 case WebAssembly::ATOMIC_RMW_OR_I64_S:
319 case WebAssembly::ATOMIC_RMW_XOR_I64:
320 case WebAssembly::ATOMIC_RMW_XOR_I64_S:
321 case WebAssembly::ATOMIC_RMW_XCHG_I64:
322 case WebAssembly::ATOMIC_RMW_XCHG_I64_S:
Heejin Ahnb3724b72018-08-01 19:40:28 +0000323 case WebAssembly::ATOMIC_RMW_CMPXCHG_I64:
324 case WebAssembly::ATOMIC_RMW_CMPXCHG_I64_S:
Heejin Ahn4128cb02018-08-02 21:44:24 +0000325 case WebAssembly::ATOMIC_WAIT_I64:
326 case WebAssembly::ATOMIC_WAIT_I64_S:
Dan Gohmanbb372242016-01-26 03:39:31 +0000327 return 3;
Thomas Livelyd183d8c2018-08-30 21:36:48 +0000328 case WebAssembly::LOAD_v16i8:
329 case WebAssembly::LOAD_v16i8_S:
330 case WebAssembly::LOAD_v8i16:
331 case WebAssembly::LOAD_v8i16_S:
332 case WebAssembly::LOAD_v4i32:
333 case WebAssembly::LOAD_v4i32_S:
334 case WebAssembly::LOAD_v2i64:
335 case WebAssembly::LOAD_v2i64_S:
336 case WebAssembly::LOAD_v4f32:
337 case WebAssembly::LOAD_v4f32_S:
338 case WebAssembly::LOAD_v2f64:
339 case WebAssembly::LOAD_v2f64_S:
340 case WebAssembly::STORE_v16i8:
341 case WebAssembly::STORE_v16i8_S:
342 case WebAssembly::STORE_v8i16:
343 case WebAssembly::STORE_v8i16_S:
344 case WebAssembly::STORE_v4i32:
345 case WebAssembly::STORE_v4i32_S:
346 case WebAssembly::STORE_v2i64:
347 case WebAssembly::STORE_v2i64_S:
348 case WebAssembly::STORE_v4f32:
349 case WebAssembly::STORE_v4f32_S:
350 case WebAssembly::STORE_v2f64:
351 case WebAssembly::STORE_v2f64_S:
352 return 4;
Derek Schuffc64d7652016-08-01 22:25:02 +0000353 default:
Wouter van Oortmerssen6b3f56b2019-06-27 18:11:15 +0000354 return -1;
355 }
356}
357
Wouter van Oortmerssend8ddf832019-07-12 22:08:25 +0000358inline unsigned GetDefaultP2Align(unsigned Opc) {
359 auto Align = GetDefaultP2AlignAny(Opc);
Wouter van Oortmerssen6b3f56b2019-06-27 18:11:15 +0000360 if (Align == -1U) {
Derek Schuffc64d7652016-08-01 22:25:02 +0000361 llvm_unreachable("Only loads and stores have p2align values");
Dan Gohmanbb372242016-01-26 03:39:31 +0000362 }
Wouter van Oortmerssen6b3f56b2019-06-27 18:11:15 +0000363 return Align;
Dan Gohmanbb372242016-01-26 03:39:31 +0000364}
365
Wouter van Oortmerssend8ddf832019-07-12 22:08:25 +0000366inline bool isArgument(unsigned Opc) {
367 switch (Opc) {
368 case WebAssembly::ARGUMENT_i32:
369 case WebAssembly::ARGUMENT_i32_S:
370 case WebAssembly::ARGUMENT_i64:
371 case WebAssembly::ARGUMENT_i64_S:
372 case WebAssembly::ARGUMENT_f32:
373 case WebAssembly::ARGUMENT_f32_S:
374 case WebAssembly::ARGUMENT_f64:
375 case WebAssembly::ARGUMENT_f64_S:
376 case WebAssembly::ARGUMENT_v16i8:
377 case WebAssembly::ARGUMENT_v16i8_S:
378 case WebAssembly::ARGUMENT_v8i16:
379 case WebAssembly::ARGUMENT_v8i16_S:
380 case WebAssembly::ARGUMENT_v4i32:
381 case WebAssembly::ARGUMENT_v4i32_S:
382 case WebAssembly::ARGUMENT_v2i64:
383 case WebAssembly::ARGUMENT_v2i64_S:
384 case WebAssembly::ARGUMENT_v4f32:
385 case WebAssembly::ARGUMENT_v4f32_S:
386 case WebAssembly::ARGUMENT_v2f64:
387 case WebAssembly::ARGUMENT_v2f64_S:
388 return true;
389 default:
390 return false;
391 }
392}
Dan Gohman4fc4e422016-10-24 19:49:43 +0000393
Wouter van Oortmerssend8ddf832019-07-12 22:08:25 +0000394inline bool isCopy(unsigned Opc) {
395 switch (Opc) {
396 case WebAssembly::COPY_I32:
397 case WebAssembly::COPY_I32_S:
398 case WebAssembly::COPY_I64:
399 case WebAssembly::COPY_I64_S:
400 case WebAssembly::COPY_F32:
401 case WebAssembly::COPY_F32_S:
402 case WebAssembly::COPY_F64:
403 case WebAssembly::COPY_F64_S:
404 case WebAssembly::COPY_V128:
405 case WebAssembly::COPY_V128_S:
406 case WebAssembly::COPY_EXCEPT_REF:
407 case WebAssembly::COPY_EXCEPT_REF_S:
408 return true;
409 default:
410 return false;
411 }
412}
Dan Gohman3acb1872016-10-24 23:27:49 +0000413
Wouter van Oortmerssend8ddf832019-07-12 22:08:25 +0000414inline bool isTee(unsigned Opc) {
415 switch (Opc) {
416 case WebAssembly::TEE_I32:
417 case WebAssembly::TEE_I32_S:
418 case WebAssembly::TEE_I64:
419 case WebAssembly::TEE_I64_S:
420 case WebAssembly::TEE_F32:
421 case WebAssembly::TEE_F32_S:
422 case WebAssembly::TEE_F64:
423 case WebAssembly::TEE_F64_S:
424 case WebAssembly::TEE_V128:
425 case WebAssembly::TEE_V128_S:
426 return true;
427 default:
428 return false;
429 }
430}
431
432inline bool isCallDirect(unsigned Opc) {
433 switch (Opc) {
434 case WebAssembly::CALL_VOID:
435 case WebAssembly::CALL_VOID_S:
436 case WebAssembly::CALL_i32:
437 case WebAssembly::CALL_i32_S:
438 case WebAssembly::CALL_i64:
439 case WebAssembly::CALL_i64_S:
440 case WebAssembly::CALL_f32:
441 case WebAssembly::CALL_f32_S:
442 case WebAssembly::CALL_f64:
443 case WebAssembly::CALL_f64_S:
444 case WebAssembly::CALL_v16i8:
445 case WebAssembly::CALL_v16i8_S:
446 case WebAssembly::CALL_v8i16:
447 case WebAssembly::CALL_v8i16_S:
448 case WebAssembly::CALL_v4i32:
449 case WebAssembly::CALL_v4i32_S:
450 case WebAssembly::CALL_v2i64:
451 case WebAssembly::CALL_v2i64_S:
452 case WebAssembly::CALL_v4f32:
453 case WebAssembly::CALL_v4f32_S:
454 case WebAssembly::CALL_v2f64:
455 case WebAssembly::CALL_v2f64_S:
456 case WebAssembly::CALL_ExceptRef:
457 case WebAssembly::CALL_ExceptRef_S:
458 case WebAssembly::RET_CALL:
459 case WebAssembly::RET_CALL_S:
460 return true;
461 default:
462 return false;
463 }
464}
465
466inline bool isCallIndirect(unsigned Opc) {
467 switch (Opc) {
468 case WebAssembly::CALL_INDIRECT_VOID:
469 case WebAssembly::CALL_INDIRECT_VOID_S:
470 case WebAssembly::CALL_INDIRECT_i32:
471 case WebAssembly::CALL_INDIRECT_i32_S:
472 case WebAssembly::CALL_INDIRECT_i64:
473 case WebAssembly::CALL_INDIRECT_i64_S:
474 case WebAssembly::CALL_INDIRECT_f32:
475 case WebAssembly::CALL_INDIRECT_f32_S:
476 case WebAssembly::CALL_INDIRECT_f64:
477 case WebAssembly::CALL_INDIRECT_f64_S:
478 case WebAssembly::CALL_INDIRECT_v16i8:
479 case WebAssembly::CALL_INDIRECT_v16i8_S:
480 case WebAssembly::CALL_INDIRECT_v8i16:
481 case WebAssembly::CALL_INDIRECT_v8i16_S:
482 case WebAssembly::CALL_INDIRECT_v4i32:
483 case WebAssembly::CALL_INDIRECT_v4i32_S:
484 case WebAssembly::CALL_INDIRECT_v2i64:
485 case WebAssembly::CALL_INDIRECT_v2i64_S:
486 case WebAssembly::CALL_INDIRECT_v4f32:
487 case WebAssembly::CALL_INDIRECT_v4f32_S:
488 case WebAssembly::CALL_INDIRECT_v2f64:
489 case WebAssembly::CALL_INDIRECT_v2f64_S:
490 case WebAssembly::CALL_INDIRECT_ExceptRef:
491 case WebAssembly::CALL_INDIRECT_ExceptRef_S:
492 case WebAssembly::RET_CALL_INDIRECT:
493 case WebAssembly::RET_CALL_INDIRECT_S:
494 return true;
495 default:
496 return false;
497 }
498}
499
500/// Returns the operand number of a callee, assuming the argument is a call
501/// instruction.
502inline unsigned getCalleeOpNo(unsigned Opc) {
503 switch (Opc) {
504 case WebAssembly::CALL_VOID:
505 case WebAssembly::CALL_VOID_S:
506 case WebAssembly::CALL_INDIRECT_VOID:
507 case WebAssembly::CALL_INDIRECT_VOID_S:
508 case WebAssembly::RET_CALL:
509 case WebAssembly::RET_CALL_S:
510 case WebAssembly::RET_CALL_INDIRECT:
511 case WebAssembly::RET_CALL_INDIRECT_S:
512 return 0;
513 case WebAssembly::CALL_i32:
514 case WebAssembly::CALL_i32_S:
515 case WebAssembly::CALL_i64:
516 case WebAssembly::CALL_i64_S:
517 case WebAssembly::CALL_f32:
518 case WebAssembly::CALL_f32_S:
519 case WebAssembly::CALL_f64:
520 case WebAssembly::CALL_f64_S:
521 case WebAssembly::CALL_v16i8:
522 case WebAssembly::CALL_v16i8_S:
523 case WebAssembly::CALL_v8i16:
524 case WebAssembly::CALL_v8i16_S:
525 case WebAssembly::CALL_v4i32:
526 case WebAssembly::CALL_v4i32_S:
527 case WebAssembly::CALL_v2i64:
528 case WebAssembly::CALL_v2i64_S:
529 case WebAssembly::CALL_v4f32:
530 case WebAssembly::CALL_v4f32_S:
531 case WebAssembly::CALL_v2f64:
532 case WebAssembly::CALL_v2f64_S:
533 case WebAssembly::CALL_ExceptRef:
534 case WebAssembly::CALL_ExceptRef_S:
535 case WebAssembly::CALL_INDIRECT_i32:
536 case WebAssembly::CALL_INDIRECT_i32_S:
537 case WebAssembly::CALL_INDIRECT_i64:
538 case WebAssembly::CALL_INDIRECT_i64_S:
539 case WebAssembly::CALL_INDIRECT_f32:
540 case WebAssembly::CALL_INDIRECT_f32_S:
541 case WebAssembly::CALL_INDIRECT_f64:
542 case WebAssembly::CALL_INDIRECT_f64_S:
543 case WebAssembly::CALL_INDIRECT_v16i8:
544 case WebAssembly::CALL_INDIRECT_v16i8_S:
545 case WebAssembly::CALL_INDIRECT_v8i16:
546 case WebAssembly::CALL_INDIRECT_v8i16_S:
547 case WebAssembly::CALL_INDIRECT_v4i32:
548 case WebAssembly::CALL_INDIRECT_v4i32_S:
549 case WebAssembly::CALL_INDIRECT_v2i64:
550 case WebAssembly::CALL_INDIRECT_v2i64_S:
551 case WebAssembly::CALL_INDIRECT_v4f32:
552 case WebAssembly::CALL_INDIRECT_v4f32_S:
553 case WebAssembly::CALL_INDIRECT_v2f64:
554 case WebAssembly::CALL_INDIRECT_v2f64_S:
555 case WebAssembly::CALL_INDIRECT_ExceptRef:
556 case WebAssembly::CALL_INDIRECT_ExceptRef_S:
557 return 1;
558 default:
559 llvm_unreachable("Not a call instruction");
560 }
561}
562
563inline bool isMarker(unsigned Opc) {
564 switch (Opc) {
565 case WebAssembly::BLOCK:
566 case WebAssembly::BLOCK_S:
567 case WebAssembly::END_BLOCK:
568 case WebAssembly::END_BLOCK_S:
569 case WebAssembly::LOOP:
570 case WebAssembly::LOOP_S:
571 case WebAssembly::END_LOOP:
572 case WebAssembly::END_LOOP_S:
573 case WebAssembly::TRY:
574 case WebAssembly::TRY_S:
575 case WebAssembly::END_TRY:
576 case WebAssembly::END_TRY_S:
577 return true;
578 default:
579 return false;
580 }
581}
Dan Gohman3acb1872016-10-24 23:27:49 +0000582
Dan Gohmanbb372242016-01-26 03:39:31 +0000583} // end namespace WebAssembly
584} // end namespace llvm
585
Dan Gohman10e730a2015-06-29 23:51:55 +0000586#endif