blob: 6efa7080cfec5a0b65acf23f3d9b3fb6b4e4724c [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//==- WebAssemblyMCTargetDesc.h - WebAssembly Target Descriptions -*- C++ -*-=//
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 This file provides WebAssembly-specific target descriptions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
16#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
17
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"
Dan Gohman10e730a2015-06-29 23:51:55 +000021
22namespace llvm {
23
Dan Gohman10e730a2015-06-29 23:51:55 +000024class MCAsmBackend;
25class MCCodeEmitter;
26class MCContext;
27class MCInstrInfo;
Dan Gohman10e730a2015-06-29 23:51:55 +000028class MCObjectWriter;
Dan Gohman10e730a2015-06-29 23:51:55 +000029class MCSubtargetInfo;
Dan Gohman3acb1872016-10-24 23:27:49 +000030class MVT;
Dan Gohman10e730a2015-06-29 23:51:55 +000031class Target;
32class Triple;
Dan Gohman53828fd2015-11-23 16:50:18 +000033class raw_pwrite_stream;
Dan Gohman10e730a2015-06-29 23:51:55 +000034
Mehdi Aminif42454b2016-10-09 23:00:34 +000035Target &getTheWebAssemblyTarget32();
36Target &getTheWebAssemblyTarget64();
Dan Gohman10e730a2015-06-29 23:51:55 +000037
Sam Clegg9d24fb72017-06-16 23:59:10 +000038MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
Dan Gohman53828fd2015-11-23 16:50:18 +000039
Dan Gohmancceedf72016-01-08 00:43:54 +000040MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
Dan Gohman10e730a2015-06-29 23:51:55 +000041
Dan Gohman05ac43f2015-12-17 01:39:00 +000042MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
43 bool Is64Bit, uint8_t OSABI);
44
Dan Gohman18eafb62017-02-22 01:23:18 +000045MCObjectWriter *createWebAssemblyWasmObjectWriter(raw_pwrite_stream &OS,
46 bool Is64Bit);
47
Dan Gohmana11fb232016-01-12 03:09:16 +000048namespace WebAssembly {
49enum OperandType {
50 /// Basic block label in a branch construct.
51 OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
Dan Gohman4fc4e422016-10-24 19:49:43 +000052 /// Local index.
53 OPERAND_LOCAL,
Dan Gohmanb89f2d32017-02-02 19:29:44 +000054 /// Global index.
55 OPERAND_GLOBAL,
Dan Gohman5a68ec72016-10-05 21:24:08 +000056 /// 32-bit integer immediates.
57 OPERAND_I32IMM,
58 /// 64-bit integer immediates.
59 OPERAND_I64IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000060 /// 32-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000061 OPERAND_F32IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000062 /// 64-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000063 OPERAND_F64IMM,
Dan Gohman00d734d2016-12-23 03:23:52 +000064 /// 32-bit unsigned function indices.
65 OPERAND_FUNCTION32,
66 /// 32-bit unsigned memory offsets.
67 OPERAND_OFFSET32,
Dan Gohmanbb372242016-01-26 03:39:31 +000068 /// p2align immediate for load and store address alignment.
Dan Gohman2726b882016-10-06 22:29:32 +000069 OPERAND_P2ALIGN,
70 /// signature immediate for block/loop.
Dan Gohmand934cb82017-02-24 23:18:00 +000071 OPERAND_SIGNATURE,
72 /// type signature immediate for call_indirect.
73 OPERAND_TYPEINDEX,
Dan Gohmana11fb232016-01-12 03:09:16 +000074};
75} // end namespace WebAssembly
76
77namespace WebAssemblyII {
78enum {
79 // For variadic instructions, this flag indicates whether an operand
80 // in the variable_ops range is an immediate value.
Dan Gohman3469ee12016-01-12 20:30:51 +000081 VariableOpIsImmediate = (1 << 0),
Dan Gohman1d68e80f2016-01-12 19:14:46 +000082 // For immediate values in the variable_ops range, this flag indicates
83 // whether the value represents a control-flow label.
Dan Gohman3acb1872016-10-24 23:27:49 +000084 VariableOpImmediateIsLabel = (1 << 1)
Dan Gohmana11fb232016-01-12 03:09:16 +000085};
86} // end namespace WebAssemblyII
87
Dan Gohman10e730a2015-06-29 23:51:55 +000088} // end namespace llvm
89
90// Defines symbolic names for WebAssembly registers. This defines a mapping from
91// register name to register number.
92//
JF Bastien5ca0bac2015-07-10 18:23:10 +000093#define GET_REGINFO_ENUM
94#include "WebAssemblyGenRegisterInfo.inc"
95
JF Bastienb9073fb2015-07-22 21:28:15 +000096// Defines symbolic names for the WebAssembly instructions.
97//
98#define GET_INSTRINFO_ENUM
99#include "WebAssemblyGenInstrInfo.inc"
100
Dan Gohman10e730a2015-06-29 23:51:55 +0000101#define GET_SUBTARGETINFO_ENUM
102#include "WebAssemblyGenSubtargetInfo.inc"
103
Dan Gohmanbb372242016-01-26 03:39:31 +0000104namespace llvm {
105namespace WebAssembly {
106
107/// Return the default p2align value for a load or store with the given opcode.
108inline unsigned GetDefaultP2Align(unsigned Opcode) {
109 switch (Opcode) {
110 case WebAssembly::LOAD8_S_I32:
111 case WebAssembly::LOAD8_U_I32:
112 case WebAssembly::LOAD8_S_I64:
113 case WebAssembly::LOAD8_U_I64:
Derek Schuff885dc592017-10-05 21:18:42 +0000114 case WebAssembly::ATOMIC_LOAD8_U_I32:
115 case WebAssembly::ATOMIC_LOAD8_U_I64:
Dan Gohmanbb372242016-01-26 03:39:31 +0000116 case WebAssembly::STORE8_I32:
117 case WebAssembly::STORE8_I64:
118 return 0;
119 case WebAssembly::LOAD16_S_I32:
120 case WebAssembly::LOAD16_U_I32:
121 case WebAssembly::LOAD16_S_I64:
122 case WebAssembly::LOAD16_U_I64:
Derek Schuff885dc592017-10-05 21:18:42 +0000123 case WebAssembly::ATOMIC_LOAD16_U_I32:
124 case WebAssembly::ATOMIC_LOAD16_U_I64:
Dan Gohmanbb372242016-01-26 03:39:31 +0000125 case WebAssembly::STORE16_I32:
126 case WebAssembly::STORE16_I64:
127 return 1;
128 case WebAssembly::LOAD_I32:
129 case WebAssembly::LOAD_F32:
130 case WebAssembly::STORE_I32:
131 case WebAssembly::STORE_F32:
132 case WebAssembly::LOAD32_S_I64:
133 case WebAssembly::LOAD32_U_I64:
134 case WebAssembly::STORE32_I64:
Derek Schuff18ba1922017-08-30 18:07:45 +0000135 case WebAssembly::ATOMIC_LOAD_I32:
Derek Schuff885dc592017-10-05 21:18:42 +0000136 case WebAssembly::ATOMIC_LOAD32_U_I64:
Dan Gohmanbb372242016-01-26 03:39:31 +0000137 return 2;
138 case WebAssembly::LOAD_I64:
139 case WebAssembly::LOAD_F64:
140 case WebAssembly::STORE_I64:
141 case WebAssembly::STORE_F64:
Derek Schuff885dc592017-10-05 21:18:42 +0000142 case WebAssembly::ATOMIC_LOAD_I64:
Dan Gohmanbb372242016-01-26 03:39:31 +0000143 return 3;
Derek Schuffc64d7652016-08-01 22:25:02 +0000144 default:
145 llvm_unreachable("Only loads and stores have p2align values");
Dan Gohmanbb372242016-01-26 03:39:31 +0000146 }
147}
148
Derek Schuffc97ba932016-01-30 21:43:08 +0000149/// The operand number of the load or store address in load/store instructions.
Dan Gohman48abaa92016-10-25 00:17:11 +0000150static const unsigned LoadAddressOperandNo = 3;
151static const unsigned StoreAddressOperandNo = 2;
Dan Gohman7f1bdb22016-10-06 22:08:28 +0000152
153/// The operand number of the load or store p2align in load/store instructions.
Dan Gohman48abaa92016-10-25 00:17:11 +0000154static const unsigned LoadP2AlignOperandNo = 1;
155static const unsigned StoreP2AlignOperandNo = 0;
Dan Gohmanbb372242016-01-26 03:39:31 +0000156
Dan Gohman2726b882016-10-06 22:29:32 +0000157/// This is used to indicate block signatures.
Dan Gohman4fc4e422016-10-24 19:49:43 +0000158enum class ExprType {
Derek Schuffe2688c42017-03-14 20:23:22 +0000159 Void = -0x40,
160 I32 = -0x01,
161 I64 = -0x02,
162 F32 = -0x03,
163 F64 = -0x04,
164 I8x16 = -0x05,
165 I16x8 = -0x06,
166 I32x4 = -0x07,
167 F32x4 = -0x08,
168 B8x16 = -0x09,
169 B16x8 = -0x0a,
170 B32x4 = -0x0b
Dan Gohman4fc4e422016-10-24 19:49:43 +0000171};
172
Dan Gohman3acb1872016-10-24 23:27:49 +0000173/// Instruction opcodes emitted via means other than CodeGen.
174static const unsigned Nop = 0x01;
175static const unsigned End = 0x0b;
176
Derek Schuffe2688c42017-03-14 20:23:22 +0000177wasm::ValType toValType(const MVT &Ty);
Dan Gohman3acb1872016-10-24 23:27:49 +0000178
Dan Gohmanbb372242016-01-26 03:39:31 +0000179} // end namespace WebAssembly
180} // end namespace llvm
181
Dan Gohman10e730a2015-06-29 23:51:55 +0000182#endif