LLVM  5.0.0
WebAssemblyMCTargetDesc.h
Go to the documentation of this file.
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/BinaryFormat/Wasm.h"
19 #include "llvm/MC/MCInstrDesc.h"
20 #include "llvm/Support/DataTypes.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 
37 
38 MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
39 
40 MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
41 
42 MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
43  bool Is64Bit, uint8_t OSABI);
44 
45 MCObjectWriter *createWebAssemblyWasmObjectWriter(raw_pwrite_stream &OS,
46  bool Is64Bit);
47 
48 namespace WebAssembly {
50  /// Basic block label in a branch construct.
52  /// Local index.
54  /// Global index.
56  /// 32-bit integer immediates.
58  /// 64-bit integer immediates.
60  /// 32-bit floating-point immediates.
62  /// 64-bit floating-point immediates.
64  /// 32-bit unsigned function indices.
66  /// 32-bit unsigned memory offsets.
68  /// p2align immediate for load and store address alignment.
70  /// signature immediate for block/loop.
72  /// type signature immediate for call_indirect.
74 };
75 } // end namespace WebAssembly
76 
77 namespace WebAssemblyII {
78 enum {
79  // For variadic instructions, this flag indicates whether an operand
80  // in the variable_ops range is an immediate value.
82  // For immediate values in the variable_ops range, this flag indicates
83  // whether the value represents a control-flow label.
85 };
86 } // end namespace WebAssemblyII
87 
88 } // end namespace llvm
89 
90 // Defines symbolic names for WebAssembly registers. This defines a mapping from
91 // register name to register number.
92 //
93 #define GET_REGINFO_ENUM
94 #include "WebAssemblyGenRegisterInfo.inc"
95 
96 // Defines symbolic names for the WebAssembly instructions.
97 //
98 #define GET_INSTRINFO_ENUM
99 #include "WebAssemblyGenInstrInfo.inc"
100 
101 #define GET_SUBTARGETINFO_ENUM
102 #include "WebAssemblyGenSubtargetInfo.inc"
103 
104 namespace llvm {
105 namespace WebAssembly {
106 
107 /// Return the default p2align value for a load or store with the given opcode.
108 inline 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:
114  case WebAssembly::STORE8_I32:
115  case WebAssembly::STORE8_I64:
116  return 0;
117  case WebAssembly::LOAD16_S_I32:
118  case WebAssembly::LOAD16_U_I32:
119  case WebAssembly::LOAD16_S_I64:
120  case WebAssembly::LOAD16_U_I64:
121  case WebAssembly::STORE16_I32:
122  case WebAssembly::STORE16_I64:
123  return 1;
124  case WebAssembly::LOAD_I32:
125  case WebAssembly::LOAD_F32:
126  case WebAssembly::STORE_I32:
127  case WebAssembly::STORE_F32:
128  case WebAssembly::LOAD32_S_I64:
129  case WebAssembly::LOAD32_U_I64:
130  case WebAssembly::STORE32_I64:
131  return 2;
132  case WebAssembly::LOAD_I64:
133  case WebAssembly::LOAD_F64:
134  case WebAssembly::STORE_I64:
135  case WebAssembly::STORE_F64:
136  return 3;
137  default:
138  llvm_unreachable("Only loads and stores have p2align values");
139  }
140 }
141 
142 /// The operand number of the load or store address in load/store instructions.
143 static const unsigned LoadAddressOperandNo = 3;
144 static const unsigned StoreAddressOperandNo = 2;
145 
146 /// The operand number of the load or store p2align in load/store instructions.
147 static const unsigned LoadP2AlignOperandNo = 1;
148 static const unsigned StoreP2AlignOperandNo = 0;
149 
150 /// This is used to indicate block signatures.
151 enum class ExprType {
152  Void = -0x40,
153  I32 = -0x01,
154  I64 = -0x02,
155  F32 = -0x03,
156  F64 = -0x04,
157  I8x16 = -0x05,
158  I16x8 = -0x06,
159  I32x4 = -0x07,
160  F32x4 = -0x08,
161  B8x16 = -0x09,
162  B16x8 = -0x0a,
163  B32x4 = -0x0b
164 };
165 
166 /// Instruction opcodes emitted via means other than CodeGen.
167 static const unsigned Nop = 0x01;
168 static const unsigned End = 0x0b;
169 
170 wasm::ValType toValType(const MVT &Ty);
171 
172 } // end namespace WebAssembly
173 } // end namespace llvm
174 
175 #endif
static const unsigned LoadP2AlignOperandNo
The operand number of the load or store p2align in load/store instructions.
32-bit floating-point immediates.
static const unsigned LoadAddressOperandNo
The operand number of the load or store address in load/store instructions.
MCObjectWriter * createWebAssemblyWasmObjectWriter(raw_pwrite_stream &OS, bool Is64Bit)
32-bit unsigned memory offsets.
Basic block label in a branch construct.
static const unsigned StoreP2AlignOperandNo
signature immediate for block/loop.
ExprType
This is used to indicate block signatures.
wasm::ValType toValType(const MVT &Ty)
Machine Value Type.
MCCodeEmitter * createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII)
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.
static const char * Target
MCAsmBackend * createWebAssemblyAsmBackend(const Triple &TT)
MCObjectWriter * createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS, bool Is64Bit, uint8_t OSABI)
static const unsigned StoreAddressOperandNo
64-bit floating-point immediates.
32-bit unsigned function indices.
llvm_unreachable("Unknown RegBank!")
p2align immediate for load and store address alignment.
static const unsigned Nop
Instruction opcodes emitted via means other than CodeGen.
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()