1 //==- WebAssemblyMCTargetDesc.h - WebAssembly Target Descriptions -*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file provides WebAssembly-specific target descriptions.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
18 #include "llvm/MC/MCInstrDesc.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/Wasm.h"
29 class MCSubtargetInfo;
33 class raw_pwrite_stream;
35 Target &getTheWebAssemblyTarget32();
36 Target &getTheWebAssemblyTarget64();
38 MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII,
41 MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
43 MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
44 bool Is64Bit, uint8_t OSABI);
46 MCObjectWriter *createWebAssemblyWasmObjectWriter(raw_pwrite_stream &OS,
49 namespace WebAssembly {
51 /// Basic block label in a branch construct.
52 OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
57 /// 32-bit integer immediates.
59 /// 64-bit integer immediates.
61 /// 32-bit floating-point immediates.
63 /// 64-bit floating-point immediates.
65 /// 32-bit unsigned function indices.
67 /// 32-bit unsigned memory offsets.
69 /// p2align immediate for load and store address alignment.
71 /// signature immediate for block/loop.
73 /// type signature immediate for call_indirect.
76 } // end namespace WebAssembly
78 namespace WebAssemblyII {
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)
87 } // end namespace WebAssemblyII
89 } // end namespace llvm
91 // Defines symbolic names for WebAssembly registers. This defines a mapping from
92 // register name to register number.
94 #define GET_REGINFO_ENUM
95 #include "WebAssemblyGenRegisterInfo.inc"
97 // Defines symbolic names for the WebAssembly instructions.
99 #define GET_INSTRINFO_ENUM
100 #include "WebAssemblyGenInstrInfo.inc"
102 #define GET_SUBTARGETINFO_ENUM
103 #include "WebAssemblyGenSubtargetInfo.inc"
106 namespace WebAssembly {
108 /// Return the default p2align value for a load or store with the given opcode.
109 inline unsigned GetDefaultP2Align(unsigned 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:
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:
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:
133 case WebAssembly::LOAD_I64:
134 case WebAssembly::LOAD_F64:
135 case WebAssembly::STORE_I64:
136 case WebAssembly::STORE_F64:
139 llvm_unreachable("Only loads and stores have p2align values");
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;
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;
151 /// This is used to indicate block signatures.
152 enum class ExprType {
167 /// Instruction opcodes emitted via means other than CodeGen.
168 static const unsigned Nop = 0x01;
169 static const unsigned End = 0x0b;
171 wasm::ValType toValType(const MVT &Ty);
173 } // end namespace WebAssembly
174 } // end namespace llvm