LLVM  9.0.0svn
WebAssemblyMCTargetDesc.h
Go to the documentation of this file.
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 "../WebAssemblySubtarget.h"
18 #include "llvm/BinaryFormat/Wasm.h"
19 #include "llvm/MC/MCInstrDesc.h"
20 #include "llvm/Support/DataTypes.h"
21 #include <memory>
22 
23 namespace llvm {
24 
25 class MCAsmBackend;
26 class MCCodeEmitter;
27 class MCContext;
28 class MCInstrInfo;
29 class MCObjectTargetWriter;
30 class MCSubtargetInfo;
31 class MVT;
32 class Target;
33 class Triple;
34 class raw_pwrite_stream;
35 
38 
39 MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
40 
41 MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
42 
43 std::unique_ptr<MCObjectTargetWriter>
45 
46 namespace WebAssembly {
48  /// Basic block label in a branch construct.
50  /// Local index.
52  /// Global index.
54  /// 32-bit integer immediates.
56  /// 64-bit integer immediates.
58  /// 32-bit floating-point immediates.
60  /// 64-bit floating-point immediates.
62  /// 8-bit vector lane immediate
64  /// 16-bit vector lane immediate
66  /// 32-bit vector lane immediate
68  /// 64-bit vector lane immediate
70  /// 32-bit unsigned function indices.
72  /// 32-bit unsigned memory offsets.
74  /// p2align immediate for load and store address alignment.
76  /// signature immediate for block/loop.
78  /// type signature immediate for call_indirect.
80  /// Event index.
82  /// A list of branch targets for br_list.
84 };
85 } // end namespace WebAssembly
86 
87 namespace WebAssemblyII {
88 
89 /// Target Operand Flag enum.
90 enum TOF {
92 
93  // On a symbol operand this indicates that the immediate is a wasm global
94  // index. The value of the wasm global will be set to the symbol address at
95  // runtime. This adds a level of indirection similar to the GOT on native
96  // platforms.
98 
99  // On a symbol operand this indicates that the immediate is the symbol
100  // address relative the __memory_base wasm global.
101  // Only applicable to data symbols.
103 
104  // On a symbol operand this indicates that the immediate is the symbol
105  // address relative the __table_base wasm global.
106  // Only applicable to function symbols.
108 };
109 
110 } // end namespace WebAssemblyII
111 
112 } // end namespace llvm
113 
114 // Defines symbolic names for WebAssembly registers. This defines a mapping from
115 // register name to register number.
116 //
117 #define GET_REGINFO_ENUM
118 #include "WebAssemblyGenRegisterInfo.inc"
119 
120 // Defines symbolic names for the WebAssembly instructions.
121 //
122 #define GET_INSTRINFO_ENUM
123 #include "WebAssemblyGenInstrInfo.inc"
124 
125 namespace llvm {
126 namespace WebAssembly {
127 
128 /// Return the default p2align value for a load or store with the given opcode.
129 inline unsigned GetDefaultP2Align(unsigned Opcode) {
130  switch (Opcode) {
131  case WebAssembly::LOAD8_S_I32:
132  case WebAssembly::LOAD8_S_I32_S:
133  case WebAssembly::LOAD8_U_I32:
134  case WebAssembly::LOAD8_U_I32_S:
135  case WebAssembly::LOAD8_S_I64:
136  case WebAssembly::LOAD8_S_I64_S:
137  case WebAssembly::LOAD8_U_I64:
138  case WebAssembly::LOAD8_U_I64_S:
139  case WebAssembly::ATOMIC_LOAD8_U_I32:
140  case WebAssembly::ATOMIC_LOAD8_U_I32_S:
141  case WebAssembly::ATOMIC_LOAD8_U_I64:
142  case WebAssembly::ATOMIC_LOAD8_U_I64_S:
143  case WebAssembly::STORE8_I32:
144  case WebAssembly::STORE8_I32_S:
145  case WebAssembly::STORE8_I64:
146  case WebAssembly::STORE8_I64_S:
147  case WebAssembly::ATOMIC_STORE8_I32:
148  case WebAssembly::ATOMIC_STORE8_I32_S:
149  case WebAssembly::ATOMIC_STORE8_I64:
150  case WebAssembly::ATOMIC_STORE8_I64_S:
151  case WebAssembly::ATOMIC_RMW8_U_ADD_I32:
152  case WebAssembly::ATOMIC_RMW8_U_ADD_I32_S:
153  case WebAssembly::ATOMIC_RMW8_U_ADD_I64:
154  case WebAssembly::ATOMIC_RMW8_U_ADD_I64_S:
155  case WebAssembly::ATOMIC_RMW8_U_SUB_I32:
156  case WebAssembly::ATOMIC_RMW8_U_SUB_I32_S:
157  case WebAssembly::ATOMIC_RMW8_U_SUB_I64:
158  case WebAssembly::ATOMIC_RMW8_U_SUB_I64_S:
159  case WebAssembly::ATOMIC_RMW8_U_AND_I32:
160  case WebAssembly::ATOMIC_RMW8_U_AND_I32_S:
161  case WebAssembly::ATOMIC_RMW8_U_AND_I64:
162  case WebAssembly::ATOMIC_RMW8_U_AND_I64_S:
163  case WebAssembly::ATOMIC_RMW8_U_OR_I32:
164  case WebAssembly::ATOMIC_RMW8_U_OR_I32_S:
165  case WebAssembly::ATOMIC_RMW8_U_OR_I64:
166  case WebAssembly::ATOMIC_RMW8_U_OR_I64_S:
167  case WebAssembly::ATOMIC_RMW8_U_XOR_I32:
168  case WebAssembly::ATOMIC_RMW8_U_XOR_I32_S:
169  case WebAssembly::ATOMIC_RMW8_U_XOR_I64:
170  case WebAssembly::ATOMIC_RMW8_U_XOR_I64_S:
171  case WebAssembly::ATOMIC_RMW8_U_XCHG_I32:
172  case WebAssembly::ATOMIC_RMW8_U_XCHG_I32_S:
173  case WebAssembly::ATOMIC_RMW8_U_XCHG_I64:
174  case WebAssembly::ATOMIC_RMW8_U_XCHG_I64_S:
175  case WebAssembly::ATOMIC_RMW8_U_CMPXCHG_I32:
176  case WebAssembly::ATOMIC_RMW8_U_CMPXCHG_I32_S:
177  case WebAssembly::ATOMIC_RMW8_U_CMPXCHG_I64:
178  case WebAssembly::ATOMIC_RMW8_U_CMPXCHG_I64_S:
179  return 0;
180  case WebAssembly::LOAD16_S_I32:
181  case WebAssembly::LOAD16_S_I32_S:
182  case WebAssembly::LOAD16_U_I32:
183  case WebAssembly::LOAD16_U_I32_S:
184  case WebAssembly::LOAD16_S_I64:
185  case WebAssembly::LOAD16_S_I64_S:
186  case WebAssembly::LOAD16_U_I64:
187  case WebAssembly::LOAD16_U_I64_S:
188  case WebAssembly::ATOMIC_LOAD16_U_I32:
189  case WebAssembly::ATOMIC_LOAD16_U_I32_S:
190  case WebAssembly::ATOMIC_LOAD16_U_I64:
191  case WebAssembly::ATOMIC_LOAD16_U_I64_S:
192  case WebAssembly::STORE16_I32:
193  case WebAssembly::STORE16_I32_S:
194  case WebAssembly::STORE16_I64:
195  case WebAssembly::STORE16_I64_S:
196  case WebAssembly::ATOMIC_STORE16_I32:
197  case WebAssembly::ATOMIC_STORE16_I32_S:
198  case WebAssembly::ATOMIC_STORE16_I64:
199  case WebAssembly::ATOMIC_STORE16_I64_S:
200  case WebAssembly::ATOMIC_RMW16_U_ADD_I32:
201  case WebAssembly::ATOMIC_RMW16_U_ADD_I32_S:
202  case WebAssembly::ATOMIC_RMW16_U_ADD_I64:
203  case WebAssembly::ATOMIC_RMW16_U_ADD_I64_S:
204  case WebAssembly::ATOMIC_RMW16_U_SUB_I32:
205  case WebAssembly::ATOMIC_RMW16_U_SUB_I32_S:
206  case WebAssembly::ATOMIC_RMW16_U_SUB_I64:
207  case WebAssembly::ATOMIC_RMW16_U_SUB_I64_S:
208  case WebAssembly::ATOMIC_RMW16_U_AND_I32:
209  case WebAssembly::ATOMIC_RMW16_U_AND_I32_S:
210  case WebAssembly::ATOMIC_RMW16_U_AND_I64:
211  case WebAssembly::ATOMIC_RMW16_U_AND_I64_S:
212  case WebAssembly::ATOMIC_RMW16_U_OR_I32:
213  case WebAssembly::ATOMIC_RMW16_U_OR_I32_S:
214  case WebAssembly::ATOMIC_RMW16_U_OR_I64:
215  case WebAssembly::ATOMIC_RMW16_U_OR_I64_S:
216  case WebAssembly::ATOMIC_RMW16_U_XOR_I32:
217  case WebAssembly::ATOMIC_RMW16_U_XOR_I32_S:
218  case WebAssembly::ATOMIC_RMW16_U_XOR_I64:
219  case WebAssembly::ATOMIC_RMW16_U_XOR_I64_S:
220  case WebAssembly::ATOMIC_RMW16_U_XCHG_I32:
221  case WebAssembly::ATOMIC_RMW16_U_XCHG_I32_S:
222  case WebAssembly::ATOMIC_RMW16_U_XCHG_I64:
223  case WebAssembly::ATOMIC_RMW16_U_XCHG_I64_S:
224  case WebAssembly::ATOMIC_RMW16_U_CMPXCHG_I32:
225  case WebAssembly::ATOMIC_RMW16_U_CMPXCHG_I32_S:
226  case WebAssembly::ATOMIC_RMW16_U_CMPXCHG_I64:
227  case WebAssembly::ATOMIC_RMW16_U_CMPXCHG_I64_S:
228  return 1;
229  case WebAssembly::LOAD_I32:
230  case WebAssembly::LOAD_I32_S:
231  case WebAssembly::LOAD_F32:
232  case WebAssembly::LOAD_F32_S:
233  case WebAssembly::STORE_I32:
234  case WebAssembly::STORE_I32_S:
235  case WebAssembly::STORE_F32:
236  case WebAssembly::STORE_F32_S:
237  case WebAssembly::LOAD32_S_I64:
238  case WebAssembly::LOAD32_S_I64_S:
239  case WebAssembly::LOAD32_U_I64:
240  case WebAssembly::LOAD32_U_I64_S:
241  case WebAssembly::STORE32_I64:
242  case WebAssembly::STORE32_I64_S:
243  case WebAssembly::ATOMIC_LOAD_I32:
244  case WebAssembly::ATOMIC_LOAD_I32_S:
245  case WebAssembly::ATOMIC_LOAD32_U_I64:
246  case WebAssembly::ATOMIC_LOAD32_U_I64_S:
247  case WebAssembly::ATOMIC_STORE_I32:
248  case WebAssembly::ATOMIC_STORE_I32_S:
249  case WebAssembly::ATOMIC_STORE32_I64:
250  case WebAssembly::ATOMIC_STORE32_I64_S:
251  case WebAssembly::ATOMIC_RMW_ADD_I32:
252  case WebAssembly::ATOMIC_RMW_ADD_I32_S:
253  case WebAssembly::ATOMIC_RMW32_U_ADD_I64:
254  case WebAssembly::ATOMIC_RMW32_U_ADD_I64_S:
255  case WebAssembly::ATOMIC_RMW_SUB_I32:
256  case WebAssembly::ATOMIC_RMW_SUB_I32_S:
257  case WebAssembly::ATOMIC_RMW32_U_SUB_I64:
258  case WebAssembly::ATOMIC_RMW32_U_SUB_I64_S:
259  case WebAssembly::ATOMIC_RMW_AND_I32:
260  case WebAssembly::ATOMIC_RMW_AND_I32_S:
261  case WebAssembly::ATOMIC_RMW32_U_AND_I64:
262  case WebAssembly::ATOMIC_RMW32_U_AND_I64_S:
263  case WebAssembly::ATOMIC_RMW_OR_I32:
264  case WebAssembly::ATOMIC_RMW_OR_I32_S:
265  case WebAssembly::ATOMIC_RMW32_U_OR_I64:
266  case WebAssembly::ATOMIC_RMW32_U_OR_I64_S:
267  case WebAssembly::ATOMIC_RMW_XOR_I32:
268  case WebAssembly::ATOMIC_RMW_XOR_I32_S:
269  case WebAssembly::ATOMIC_RMW32_U_XOR_I64:
270  case WebAssembly::ATOMIC_RMW32_U_XOR_I64_S:
271  case WebAssembly::ATOMIC_RMW_XCHG_I32:
272  case WebAssembly::ATOMIC_RMW_XCHG_I32_S:
273  case WebAssembly::ATOMIC_RMW32_U_XCHG_I64:
274  case WebAssembly::ATOMIC_RMW32_U_XCHG_I64_S:
275  case WebAssembly::ATOMIC_RMW_CMPXCHG_I32:
276  case WebAssembly::ATOMIC_RMW_CMPXCHG_I32_S:
277  case WebAssembly::ATOMIC_RMW32_U_CMPXCHG_I64:
278  case WebAssembly::ATOMIC_RMW32_U_CMPXCHG_I64_S:
279  case WebAssembly::ATOMIC_NOTIFY:
280  case WebAssembly::ATOMIC_NOTIFY_S:
281  case WebAssembly::ATOMIC_WAIT_I32:
282  case WebAssembly::ATOMIC_WAIT_I32_S:
283  return 2;
284  case WebAssembly::LOAD_I64:
285  case WebAssembly::LOAD_I64_S:
286  case WebAssembly::LOAD_F64:
287  case WebAssembly::LOAD_F64_S:
288  case WebAssembly::STORE_I64:
289  case WebAssembly::STORE_I64_S:
290  case WebAssembly::STORE_F64:
291  case WebAssembly::STORE_F64_S:
292  case WebAssembly::ATOMIC_LOAD_I64:
293  case WebAssembly::ATOMIC_LOAD_I64_S:
294  case WebAssembly::ATOMIC_STORE_I64:
295  case WebAssembly::ATOMIC_STORE_I64_S:
296  case WebAssembly::ATOMIC_RMW_ADD_I64:
297  case WebAssembly::ATOMIC_RMW_ADD_I64_S:
298  case WebAssembly::ATOMIC_RMW_SUB_I64:
299  case WebAssembly::ATOMIC_RMW_SUB_I64_S:
300  case WebAssembly::ATOMIC_RMW_AND_I64:
301  case WebAssembly::ATOMIC_RMW_AND_I64_S:
302  case WebAssembly::ATOMIC_RMW_OR_I64:
303  case WebAssembly::ATOMIC_RMW_OR_I64_S:
304  case WebAssembly::ATOMIC_RMW_XOR_I64:
305  case WebAssembly::ATOMIC_RMW_XOR_I64_S:
306  case WebAssembly::ATOMIC_RMW_XCHG_I64:
307  case WebAssembly::ATOMIC_RMW_XCHG_I64_S:
308  case WebAssembly::ATOMIC_RMW_CMPXCHG_I64:
309  case WebAssembly::ATOMIC_RMW_CMPXCHG_I64_S:
310  case WebAssembly::ATOMIC_WAIT_I64:
311  case WebAssembly::ATOMIC_WAIT_I64_S:
312  return 3;
313  case WebAssembly::LOAD_v16i8:
314  case WebAssembly::LOAD_v16i8_S:
315  case WebAssembly::LOAD_v8i16:
316  case WebAssembly::LOAD_v8i16_S:
317  case WebAssembly::LOAD_v4i32:
318  case WebAssembly::LOAD_v4i32_S:
319  case WebAssembly::LOAD_v2i64:
320  case WebAssembly::LOAD_v2i64_S:
321  case WebAssembly::LOAD_v4f32:
322  case WebAssembly::LOAD_v4f32_S:
323  case WebAssembly::LOAD_v2f64:
324  case WebAssembly::LOAD_v2f64_S:
325  case WebAssembly::STORE_v16i8:
326  case WebAssembly::STORE_v16i8_S:
327  case WebAssembly::STORE_v8i16:
328  case WebAssembly::STORE_v8i16_S:
329  case WebAssembly::STORE_v4i32:
330  case WebAssembly::STORE_v4i32_S:
331  case WebAssembly::STORE_v2i64:
332  case WebAssembly::STORE_v2i64_S:
333  case WebAssembly::STORE_v4f32:
334  case WebAssembly::STORE_v4f32_S:
335  case WebAssembly::STORE_v2f64:
336  case WebAssembly::STORE_v2f64_S:
337  return 4;
338  default:
339  llvm_unreachable("Only loads and stores have p2align values");
340  }
341 }
342 
343 /// This is used to indicate block signatures.
344 enum class ExprType : unsigned {
345  Void = 0x40,
346  I32 = 0x7F,
347  I64 = 0x7E,
348  F32 = 0x7D,
349  F64 = 0x7C,
350  V128 = 0x7B,
351  ExceptRef = 0x68,
352  Invalid = 0x00
353 };
354 
355 /// Instruction opcodes emitted via means other than CodeGen.
356 static const unsigned Nop = 0x01;
357 static const unsigned End = 0x0b;
358 
359 wasm::ValType toValType(const MVT &Ty);
360 
361 } // end namespace WebAssembly
362 } // end namespace llvm
363 
364 #endif
32-bit floating-point immediates.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
std::unique_ptr< MCObjectTargetWriter > createWebAssemblyWasmObjectWriter(bool Is64Bit)
32-bit unsigned memory offsets.
Basic block label in a branch construct.
A list of branch targets for br_list.
signature immediate for block/loop.
wasm::ValType toValType(const MVT &Ty)
Machine Value Type.
MCCodeEmitter * createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII)
TOF
Target Operand Flag enum.
static const unsigned End
unsigned GetDefaultP2Align(unsigned Opcode)
Return the default p2align value for a load or store with the given opcode.
type signature immediate for call_indirect.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ExprType
This is used to indicate block signatures.
MCAsmBackend * createWebAssemblyAsmBackend(const Triple &TT)
64-bit floating-point immediates.
32-bit unsigned function indices.
p2align immediate for load and store address alignment.
static const unsigned Nop
Instruction opcodes emitted via means other than CodeGen.
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()