blob: 5fa277324d60fb0533e0389f9c513638da7bcb67 [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
Dan Gohmana11fb232016-01-12 03:09:16 +000018#include "llvm/MC/MCInstrDesc.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000019#include "llvm/Support/DataTypes.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000020
21namespace llvm {
22
Dan Gohman10e730a2015-06-29 23:51:55 +000023class MCAsmBackend;
24class MCCodeEmitter;
25class MCContext;
26class MCInstrInfo;
Dan Gohman10e730a2015-06-29 23:51:55 +000027class MCObjectWriter;
Dan Gohman10e730a2015-06-29 23:51:55 +000028class MCSubtargetInfo;
Dan Gohman10e730a2015-06-29 23:51:55 +000029class Target;
30class Triple;
Dan Gohman53828fd2015-11-23 16:50:18 +000031class raw_pwrite_stream;
Dan Gohman10e730a2015-06-29 23:51:55 +000032
Mehdi Aminif42454b2016-10-09 23:00:34 +000033Target &getTheWebAssemblyTarget32();
34Target &getTheWebAssemblyTarget64();
Dan Gohman10e730a2015-06-29 23:51:55 +000035
Dan Gohmancff79832016-01-19 21:31:41 +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
Dan Gohman05ac43f2015-12-17 01:39:00 +000040MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
41 bool Is64Bit, uint8_t OSABI);
42
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 Gohman5a68ec72016-10-05 21:24:08 +000049 /// 32-bit integer immediates.
50 OPERAND_I32IMM,
51 /// 64-bit integer immediates.
52 OPERAND_I64IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000053 /// 32-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000054 OPERAND_F32IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000055 /// 64-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000056 OPERAND_F64IMM,
Dan Gohmanbb372242016-01-26 03:39:31 +000057 /// p2align immediate for load and store address alignment.
Dan Gohman2726b882016-10-06 22:29:32 +000058 OPERAND_P2ALIGN,
59 /// signature immediate for block/loop.
60 OPERAND_SIGNATURE
Dan Gohmana11fb232016-01-12 03:09:16 +000061};
Dan Gohman3469ee12016-01-12 20:30:51 +000062
63/// WebAssembly-specific directive identifiers.
64enum Directive {
65 // FIXME: This is not the real binary encoding.
66 DotParam = UINT64_MAX - 0, ///< .param
67 DotResult = UINT64_MAX - 1, ///< .result
68 DotLocal = UINT64_MAX - 2, ///< .local
69 DotEndFunc = UINT64_MAX - 3, ///< .endfunc
Dan Gohman2726b882016-10-06 22:29:32 +000070 DotIndIdx = UINT64_MAX - 4, ///< .indidx
Dan Gohman3469ee12016-01-12 20:30:51 +000071};
72
Dan Gohmana11fb232016-01-12 03:09:16 +000073} // end namespace WebAssembly
74
75namespace WebAssemblyII {
76enum {
77 // For variadic instructions, this flag indicates whether an operand
78 // in the variable_ops range is an immediate value.
Dan Gohman3469ee12016-01-12 20:30:51 +000079 VariableOpIsImmediate = (1 << 0),
Dan Gohman1d68e80f2016-01-12 19:14:46 +000080 // For immediate values in the variable_ops range, this flag indicates
81 // whether the value represents a control-flow label.
Dan Gohman3469ee12016-01-12 20:30:51 +000082 VariableOpImmediateIsLabel = (1 << 1),
Dan Gohman4fc4e422016-10-24 19:49:43 +000083 // For immediate values in the variable_ops range, this flag indicates
84 // whether the value represents a ValType.
85 VariableOpImmediateIsType = (1 << 2),
Dan Gohmana11fb232016-01-12 03:09:16 +000086};
87} // end namespace WebAssemblyII
88
Dan Gohman10e730a2015-06-29 23:51:55 +000089} // end namespace llvm
90
91// Defines symbolic names for WebAssembly registers. This defines a mapping from
92// register name to register number.
93//
JF Bastien5ca0bac2015-07-10 18:23:10 +000094#define GET_REGINFO_ENUM
95#include "WebAssemblyGenRegisterInfo.inc"
96
JF Bastienb9073fb2015-07-22 21:28:15 +000097// Defines symbolic names for the WebAssembly instructions.
98//
99#define GET_INSTRINFO_ENUM
100#include "WebAssemblyGenInstrInfo.inc"
101
Dan Gohman10e730a2015-06-29 23:51:55 +0000102#define GET_SUBTARGETINFO_ENUM
103#include "WebAssemblyGenSubtargetInfo.inc"
104
Dan Gohmanbb372242016-01-26 03:39:31 +0000105namespace llvm {
106namespace WebAssembly {
107
108/// Return the default p2align value for a load or store with the given opcode.
109inline unsigned GetDefaultP2Align(unsigned Opcode) {
110 switch (Opcode) {
111 case WebAssembly::LOAD8_S_I32:
112 case WebAssembly::LOAD8_U_I32:
113 case WebAssembly::LOAD8_S_I64:
114 case WebAssembly::LOAD8_U_I64:
115 case WebAssembly::STORE8_I32:
116 case WebAssembly::STORE8_I64:
117 return 0;
118 case WebAssembly::LOAD16_S_I32:
119 case WebAssembly::LOAD16_U_I32:
120 case WebAssembly::LOAD16_S_I64:
121 case WebAssembly::LOAD16_U_I64:
122 case WebAssembly::STORE16_I32:
123 case WebAssembly::STORE16_I64:
124 return 1;
125 case WebAssembly::LOAD_I32:
126 case WebAssembly::LOAD_F32:
127 case WebAssembly::STORE_I32:
128 case WebAssembly::STORE_F32:
129 case WebAssembly::LOAD32_S_I64:
130 case WebAssembly::LOAD32_U_I64:
131 case WebAssembly::STORE32_I64:
132 return 2;
133 case WebAssembly::LOAD_I64:
134 case WebAssembly::LOAD_F64:
135 case WebAssembly::STORE_I64:
136 case WebAssembly::STORE_F64:
137 return 3;
Derek Schuffc64d7652016-08-01 22:25:02 +0000138 default:
139 llvm_unreachable("Only loads and stores have p2align values");
Dan Gohmanbb372242016-01-26 03:39:31 +0000140 }
141}
142
Derek Schuffc97ba932016-01-30 21:43:08 +0000143/// The operand number of the load or store address in load/store instructions.
Dan Gohman7f1bdb22016-10-06 22:08:28 +0000144static const unsigned LoadAddressOperandNo = 2;
145static const unsigned StoreAddressOperandNo = 1;
146
147/// The operand number of the load or store p2align in load/store instructions.
148static const unsigned LoadP2AlignOperandNo = 3;
149static const unsigned StoreP2AlignOperandNo = 2;
Dan Gohmanbb372242016-01-26 03:39:31 +0000150
Dan Gohman2726b882016-10-06 22:29:32 +0000151/// This is used to indicate block signatures.
Dan Gohman4fc4e422016-10-24 19:49:43 +0000152enum class ExprType {
Dan Gohman2726b882016-10-06 22:29:32 +0000153 Void = 0,
154 I32 = 1,
155 I64 = 2,
156 F32 = 3,
157 F64 = 4,
158 I8x16 = 5,
159 I16x8 = 6,
160 I32x4 = 7,
161 I64x2 = 8,
162 F32x4 = 9,
163 F64x2 = 10
164};
165
Dan Gohman4fc4e422016-10-24 19:49:43 +0000166/// This is used to indicate local types.
167enum class ValType {
168 I32 = 1,
169 I64 = 2,
170 F32 = 3,
171 F64 = 4,
172 I8x16 = 5,
173 I16x8 = 6,
174 I32x4 = 7,
175 I64x2 = 8,
176 F32x4 = 9,
177 F64x2 = 10
178};
179
Dan Gohmanbb372242016-01-26 03:39:31 +0000180} // end namespace WebAssembly
181} // end namespace llvm
182
Dan Gohman10e730a2015-06-29 23:51:55 +0000183#endif