blob: f9768497734c178b742861583a6d34478f14066e [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"
Sam Kolton3381d7a2016-10-06 13:46:08 +000021#include "llvm/MC/MCDisassembler/MCSymbolizer.h"
Tom Stellarde1818af2016-02-18 03:42:32 +000022
23namespace llvm {
24
Sam Kolton3381d7a2016-10-06 13:46:08 +000025class MCContext;
26class MCInst;
27class MCOperand;
28class MCSubtargetInfo;
29class Twine;
Tom Stellarde1818af2016-02-18 03:42:32 +000030
Sam Kolton3381d7a2016-10-06 13:46:08 +000031//===----------------------------------------------------------------------===//
32// AMDGPUDisassembler
33//===----------------------------------------------------------------------===//
Nikolay Haustov161a1582016-02-25 16:09:14 +000034
Sam Kolton3381d7a2016-10-06 13:46:08 +000035class AMDGPUDisassembler : public MCDisassembler {
36private:
37 mutable ArrayRef<uint8_t> Bytes;
Tom Stellarde1818af2016-02-18 03:42:32 +000038
Sam Kolton3381d7a2016-10-06 13:46:08 +000039public:
40 AMDGPUDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) :
41 MCDisassembler(STI, Ctx) {}
Tom Stellarde1818af2016-02-18 03:42:32 +000042
Sam Kolton3381d7a2016-10-06 13:46:08 +000043 ~AMDGPUDisassembler() {}
Tom Stellarde1818af2016-02-18 03:42:32 +000044
Sam Kolton3381d7a2016-10-06 13:46:08 +000045 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 Stellarde1818af2016-02-18 03:42:32 +000048
Sam Kolton3381d7a2016-10-06 13:46:08 +000049 const char* getRegClassName(unsigned RegClassID) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000050
Sam Kolton3381d7a2016-10-06 13:46:08 +000051 MCOperand createRegOperand(unsigned int RegId) const;
52 MCOperand createRegOperand(unsigned RegClassID, unsigned Val) const;
53 MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000054
Sam Kolton3381d7a2016-10-06 13:46:08 +000055 MCOperand errOperand(unsigned V, const llvm::Twine& ErrMsg) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000056
Sam Kolton3381d7a2016-10-06 13:46:08 +000057 DecodeStatus tryDecodeInst(const uint8_t* Table,
58 MCInst &MI,
59 uint64_t Inst,
60 uint64_t Address) const;
Tom Stellarde1818af2016-02-18 03:42:32 +000061
Sam Kolton3381d7a2016-10-06 13:46:08 +000062 MCOperand decodeOperand_VGPR_32(unsigned Val) const;
63 MCOperand decodeOperand_VS_32(unsigned Val) const;
64 MCOperand decodeOperand_VS_64(unsigned Val) const;
Nikolay Haustov161a1582016-02-25 16:09:14 +000065
Sam Kolton3381d7a2016-10-06 13:46:08 +000066 MCOperand decodeOperand_VReg_64(unsigned Val) const;
67 MCOperand decodeOperand_VReg_96(unsigned Val) const;
68 MCOperand decodeOperand_VReg_128(unsigned Val) const;
Nikolay Haustovac106ad2016-03-01 13:57:29 +000069
Sam Kolton3381d7a2016-10-06 13:46:08 +000070 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 Haustovac106ad2016-03-01 13:57:29 +000076
Sam Kolton3381d7a2016-10-06 13:46:08 +000077 enum OpWidthTy {
78 OPW32,
79 OPW64,
80 OPW128,
81 OPW_LAST_,
82 OPW_FIRST_ = OPW32
Tom Stellarde1818af2016-02-18 03:42:32 +000083 };
Sam Kolton3381d7a2016-10-06 13:46:08 +000084 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
101class AMDGPUSymbolizer : public MCSymbolizer {
102private:
103 void *DisInfo;
104
105public:
106 AMDGPUSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo,
Matt Arsenaultf3dd8632016-11-01 00:55:14 +0000107 void *disInfo)
Sam Kolton3381d7a2016-10-06 13:46:08 +0000108 : 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 Arsenault92b355b2016-11-15 19:34:37 +0000117 uint64_t Address) override;
Sam Kolton3381d7a2016-10-06 13:46:08 +0000118};
119
Tom Stellarde1818af2016-02-18 03:42:32 +0000120} // namespace llvm
121
Nikolay Haustovac106ad2016-03-01 13:57:29 +0000122#endif //LLVM_LIB_TARGET_AMDGPU_DISASSEMBLER_AMDGPUDISASSEMBLER_H