Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 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 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCInstrDesc.h" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 19 | #include "llvm/Support/DataTypes.h" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 23 | class MCAsmBackend; |
| 24 | class MCCodeEmitter; |
| 25 | class MCContext; |
| 26 | class MCInstrInfo; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 27 | class MCObjectWriter; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 28 | class MCSubtargetInfo; |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 29 | class MVT; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 30 | class Target; |
| 31 | class Triple; |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 32 | class raw_pwrite_stream; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 33 | |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 34 | Target &getTheWebAssemblyTarget32(); |
| 35 | Target &getTheWebAssemblyTarget64(); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 36 | |
Dan Gohman | cff7983 | 2016-01-19 21:31:41 +0000 | [diff] [blame] | 37 | MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII); |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 38 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 39 | MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 40 | |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 41 | MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS, |
| 42 | bool Is64Bit, uint8_t OSABI); |
| 43 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 44 | namespace WebAssembly { |
| 45 | enum OperandType { |
| 46 | /// Basic block label in a branch construct. |
| 47 | OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET, |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 48 | /// Local index. |
| 49 | OPERAND_LOCAL, |
Dan Gohman | b89f2d3 | 2017-02-02 19:29:44 +0000 | [diff] [blame] | 50 | /// Global index. |
| 51 | OPERAND_GLOBAL, |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 52 | /// 32-bit integer immediates. |
| 53 | OPERAND_I32IMM, |
| 54 | /// 64-bit integer immediates. |
| 55 | OPERAND_I64IMM, |
Dan Gohman | aa74291 | 2016-02-16 15:14:23 +0000 | [diff] [blame] | 56 | /// 32-bit floating-point immediates. |
Dan Gohman | 4b8e8be | 2016-10-03 21:31:31 +0000 | [diff] [blame] | 57 | OPERAND_F32IMM, |
Dan Gohman | aa74291 | 2016-02-16 15:14:23 +0000 | [diff] [blame] | 58 | /// 64-bit floating-point immediates. |
Dan Gohman | 4b8e8be | 2016-10-03 21:31:31 +0000 | [diff] [blame] | 59 | OPERAND_F64IMM, |
Dan Gohman | 00d734d | 2016-12-23 03:23:52 +0000 | [diff] [blame] | 60 | /// 32-bit unsigned function indices. |
| 61 | OPERAND_FUNCTION32, |
| 62 | /// 32-bit unsigned memory offsets. |
| 63 | OPERAND_OFFSET32, |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 64 | /// p2align immediate for load and store address alignment. |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 65 | OPERAND_P2ALIGN, |
| 66 | /// signature immediate for block/loop. |
| 67 | OPERAND_SIGNATURE |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 68 | }; |
| 69 | } // end namespace WebAssembly |
| 70 | |
| 71 | namespace WebAssemblyII { |
| 72 | enum { |
| 73 | // For variadic instructions, this flag indicates whether an operand |
| 74 | // in the variable_ops range is an immediate value. |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 75 | VariableOpIsImmediate = (1 << 0), |
Dan Gohman | 1d68e80f | 2016-01-12 19:14:46 +0000 | [diff] [blame] | 76 | // For immediate values in the variable_ops range, this flag indicates |
| 77 | // whether the value represents a control-flow label. |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 78 | VariableOpImmediateIsLabel = (1 << 1) |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 79 | }; |
| 80 | } // end namespace WebAssemblyII |
| 81 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 82 | } // end namespace llvm |
| 83 | |
| 84 | // Defines symbolic names for WebAssembly registers. This defines a mapping from |
| 85 | // register name to register number. |
| 86 | // |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 87 | #define GET_REGINFO_ENUM |
| 88 | #include "WebAssemblyGenRegisterInfo.inc" |
| 89 | |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 90 | // Defines symbolic names for the WebAssembly instructions. |
| 91 | // |
| 92 | #define GET_INSTRINFO_ENUM |
| 93 | #include "WebAssemblyGenInstrInfo.inc" |
| 94 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 95 | #define GET_SUBTARGETINFO_ENUM |
| 96 | #include "WebAssemblyGenSubtargetInfo.inc" |
| 97 | |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 98 | namespace llvm { |
| 99 | namespace WebAssembly { |
| 100 | |
| 101 | /// Return the default p2align value for a load or store with the given opcode. |
| 102 | inline 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 Schuff | c64d765 | 2016-08-01 22:25:02 +0000 | [diff] [blame] | 131 | default: |
| 132 | llvm_unreachable("Only loads and stores have p2align values"); |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Derek Schuff | c97ba93 | 2016-01-30 21:43:08 +0000 | [diff] [blame] | 136 | /// The operand number of the load or store address in load/store instructions. |
Dan Gohman | 48abaa9 | 2016-10-25 00:17:11 +0000 | [diff] [blame] | 137 | static const unsigned LoadAddressOperandNo = 3; |
| 138 | static const unsigned StoreAddressOperandNo = 2; |
Dan Gohman | 7f1bdb2 | 2016-10-06 22:08:28 +0000 | [diff] [blame] | 139 | |
| 140 | /// The operand number of the load or store p2align in load/store instructions. |
Dan Gohman | 48abaa9 | 2016-10-25 00:17:11 +0000 | [diff] [blame] | 141 | static const unsigned LoadP2AlignOperandNo = 1; |
| 142 | static const unsigned StoreP2AlignOperandNo = 0; |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 143 | |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 144 | /// This is used to indicate block signatures. |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 145 | enum class ExprType { |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 146 | Void = 0x40, |
| 147 | I32 = 0x7f, |
| 148 | I64 = 0x7e, |
| 149 | F32 = 0x7d, |
| 150 | F64 = 0x7c, |
| 151 | I8x16 = 0x7b, |
| 152 | I16x8 = 0x7a, |
| 153 | I32x4 = 0x79, |
| 154 | F32x4 = 0x78, |
| 155 | B8x16 = 0x77, |
| 156 | B16x8 = 0x76, |
| 157 | B32x4 = 0x75 |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 158 | }; |
| 159 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 160 | /// This is used to indicate local types. |
| 161 | enum class ValType { |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 162 | I32 = 0x7f, |
| 163 | I64 = 0x7e, |
| 164 | F32 = 0x7d, |
| 165 | F64 = 0x7c, |
| 166 | I8x16 = 0x7b, |
| 167 | I16x8 = 0x7a, |
| 168 | I32x4 = 0x79, |
| 169 | F32x4 = 0x78, |
| 170 | B8x16 = 0x77, |
| 171 | B16x8 = 0x76, |
| 172 | B32x4 = 0x75 |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 175 | /// Instruction opcodes emitted via means other than CodeGen. |
| 176 | static const unsigned Nop = 0x01; |
| 177 | static const unsigned End = 0x0b; |
| 178 | |
| 179 | ValType toValType(const MVT &Ty); |
| 180 | |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 181 | } // end namespace WebAssembly |
| 182 | } // end namespace llvm |
| 183 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 184 | #endif |