#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
#include "../WebAssemblySubtarget.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Support/DataTypes.h"
#include <memory>
namespace llvm {
class MCAsmBackend;
class MCCodeEmitter;
class MCInstrInfo;
class MCObjectTargetWriter;
class Triple;
MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
std::unique_ptr<MCObjectTargetWriter>
createWebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten);
namespace WebAssembly {
enum OperandType {
OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
OPERAND_LOCAL,
OPERAND_GLOBAL,
OPERAND_I32IMM,
OPERAND_I64IMM,
OPERAND_F32IMM,
OPERAND_F64IMM,
OPERAND_VEC_I8IMM,
OPERAND_VEC_I16IMM,
OPERAND_VEC_I32IMM,
OPERAND_VEC_I64IMM,
OPERAND_FUNCTION32,
OPERAND_OFFSET32,
OPERAND_OFFSET64,
OPERAND_P2ALIGN,
OPERAND_SIGNATURE,
OPERAND_TYPEINDEX,
OPERAND_TAG,
OPERAND_BRLIST,
OPERAND_TABLE,
};
}
namespace WebAssemblyII {
enum TOF {
MO_NO_FLAG = 0,
MO_GOT,
MO_GOT_TLS,
MO_MEMORY_BASE_REL,
MO_TLS_BASE_REL,
MO_TABLE_BASE_REL,
};
}
}
#define GET_REGINFO_ENUM
#include "WebAssemblyGenRegisterInfo.inc"
#define GET_INSTRINFO_ENUM
#define GET_INSTRINFO_MC_HELPER_DECLS
#include "WebAssemblyGenInstrInfo.inc"
namespace llvm {
namespace WebAssembly {
static const unsigned Nop = 0x01;
static const unsigned End = 0x0b;
inline unsigned GetDefaultP2AlignAny(unsigned Opc) {
switch (Opc) {
#define WASM_LOAD_STORE(NAME) \
case WebAssembly::NAME##_A32: \
case WebAssembly::NAME##_A64: \
case WebAssembly::NAME##_A32_S: \
case WebAssembly::NAME##_A64_S:
WASM_LOAD_STORE(LOAD8_S_I32)
WASM_LOAD_STORE(LOAD8_U_I32)
WASM_LOAD_STORE(LOAD8_S_I64)
WASM_LOAD_STORE(LOAD8_U_I64)
WASM_LOAD_STORE(ATOMIC_LOAD8_U_I32)
WASM_LOAD_STORE(ATOMIC_LOAD8_U_I64)
WASM_LOAD_STORE(STORE8_I32)
WASM_LOAD_STORE(STORE8_I64)
WASM_LOAD_STORE(ATOMIC_STORE8_I32)
WASM_LOAD_STORE(ATOMIC_STORE8_I64)
WASM_LOAD_STORE(ATOMIC_RMW8_U_ADD_I32)
WASM_LOAD_STORE(ATOMIC_RMW8_U_ADD_I64)
WASM_LOAD_STORE(ATOMIC_RMW8_U_SUB_I32)
WASM_LOAD_STORE(ATOMIC_RMW8_U_SUB_I64)
WASM_LOAD_STORE(ATOMIC_RMW8_U_AND_I32)
WASM_LOAD_STORE(ATOMIC_RMW8_U_AND_I64)
WASM_LOAD_STORE(ATOMIC_RMW8_U_OR_I32)
WASM_LOAD_STORE(ATOMIC_RMW8_U_OR_I64)
WASM_LOAD_STORE(ATOMIC_RMW8_U_XOR_I32)
WASM_LOAD_STORE(ATOMIC_RMW8_U_XOR_I64)
WASM_LOAD_STORE(ATOMIC_RMW8_U_XCHG_I32)
WASM_LOAD_STORE(ATOMIC_RMW8_U_XCHG_I64)
WASM_LOAD_STORE(ATOMIC_RMW8_U_CMPXCHG_I32)
WASM_LOAD_STORE(ATOMIC_RMW8_U_CMPXCHG_I64)
WASM_LOAD_STORE(LOAD8_SPLAT)
WASM_LOAD_STORE(LOAD_LANE_I8x16)
WASM_LOAD_STORE(STORE_LANE_I8x16)
return 0;
WASM_LOAD_STORE(LOAD16_S_I32)
WASM_LOAD_STORE(LOAD16_U_I32)
WASM_LOAD_STORE(LOAD16_S_I64)
WASM_LOAD_STORE(LOAD16_U_I64)
WASM_LOAD_STORE(ATOMIC_LOAD16_U_I32)
WASM_LOAD_STORE(ATOMIC_LOAD16_U_I64)
WASM_LOAD_STORE(STORE16_I32)
WASM_LOAD_STORE(STORE16_I64)
WASM_LOAD_STORE(ATOMIC_STORE16_I32)
WASM_LOAD_STORE(ATOMIC_STORE16_I64)
WASM_LOAD_STORE(ATOMIC_RMW16_U_ADD_I32)
WASM_LOAD_STORE(ATOMIC_RMW16_U_ADD_I64)
WASM_LOAD_STORE(ATOMIC_RMW16_U_SUB_I32)
WASM_LOAD_STORE(ATOMIC_RMW16_U_SUB_I64)
WASM_LOAD_STORE(ATOMIC_RMW16_U_AND_I32)
WASM_LOAD_STORE(ATOMIC_RMW16_U_AND_I64)
WASM_LOAD_STORE(ATOMIC_RMW16_U_OR_I32)
WASM_LOAD_STORE(ATOMIC_RMW16_U_OR_I64)
WASM_LOAD_STORE(ATOMIC_RMW16_U_XOR_I32)
WASM_LOAD_STORE(ATOMIC_RMW16_U_XOR_I64)
WASM_LOAD_STORE(ATOMIC_RMW16_U_XCHG_I32)
WASM_LOAD_STORE(ATOMIC_RMW16_U_XCHG_I64)
WASM_LOAD_STORE(ATOMIC_RMW16_U_CMPXCHG_I32)
WASM_LOAD_STORE(ATOMIC_RMW16_U_CMPXCHG_I64)
WASM_LOAD_STORE(LOAD16_SPLAT)
WASM_LOAD_STORE(LOAD_LANE_I16x8)
WASM_LOAD_STORE(STORE_LANE_I16x8)
return 1;
WASM_LOAD_STORE(LOAD_I32)
WASM_LOAD_STORE(LOAD_F32)
WASM_LOAD_STORE(STORE_I32)
WASM_LOAD_STORE(STORE_F32)
WASM_LOAD_STORE(LOAD32_S_I64)
WASM_LOAD_STORE(LOAD32_U_I64)
WASM_LOAD_STORE(STORE32_I64)
WASM_LOAD_STORE(ATOMIC_LOAD_I32)
WASM_LOAD_STORE(ATOMIC_LOAD32_U_I64)
WASM_LOAD_STORE(ATOMIC_STORE_I32)
WASM_LOAD_STORE(ATOMIC_STORE32_I64)
WASM_LOAD_STORE(ATOMIC_RMW_ADD_I32)
WASM_LOAD_STORE(ATOMIC_RMW32_U_ADD_I64)
WASM_LOAD_STORE(ATOMIC_RMW_SUB_I32)
WASM_LOAD_STORE(ATOMIC_RMW32_U_SUB_I64)
WASM_LOAD_STORE(ATOMIC_RMW_AND_I32)
WASM_LOAD_STORE(ATOMIC_RMW32_U_AND_I64)
WASM_LOAD_STORE(ATOMIC_RMW_OR_I32)
WASM_LOAD_STORE(ATOMIC_RMW32_U_OR_I64)
WASM_LOAD_STORE(ATOMIC_RMW_XOR_I32)
WASM_LOAD_STORE(ATOMIC_RMW32_U_XOR_I64)
WASM_LOAD_STORE(ATOMIC_RMW_XCHG_I32)
WASM_LOAD_STORE(ATOMIC_RMW32_U_XCHG_I64)
WASM_LOAD_STORE(ATOMIC_RMW_CMPXCHG_I32)
WASM_LOAD_STORE(ATOMIC_RMW32_U_CMPXCHG_I64)
WASM_LOAD_STORE(MEMORY_ATOMIC_NOTIFY)
WASM_LOAD_STORE(MEMORY_ATOMIC_WAIT32)
WASM_LOAD_STORE(LOAD32_SPLAT)
WASM_LOAD_STORE(LOAD_ZERO_I32x4)
WASM_LOAD_STORE(LOAD_LANE_I32x4)
WASM_LOAD_STORE(STORE_LANE_I32x4)
return 2;
WASM_LOAD_STORE(LOAD_I64)
WASM_LOAD_STORE(LOAD_F64)
WASM_LOAD_STORE(STORE_I64)
WASM_LOAD_STORE(STORE_F64)
WASM_LOAD_STORE(ATOMIC_LOAD_I64)
WASM_LOAD_STORE(ATOMIC_STORE_I64)
WASM_LOAD_STORE(ATOMIC_RMW_ADD_I64)
WASM_LOAD_STORE(ATOMIC_RMW_SUB_I64)
WASM_LOAD_STORE(ATOMIC_RMW_AND_I64)
WASM_LOAD_STORE(ATOMIC_RMW_OR_I64)
WASM_LOAD_STORE(ATOMIC_RMW_XOR_I64)
WASM_LOAD_STORE(ATOMIC_RMW_XCHG_I64)
WASM_LOAD_STORE(ATOMIC_RMW_CMPXCHG_I64)
WASM_LOAD_STORE(MEMORY_ATOMIC_WAIT64)
WASM_LOAD_STORE(LOAD64_SPLAT)
WASM_LOAD_STORE(LOAD_EXTEND_S_I16x8)
WASM_LOAD_STORE(LOAD_EXTEND_U_I16x8)
WASM_LOAD_STORE(LOAD_EXTEND_S_I32x4)
WASM_LOAD_STORE(LOAD_EXTEND_U_I32x4)
WASM_LOAD_STORE(LOAD_EXTEND_S_I64x2)
WASM_LOAD_STORE(LOAD_EXTEND_U_I64x2)
WASM_LOAD_STORE(LOAD_ZERO_I64x2)
WASM_LOAD_STORE(LOAD_LANE_I64x2)
WASM_LOAD_STORE(STORE_LANE_I64x2)
return 3;
WASM_LOAD_STORE(LOAD_V128)
WASM_LOAD_STORE(STORE_V128)
return 4;
default:
return -1;
}
#undef WASM_LOAD_STORE
}
inline unsigned GetDefaultP2Align(unsigned Opc) {
auto Align = GetDefaultP2AlignAny(Opc);
if (Align == -1U) {
llvm_unreachable("Only loads and stores have p2align values");
}
return Align;
}
inline bool isArgument(unsigned Opc) {
switch (Opc) {
case WebAssembly::ARGUMENT_i32:
case WebAssembly::ARGUMENT_i32_S:
case WebAssembly::ARGUMENT_i64:
case WebAssembly::ARGUMENT_i64_S:
case WebAssembly::ARGUMENT_f32:
case WebAssembly::ARGUMENT_f32_S:
case WebAssembly::ARGUMENT_f64:
case WebAssembly::ARGUMENT_f64_S:
case WebAssembly::ARGUMENT_v16i8:
case WebAssembly::ARGUMENT_v16i8_S:
case WebAssembly::ARGUMENT_v8i16:
case WebAssembly::ARGUMENT_v8i16_S:
case WebAssembly::ARGUMENT_v4i32:
case WebAssembly::ARGUMENT_v4i32_S:
case WebAssembly::ARGUMENT_v2i64:
case WebAssembly::ARGUMENT_v2i64_S:
case WebAssembly::ARGUMENT_v4f32:
case WebAssembly::ARGUMENT_v4f32_S:
case WebAssembly::ARGUMENT_v2f64:
case WebAssembly::ARGUMENT_v2f64_S:
case WebAssembly::ARGUMENT_funcref:
case WebAssembly::ARGUMENT_funcref_S:
case WebAssembly::ARGUMENT_externref:
case WebAssembly::ARGUMENT_externref_S:
return true;
default:
return false;
}
}
inline bool isCopy(unsigned Opc) {
switch (Opc) {
case WebAssembly::COPY_I32:
case WebAssembly::COPY_I32_S:
case WebAssembly::COPY_I64:
case WebAssembly::COPY_I64_S:
case WebAssembly::COPY_F32:
case WebAssembly::COPY_F32_S:
case WebAssembly::COPY_F64:
case WebAssembly::COPY_F64_S:
case WebAssembly::COPY_V128:
case WebAssembly::COPY_V128_S:
case WebAssembly::COPY_FUNCREF:
case WebAssembly::COPY_FUNCREF_S:
case WebAssembly::COPY_EXTERNREF:
case WebAssembly::COPY_EXTERNREF_S:
return true;
default:
return false;
}
}
inline bool isTee(unsigned Opc) {
switch (Opc) {
case WebAssembly::TEE_I32:
case WebAssembly::TEE_I32_S:
case WebAssembly::TEE_I64:
case WebAssembly::TEE_I64_S:
case WebAssembly::TEE_F32:
case WebAssembly::TEE_F32_S:
case WebAssembly::TEE_F64:
case WebAssembly::TEE_F64_S:
case WebAssembly::TEE_V128:
case WebAssembly::TEE_V128_S:
case WebAssembly::TEE_FUNCREF:
case WebAssembly::TEE_FUNCREF_S:
case WebAssembly::TEE_EXTERNREF:
case WebAssembly::TEE_EXTERNREF_S:
return true;
default:
return false;
}
}
inline bool isCallDirect(unsigned Opc) {
switch (Opc) {
case WebAssembly::CALL:
case WebAssembly::CALL_S:
case WebAssembly::RET_CALL:
case WebAssembly::RET_CALL_S:
return true;
default:
return false;
}
}
inline bool isCallIndirect(unsigned Opc) {
switch (Opc) {
case WebAssembly::CALL_INDIRECT:
case WebAssembly::CALL_INDIRECT_S:
case WebAssembly::RET_CALL_INDIRECT:
case WebAssembly::RET_CALL_INDIRECT_S:
return true;
default:
return false;
}
}
inline bool isBrTable(const MachineInstr &MI) {
switch (MI.getOpcode()) {
case WebAssembly::BR_TABLE_I32:
case WebAssembly::BR_TABLE_I32_S:
case WebAssembly::BR_TABLE_I64:
case WebAssembly::BR_TABLE_I64_S:
return true;
default:
return false;
}
}
inline bool isMarker(unsigned Opc) {
switch (Opc) {
case WebAssembly::BLOCK:
case WebAssembly::BLOCK_S:
case WebAssembly::END_BLOCK:
case WebAssembly::END_BLOCK_S:
case WebAssembly::LOOP:
case WebAssembly::LOOP_S:
case WebAssembly::END_LOOP:
case WebAssembly::END_LOOP_S:
case WebAssembly::TRY:
case WebAssembly::TRY_S:
case WebAssembly::END_TRY:
case WebAssembly::END_TRY_S:
return true;
default:
return false;
}
}
inline bool isCatch(unsigned Opc) {
switch (Opc) {
case WebAssembly::CATCH:
case WebAssembly::CATCH_S:
case WebAssembly::CATCH_ALL:
case WebAssembly::CATCH_ALL_S:
return true;
default:
return false;
}
}
} }
#endif