xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //==- WebAssemblyMCTargetDesc.h - WebAssembly Target Descriptions -*- C++ -*-=//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file provides WebAssembly-specific target descriptions.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
15 #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
16 
17 #include "llvm/BinaryFormat/Wasm.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCInstrDesc.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/DataTypes.h"
22 #include <memory>
23 
24 namespace llvm {
25 
26 class MCAsmBackend;
27 class MCCodeEmitter;
28 class MCInstrInfo;
29 class MCObjectTargetWriter;
30 class Triple;
31 
32 MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII,
33                                               MCContext &Ctx);
34 
35 MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
36 
37 std::unique_ptr<MCObjectTargetWriter>
38 createWebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten);
39 
40 namespace WebAssembly {
41 
42 enum OperandType {
43   /// Basic block label in a branch construct.
44   OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
45   /// Local index.
46   OPERAND_LOCAL,
47   /// Global index.
48   OPERAND_GLOBAL,
49   /// 32-bit integer immediates.
50   OPERAND_I32IMM,
51   /// 64-bit integer immediates.
52   OPERAND_I64IMM,
53   /// 32-bit floating-point immediates.
54   OPERAND_F32IMM,
55   /// 64-bit floating-point immediates.
56   OPERAND_F64IMM,
57   /// 8-bit vector lane immediate
58   OPERAND_VEC_I8IMM,
59   /// 16-bit vector lane immediate
60   OPERAND_VEC_I16IMM,
61   /// 32-bit vector lane immediate
62   OPERAND_VEC_I32IMM,
63   /// 64-bit vector lane immediate
64   OPERAND_VEC_I64IMM,
65   /// 32-bit unsigned function indices.
66   OPERAND_FUNCTION32,
67   /// 32-bit unsigned memory offsets.
68   OPERAND_OFFSET32,
69   /// 64-bit unsigned memory offsets.
70   OPERAND_OFFSET64,
71   /// p2align immediate for load and store address alignment.
72   OPERAND_P2ALIGN,
73   /// signature immediate for block/loop.
74   OPERAND_SIGNATURE,
75   /// type signature immediate for call_indirect.
76   OPERAND_TYPEINDEX,
77   /// Tag index.
78   OPERAND_TAG,
79   /// A list of branch targets for br_list.
80   OPERAND_BRLIST,
81   /// 32-bit unsigned table number.
82   OPERAND_TABLE,
83   /// A list of catch clauses for try_table.
84   OPERAND_CATCH_LIST,
85 };
86 } // end namespace WebAssembly
87 
88 namespace WebAssemblyII {
89 
90 /// Target Operand Flag enum.
91 enum TOF {
92   MO_NO_FLAG = 0,
93 
94   // On a symbol operand this indicates that the immediate is a wasm global
95   // index.  The value of the wasm global will be set to the symbol address at
96   // runtime.  This adds a level of indirection similar to the GOT on native
97   // platforms.
98   MO_GOT,
99 
100   // Same as MO_GOT but the address stored in the global is a TLS address.
101   MO_GOT_TLS,
102 
103   // On a symbol operand this indicates that the immediate is the symbol
104   // address relative the __memory_base wasm global.
105   // Only applicable to data symbols.
106   MO_MEMORY_BASE_REL,
107 
108   // On a symbol operand this indicates that the immediate is the symbol
109   // address relative the __tls_base wasm global.
110   // Only applicable to data symbols.
111   MO_TLS_BASE_REL,
112 
113   // On a symbol operand this indicates that the immediate is the symbol
114   // address relative the __table_base wasm global.
115   // Only applicable to function symbols.
116   MO_TABLE_BASE_REL,
117 
118   // On a block signature operand this indicates that this is a destination
119   // block of a (catch_ref) clause in try_table.
120   MO_CATCH_BLOCK_SIG,
121 };
122 
123 } // end namespace WebAssemblyII
124 
125 } // end namespace llvm
126 
127 // Defines symbolic names for WebAssembly registers. This defines a mapping from
128 // register name to register number.
129 //
130 #define GET_REGINFO_ENUM
131 #include "WebAssemblyGenRegisterInfo.inc"
132 
133 // Defines symbolic names for the WebAssembly instructions.
134 //
135 #define GET_INSTRINFO_ENUM
136 #define GET_INSTRINFO_MC_HELPER_DECLS
137 #include "WebAssemblyGenInstrInfo.inc"
138 
139 namespace llvm {
140 namespace WebAssembly {
141 
142 /// Instruction opcodes emitted via means other than CodeGen.
143 static const unsigned Nop = 0x01;
144 static const unsigned End = 0x0b;
145 
146 /// Return the default p2align value for a load or store with the given opcode.
GetDefaultP2AlignAny(unsigned Opc)147 inline unsigned GetDefaultP2AlignAny(unsigned Opc) {
148   switch (Opc) {
149 #define WASM_LOAD_STORE(NAME) \
150   case WebAssembly::NAME##_A32: \
151   case WebAssembly::NAME##_A64: \
152   case WebAssembly::NAME##_A32_S: \
153   case WebAssembly::NAME##_A64_S:
154   WASM_LOAD_STORE(LOAD8_S_I32)
155   WASM_LOAD_STORE(LOAD8_U_I32)
156   WASM_LOAD_STORE(LOAD8_S_I64)
157   WASM_LOAD_STORE(LOAD8_U_I64)
158   WASM_LOAD_STORE(ATOMIC_LOAD8_U_I32)
159   WASM_LOAD_STORE(ATOMIC_LOAD8_U_I64)
160   WASM_LOAD_STORE(STORE8_I32)
161   WASM_LOAD_STORE(STORE8_I64)
162   WASM_LOAD_STORE(ATOMIC_STORE8_I32)
163   WASM_LOAD_STORE(ATOMIC_STORE8_I64)
164   WASM_LOAD_STORE(ATOMIC_RMW8_U_ADD_I32)
165   WASM_LOAD_STORE(ATOMIC_RMW8_U_ADD_I64)
166   WASM_LOAD_STORE(ATOMIC_RMW8_U_SUB_I32)
167   WASM_LOAD_STORE(ATOMIC_RMW8_U_SUB_I64)
168   WASM_LOAD_STORE(ATOMIC_RMW8_U_AND_I32)
169   WASM_LOAD_STORE(ATOMIC_RMW8_U_AND_I64)
170   WASM_LOAD_STORE(ATOMIC_RMW8_U_OR_I32)
171   WASM_LOAD_STORE(ATOMIC_RMW8_U_OR_I64)
172   WASM_LOAD_STORE(ATOMIC_RMW8_U_XOR_I32)
173   WASM_LOAD_STORE(ATOMIC_RMW8_U_XOR_I64)
174   WASM_LOAD_STORE(ATOMIC_RMW8_U_XCHG_I32)
175   WASM_LOAD_STORE(ATOMIC_RMW8_U_XCHG_I64)
176   WASM_LOAD_STORE(ATOMIC_RMW8_U_CMPXCHG_I32)
177   WASM_LOAD_STORE(ATOMIC_RMW8_U_CMPXCHG_I64)
178   WASM_LOAD_STORE(LOAD8_SPLAT)
179   WASM_LOAD_STORE(LOAD_LANE_8)
180   WASM_LOAD_STORE(STORE_LANE_I8x16)
181   return 0;
182   WASM_LOAD_STORE(LOAD16_S_I32)
183   WASM_LOAD_STORE(LOAD16_U_I32)
184   WASM_LOAD_STORE(LOAD16_S_I64)
185   WASM_LOAD_STORE(LOAD16_U_I64)
186   WASM_LOAD_STORE(ATOMIC_LOAD16_U_I32)
187   WASM_LOAD_STORE(ATOMIC_LOAD16_U_I64)
188   WASM_LOAD_STORE(STORE16_I32)
189   WASM_LOAD_STORE(STORE16_I64)
190   WASM_LOAD_STORE(ATOMIC_STORE16_I32)
191   WASM_LOAD_STORE(ATOMIC_STORE16_I64)
192   WASM_LOAD_STORE(ATOMIC_RMW16_U_ADD_I32)
193   WASM_LOAD_STORE(ATOMIC_RMW16_U_ADD_I64)
194   WASM_LOAD_STORE(ATOMIC_RMW16_U_SUB_I32)
195   WASM_LOAD_STORE(ATOMIC_RMW16_U_SUB_I64)
196   WASM_LOAD_STORE(ATOMIC_RMW16_U_AND_I32)
197   WASM_LOAD_STORE(ATOMIC_RMW16_U_AND_I64)
198   WASM_LOAD_STORE(ATOMIC_RMW16_U_OR_I32)
199   WASM_LOAD_STORE(ATOMIC_RMW16_U_OR_I64)
200   WASM_LOAD_STORE(ATOMIC_RMW16_U_XOR_I32)
201   WASM_LOAD_STORE(ATOMIC_RMW16_U_XOR_I64)
202   WASM_LOAD_STORE(ATOMIC_RMW16_U_XCHG_I32)
203   WASM_LOAD_STORE(ATOMIC_RMW16_U_XCHG_I64)
204   WASM_LOAD_STORE(ATOMIC_RMW16_U_CMPXCHG_I32)
205   WASM_LOAD_STORE(ATOMIC_RMW16_U_CMPXCHG_I64)
206   WASM_LOAD_STORE(LOAD16_SPLAT)
207   WASM_LOAD_STORE(LOAD_LANE_16)
208   WASM_LOAD_STORE(STORE_LANE_I16x8)
209   WASM_LOAD_STORE(LOAD_F16_F32)
210   WASM_LOAD_STORE(STORE_F16_F32)
211   return 1;
212   WASM_LOAD_STORE(LOAD_I32)
213   WASM_LOAD_STORE(LOAD_F32)
214   WASM_LOAD_STORE(STORE_I32)
215   WASM_LOAD_STORE(STORE_F32)
216   WASM_LOAD_STORE(LOAD32_S_I64)
217   WASM_LOAD_STORE(LOAD32_U_I64)
218   WASM_LOAD_STORE(STORE32_I64)
219   WASM_LOAD_STORE(ATOMIC_LOAD_I32)
220   WASM_LOAD_STORE(ATOMIC_LOAD32_U_I64)
221   WASM_LOAD_STORE(ATOMIC_STORE_I32)
222   WASM_LOAD_STORE(ATOMIC_STORE32_I64)
223   WASM_LOAD_STORE(ATOMIC_RMW_ADD_I32)
224   WASM_LOAD_STORE(ATOMIC_RMW32_U_ADD_I64)
225   WASM_LOAD_STORE(ATOMIC_RMW_SUB_I32)
226   WASM_LOAD_STORE(ATOMIC_RMW32_U_SUB_I64)
227   WASM_LOAD_STORE(ATOMIC_RMW_AND_I32)
228   WASM_LOAD_STORE(ATOMIC_RMW32_U_AND_I64)
229   WASM_LOAD_STORE(ATOMIC_RMW_OR_I32)
230   WASM_LOAD_STORE(ATOMIC_RMW32_U_OR_I64)
231   WASM_LOAD_STORE(ATOMIC_RMW_XOR_I32)
232   WASM_LOAD_STORE(ATOMIC_RMW32_U_XOR_I64)
233   WASM_LOAD_STORE(ATOMIC_RMW_XCHG_I32)
234   WASM_LOAD_STORE(ATOMIC_RMW32_U_XCHG_I64)
235   WASM_LOAD_STORE(ATOMIC_RMW_CMPXCHG_I32)
236   WASM_LOAD_STORE(ATOMIC_RMW32_U_CMPXCHG_I64)
237   WASM_LOAD_STORE(MEMORY_ATOMIC_NOTIFY)
238   WASM_LOAD_STORE(MEMORY_ATOMIC_WAIT32)
239   WASM_LOAD_STORE(LOAD32_SPLAT)
240   WASM_LOAD_STORE(LOAD_ZERO_32)
241   WASM_LOAD_STORE(LOAD_LANE_32)
242   WASM_LOAD_STORE(STORE_LANE_I32x4)
243   return 2;
244   WASM_LOAD_STORE(LOAD_I64)
245   WASM_LOAD_STORE(LOAD_F64)
246   WASM_LOAD_STORE(STORE_I64)
247   WASM_LOAD_STORE(STORE_F64)
248   WASM_LOAD_STORE(ATOMIC_LOAD_I64)
249   WASM_LOAD_STORE(ATOMIC_STORE_I64)
250   WASM_LOAD_STORE(ATOMIC_RMW_ADD_I64)
251   WASM_LOAD_STORE(ATOMIC_RMW_SUB_I64)
252   WASM_LOAD_STORE(ATOMIC_RMW_AND_I64)
253   WASM_LOAD_STORE(ATOMIC_RMW_OR_I64)
254   WASM_LOAD_STORE(ATOMIC_RMW_XOR_I64)
255   WASM_LOAD_STORE(ATOMIC_RMW_XCHG_I64)
256   WASM_LOAD_STORE(ATOMIC_RMW_CMPXCHG_I64)
257   WASM_LOAD_STORE(MEMORY_ATOMIC_WAIT64)
258   WASM_LOAD_STORE(LOAD64_SPLAT)
259   WASM_LOAD_STORE(LOAD_EXTEND_S_I16x8)
260   WASM_LOAD_STORE(LOAD_EXTEND_U_I16x8)
261   WASM_LOAD_STORE(LOAD_EXTEND_S_I32x4)
262   WASM_LOAD_STORE(LOAD_EXTEND_U_I32x4)
263   WASM_LOAD_STORE(LOAD_EXTEND_S_I64x2)
264   WASM_LOAD_STORE(LOAD_EXTEND_U_I64x2)
265   WASM_LOAD_STORE(LOAD_ZERO_64)
266   WASM_LOAD_STORE(LOAD_LANE_64)
267   WASM_LOAD_STORE(STORE_LANE_I64x2)
268   return 3;
269   WASM_LOAD_STORE(LOAD_V128)
270   WASM_LOAD_STORE(STORE_V128)
271     return 4;
272   default:
273     return -1;
274   }
275 #undef WASM_LOAD_STORE
276 }
277 
GetDefaultP2Align(unsigned Opc)278 inline unsigned GetDefaultP2Align(unsigned Opc) {
279   auto Align = GetDefaultP2AlignAny(Opc);
280   if (Align == -1U) {
281     llvm_unreachable("Only loads and stores have p2align values");
282   }
283   return Align;
284 }
285 
isConst(unsigned Opc)286 inline bool isConst(unsigned Opc) {
287   switch (Opc) {
288   case WebAssembly::CONST_I32:
289   case WebAssembly::CONST_I32_S:
290   case WebAssembly::CONST_I64:
291   case WebAssembly::CONST_I64_S:
292   case WebAssembly::CONST_F32:
293   case WebAssembly::CONST_F32_S:
294   case WebAssembly::CONST_F64:
295   case WebAssembly::CONST_F64_S:
296   case WebAssembly::CONST_V128_I8x16:
297   case WebAssembly::CONST_V128_I8x16_S:
298   case WebAssembly::CONST_V128_I16x8:
299   case WebAssembly::CONST_V128_I16x8_S:
300   case WebAssembly::CONST_V128_I32x4:
301   case WebAssembly::CONST_V128_I32x4_S:
302   case WebAssembly::CONST_V128_I64x2:
303   case WebAssembly::CONST_V128_I64x2_S:
304   case WebAssembly::CONST_V128_F32x4:
305   case WebAssembly::CONST_V128_F32x4_S:
306   case WebAssembly::CONST_V128_F64x2:
307   case WebAssembly::CONST_V128_F64x2_S:
308     return true;
309   default:
310     return false;
311   }
312 }
313 
isScalarConst(unsigned Opc)314 inline bool isScalarConst(unsigned Opc) {
315   switch (Opc) {
316   case WebAssembly::CONST_I32:
317   case WebAssembly::CONST_I32_S:
318   case WebAssembly::CONST_I64:
319   case WebAssembly::CONST_I64_S:
320   case WebAssembly::CONST_F32:
321   case WebAssembly::CONST_F32_S:
322   case WebAssembly::CONST_F64:
323   case WebAssembly::CONST_F64_S:
324     return true;
325   default:
326     return false;
327   }
328 }
329 
isArgument(unsigned Opc)330 inline bool isArgument(unsigned Opc) {
331   switch (Opc) {
332   case WebAssembly::ARGUMENT_i32:
333   case WebAssembly::ARGUMENT_i32_S:
334   case WebAssembly::ARGUMENT_i64:
335   case WebAssembly::ARGUMENT_i64_S:
336   case WebAssembly::ARGUMENT_f32:
337   case WebAssembly::ARGUMENT_f32_S:
338   case WebAssembly::ARGUMENT_f64:
339   case WebAssembly::ARGUMENT_f64_S:
340   case WebAssembly::ARGUMENT_v16i8:
341   case WebAssembly::ARGUMENT_v16i8_S:
342   case WebAssembly::ARGUMENT_v8i16:
343   case WebAssembly::ARGUMENT_v8i16_S:
344   case WebAssembly::ARGUMENT_v4i32:
345   case WebAssembly::ARGUMENT_v4i32_S:
346   case WebAssembly::ARGUMENT_v2i64:
347   case WebAssembly::ARGUMENT_v2i64_S:
348   case WebAssembly::ARGUMENT_v8f16:
349   case WebAssembly::ARGUMENT_v8f16_S:
350   case WebAssembly::ARGUMENT_v4f32:
351   case WebAssembly::ARGUMENT_v4f32_S:
352   case WebAssembly::ARGUMENT_v2f64:
353   case WebAssembly::ARGUMENT_v2f64_S:
354   case WebAssembly::ARGUMENT_funcref:
355   case WebAssembly::ARGUMENT_funcref_S:
356   case WebAssembly::ARGUMENT_externref:
357   case WebAssembly::ARGUMENT_externref_S:
358   case WebAssembly::ARGUMENT_exnref:
359   case WebAssembly::ARGUMENT_exnref_S:
360     return true;
361   default:
362     return false;
363   }
364 }
365 
isCopy(unsigned Opc)366 inline bool isCopy(unsigned Opc) {
367   switch (Opc) {
368   case WebAssembly::COPY_I32:
369   case WebAssembly::COPY_I32_S:
370   case WebAssembly::COPY_I64:
371   case WebAssembly::COPY_I64_S:
372   case WebAssembly::COPY_F32:
373   case WebAssembly::COPY_F32_S:
374   case WebAssembly::COPY_F64:
375   case WebAssembly::COPY_F64_S:
376   case WebAssembly::COPY_V128:
377   case WebAssembly::COPY_V128_S:
378   case WebAssembly::COPY_FUNCREF:
379   case WebAssembly::COPY_FUNCREF_S:
380   case WebAssembly::COPY_EXTERNREF:
381   case WebAssembly::COPY_EXTERNREF_S:
382   case WebAssembly::COPY_EXNREF:
383   case WebAssembly::COPY_EXNREF_S:
384     return true;
385   default:
386     return false;
387   }
388 }
389 
isTee(unsigned Opc)390 inline bool isTee(unsigned Opc) {
391   switch (Opc) {
392   case WebAssembly::TEE_I32:
393   case WebAssembly::TEE_I32_S:
394   case WebAssembly::TEE_I64:
395   case WebAssembly::TEE_I64_S:
396   case WebAssembly::TEE_F32:
397   case WebAssembly::TEE_F32_S:
398   case WebAssembly::TEE_F64:
399   case WebAssembly::TEE_F64_S:
400   case WebAssembly::TEE_V128:
401   case WebAssembly::TEE_V128_S:
402   case WebAssembly::TEE_FUNCREF:
403   case WebAssembly::TEE_FUNCREF_S:
404   case WebAssembly::TEE_EXTERNREF:
405   case WebAssembly::TEE_EXTERNREF_S:
406   case WebAssembly::TEE_EXNREF:
407   case WebAssembly::TEE_EXNREF_S:
408     return true;
409   default:
410     return false;
411   }
412 }
413 
isCallDirect(unsigned Opc)414 inline bool isCallDirect(unsigned Opc) {
415   switch (Opc) {
416   case WebAssembly::CALL:
417   case WebAssembly::CALL_S:
418   case WebAssembly::RET_CALL:
419   case WebAssembly::RET_CALL_S:
420     return true;
421   default:
422     return false;
423   }
424 }
425 
isCallIndirect(unsigned Opc)426 inline bool isCallIndirect(unsigned Opc) {
427   switch (Opc) {
428   case WebAssembly::CALL_INDIRECT:
429   case WebAssembly::CALL_INDIRECT_S:
430   case WebAssembly::RET_CALL_INDIRECT:
431   case WebAssembly::RET_CALL_INDIRECT_S:
432     return true;
433   default:
434     return false;
435   }
436 }
437 
isBrTable(unsigned Opc)438 inline bool isBrTable(unsigned Opc) {
439   switch (Opc) {
440   case WebAssembly::BR_TABLE_I32:
441   case WebAssembly::BR_TABLE_I32_S:
442   case WebAssembly::BR_TABLE_I64:
443   case WebAssembly::BR_TABLE_I64_S:
444     return true;
445   default:
446     return false;
447   }
448 }
449 
isMarker(unsigned Opc)450 inline bool isMarker(unsigned Opc) {
451   switch (Opc) {
452   case WebAssembly::BLOCK:
453   case WebAssembly::BLOCK_S:
454   case WebAssembly::END_BLOCK:
455   case WebAssembly::END_BLOCK_S:
456   case WebAssembly::LOOP:
457   case WebAssembly::LOOP_S:
458   case WebAssembly::END_LOOP:
459   case WebAssembly::END_LOOP_S:
460   case WebAssembly::TRY:
461   case WebAssembly::TRY_S:
462   case WebAssembly::END_TRY:
463   case WebAssembly::END_TRY_S:
464   case WebAssembly::TRY_TABLE:
465   case WebAssembly::TRY_TABLE_S:
466   case WebAssembly::END_TRY_TABLE:
467   case WebAssembly::END_TRY_TABLE_S:
468     return true;
469   default:
470     return false;
471   }
472 }
473 
isEndMarker(unsigned Opc)474 inline bool isEndMarker(unsigned Opc) {
475   switch (Opc) {
476   case WebAssembly::END_BLOCK:
477   case WebAssembly::END_BLOCK_S:
478   case WebAssembly::END_LOOP:
479   case WebAssembly::END_LOOP_S:
480   case WebAssembly::END_TRY:
481   case WebAssembly::END_TRY_S:
482   case WebAssembly::END_TRY_TABLE:
483   case WebAssembly::END_TRY_TABLE_S:
484     return true;
485   default:
486     return false;
487   }
488 }
489 
isTry(unsigned Opc)490 inline bool isTry(unsigned Opc) {
491   switch (Opc) {
492   case WebAssembly::TRY:
493   case WebAssembly::TRY_S:
494   case WebAssembly::TRY_TABLE:
495   case WebAssembly::TRY_TABLE_S:
496     return true;
497   default:
498     return false;
499   }
500 }
501 
isCatch(unsigned Opc)502 inline bool isCatch(unsigned Opc) {
503   switch (Opc) {
504   case WebAssembly::CATCH_LEGACY:
505   case WebAssembly::CATCH_LEGACY_S:
506   case WebAssembly::CATCH_ALL_LEGACY:
507   case WebAssembly::CATCH_ALL_LEGACY_S:
508   case WebAssembly::CATCH:
509   case WebAssembly::CATCH_S:
510   case WebAssembly::CATCH_REF:
511   case WebAssembly::CATCH_REF_S:
512   case WebAssembly::CATCH_ALL:
513   case WebAssembly::CATCH_ALL_S:
514   case WebAssembly::CATCH_ALL_REF:
515   case WebAssembly::CATCH_ALL_REF_S:
516     return true;
517   default:
518     return false;
519   }
520 }
521 
isCatchAll(unsigned Opc)522 inline bool isCatchAll(unsigned Opc) {
523   switch (Opc) {
524   case WebAssembly::CATCH_ALL_LEGACY:
525   case WebAssembly::CATCH_ALL_LEGACY_S:
526   case WebAssembly::CATCH_ALL:
527   case WebAssembly::CATCH_ALL_S:
528   case WebAssembly::CATCH_ALL_REF:
529   case WebAssembly::CATCH_ALL_REF_S:
530     return true;
531   default:
532     return false;
533   }
534 }
535 
isLocalGet(unsigned Opc)536 inline bool isLocalGet(unsigned Opc) {
537   switch (Opc) {
538   case WebAssembly::LOCAL_GET_I32:
539   case WebAssembly::LOCAL_GET_I32_S:
540   case WebAssembly::LOCAL_GET_I64:
541   case WebAssembly::LOCAL_GET_I64_S:
542   case WebAssembly::LOCAL_GET_F32:
543   case WebAssembly::LOCAL_GET_F32_S:
544   case WebAssembly::LOCAL_GET_F64:
545   case WebAssembly::LOCAL_GET_F64_S:
546   case WebAssembly::LOCAL_GET_V128:
547   case WebAssembly::LOCAL_GET_V128_S:
548   case WebAssembly::LOCAL_GET_FUNCREF:
549   case WebAssembly::LOCAL_GET_FUNCREF_S:
550   case WebAssembly::LOCAL_GET_EXTERNREF:
551   case WebAssembly::LOCAL_GET_EXTERNREF_S:
552   case WebAssembly::LOCAL_GET_EXNREF:
553   case WebAssembly::LOCAL_GET_EXNREF_S:
554     return true;
555   default:
556     return false;
557   }
558 }
559 
isLocalSet(unsigned Opc)560 inline bool isLocalSet(unsigned Opc) {
561   switch (Opc) {
562   case WebAssembly::LOCAL_SET_I32:
563   case WebAssembly::LOCAL_SET_I32_S:
564   case WebAssembly::LOCAL_SET_I64:
565   case WebAssembly::LOCAL_SET_I64_S:
566   case WebAssembly::LOCAL_SET_F32:
567   case WebAssembly::LOCAL_SET_F32_S:
568   case WebAssembly::LOCAL_SET_F64:
569   case WebAssembly::LOCAL_SET_F64_S:
570   case WebAssembly::LOCAL_SET_V128:
571   case WebAssembly::LOCAL_SET_V128_S:
572   case WebAssembly::LOCAL_SET_FUNCREF:
573   case WebAssembly::LOCAL_SET_FUNCREF_S:
574   case WebAssembly::LOCAL_SET_EXTERNREF:
575   case WebAssembly::LOCAL_SET_EXTERNREF_S:
576   case WebAssembly::LOCAL_SET_EXNREF:
577   case WebAssembly::LOCAL_SET_EXNREF_S:
578     return true;
579   default:
580     return false;
581   }
582 }
583 
isLocalTee(unsigned Opc)584 inline bool isLocalTee(unsigned Opc) {
585   switch (Opc) {
586   case WebAssembly::LOCAL_TEE_I32:
587   case WebAssembly::LOCAL_TEE_I32_S:
588   case WebAssembly::LOCAL_TEE_I64:
589   case WebAssembly::LOCAL_TEE_I64_S:
590   case WebAssembly::LOCAL_TEE_F32:
591   case WebAssembly::LOCAL_TEE_F32_S:
592   case WebAssembly::LOCAL_TEE_F64:
593   case WebAssembly::LOCAL_TEE_F64_S:
594   case WebAssembly::LOCAL_TEE_V128:
595   case WebAssembly::LOCAL_TEE_V128_S:
596   case WebAssembly::LOCAL_TEE_FUNCREF:
597   case WebAssembly::LOCAL_TEE_FUNCREF_S:
598   case WebAssembly::LOCAL_TEE_EXTERNREF:
599   case WebAssembly::LOCAL_TEE_EXTERNREF_S:
600   case WebAssembly::LOCAL_TEE_EXNREF:
601   case WebAssembly::LOCAL_TEE_EXNREF_S:
602     return true;
603   default:
604     return false;
605   }
606 }
607 
608 static const unsigned UnusedReg = -1u;
609 
610 // For a given stackified WAReg, return the id number to print with push/pop.
getWARegStackId(unsigned Reg)611 unsigned inline getWARegStackId(unsigned Reg) {
612   assert(Reg & INT32_MIN);
613   return Reg & INT32_MAX;
614 }
615 
616 } // end namespace WebAssembly
617 } // end namespace llvm
618 
619 #define GET_SUBTARGETINFO_ENUM
620 #include "WebAssemblyGenSubtargetInfo.inc"
621 
622 #endif
623