blob: c8b2f1ff239ae261a874658bfd6b4dbfc1957753 [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;
Nikolay Haustov161a1582016-02-25 16:09:14 +000069
Sam Kolton3381d7a2016-10-06 13:46:08 +000070 MCOperand decodeOperand_VReg_64(unsigned Val) const;
71 MCOperand decodeOperand_VReg_96(unsigned Val) const;
72 MCOperand decodeOperand_VReg_128(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000073
Sam Kolton3381d7a2016-10-06 13:46:08 +000074 MCOperand decodeOperand_SReg_32(unsigned Val) const;
Matt Arsenault640c44b2016-11-29 19:39:53 +000075 MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const;
Sam Kolton3381d7a2016-10-06 13:46:08 +000076 MCOperand decodeOperand_SReg_64(unsigned Val) const;
Matt Arsenault640c44b2016-11-29 19:39:53 +000077 MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const;
Sam Kolton3381d7a2016-10-06 13:46:08 +000078 MCOperand decodeOperand_SReg_128(unsigned Val) const;
79 MCOperand decodeOperand_SReg_256(unsigned Val) const;
80 MCOperand decodeOperand_SReg_512(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000081
Sam Kolton3381d7a2016-10-06 13:46:08 +000082 enum OpWidthTy {
83 OPW32,
84 OPW64,
85 OPW128,
86 OPW_LAST_,
87 OPW_FIRST_ = OPW32
Tom Stellarde1818af2016-02-18 03:42:32 +000088 };
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000089
Sam Kolton3381d7a2016-10-06 13:46:08 +000090 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
107class AMDGPUSymbolizer : public MCSymbolizer {
108private:
109 void *DisInfo;
110
111public:
112 AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo,
Matt Arsenaultf3dd8632016-11-01 00:55:14 +0000113 void *disInfo)
Sam Kolton3381d7a2016-10-06 13:46:08 +0000114 : 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 Arsenault92b355b2016-11-15 19:34:37 +0000123 uint64_t Address) override;
Sam Kolton3381d7a2016-10-06 13:46:08 +0000124};
125
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000126} // end namespace llvm
Tom Stellarde1818af2016-02-18 03:42:32 +0000127
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000128#endif // LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H