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 |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 11 | /// This file provides WebAssembly-specific target descriptions. |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H |
| 16 | #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H |
| 17 | |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 18 | #include "llvm/BinaryFormat/Wasm.h" |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCInstrDesc.h" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 20 | #include "llvm/Support/DataTypes.h" |
Derek Schuff | 669300d | 2017-10-10 17:31:43 +0000 | [diff] [blame] | 21 | #include <memory> |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 25 | class MCAsmBackend; |
| 26 | class MCCodeEmitter; |
| 27 | class MCContext; |
| 28 | class MCInstrInfo; |
Peter Collingbourne | dcd7d6c | 2018-05-21 19:20:29 +0000 | [diff] [blame] | 29 | class MCObjectTargetWriter; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 30 | class MCSubtargetInfo; |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 31 | class MVT; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 32 | class Target; |
| 33 | class Triple; |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 34 | class raw_pwrite_stream; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 35 | |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 36 | Target &getTheWebAssemblyTarget32(); |
| 37 | Target &getTheWebAssemblyTarget64(); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 38 | |
Sam Clegg | 9d24fb7 | 2017-06-16 23:59:10 +0000 | [diff] [blame] | 39 | MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII); |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 40 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 41 | MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 42 | |
Peter Collingbourne | dcd7d6c | 2018-05-21 19:20:29 +0000 | [diff] [blame] | 43 | std::unique_ptr<MCObjectTargetWriter> |
| 44 | createWebAssemblyELFObjectWriter(bool Is64Bit, uint8_t OSABI); |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 45 | |
Peter Collingbourne | dcd7d6c | 2018-05-21 19:20:29 +0000 | [diff] [blame] | 46 | std::unique_ptr<MCObjectTargetWriter> |
| 47 | createWebAssemblyWasmObjectWriter(bool Is64Bit); |
Dan Gohman | 18eafb6 | 2017-02-22 01:23:18 +0000 | [diff] [blame] | 48 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 49 | namespace WebAssembly { |
| 50 | enum OperandType { |
| 51 | /// Basic block label in a branch construct. |
| 52 | OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET, |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 53 | /// Local index. |
| 54 | OPERAND_LOCAL, |
Dan Gohman | b89f2d3 | 2017-02-02 19:29:44 +0000 | [diff] [blame] | 55 | /// Global index. |
| 56 | OPERAND_GLOBAL, |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 57 | /// 32-bit integer immediates. |
| 58 | OPERAND_I32IMM, |
| 59 | /// 64-bit integer immediates. |
| 60 | OPERAND_I64IMM, |
Dan Gohman | aa74291 | 2016-02-16 15:14:23 +0000 | [diff] [blame] | 61 | /// 32-bit floating-point immediates. |
Dan Gohman | 4b8e8be | 2016-10-03 21:31:31 +0000 | [diff] [blame] | 62 | OPERAND_F32IMM, |
Dan Gohman | aa74291 | 2016-02-16 15:14:23 +0000 | [diff] [blame] | 63 | /// 64-bit floating-point immediates. |
Dan Gohman | 4b8e8be | 2016-10-03 21:31:31 +0000 | [diff] [blame] | 64 | OPERAND_F64IMM, |
Dan Gohman | 00d734d | 2016-12-23 03:23:52 +0000 | [diff] [blame] | 65 | /// 32-bit unsigned function indices. |
| 66 | OPERAND_FUNCTION32, |
| 67 | /// 32-bit unsigned memory offsets. |
| 68 | OPERAND_OFFSET32, |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 69 | /// p2align immediate for load and store address alignment. |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 70 | OPERAND_P2ALIGN, |
| 71 | /// signature immediate for block/loop. |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 72 | OPERAND_SIGNATURE, |
| 73 | /// type signature immediate for call_indirect. |
| 74 | OPERAND_TYPEINDEX, |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 75 | }; |
| 76 | } // end namespace WebAssembly |
| 77 | |
| 78 | namespace WebAssemblyII { |
| 79 | enum { |
| 80 | // For variadic instructions, this flag indicates whether an operand |
| 81 | // in the variable_ops range is an immediate value. |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 82 | VariableOpIsImmediate = (1 << 0), |
Dan Gohman | 1d68e80f | 2016-01-12 19:14:46 +0000 | [diff] [blame] | 83 | // For immediate values in the variable_ops range, this flag indicates |
| 84 | // whether the value represents a control-flow label. |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 85 | VariableOpImmediateIsLabel = (1 << 1) |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 86 | }; |
| 87 | } // end namespace WebAssemblyII |
| 88 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 89 | } // end namespace llvm |
| 90 | |
| 91 | // Defines symbolic names for WebAssembly registers. This defines a mapping from |
| 92 | // register name to register number. |
| 93 | // |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 94 | #define GET_REGINFO_ENUM |
| 95 | #include "WebAssemblyGenRegisterInfo.inc" |
| 96 | |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 97 | // Defines symbolic names for the WebAssembly instructions. |
| 98 | // |
| 99 | #define GET_INSTRINFO_ENUM |
| 100 | #include "WebAssemblyGenInstrInfo.inc" |
| 101 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 102 | #define GET_SUBTARGETINFO_ENUM |
| 103 | #include "WebAssemblyGenSubtargetInfo.inc" |
| 104 | |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 105 | namespace llvm { |
| 106 | namespace WebAssembly { |
| 107 | |
| 108 | /// Return the default p2align value for a load or store with the given opcode. |
| 109 | inline unsigned GetDefaultP2Align(unsigned Opcode) { |
| 110 | switch (Opcode) { |
| 111 | case WebAssembly::LOAD8_S_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 112 | case WebAssembly::LOAD8_S_I32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 113 | case WebAssembly::LOAD8_U_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 114 | case WebAssembly::LOAD8_U_I32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 115 | case WebAssembly::LOAD8_S_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 116 | case WebAssembly::LOAD8_S_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 117 | case WebAssembly::LOAD8_U_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 118 | case WebAssembly::LOAD8_U_I64_S: |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 119 | case WebAssembly::ATOMIC_LOAD8_U_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 120 | case WebAssembly::ATOMIC_LOAD8_U_I32_S: |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 121 | case WebAssembly::ATOMIC_LOAD8_U_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 122 | case WebAssembly::ATOMIC_LOAD8_U_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 123 | case WebAssembly::STORE8_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 124 | case WebAssembly::STORE8_I32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 125 | case WebAssembly::STORE8_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 126 | case WebAssembly::STORE8_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 127 | return 0; |
| 128 | case WebAssembly::LOAD16_S_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 129 | case WebAssembly::LOAD16_S_I32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 130 | case WebAssembly::LOAD16_U_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 131 | case WebAssembly::LOAD16_U_I32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 132 | case WebAssembly::LOAD16_S_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 133 | case WebAssembly::LOAD16_S_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 134 | case WebAssembly::LOAD16_U_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 135 | case WebAssembly::LOAD16_U_I64_S: |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 136 | case WebAssembly::ATOMIC_LOAD16_U_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 137 | case WebAssembly::ATOMIC_LOAD16_U_I32_S: |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 138 | case WebAssembly::ATOMIC_LOAD16_U_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 139 | case WebAssembly::ATOMIC_LOAD16_U_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 140 | case WebAssembly::STORE16_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 141 | case WebAssembly::STORE16_I32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 142 | case WebAssembly::STORE16_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 143 | case WebAssembly::STORE16_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 144 | return 1; |
| 145 | case WebAssembly::LOAD_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 146 | case WebAssembly::LOAD_I32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 147 | case WebAssembly::LOAD_F32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 148 | case WebAssembly::LOAD_F32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 149 | case WebAssembly::STORE_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 150 | case WebAssembly::STORE_I32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 151 | case WebAssembly::STORE_F32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 152 | case WebAssembly::STORE_F32_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 153 | case WebAssembly::LOAD32_S_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 154 | case WebAssembly::LOAD32_S_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 155 | case WebAssembly::LOAD32_U_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 156 | case WebAssembly::LOAD32_U_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 157 | case WebAssembly::STORE32_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 158 | case WebAssembly::STORE32_I64_S: |
Derek Schuff | 18ba192 | 2017-08-30 18:07:45 +0000 | [diff] [blame] | 159 | case WebAssembly::ATOMIC_LOAD_I32: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 160 | case WebAssembly::ATOMIC_LOAD_I32_S: |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 161 | case WebAssembly::ATOMIC_LOAD32_U_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 162 | case WebAssembly::ATOMIC_LOAD32_U_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 163 | return 2; |
| 164 | case WebAssembly::LOAD_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 165 | case WebAssembly::LOAD_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 166 | case WebAssembly::LOAD_F64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 167 | case WebAssembly::LOAD_F64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 168 | case WebAssembly::STORE_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 169 | case WebAssembly::STORE_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 170 | case WebAssembly::STORE_F64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 171 | case WebAssembly::STORE_F64_S: |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 172 | case WebAssembly::ATOMIC_LOAD_I64: |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame^] | 173 | case WebAssembly::ATOMIC_LOAD_I64_S: |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 174 | return 3; |
Derek Schuff | c64d765 | 2016-08-01 22:25:02 +0000 | [diff] [blame] | 175 | default: |
| 176 | llvm_unreachable("Only loads and stores have p2align values"); |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Derek Schuff | c97ba93 | 2016-01-30 21:43:08 +0000 | [diff] [blame] | 180 | /// 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] | 181 | static const unsigned LoadAddressOperandNo = 3; |
| 182 | static const unsigned StoreAddressOperandNo = 2; |
Dan Gohman | 7f1bdb2 | 2016-10-06 22:08:28 +0000 | [diff] [blame] | 183 | |
| 184 | /// 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] | 185 | static const unsigned LoadP2AlignOperandNo = 1; |
| 186 | static const unsigned StoreP2AlignOperandNo = 0; |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 187 | |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 188 | /// This is used to indicate block signatures. |
Heejin Ahn | 0c69a3e | 2018-03-02 20:52:59 +0000 | [diff] [blame] | 189 | enum class ExprType : unsigned { |
Heejin Ahn | 0de5872 | 2018-03-08 04:05:37 +0000 | [diff] [blame] | 190 | Void = 0x40, |
| 191 | I32 = 0x7F, |
| 192 | I64 = 0x7E, |
| 193 | F32 = 0x7D, |
| 194 | F64 = 0x7C, |
| 195 | I8x16 = 0x7B, |
| 196 | I16x8 = 0x7A, |
| 197 | I32x4 = 0x79, |
| 198 | F32x4 = 0x78, |
| 199 | B8x16 = 0x77, |
| 200 | B16x8 = 0x76, |
| 201 | B32x4 = 0x75, |
| 202 | ExceptRef = 0x68 |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 205 | /// Instruction opcodes emitted via means other than CodeGen. |
| 206 | static const unsigned Nop = 0x01; |
| 207 | static const unsigned End = 0x0b; |
| 208 | |
Derek Schuff | e2688c4 | 2017-03-14 20:23:22 +0000 | [diff] [blame] | 209 | wasm::ValType toValType(const MVT &Ty); |
Dan Gohman | 3acb187 | 2016-10-24 23:27:49 +0000 | [diff] [blame] | 210 | |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 211 | } // end namespace WebAssembly |
| 212 | } // end namespace llvm |
| 213 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 214 | #endif |