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 | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 29 | class Target; |
| 30 | class Triple; |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 31 | class raw_pwrite_stream; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 32 | |
Dan Gohman | d82494b | 2015-07-01 21:42:34 +0000 | [diff] [blame] | 33 | extern Target TheWebAssemblyTarget32; |
| 34 | extern Target TheWebAssemblyTarget64; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 35 | |
Dan Gohman | cff7983 | 2016-01-19 21:31:41 +0000 | [diff] [blame] | 36 | MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII); |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 37 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 38 | MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 39 | |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 40 | MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS, |
| 41 | bool Is64Bit, uint8_t OSABI); |
| 42 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 43 | namespace WebAssembly { |
| 44 | enum OperandType { |
| 45 | /// Basic block label in a branch construct. |
| 46 | OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET, |
Dan Gohman | aa74291 | 2016-02-16 15:14:23 +0000 | [diff] [blame] | 47 | /// 32-bit floating-point immediates. |
| 48 | OPERAND_FP32IMM, |
| 49 | /// 64-bit floating-point immediates. |
| 50 | OPERAND_FP64IMM, |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 51 | /// p2align immediate for load and store address alignment. |
| 52 | OPERAND_P2ALIGN |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 53 | }; |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 54 | |
| 55 | /// WebAssembly-specific directive identifiers. |
| 56 | enum Directive { |
| 57 | // FIXME: This is not the real binary encoding. |
| 58 | DotParam = UINT64_MAX - 0, ///< .param |
| 59 | DotResult = UINT64_MAX - 1, ///< .result |
| 60 | DotLocal = UINT64_MAX - 2, ///< .local |
| 61 | DotEndFunc = UINT64_MAX - 3, ///< .endfunc |
Derek Schuff | c64d765 | 2016-08-01 22:25:02 +0000 | [diff] [blame] | 62 | DotIndIdx = UINT64_MAX - 4, /// < .indidx |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 65 | } // end namespace WebAssembly |
| 66 | |
| 67 | namespace WebAssemblyII { |
| 68 | enum { |
| 69 | // For variadic instructions, this flag indicates whether an operand |
| 70 | // in the variable_ops range is an immediate value. |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 71 | VariableOpIsImmediate = (1 << 0), |
Dan Gohman | 1d68e80f | 2016-01-12 19:14:46 +0000 | [diff] [blame] | 72 | // For immediate values in the variable_ops range, this flag indicates |
| 73 | // whether the value represents a control-flow label. |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 74 | VariableOpImmediateIsLabel = (1 << 1), |
Dan Gohman | a11fb23 | 2016-01-12 03:09:16 +0000 | [diff] [blame] | 75 | }; |
| 76 | } // end namespace WebAssemblyII |
| 77 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 78 | } // end namespace llvm |
| 79 | |
| 80 | // Defines symbolic names for WebAssembly registers. This defines a mapping from |
| 81 | // register name to register number. |
| 82 | // |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 83 | #define GET_REGINFO_ENUM |
| 84 | #include "WebAssemblyGenRegisterInfo.inc" |
| 85 | |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 86 | // Defines symbolic names for the WebAssembly instructions. |
| 87 | // |
| 88 | #define GET_INSTRINFO_ENUM |
| 89 | #include "WebAssemblyGenInstrInfo.inc" |
| 90 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 91 | #define GET_SUBTARGETINFO_ENUM |
| 92 | #include "WebAssemblyGenSubtargetInfo.inc" |
| 93 | |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 94 | namespace llvm { |
| 95 | namespace WebAssembly { |
| 96 | |
| 97 | /// Return the default p2align value for a load or store with the given opcode. |
| 98 | inline unsigned GetDefaultP2Align(unsigned Opcode) { |
| 99 | switch (Opcode) { |
| 100 | case WebAssembly::LOAD8_S_I32: |
| 101 | case WebAssembly::LOAD8_U_I32: |
| 102 | case WebAssembly::LOAD8_S_I64: |
| 103 | case WebAssembly::LOAD8_U_I64: |
| 104 | case WebAssembly::STORE8_I32: |
| 105 | case WebAssembly::STORE8_I64: |
| 106 | return 0; |
| 107 | case WebAssembly::LOAD16_S_I32: |
| 108 | case WebAssembly::LOAD16_U_I32: |
| 109 | case WebAssembly::LOAD16_S_I64: |
| 110 | case WebAssembly::LOAD16_U_I64: |
| 111 | case WebAssembly::STORE16_I32: |
| 112 | case WebAssembly::STORE16_I64: |
| 113 | return 1; |
| 114 | case WebAssembly::LOAD_I32: |
| 115 | case WebAssembly::LOAD_F32: |
| 116 | case WebAssembly::STORE_I32: |
| 117 | case WebAssembly::STORE_F32: |
| 118 | case WebAssembly::LOAD32_S_I64: |
| 119 | case WebAssembly::LOAD32_U_I64: |
| 120 | case WebAssembly::STORE32_I64: |
| 121 | return 2; |
| 122 | case WebAssembly::LOAD_I64: |
| 123 | case WebAssembly::LOAD_F64: |
| 124 | case WebAssembly::STORE_I64: |
| 125 | case WebAssembly::STORE_F64: |
| 126 | return 3; |
Derek Schuff | c64d765 | 2016-08-01 22:25:02 +0000 | [diff] [blame] | 127 | default: |
| 128 | llvm_unreachable("Only loads and stores have p2align values"); |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
Derek Schuff | c97ba93 | 2016-01-30 21:43:08 +0000 | [diff] [blame] | 132 | /// The operand number of the load or store address in load/store instructions. |
| 133 | static const unsigned MemOpAddressOperandNo = 2; |
Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 134 | /// The operand number of the stored value in a store instruction. |
| 135 | static const unsigned StoreValueOperandNo = 4; |
| 136 | |
| 137 | } // end namespace WebAssembly |
| 138 | } // end namespace llvm |
| 139 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 140 | #endif |