Eugene Zelenko | c8fbf6f | 2017-08-10 00:46:15 +0000 | [diff] [blame] | 1 | //===- AMDGPUDisassembler.hpp - Disassembler for AMDGPU ISA -----*- C++ -*-===// |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | /// \file |
| 10 | /// |
| 11 | /// This file contains declaration for AMDGPU ISA disassembler |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H |
| 16 | #define LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H |
| 17 | |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/ArrayRef.h" |
Matt Arsenault | cad7fa8 | 2017-12-13 21:07:51 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCContext.h" |
| 20 | #include "llvm/MC/MCInstrInfo.h" |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCDisassembler/MCDisassembler.h" |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCDisassembler/MCRelocationInfo.h" |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCDisassembler/MCSymbolizer.h" |
Matt Arsenault | cad7fa8 | 2017-12-13 21:07:51 +0000 | [diff] [blame] | 24 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 25 | #include <algorithm> |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 26 | #include <cstdint> |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 27 | #include <memory> |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 28 | |
| 29 | namespace llvm { |
| 30 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 31 | class MCInst; |
| 32 | class MCOperand; |
| 33 | class MCSubtargetInfo; |
| 34 | class Twine; |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 35 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
| 37 | // AMDGPUDisassembler |
| 38 | //===----------------------------------------------------------------------===// |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 39 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 40 | class AMDGPUDisassembler : public MCDisassembler { |
| 41 | private: |
Matt Arsenault | cad7fa8 | 2017-12-13 21:07:51 +0000 | [diff] [blame] | 42 | std::unique_ptr<MCInstrInfo const> const MCII; |
| 43 | const MCRegisterInfo &MRI; |
Matt Arsenault | ca64ef2 | 2019-05-22 16:28:41 +0000 | [diff] [blame] | 44 | const unsigned TargetMaxInstBytes; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 45 | mutable ArrayRef<uint8_t> Bytes; |
Dmitry Preobrazhensky | ce941c9 | 2017-05-19 14:27:52 +0000 | [diff] [blame] | 46 | mutable uint32_t Literal; |
| 47 | mutable bool HasLiteral; |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 48 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 49 | public: |
Matt Arsenault | cad7fa8 | 2017-12-13 21:07:51 +0000 | [diff] [blame] | 50 | AMDGPUDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, |
Matt Arsenault | ca64ef2 | 2019-05-22 16:28:41 +0000 | [diff] [blame] | 51 | MCInstrInfo const *MCII); |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 52 | ~AMDGPUDisassembler() override = default; |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 53 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 54 | DecodeStatus getInstruction(MCInst &MI, uint64_t &Size, |
| 55 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
| 56 | raw_ostream &WS, raw_ostream &CS) const override; |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 57 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 58 | const char* getRegClassName(unsigned RegClassID) const; |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 59 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 60 | MCOperand createRegOperand(unsigned int RegId) const; |
| 61 | MCOperand createRegOperand(unsigned RegClassID, unsigned Val) const; |
| 62 | MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const; |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 63 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 64 | MCOperand errOperand(unsigned V, const Twine& ErrMsg) const; |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 65 | |
Eugene Zelenko | c8fbf6f | 2017-08-10 00:46:15 +0000 | [diff] [blame] | 66 | DecodeStatus tryDecodeInst(const uint8_t* Table, MCInst &MI, uint64_t Inst, |
| 67 | uint64_t Address) const; |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 68 | |
Sam Kolton | 549c89d | 2017-06-21 08:53:38 +0000 | [diff] [blame] | 69 | DecodeStatus convertSDWAInst(MCInst &MI) const; |
Stanislav Mekhanoshin | 245b5ba | 2019-06-12 18:02:41 +0000 | [diff] [blame] | 70 | DecodeStatus convertDPP8Inst(MCInst &MI) const; |
Matt Arsenault | cad7fa8 | 2017-12-13 21:07:51 +0000 | [diff] [blame] | 71 | DecodeStatus convertMIMGInst(MCInst &MI) const; |
Sam Kolton | 549c89d | 2017-06-21 08:53:38 +0000 | [diff] [blame] | 72 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 73 | MCOperand decodeOperand_VGPR_32(unsigned Val) const; |
Dmitry Preobrazhensky | 6023d59 | 2019-03-04 12:48:32 +0000 | [diff] [blame] | 74 | MCOperand decodeOperand_VRegOrLds_32(unsigned Val) const; |
| 75 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 76 | MCOperand decodeOperand_VS_32(unsigned Val) const; |
| 77 | MCOperand decodeOperand_VS_64(unsigned Val) const; |
Dmitry Preobrazhensky | 30fc523 | 2017-07-18 13:12:48 +0000 | [diff] [blame] | 78 | MCOperand decodeOperand_VS_128(unsigned Val) const; |
Matt Arsenault | 4bd7236 | 2016-12-10 00:39:12 +0000 | [diff] [blame] | 79 | MCOperand decodeOperand_VSrc16(unsigned Val) const; |
Matt Arsenault | 9be7b0d | 2017-02-27 18:49:11 +0000 | [diff] [blame] | 80 | MCOperand decodeOperand_VSrcV216(unsigned Val) const; |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 81 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 82 | MCOperand decodeOperand_VReg_64(unsigned Val) const; |
| 83 | MCOperand decodeOperand_VReg_96(unsigned Val) const; |
| 84 | MCOperand decodeOperand_VReg_128(unsigned Val) const; |
Stanislav Mekhanoshin | 9e77d0c | 2019-07-09 19:41:51 +0000 | [diff] [blame] | 85 | MCOperand decodeOperand_VReg_256(unsigned Val) const; |
| 86 | MCOperand decodeOperand_VReg_512(unsigned Val) const; |
Nikolay Haustov | ac106ad | 2016-03-01 13:57:29 +0000 | [diff] [blame] | 87 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 88 | MCOperand decodeOperand_SReg_32(unsigned Val) const; |
Matt Arsenault | 640c44b | 2016-11-29 19:39:53 +0000 | [diff] [blame] | 89 | MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const; |
Matt Arsenault | ca7b0a1 | 2017-07-21 15:36:16 +0000 | [diff] [blame] | 90 | MCOperand decodeOperand_SReg_32_XEXEC_HI(unsigned Val) const; |
Dmitry Preobrazhensky | 6023d59 | 2019-03-04 12:48:32 +0000 | [diff] [blame] | 91 | MCOperand decodeOperand_SRegOrLds_32(unsigned Val) const; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 92 | MCOperand decodeOperand_SReg_64(unsigned Val) const; |
Matt Arsenault | 640c44b | 2016-11-29 19:39:53 +0000 | [diff] [blame] | 93 | MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 94 | MCOperand decodeOperand_SReg_128(unsigned Val) const; |
| 95 | MCOperand decodeOperand_SReg_256(unsigned Val) const; |
| 96 | MCOperand decodeOperand_SReg_512(unsigned Val) const; |
Nikolay Haustov | ac106ad | 2016-03-01 13:57:29 +0000 | [diff] [blame] | 97 | |
Stanislav Mekhanoshin | 9e77d0c | 2019-07-09 19:41:51 +0000 | [diff] [blame] | 98 | MCOperand decodeOperand_AGPR_32(unsigned Val) const; |
| 99 | MCOperand decodeOperand_AReg_128(unsigned Val) const; |
| 100 | MCOperand decodeOperand_AReg_512(unsigned Val) const; |
| 101 | MCOperand decodeOperand_AReg_1024(unsigned Val) const; |
| 102 | MCOperand decodeOperand_AV_32(unsigned Val) const; |
| 103 | MCOperand decodeOperand_AV_64(unsigned Val) const; |
| 104 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 105 | enum OpWidthTy { |
| 106 | OPW32, |
| 107 | OPW64, |
| 108 | OPW128, |
Dmitry Preobrazhensky | 2713495 | 2017-12-22 15:18:06 +0000 | [diff] [blame] | 109 | OPW256, |
| 110 | OPW512, |
Stanislav Mekhanoshin | 9e77d0c | 2019-07-09 19:41:51 +0000 | [diff] [blame] | 111 | OPW1024, |
Matt Arsenault | 4bd7236 | 2016-12-10 00:39:12 +0000 | [diff] [blame] | 112 | OPW16, |
Matt Arsenault | 9be7b0d | 2017-02-27 18:49:11 +0000 | [diff] [blame] | 113 | OPWV216, |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 114 | OPW_LAST_, |
| 115 | OPW_FIRST_ = OPW32 |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 116 | }; |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 117 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 118 | unsigned getVgprClassId(const OpWidthTy Width) const; |
Stanislav Mekhanoshin | 9e77d0c | 2019-07-09 19:41:51 +0000 | [diff] [blame] | 119 | unsigned getAgprClassId(const OpWidthTy Width) const; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 120 | unsigned getSgprClassId(const OpWidthTy Width) const; |
| 121 | unsigned getTtmpClassId(const OpWidthTy Width) const; |
| 122 | |
| 123 | static MCOperand decodeIntImmed(unsigned Imm); |
Matt Arsenault | 4bd7236 | 2016-12-10 00:39:12 +0000 | [diff] [blame] | 124 | static MCOperand decodeFPImmed(OpWidthTy Width, unsigned Imm); |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 125 | MCOperand decodeLiteralConstant() const; |
| 126 | |
| 127 | MCOperand decodeSrcOp(const OpWidthTy Width, unsigned Val) const; |
Dmitry Preobrazhensky | 2713495 | 2017-12-22 15:18:06 +0000 | [diff] [blame] | 128 | MCOperand decodeDstOp(const OpWidthTy Width, unsigned Val) const; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 129 | MCOperand decodeSpecialReg32(unsigned Val) const; |
| 130 | MCOperand decodeSpecialReg64(unsigned Val) const; |
Sam Kolton | 363f47a | 2017-05-26 15:52:00 +0000 | [diff] [blame] | 131 | |
Sam Kolton | 549c89d | 2017-06-21 08:53:38 +0000 | [diff] [blame] | 132 | MCOperand decodeSDWASrc(const OpWidthTy Width, unsigned Val) const; |
| 133 | MCOperand decodeSDWASrc16(unsigned Val) const; |
| 134 | MCOperand decodeSDWASrc32(unsigned Val) const; |
| 135 | MCOperand decodeSDWAVopcDst(unsigned Val) const; |
Dmitry Preobrazhensky | ac2b026 | 2017-12-11 15:23:20 +0000 | [diff] [blame] | 136 | |
Stanislav Mekhanoshin | ab4f2ea | 2019-06-18 19:10:59 +0000 | [diff] [blame] | 137 | MCOperand decodeBoolReg(unsigned Val) const; |
| 138 | |
Dmitry Preobrazhensky | ac2b026 | 2017-12-11 15:23:20 +0000 | [diff] [blame] | 139 | int getTTmpIdx(unsigned Val) const; |
| 140 | |
| 141 | bool isVI() const; |
| 142 | bool isGFX9() const; |
Stanislav Mekhanoshin | 33d806a | 2019-04-24 17:28:30 +0000 | [diff] [blame] | 143 | bool isGFX10() const; |
Stanislav Mekhanoshin | 245b5ba | 2019-06-12 18:02:41 +0000 | [diff] [blame] | 144 | }; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 145 | |
| 146 | //===----------------------------------------------------------------------===// |
| 147 | // AMDGPUSymbolizer |
| 148 | //===----------------------------------------------------------------------===// |
| 149 | |
| 150 | class AMDGPUSymbolizer : public MCSymbolizer { |
| 151 | private: |
| 152 | void *DisInfo; |
| 153 | |
| 154 | public: |
| 155 | AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo, |
Matt Arsenault | f3dd863 | 2016-11-01 00:55:14 +0000 | [diff] [blame] | 156 | void *disInfo) |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 157 | : MCSymbolizer(Ctx, std::move(RelInfo)), DisInfo(disInfo) {} |
| 158 | |
| 159 | bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream, |
| 160 | int64_t Value, uint64_t Address, |
| 161 | bool IsBranch, uint64_t Offset, |
| 162 | uint64_t InstSize) override; |
| 163 | |
| 164 | void tryAddingPcLoadReferenceComment(raw_ostream &cStream, |
| 165 | int64_t Value, |
Matt Arsenault | 92b355b | 2016-11-15 19:34:37 +0000 | [diff] [blame] | 166 | uint64_t Address) override; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 169 | } // end namespace llvm |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 170 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame] | 171 | #endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H |