blob: 620bae0a6d1a93f9ccabe6e3aeccb155416f329a [file] [log] [blame]
Tom Stellarde1818af2016-02-18 03:42:32 +00001//===-- 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 Aminib550cb12016-04-18 09:17:29 +000019#include "llvm/ADT/ArrayRef.h"
Tom Stellarde1818af2016-02-18 03:42:32 +000020#include "llvm/MC/MCDisassembler/MCDisassembler.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000021#include "llvm/MC/MCDisassembler/MCRelocationInfo.h"
Sam Kolton3381d7a2016-10-06 13:46:08 +000022#include "llvm/MC/MCDisassembler/MCSymbolizer.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000023#include <cstdint>
24#include <algorithm>
25#include <memory>
Tom Stellarde1818af2016-02-18 03:42:32 +000026
27namespace llvm {
28
Sam Kolton3381d7a2016-10-06 13:46:08 +000029class MCContext;
30class MCInst;
31class MCOperand;
32class MCSubtargetInfo;
33class Twine;
Tom Stellarde1818af2016-02-18 03:42:32 +000034
Sam Kolton3381d7a2016-10-06 13:46:08 +000035//===----------------------------------------------------------------------===//
36// AMDGPUDisassembler
37//===----------------------------------------------------------------------===//
Nikolay Haustov161a1582016-02-25 16:09:14 +000038
Sam Kolton3381d7a2016-10-06 13:46:08 +000039class AMDGPUDisassembler : public MCDisassembler {
40private:
41 mutable ArrayRef<uint8_t> Bytes;
Dmitry Preobrazhenskyce941c92017-05-19 14:27:52 +000042 mutable uint32_t Literal;
43 mutable bool HasLiteral;
Tom Stellarde1818af2016-02-18 03:42:32 +000044
Sam Kolton3381d7a2016-10-06 13:46:08 +000045public:
46 AMDGPUDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) :
47 MCDisassembler(STI, Ctx) {}
Tom Stellarde1818af2016-02-18 03:42:32 +000048
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000049 ~AMDGPUDisassembler() override = default;
Tom Stellarde1818af2016-02-18 03:42:32 +000050
Sam Kolton3381d7a2016-10-06 13:46:08 +000051 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 Stellarde1818af2016-02-18 03:42:32 +000054
Sam Kolton3381d7a2016-10-06 13:46:08 +000055 const char* getRegClassName(unsigned RegClassID) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000056
Sam Kolton3381d7a2016-10-06 13:46:08 +000057 MCOperand createRegOperand(unsigned int RegId) const;
58 MCOperand createRegOperand(unsigned RegClassID, unsigned Val) const;
59 MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000060
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000061 MCOperand errOperand(unsigned V, const Twine& ErrMsg) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000062
Sam Kolton3381d7a2016-10-06 13:46:08 +000063 DecodeStatus tryDecodeInst(const uint8_t* Table,
64 MCInst &MI,
65 uint64_t Inst,
66 uint64_t Address) const;
Tom Stellarde1818af2016-02-18 03:42:32 +000067
Sam Kolton3381d7a2016-10-06 13:46:08 +000068 MCOperand decodeOperand_VGPR_32(unsigned Val) const;
69 MCOperand decodeOperand_VS_32(unsigned Val) const;
70 MCOperand decodeOperand_VS_64(unsigned Val) const;
Matt Arsenault4bd72362016-12-10 00:39:12 +000071 MCOperand decodeOperand_VSrc16(unsigned Val) const;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000072 MCOperand decodeOperand_VSrcV216(unsigned Val) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000073
Sam Kolton3381d7a2016-10-06 13:46:08 +000074 MCOperand decodeOperand_VReg_64(unsigned Val) const;
75 MCOperand decodeOperand_VReg_96(unsigned Val) const;
76 MCOperand decodeOperand_VReg_128(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000077
Sam Kolton3381d7a2016-10-06 13:46:08 +000078 MCOperand decodeOperand_SReg_32(unsigned Val) const;
Matt Arsenault640c44b2016-11-29 19:39:53 +000079 MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const;
Sam Kolton3381d7a2016-10-06 13:46:08 +000080 MCOperand decodeOperand_SReg_64(unsigned Val) const;
Matt Arsenault640c44b2016-11-29 19:39:53 +000081 MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const;
Sam Kolton3381d7a2016-10-06 13:46:08 +000082 MCOperand decodeOperand_SReg_128(unsigned Val) const;
83 MCOperand decodeOperand_SReg_256(unsigned Val) const;
84 MCOperand decodeOperand_SReg_512(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000085
Sam Kolton3381d7a2016-10-06 13:46:08 +000086 enum OpWidthTy {
87 OPW32,
88 OPW64,
89 OPW128,
Matt Arsenault4bd72362016-12-10 00:39:12 +000090 OPW16,
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000091 OPWV216,
Sam Kolton3381d7a2016-10-06 13:46:08 +000092 OPW_LAST_,
93 OPW_FIRST_ = OPW32
Tom Stellarde1818af2016-02-18 03:42:32 +000094 };
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000095
Sam Kolton3381d7a2016-10-06 13:46:08 +000096 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 Arsenault4bd72362016-12-10 00:39:12 +0000101 static MCOperand decodeFPImmed(OpWidthTy Width, unsigned Imm);
Sam Kolton3381d7a2016-10-06 13:46:08 +0000102 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;
107};
108
109//===----------------------------------------------------------------------===//
110// AMDGPUSymbolizer
111//===----------------------------------------------------------------------===//
112
113class AMDGPUSymbolizer : public MCSymbolizer {
114private:
115 void *DisInfo;
116
117public:
118 AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo,
Matt Arsenaultf3dd8632016-11-01 00:55:14 +0000119 void *disInfo)
Sam Kolton3381d7a2016-10-06 13:46:08 +0000120 : MCSymbolizer(Ctx, std::move(RelInfo)), DisInfo(disInfo) {}
121
122 bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream,
123 int64_t Value, uint64_t Address,
124 bool IsBranch, uint64_t Offset,
125 uint64_t InstSize) override;
126
127 void tryAddingPcLoadReferenceComment(raw_ostream &cStream,
128 int64_t Value,
Matt Arsenault92b355b2016-11-15 19:34:37 +0000129 uint64_t Address) override;
Sam Kolton3381d7a2016-10-06 13:46:08 +0000130};
131
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000132} // end namespace llvm
Tom Stellarde1818af2016-02-18 03:42:32 +0000133
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000134#endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H