blob: d50665187e10ba49aba71a5b8d27c3efeade312c [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;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000070 MCOperand decodeOperand_VSrcV216(unsigned Val) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000071
Sam Kolton3381d7a2016-10-06 13:46:08 +000072 MCOperand decodeOperand_VReg_64(unsigned Val) const;
73 MCOperand decodeOperand_VReg_96(unsigned Val) const;
74 MCOperand decodeOperand_VReg_128(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000075
Sam Kolton3381d7a2016-10-06 13:46:08 +000076 MCOperand decodeOperand_SReg_32(unsigned Val) const;
Matt Arsenault640c44b2016-11-29 19:39:53 +000077 MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const;
Sam Kolton3381d7a2016-10-06 13:46:08 +000078 MCOperand decodeOperand_SReg_64(unsigned Val) const;
Matt Arsenault640c44b2016-11-29 19:39:53 +000079 MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const;
Sam Kolton3381d7a2016-10-06 13:46:08 +000080 MCOperand decodeOperand_SReg_128(unsigned Val) const;
81 MCOperand decodeOperand_SReg_256(unsigned Val) const;
82 MCOperand decodeOperand_SReg_512(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000083
Sam Kolton3381d7a2016-10-06 13:46:08 +000084 enum OpWidthTy {
85 OPW32,
86 OPW64,
87 OPW128,
Matt Arsenault4bd72362016-12-10 00:39:12 +000088 OPW16,
Matt Arsenault9be7b0d2017-02-27 18:49:11 +000089 OPWV216,
Sam Kolton3381d7a2016-10-06 13:46:08 +000090 OPW_LAST_,
91 OPW_FIRST_ = OPW32
Tom Stellarde1818af2016-02-18 03:42:32 +000092 };
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000093
Sam Kolton3381d7a2016-10-06 13:46:08 +000094 unsigned getVgprClassId(const OpWidthTy Width) const;
95 unsigned getSgprClassId(const OpWidthTy Width) const;
96 unsigned getTtmpClassId(const OpWidthTy Width) const;
97
98 static MCOperand decodeIntImmed(unsigned Imm);
Matt Arsenault4bd72362016-12-10 00:39:12 +000099 static MCOperand decodeFPImmed(OpWidthTy Width, unsigned Imm);
Sam Kolton3381d7a2016-10-06 13:46:08 +0000100 MCOperand decodeLiteralConstant() const;
101
102 MCOperand decodeSrcOp(const OpWidthTy Width, unsigned Val) const;
103 MCOperand decodeSpecialReg32(unsigned Val) const;
104 MCOperand decodeSpecialReg64(unsigned Val) const;
105};
106
107//===----------------------------------------------------------------------===//
108// AMDGPUSymbolizer
109//===----------------------------------------------------------------------===//
110
111class AMDGPUSymbolizer : public MCSymbolizer {
112private:
113 void *DisInfo;
114
115public:
116 AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo,
Matt Arsenaultf3dd8632016-11-01 00:55:14 +0000117 void *disInfo)
Sam Kolton3381d7a2016-10-06 13:46:08 +0000118 : MCSymbolizer(Ctx, std::move(RelInfo)), DisInfo(disInfo) {}
119
120 bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream,
121 int64_t Value, uint64_t Address,
122 bool IsBranch, uint64_t Offset,
123 uint64_t InstSize) override;
124
125 void tryAddingPcLoadReferenceComment(raw_ostream &cStream,
126 int64_t Value,
Matt Arsenault92b355b2016-11-15 19:34:37 +0000127 uint64_t Address) override;
Sam Kolton3381d7a2016-10-06 13:46:08 +0000128};
129
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000130} // end namespace llvm
Tom Stellarde1818af2016-02-18 03:42:32 +0000131
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000132#endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H