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