blob: ee5883a984e0caafc97b1c21543c9d3387e9ba28 [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;
Tom Stellarde1818af2016-02-18 03:42:32 +000042
Sam Kolton3381d7a2016-10-06 13:46:08 +000043public:
44 AMDGPUDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) :
45 MCDisassembler(STI, Ctx) {}
Tom Stellarde1818af2016-02-18 03:42:32 +000046
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000047 ~AMDGPUDisassembler() override = default;
Tom Stellarde1818af2016-02-18 03:42:32 +000048
Sam Kolton3381d7a2016-10-06 13:46:08 +000049 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 Stellarde1818af2016-02-18 03:42:32 +000052
Sam Kolton3381d7a2016-10-06 13:46:08 +000053 const char* getRegClassName(unsigned RegClassID) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000054
Sam Kolton3381d7a2016-10-06 13:46:08 +000055 MCOperand createRegOperand(unsigned int RegId) const;
56 MCOperand createRegOperand(unsigned RegClassID, unsigned Val) const;
57 MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000058
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000059 MCOperand errOperand(unsigned V, const Twine& ErrMsg) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000060
Sam Kolton3381d7a2016-10-06 13:46:08 +000061 DecodeStatus tryDecodeInst(const uint8_t* Table,
62 MCInst &MI,
63 uint64_t Inst,
64 uint64_t Address) const;
Tom Stellarde1818af2016-02-18 03:42:32 +000065
Sam Kolton3381d7a2016-10-06 13:46:08 +000066 MCOperand decodeOperand_VGPR_32(unsigned Val) const;
67 MCOperand decodeOperand_VS_32(unsigned Val) const;
68 MCOperand decodeOperand_VS_64(unsigned Val) const;
Matt Arsenault4bd72362016-12-10 00:39:12 +000069 MCOperand decodeOperand_VSrc16(unsigned Val) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000070
Sam Kolton3381d7a2016-10-06 13:46:08 +000071 MCOperand decodeOperand_VReg_64(unsigned Val) const;
72 MCOperand decodeOperand_VReg_96(unsigned Val) const;
73 MCOperand decodeOperand_VReg_128(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000074
Sam Kolton3381d7a2016-10-06 13:46:08 +000075 MCOperand decodeOperand_SReg_32(unsigned Val) const;
Matt Arsenault640c44b2016-11-29 19:39:53 +000076 MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const;
Sam Kolton3381d7a2016-10-06 13:46:08 +000077 MCOperand decodeOperand_SReg_64(unsigned Val) const;
Matt Arsenault640c44b2016-11-29 19:39:53 +000078 MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const;
Sam Kolton3381d7a2016-10-06 13:46:08 +000079 MCOperand decodeOperand_SReg_128(unsigned Val) const;
80 MCOperand decodeOperand_SReg_256(unsigned Val) const;
81 MCOperand decodeOperand_SReg_512(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000082
Sam Kolton3381d7a2016-10-06 13:46:08 +000083 enum OpWidthTy {
84 OPW32,
85 OPW64,
86 OPW128,
Matt Arsenault4bd72362016-12-10 00:39:12 +000087 OPW16,
Sam Kolton3381d7a2016-10-06 13:46:08 +000088 OPW_LAST_,
89 OPW_FIRST_ = OPW32
Tom Stellarde1818af2016-02-18 03:42:32 +000090 };
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000091
Sam Kolton3381d7a2016-10-06 13:46:08 +000092 unsigned getVgprClassId(const OpWidthTy Width) const;
93 unsigned getSgprClassId(const OpWidthTy Width) const;
94 unsigned getTtmpClassId(const OpWidthTy Width) const;
95
96 static MCOperand decodeIntImmed(unsigned Imm);
Matt Arsenault4bd72362016-12-10 00:39:12 +000097 static MCOperand decodeFPImmed(OpWidthTy Width, unsigned Imm);
Sam Kolton3381d7a2016-10-06 13:46:08 +000098 MCOperand decodeLiteralConstant() const;
99
100 MCOperand decodeSrcOp(const OpWidthTy Width, unsigned Val) const;
101 MCOperand decodeSpecialReg32(unsigned Val) const;
102 MCOperand decodeSpecialReg64(unsigned Val) const;
103};
104
105//===----------------------------------------------------------------------===//
106// AMDGPUSymbolizer
107//===----------------------------------------------------------------------===//
108
109class AMDGPUSymbolizer : public MCSymbolizer {
110private:
111 void *DisInfo;
112
113public:
114 AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo,
Matt Arsenaultf3dd8632016-11-01 00:55:14 +0000115 void *disInfo)
Sam Kolton3381d7a2016-10-06 13:46:08 +0000116 : MCSymbolizer(Ctx, std::move(RelInfo)), DisInfo(disInfo) {}
117
118 bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream,
119 int64_t Value, uint64_t Address,
120 bool IsBranch, uint64_t Offset,
121 uint64_t InstSize) override;
122
123 void tryAddingPcLoadReferenceComment(raw_ostream &cStream,
124 int64_t Value,
Matt Arsenault92b355b2016-11-15 19:34:37 +0000125 uint64_t Address) override;
Sam Kolton3381d7a2016-10-06 13:46:08 +0000126};
127
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000128} // end namespace llvm
Tom Stellarde1818af2016-02-18 03:42:32 +0000129
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000130#endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H