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 <cstdint> |
| 24 | #include <algorithm> |
| 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; |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 42 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 43 | public: |
| 44 | AMDGPUDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) : |
| 45 | MCDisassembler(STI, Ctx) {} |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 46 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame^] | 47 | ~AMDGPUDisassembler() override = default; |
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 | DecodeStatus getInstruction(MCInst &MI, uint64_t &Size, |
| 50 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
| 51 | raw_ostream &WS, raw_ostream &CS) const override; |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 52 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 53 | const char* getRegClassName(unsigned RegClassID) const; |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 54 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 55 | MCOperand createRegOperand(unsigned int RegId) const; |
| 56 | MCOperand createRegOperand(unsigned RegClassID, unsigned Val) const; |
| 57 | MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const; |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 58 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame^] | 59 | MCOperand errOperand(unsigned V, const Twine& ErrMsg) const; |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 60 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 61 | DecodeStatus tryDecodeInst(const uint8_t* Table, |
| 62 | MCInst &MI, |
| 63 | uint64_t Inst, |
| 64 | uint64_t Address) const; |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 65 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 66 | MCOperand decodeOperand_VGPR_32(unsigned Val) const; |
| 67 | MCOperand decodeOperand_VS_32(unsigned Val) const; |
| 68 | MCOperand decodeOperand_VS_64(unsigned Val) const; |
Nikolay Haustov | 161a158 | 2016-02-25 16:09:14 +0000 | [diff] [blame] | 69 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 70 | MCOperand decodeOperand_VReg_64(unsigned Val) const; |
| 71 | MCOperand decodeOperand_VReg_96(unsigned Val) const; |
| 72 | MCOperand decodeOperand_VReg_128(unsigned Val) const; |
Nikolay Haustov | ac106ad | 2016-03-01 13:57:29 +0000 | [diff] [blame] | 73 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 74 | MCOperand decodeOperand_SReg_32(unsigned Val) const; |
Matt Arsenault | 640c44b | 2016-11-29 19:39:53 +0000 | [diff] [blame] | 75 | MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 76 | MCOperand decodeOperand_SReg_64(unsigned Val) const; |
Matt Arsenault | 640c44b | 2016-11-29 19:39:53 +0000 | [diff] [blame] | 77 | MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 78 | MCOperand decodeOperand_SReg_128(unsigned Val) const; |
| 79 | MCOperand decodeOperand_SReg_256(unsigned Val) const; |
| 80 | MCOperand decodeOperand_SReg_512(unsigned Val) const; |
Nikolay Haustov | ac106ad | 2016-03-01 13:57:29 +0000 | [diff] [blame] | 81 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 82 | enum OpWidthTy { |
| 83 | OPW32, |
| 84 | OPW64, |
| 85 | OPW128, |
| 86 | OPW_LAST_, |
| 87 | OPW_FIRST_ = OPW32 |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 88 | }; |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame^] | 89 | |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 90 | unsigned getVgprClassId(const OpWidthTy Width) const; |
| 91 | unsigned getSgprClassId(const OpWidthTy Width) const; |
| 92 | unsigned getTtmpClassId(const OpWidthTy Width) const; |
| 93 | |
| 94 | static MCOperand decodeIntImmed(unsigned Imm); |
| 95 | static MCOperand decodeFPImmed(bool Is32, unsigned Imm); |
| 96 | MCOperand decodeLiteralConstant() const; |
| 97 | |
| 98 | MCOperand decodeSrcOp(const OpWidthTy Width, unsigned Val) const; |
| 99 | MCOperand decodeSpecialReg32(unsigned Val) const; |
| 100 | MCOperand decodeSpecialReg64(unsigned Val) const; |
| 101 | }; |
| 102 | |
| 103 | //===----------------------------------------------------------------------===// |
| 104 | // AMDGPUSymbolizer |
| 105 | //===----------------------------------------------------------------------===// |
| 106 | |
| 107 | class AMDGPUSymbolizer : public MCSymbolizer { |
| 108 | private: |
| 109 | void *DisInfo; |
| 110 | |
| 111 | public: |
| 112 | AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo, |
Matt Arsenault | f3dd863 | 2016-11-01 00:55:14 +0000 | [diff] [blame] | 113 | void *disInfo) |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 114 | : MCSymbolizer(Ctx, std::move(RelInfo)), DisInfo(disInfo) {} |
| 115 | |
| 116 | bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream, |
| 117 | int64_t Value, uint64_t Address, |
| 118 | bool IsBranch, uint64_t Offset, |
| 119 | uint64_t InstSize) override; |
| 120 | |
| 121 | void tryAddingPcLoadReferenceComment(raw_ostream &cStream, |
| 122 | int64_t Value, |
Matt Arsenault | 92b355b | 2016-11-15 19:34:37 +0000 | [diff] [blame] | 123 | uint64_t Address) override; |
Sam Kolton | 3381d7a | 2016-10-06 13:46:08 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame^] | 126 | } // end namespace llvm |
Tom Stellard | e1818af | 2016-02-18 03:42:32 +0000 | [diff] [blame] | 127 | |
Eugene Zelenko | 2bc2f33 | 2016-12-09 22:06:55 +0000 | [diff] [blame^] | 128 | #endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H |