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