2015-06-30 07:51:55 +08:00
|
|
|
//==- WebAssemblyMCTargetDesc.h - WebAssembly Target Descriptions -*- C++ -*-=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file provides WebAssembly-specific target descriptions.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
|
|
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
|
|
|
|
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Wasm.h"
|
2016-01-12 11:09:16 +08:00
|
|
|
#include "llvm/MC/MCInstrDesc.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2017-10-11 01:31:43 +08:00
|
|
|
#include <memory>
|
2015-06-30 07:51:55 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class MCAsmBackend;
|
|
|
|
class MCCodeEmitter;
|
|
|
|
class MCContext;
|
|
|
|
class MCInstrInfo;
|
|
|
|
class MCObjectWriter;
|
|
|
|
class MCSubtargetInfo;
|
2016-10-25 07:27:49 +08:00
|
|
|
class MVT;
|
2015-06-30 07:51:55 +08:00
|
|
|
class Target;
|
|
|
|
class Triple;
|
2015-11-24 00:50:18 +08:00
|
|
|
class raw_pwrite_stream;
|
2015-06-30 07:51:55 +08:00
|
|
|
|
2016-10-10 07:00:34 +08:00
|
|
|
Target &getTheWebAssemblyTarget32();
|
|
|
|
Target &getTheWebAssemblyTarget64();
|
2015-06-30 07:51:55 +08:00
|
|
|
|
2017-06-17 07:59:10 +08:00
|
|
|
MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
|
2015-11-24 00:50:18 +08:00
|
|
|
|
2016-01-08 08:43:54 +08:00
|
|
|
MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
|
2015-06-30 07:51:55 +08:00
|
|
|
|
2017-10-11 01:31:43 +08:00
|
|
|
std::unique_ptr<MCObjectWriter>
|
|
|
|
createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
|
|
|
|
bool Is64Bit, uint8_t OSABI);
|
2015-12-17 09:39:00 +08:00
|
|
|
|
2017-10-11 01:31:43 +08:00
|
|
|
std::unique_ptr<MCObjectWriter>
|
|
|
|
createWebAssemblyWasmObjectWriter(raw_pwrite_stream &OS,
|
|
|
|
bool Is64Bit);
|
2017-02-22 09:23:18 +08:00
|
|
|
|
2016-01-12 11:09:16 +08:00
|
|
|
namespace WebAssembly {
|
|
|
|
enum OperandType {
|
|
|
|
/// Basic block label in a branch construct.
|
|
|
|
OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
|
2016-10-25 03:49:43 +08:00
|
|
|
/// Local index.
|
|
|
|
OPERAND_LOCAL,
|
2017-02-03 03:29:44 +08:00
|
|
|
/// Global index.
|
|
|
|
OPERAND_GLOBAL,
|
2016-10-06 05:24:08 +08:00
|
|
|
/// 32-bit integer immediates.
|
|
|
|
OPERAND_I32IMM,
|
|
|
|
/// 64-bit integer immediates.
|
|
|
|
OPERAND_I64IMM,
|
2016-02-16 23:14:23 +08:00
|
|
|
/// 32-bit floating-point immediates.
|
2016-10-04 05:31:31 +08:00
|
|
|
OPERAND_F32IMM,
|
2016-02-16 23:14:23 +08:00
|
|
|
/// 64-bit floating-point immediates.
|
2016-10-04 05:31:31 +08:00
|
|
|
OPERAND_F64IMM,
|
2016-12-23 11:23:52 +08:00
|
|
|
/// 32-bit unsigned function indices.
|
|
|
|
OPERAND_FUNCTION32,
|
|
|
|
/// 32-bit unsigned memory offsets.
|
|
|
|
OPERAND_OFFSET32,
|
2016-01-26 11:39:31 +08:00
|
|
|
/// p2align immediate for load and store address alignment.
|
2016-10-07 06:29:32 +08:00
|
|
|
OPERAND_P2ALIGN,
|
|
|
|
/// signature immediate for block/loop.
|
2017-02-25 07:18:00 +08:00
|
|
|
OPERAND_SIGNATURE,
|
|
|
|
/// type signature immediate for call_indirect.
|
|
|
|
OPERAND_TYPEINDEX,
|
2016-01-12 11:09:16 +08:00
|
|
|
};
|
|
|
|
} // end namespace WebAssembly
|
|
|
|
|
|
|
|
namespace WebAssemblyII {
|
|
|
|
enum {
|
|
|
|
// For variadic instructions, this flag indicates whether an operand
|
|
|
|
// in the variable_ops range is an immediate value.
|
2016-01-13 04:30:51 +08:00
|
|
|
VariableOpIsImmediate = (1 << 0),
|
[WebAssembly] Make CFG stackification independent of basic-block labels.
This patch changes the way labels are referenced. Instead of referencing the
basic-block label name (eg. .LBB0_0), instructions now just have an immediate
which indicates the depth in the control-flow stack to find a label to jump to.
This makes them much closer to what we expect to have in the binary encoding,
and avoids the problem of basic-block label names not being explicit in the
binary encoding.
Also, it terminates blocks and loops with end_block and end_loop instructions,
rather than basic-block label names, for similar reasons.
This will also fix problems where two constructs appear to have the same label,
because we no longer explicitly use labels, so consumers that need labels will
presumably create their own labels, and presumably they won't reuse labels
when they do.
This patch does make the code a little more awkward to read; as a partial
mitigation, this patch also introduces comments showing where the labels are,
and comments on each branch showing where it's branching to.
llvm-svn: 257505
2016-01-13 03:14:46 +08:00
|
|
|
// For immediate values in the variable_ops range, this flag indicates
|
|
|
|
// whether the value represents a control-flow label.
|
2016-10-25 07:27:49 +08:00
|
|
|
VariableOpImmediateIsLabel = (1 << 1)
|
2016-01-12 11:09:16 +08:00
|
|
|
};
|
|
|
|
} // end namespace WebAssemblyII
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
// Defines symbolic names for WebAssembly registers. This defines a mapping from
|
|
|
|
// register name to register number.
|
|
|
|
//
|
2015-07-11 02:23:10 +08:00
|
|
|
#define GET_REGINFO_ENUM
|
|
|
|
#include "WebAssemblyGenRegisterInfo.inc"
|
|
|
|
|
2015-07-23 05:28:15 +08:00
|
|
|
// Defines symbolic names for the WebAssembly instructions.
|
|
|
|
//
|
|
|
|
#define GET_INSTRINFO_ENUM
|
|
|
|
#include "WebAssemblyGenInstrInfo.inc"
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
#define GET_SUBTARGETINFO_ENUM
|
|
|
|
#include "WebAssemblyGenSubtargetInfo.inc"
|
|
|
|
|
2016-01-26 11:39:31 +08:00
|
|
|
namespace llvm {
|
|
|
|
namespace WebAssembly {
|
|
|
|
|
|
|
|
/// Return the default p2align value for a load or store with the given opcode.
|
|
|
|
inline unsigned GetDefaultP2Align(unsigned Opcode) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case WebAssembly::LOAD8_S_I32:
|
|
|
|
case WebAssembly::LOAD8_U_I32:
|
|
|
|
case WebAssembly::LOAD8_S_I64:
|
|
|
|
case WebAssembly::LOAD8_U_I64:
|
2017-10-06 05:18:42 +08:00
|
|
|
case WebAssembly::ATOMIC_LOAD8_U_I32:
|
|
|
|
case WebAssembly::ATOMIC_LOAD8_U_I64:
|
2016-01-26 11:39:31 +08:00
|
|
|
case WebAssembly::STORE8_I32:
|
|
|
|
case WebAssembly::STORE8_I64:
|
|
|
|
return 0;
|
|
|
|
case WebAssembly::LOAD16_S_I32:
|
|
|
|
case WebAssembly::LOAD16_U_I32:
|
|
|
|
case WebAssembly::LOAD16_S_I64:
|
|
|
|
case WebAssembly::LOAD16_U_I64:
|
2017-10-06 05:18:42 +08:00
|
|
|
case WebAssembly::ATOMIC_LOAD16_U_I32:
|
|
|
|
case WebAssembly::ATOMIC_LOAD16_U_I64:
|
2016-01-26 11:39:31 +08:00
|
|
|
case WebAssembly::STORE16_I32:
|
|
|
|
case WebAssembly::STORE16_I64:
|
|
|
|
return 1;
|
|
|
|
case WebAssembly::LOAD_I32:
|
|
|
|
case WebAssembly::LOAD_F32:
|
|
|
|
case WebAssembly::STORE_I32:
|
|
|
|
case WebAssembly::STORE_F32:
|
|
|
|
case WebAssembly::LOAD32_S_I64:
|
|
|
|
case WebAssembly::LOAD32_U_I64:
|
|
|
|
case WebAssembly::STORE32_I64:
|
2017-08-31 02:07:45 +08:00
|
|
|
case WebAssembly::ATOMIC_LOAD_I32:
|
2017-10-06 05:18:42 +08:00
|
|
|
case WebAssembly::ATOMIC_LOAD32_U_I64:
|
2016-01-26 11:39:31 +08:00
|
|
|
return 2;
|
|
|
|
case WebAssembly::LOAD_I64:
|
|
|
|
case WebAssembly::LOAD_F64:
|
|
|
|
case WebAssembly::STORE_I64:
|
|
|
|
case WebAssembly::STORE_F64:
|
2017-10-06 05:18:42 +08:00
|
|
|
case WebAssembly::ATOMIC_LOAD_I64:
|
2016-01-26 11:39:31 +08:00
|
|
|
return 3;
|
2016-08-02 06:25:02 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Only loads and stores have p2align values");
|
2016-01-26 11:39:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-31 05:43:08 +08:00
|
|
|
/// The operand number of the load or store address in load/store instructions.
|
2016-10-25 08:17:11 +08:00
|
|
|
static const unsigned LoadAddressOperandNo = 3;
|
|
|
|
static const unsigned StoreAddressOperandNo = 2;
|
2016-10-07 06:08:28 +08:00
|
|
|
|
|
|
|
/// The operand number of the load or store p2align in load/store instructions.
|
2016-10-25 08:17:11 +08:00
|
|
|
static const unsigned LoadP2AlignOperandNo = 1;
|
|
|
|
static const unsigned StoreP2AlignOperandNo = 0;
|
2016-01-26 11:39:31 +08:00
|
|
|
|
2016-10-07 06:29:32 +08:00
|
|
|
/// This is used to indicate block signatures.
|
2018-03-03 04:52:59 +08:00
|
|
|
enum class ExprType : unsigned {
|
2018-03-08 12:05:37 +08:00
|
|
|
Void = 0x40,
|
|
|
|
I32 = 0x7F,
|
|
|
|
I64 = 0x7E,
|
|
|
|
F32 = 0x7D,
|
|
|
|
F64 = 0x7C,
|
|
|
|
I8x16 = 0x7B,
|
|
|
|
I16x8 = 0x7A,
|
|
|
|
I32x4 = 0x79,
|
|
|
|
F32x4 = 0x78,
|
|
|
|
B8x16 = 0x77,
|
|
|
|
B16x8 = 0x76,
|
|
|
|
B32x4 = 0x75,
|
|
|
|
ExceptRef = 0x68
|
2016-10-25 03:49:43 +08:00
|
|
|
};
|
|
|
|
|
2016-10-25 07:27:49 +08:00
|
|
|
/// Instruction opcodes emitted via means other than CodeGen.
|
|
|
|
static const unsigned Nop = 0x01;
|
|
|
|
static const unsigned End = 0x0b;
|
|
|
|
|
2017-03-15 04:23:22 +08:00
|
|
|
wasm::ValType toValType(const MVT &Ty);
|
2016-10-25 07:27:49 +08:00
|
|
|
|
2016-01-26 11:39:31 +08:00
|
|
|
} // end namespace WebAssembly
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
#endif
|