blob: 0fc65e5a836fde42f0a4296bee823888964f6286 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//==- 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
Dan Gohmana11fb232016-01-12 03:09:16 +000018#include "llvm/MC/MCInstrDesc.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000019#include "llvm/Support/DataTypes.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000020
21namespace llvm {
22
Dan Gohman10e730a2015-06-29 23:51:55 +000023class MCAsmBackend;
24class MCCodeEmitter;
25class MCContext;
26class MCInstrInfo;
Dan Gohman10e730a2015-06-29 23:51:55 +000027class MCObjectWriter;
Dan Gohman10e730a2015-06-29 23:51:55 +000028class MCSubtargetInfo;
Dan Gohman10e730a2015-06-29 23:51:55 +000029class Target;
30class Triple;
Dan Gohman53828fd2015-11-23 16:50:18 +000031class raw_pwrite_stream;
Dan Gohman10e730a2015-06-29 23:51:55 +000032
Dan Gohmand82494b2015-07-01 21:42:34 +000033extern Target TheWebAssemblyTarget32;
34extern Target TheWebAssemblyTarget64;
Dan Gohman10e730a2015-06-29 23:51:55 +000035
Dan Gohmancff79832016-01-19 21:31:41 +000036MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
Dan Gohman53828fd2015-11-23 16:50:18 +000037
Dan Gohmancceedf72016-01-08 00:43:54 +000038MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
Dan Gohman10e730a2015-06-29 23:51:55 +000039
Dan Gohman05ac43f2015-12-17 01:39:00 +000040MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS,
41 bool Is64Bit, uint8_t OSABI);
42
Dan Gohmana11fb232016-01-12 03:09:16 +000043namespace WebAssembly {
44enum OperandType {
45 /// Basic block label in a branch construct.
46 OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,
Dan Gohman5a68ec72016-10-05 21:24:08 +000047 /// 32-bit integer immediates.
48 OPERAND_I32IMM,
49 /// 64-bit integer immediates.
50 OPERAND_I64IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000051 /// 32-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000052 OPERAND_F32IMM,
Dan Gohmanaa742912016-02-16 15:14:23 +000053 /// 64-bit floating-point immediates.
Dan Gohman4b8e8be2016-10-03 21:31:31 +000054 OPERAND_F64IMM,
Dan Gohmanbb372242016-01-26 03:39:31 +000055 /// p2align immediate for load and store address alignment.
56 OPERAND_P2ALIGN
Dan Gohmana11fb232016-01-12 03:09:16 +000057};
Dan Gohman3469ee12016-01-12 20:30:51 +000058
59/// WebAssembly-specific directive identifiers.
60enum Directive {
61 // FIXME: This is not the real binary encoding.
62 DotParam = UINT64_MAX - 0, ///< .param
63 DotResult = UINT64_MAX - 1, ///< .result
64 DotLocal = UINT64_MAX - 2, ///< .local
65 DotEndFunc = UINT64_MAX - 3, ///< .endfunc
Derek Schuffc64d7652016-08-01 22:25:02 +000066 DotIndIdx = UINT64_MAX - 4, /// < .indidx
Dan Gohman3469ee12016-01-12 20:30:51 +000067};
68
Dan Gohmana11fb232016-01-12 03:09:16 +000069} // end namespace WebAssembly
70
71namespace WebAssemblyII {
72enum {
73 // For variadic instructions, this flag indicates whether an operand
74 // in the variable_ops range is an immediate value.
Dan Gohman3469ee12016-01-12 20:30:51 +000075 VariableOpIsImmediate = (1 << 0),
Dan Gohman1d68e80f2016-01-12 19:14:46 +000076 // For immediate values in the variable_ops range, this flag indicates
77 // whether the value represents a control-flow label.
Dan Gohman3469ee12016-01-12 20:30:51 +000078 VariableOpImmediateIsLabel = (1 << 1),
Dan Gohmana11fb232016-01-12 03:09:16 +000079};
80} // end namespace WebAssemblyII
81
Dan Gohman10e730a2015-06-29 23:51:55 +000082} // end namespace llvm
83
84// Defines symbolic names for WebAssembly registers. This defines a mapping from
85// register name to register number.
86//
JF Bastien5ca0bac2015-07-10 18:23:10 +000087#define GET_REGINFO_ENUM
88#include "WebAssemblyGenRegisterInfo.inc"
89
JF Bastienb9073fb2015-07-22 21:28:15 +000090// Defines symbolic names for the WebAssembly instructions.
91//
92#define GET_INSTRINFO_ENUM
93#include "WebAssemblyGenInstrInfo.inc"
94
Dan Gohman10e730a2015-06-29 23:51:55 +000095#define GET_SUBTARGETINFO_ENUM
96#include "WebAssemblyGenSubtargetInfo.inc"
97
Dan Gohmanbb372242016-01-26 03:39:31 +000098namespace llvm {
99namespace WebAssembly {
100
101/// Return the default p2align value for a load or store with the given opcode.
102inline unsigned GetDefaultP2Align(unsigned Opcode) {
103 switch (Opcode) {
104 case WebAssembly::LOAD8_S_I32:
105 case WebAssembly::LOAD8_U_I32:
106 case WebAssembly::LOAD8_S_I64:
107 case WebAssembly::LOAD8_U_I64:
108 case WebAssembly::STORE8_I32:
109 case WebAssembly::STORE8_I64:
110 return 0;
111 case WebAssembly::LOAD16_S_I32:
112 case WebAssembly::LOAD16_U_I32:
113 case WebAssembly::LOAD16_S_I64:
114 case WebAssembly::LOAD16_U_I64:
115 case WebAssembly::STORE16_I32:
116 case WebAssembly::STORE16_I64:
117 return 1;
118 case WebAssembly::LOAD_I32:
119 case WebAssembly::LOAD_F32:
120 case WebAssembly::STORE_I32:
121 case WebAssembly::STORE_F32:
122 case WebAssembly::LOAD32_S_I64:
123 case WebAssembly::LOAD32_U_I64:
124 case WebAssembly::STORE32_I64:
125 return 2;
126 case WebAssembly::LOAD_I64:
127 case WebAssembly::LOAD_F64:
128 case WebAssembly::STORE_I64:
129 case WebAssembly::STORE_F64:
130 return 3;
Derek Schuffc64d7652016-08-01 22:25:02 +0000131 default:
132 llvm_unreachable("Only loads and stores have p2align values");
Dan Gohmanbb372242016-01-26 03:39:31 +0000133 }
134}
135
Derek Schuffc97ba932016-01-30 21:43:08 +0000136/// The operand number of the load or store address in load/store instructions.
137static const unsigned MemOpAddressOperandNo = 2;
Dan Gohmanbb372242016-01-26 03:39:31 +0000138/// The operand number of the stored value in a store instruction.
139static const unsigned StoreValueOperandNo = 4;
140
141} // end namespace WebAssembly
142} // end namespace llvm
143
Dan Gohman10e730a2015-06-29 23:51:55 +0000144#endif