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