blob: 2d6821fad8e48d6e8bd9cead7b5be31dd82be378 [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 Gohman3acb1872016-10-24 23:27:49 +000029class MVT;
Dan Gohman10e730a2015-06-29 23:51:55 +000030class Target;
31class Triple;
Dan Gohman53828fd2015-11-23 16:50:18 +000032class raw_pwrite_stream;
Dan Gohman10e730a2015-06-29 23:51:55 +000033
Mehdi Aminif42454b2016-10-09 23:00:34 +000034Target &getTheWebAssemblyTarget32();
35Target &getTheWebAssemblyTarget64();
Dan Gohman10e730a2015-06-29 23:51:55 +000036
Dan Gohmancff79832016-01-19 21:31:41 +000037MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
Dan Gohman53828fd2015-11-23 16:50:18 +000038
Dan Gohmancceedf72016-01-08 00:43:54 +000039MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
Dan Gohman10e730a2015-06-29 23:51:55 +000040
Dan Gohman05ac43f2015-12-17 01:39:00 +000041MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
42 bool Is64Bit, uint8_t OSABI);
43
Dan Gohmana11fb232016-01-12 03:09:16 +000044namespace WebAssembly {
45enum OperandType {
46 /// Basic block label in a branch construct.
47 OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
Dan Gohman4fc4e422016-10-24 19:49:43 +000048 /// Local index.
49 OPERAND_LOCAL,
Dan Gohman5a68ec72016-10-05 21:24:08 +000050 /// 32-bit integer immediates.
51 OPERAND_I32IMM,
52 /// 64-bit integer immediates.
53 OPERAND_I64IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000054 /// 32-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000055 OPERAND_F32IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000056 /// 64-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000057 OPERAND_F64IMM,
Dan Gohmanbb372242016-01-26 03:39:31 +000058 /// p2align immediate for load and store address alignment.
Dan Gohman2726b882016-10-06 22:29:32 +000059 OPERAND_P2ALIGN,
60 /// signature immediate for block/loop.
61 OPERAND_SIGNATURE
Dan Gohmana11fb232016-01-12 03:09:16 +000062};
63} // end namespace WebAssembly
64
65namespace WebAssemblyII {
66enum {
67 // For variadic instructions, this flag indicates whether an operand
68 // in the variable_ops range is an immediate value.
Dan Gohman3469ee12016-01-12 20:30:51 +000069 VariableOpIsImmediate = (1 << 0),
Dan Gohman1d68e80f2016-01-12 19:14:46 +000070 // For immediate values in the variable_ops range, this flag indicates
71 // whether the value represents a control-flow label.
Dan Gohman3acb1872016-10-24 23:27:49 +000072 VariableOpImmediateIsLabel = (1 << 1)
Dan Gohmana11fb232016-01-12 03:09:16 +000073};
74} // end namespace WebAssemblyII
75
Dan Gohman10e730a2015-06-29 23:51:55 +000076} // end namespace llvm
77
78// Defines symbolic names for WebAssembly registers. This defines a mapping from
79// register name to register number.
80//
JF Bastien5ca0bac2015-07-10 18:23:10 +000081#define GET_REGINFO_ENUM
82#include "WebAssemblyGenRegisterInfo.inc"
83
JF Bastienb9073fb2015-07-22 21:28:15 +000084// Defines symbolic names for the WebAssembly instructions.
85//
86#define GET_INSTRINFO_ENUM
87#include "WebAssemblyGenInstrInfo.inc"
88
Dan Gohman10e730a2015-06-29 23:51:55 +000089#define GET_SUBTARGETINFO_ENUM
90#include "WebAssemblyGenSubtargetInfo.inc"
91
Dan Gohmanbb372242016-01-26 03:39:31 +000092namespace llvm {
93namespace WebAssembly {
94
95/// Return the default p2align value for a load or store with the given opcode.
96inline unsigned GetDefaultP2Align(unsigned Opcode) {
97 switch (Opcode) {
98 case WebAssembly::LOAD8_S_I32:
99 case WebAssembly::LOAD8_U_I32:
100 case WebAssembly::LOAD8_S_I64:
101 case WebAssembly::LOAD8_U_I64:
102 case WebAssembly::STORE8_I32:
103 case WebAssembly::STORE8_I64:
104 return 0;
105 case WebAssembly::LOAD16_S_I32:
106 case WebAssembly::LOAD16_U_I32:
107 case WebAssembly::LOAD16_S_I64:
108 case WebAssembly::LOAD16_U_I64:
109 case WebAssembly::STORE16_I32:
110 case WebAssembly::STORE16_I64:
111 return 1;
112 case WebAssembly::LOAD_I32:
113 case WebAssembly::LOAD_F32:
114 case WebAssembly::STORE_I32:
115 case WebAssembly::STORE_F32:
116 case WebAssembly::LOAD32_S_I64:
117 case WebAssembly::LOAD32_U_I64:
118 case WebAssembly::STORE32_I64:
119 return 2;
120 case WebAssembly::LOAD_I64:
121 case WebAssembly::LOAD_F64:
122 case WebAssembly::STORE_I64:
123 case WebAssembly::STORE_F64:
124 return 3;
Derek Schuffc64d7652016-08-01 22:25:02 +0000125 default:
126 llvm_unreachable("Only loads and stores have p2align values");
Dan Gohmanbb372242016-01-26 03:39:31 +0000127 }
128}
129
Derek Schuffc97ba932016-01-30 21:43:08 +0000130/// The operand number of the load or store address in load/store instructions.
Dan Gohman48abaa92016-10-25 00:17:11 +0000131static const unsigned LoadAddressOperandNo = 3;
132static const unsigned StoreAddressOperandNo = 2;
Dan Gohman7f1bdb22016-10-06 22:08:28 +0000133
134/// The operand number of the load or store p2align in load/store instructions.
Dan Gohman48abaa92016-10-25 00:17:11 +0000135static const unsigned LoadP2AlignOperandNo = 1;
136static const unsigned StoreP2AlignOperandNo = 0;
Dan Gohmanbb372242016-01-26 03:39:31 +0000137
Dan Gohman2726b882016-10-06 22:29:32 +0000138/// This is used to indicate block signatures.
Dan Gohman4fc4e422016-10-24 19:49:43 +0000139enum class ExprType {
Dan Gohman3acb1872016-10-24 23:27:49 +0000140 Void = 0x40,
141 I32 = 0x7f,
142 I64 = 0x7e,
143 F32 = 0x7d,
144 F64 = 0x7c,
145 I8x16 = 0x7b,
146 I16x8 = 0x7a,
147 I32x4 = 0x79,
148 F32x4 = 0x78,
149 B8x16 = 0x77,
150 B16x8 = 0x76,
151 B32x4 = 0x75
Dan Gohman2726b882016-10-06 22:29:32 +0000152};
153
Dan Gohman4fc4e422016-10-24 19:49:43 +0000154/// This is used to indicate local types.
155enum class ValType {
Dan Gohman3acb1872016-10-24 23:27:49 +0000156 I32 = 0x7f,
157 I64 = 0x7e,
158 F32 = 0x7d,
159 F64 = 0x7c,
160 I8x16 = 0x7b,
161 I16x8 = 0x7a,
162 I32x4 = 0x79,
163 F32x4 = 0x78,
164 B8x16 = 0x77,
165 B16x8 = 0x76,
166 B32x4 = 0x75
Dan Gohman4fc4e422016-10-24 19:49:43 +0000167};
168
Dan Gohman3acb1872016-10-24 23:27:49 +0000169/// Instruction opcodes emitted via means other than CodeGen.
170static const unsigned Nop = 0x01;
171static const unsigned End = 0x0b;
172
173ValType toValType(const MVT &Ty);
174
Dan Gohmanbb372242016-01-26 03:39:31 +0000175} // end namespace WebAssembly
176} // end namespace llvm
177
Dan Gohman10e730a2015-06-29 23:51:55 +0000178#endif