]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r303197, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / WebAssembly / MCTargetDesc / WebAssemblyMCTargetDesc.h
1 //==- 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
18 #include "llvm/MC/MCInstrDesc.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/Wasm.h"
21
22 namespace llvm {
23
24 class MCAsmBackend;
25 class MCCodeEmitter;
26 class MCContext;
27 class MCInstrInfo;
28 class MCObjectWriter;
29 class MCSubtargetInfo;
30 class MVT;
31 class Target;
32 class Triple;
33 class raw_pwrite_stream;
34
35 Target &getTheWebAssemblyTarget32();
36 Target &getTheWebAssemblyTarget64();
37
38 MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII,
39                                               MCContext &Ctx);
40
41 MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
42
43 MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
44                                                  bool Is64Bit, uint8_t OSABI);
45
46 MCObjectWriter *createWebAssemblyWasmObjectWriter(raw_pwrite_stream &OS,
47                                                   bool Is64Bit);
48
49 namespace WebAssembly {
50 enum OperandType {
51   /// Basic block label in a branch construct.
52   OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
53   /// Local index.
54   OPERAND_LOCAL,
55   /// Global index.
56   OPERAND_GLOBAL,
57   /// 32-bit integer immediates.
58   OPERAND_I32IMM,
59   /// 64-bit integer immediates.
60   OPERAND_I64IMM,
61   /// 32-bit floating-point immediates.
62   OPERAND_F32IMM,
63   /// 64-bit floating-point immediates.
64   OPERAND_F64IMM,
65   /// 32-bit unsigned function indices.
66   OPERAND_FUNCTION32,
67   /// 32-bit unsigned memory offsets.
68   OPERAND_OFFSET32,
69   /// p2align immediate for load and store address alignment.
70   OPERAND_P2ALIGN,
71   /// signature immediate for block/loop.
72   OPERAND_SIGNATURE,
73   /// type signature immediate for call_indirect.
74   OPERAND_TYPEINDEX,
75 };
76 } // end namespace WebAssembly
77
78 namespace WebAssemblyII {
79 enum {
80   // For variadic instructions, this flag indicates whether an operand
81   // in the variable_ops range is an immediate value.
82   VariableOpIsImmediate = (1 << 0),
83   // For immediate values in the variable_ops range, this flag indicates
84   // whether the value represents a control-flow label.
85   VariableOpImmediateIsLabel = (1 << 1)
86 };
87 } // end namespace WebAssemblyII
88
89 } // end namespace llvm
90
91 // Defines symbolic names for WebAssembly registers. This defines a mapping from
92 // register name to register number.
93 //
94 #define GET_REGINFO_ENUM
95 #include "WebAssemblyGenRegisterInfo.inc"
96
97 // Defines symbolic names for the WebAssembly instructions.
98 //
99 #define GET_INSTRINFO_ENUM
100 #include "WebAssemblyGenInstrInfo.inc"
101
102 #define GET_SUBTARGETINFO_ENUM
103 #include "WebAssemblyGenSubtargetInfo.inc"
104
105 namespace llvm {
106 namespace WebAssembly {
107
108 /// Return the default p2align value for a load or store with the given opcode.
109 inline 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;
138   default:
139     llvm_unreachable("Only loads and stores have p2align values");
140   }
141 }
142
143 /// The operand number of the load or store address in load/store instructions.
144 static const unsigned LoadAddressOperandNo = 3;
145 static const unsigned StoreAddressOperandNo = 2;
146
147 /// The operand number of the load or store p2align in load/store instructions.
148 static const unsigned LoadP2AlignOperandNo = 1;
149 static const unsigned StoreP2AlignOperandNo = 0;
150
151 /// This is used to indicate block signatures.
152 enum class ExprType {
153   Void    = -0x40,
154   I32     = -0x01,
155   I64     = -0x02,
156   F32     = -0x03,
157   F64     = -0x04,
158   I8x16   = -0x05,
159   I16x8   = -0x06,
160   I32x4   = -0x07,
161   F32x4   = -0x08,
162   B8x16   = -0x09,
163   B16x8   = -0x0a,
164   B32x4   = -0x0b
165 };
166
167 /// Instruction opcodes emitted via means other than CodeGen.
168 static const unsigned Nop = 0x01;
169 static const unsigned End = 0x0b;
170
171 wasm::ValType toValType(const MVT &Ty);
172
173 } // end namespace WebAssembly
174 } // end namespace llvm
175
176 #endif