2017-08-10 08:46:15 +08:00
|
|
|
//===- AMDGPUDisassembler.cpp - Disassembler for AMDGPU ISA ---------------===//
|
2016-02-18 11:42:32 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
///
|
|
|
|
/// This file contains definition for AMDGPU ISA disassembler
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// ToDo: What to do with instruction suffixes (v_mov_b32 vs v_mov_b32_e32)?
|
|
|
|
|
2017-08-10 08:46:15 +08:00
|
|
|
#include "Disassembler/AMDGPUDisassembler.h"
|
2016-02-18 11:42:32 +08:00
|
|
|
#include "AMDGPU.h"
|
|
|
|
#include "AMDGPURegisterInfo.h"
|
2016-05-24 20:05:16 +08:00
|
|
|
#include "SIDefines.h"
|
2016-02-18 11:42:32 +08:00
|
|
|
#include "Utils/AMDGPUBaseInfo.h"
|
2017-08-10 08:46:15 +08:00
|
|
|
#include "llvm-c/Disassembler.h"
|
|
|
|
#include "llvm/ADT/APInt.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2016-03-01 21:57:29 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2017-08-10 08:46:15 +08:00
|
|
|
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
2016-02-18 11:42:32 +08:00
|
|
|
#include "llvm/MC/MCFixedLenDisassembler.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2016-03-01 21:57:29 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2017-08-10 08:46:15 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2016-02-18 11:42:32 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2017-08-10 08:46:15 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iterator>
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
2016-02-18 11:42:32 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "amdgpu-disassembler"
|
|
|
|
|
2017-08-10 08:46:15 +08:00
|
|
|
using DecodeStatus = llvm::MCDisassembler::DecodeStatus;
|
2016-02-18 11:42:32 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
inline static MCDisassembler::DecodeStatus
|
|
|
|
addOperand(MCInst &Inst, const MCOperand& Opnd) {
|
|
|
|
Inst.addOperand(Opnd);
|
|
|
|
return Opnd.isValid() ?
|
|
|
|
MCDisassembler::Success :
|
|
|
|
MCDisassembler::SoftFail;
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
static int insertNamedMCOperand(MCInst &MI, const MCOperand &Op,
|
|
|
|
uint16_t NameIdx) {
|
|
|
|
int OpIdx = AMDGPU::getNamedOperandIdx(MI.getOpcode(), NameIdx);
|
|
|
|
if (OpIdx != -1) {
|
|
|
|
auto I = MI.begin();
|
|
|
|
std::advance(I, OpIdx);
|
|
|
|
MI.insert(I, Op);
|
|
|
|
}
|
|
|
|
return OpIdx;
|
|
|
|
}
|
|
|
|
|
2016-10-06 21:46:08 +08:00
|
|
|
static DecodeStatus decodeSoppBrTarget(MCInst &Inst, unsigned Imm,
|
|
|
|
uint64_t Addr, const void *Decoder) {
|
|
|
|
auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder);
|
|
|
|
|
|
|
|
APInt SignedOffset(18, Imm * 4, true);
|
|
|
|
int64_t Offset = (SignedOffset.sext(64) + 4 + Addr).getSExtValue();
|
|
|
|
|
|
|
|
if (DAsm->tryAddingSymbolicOperand(Inst, Offset, Addr, true, 2, 2))
|
|
|
|
return MCDisassembler::Success;
|
2016-11-01 08:55:14 +08:00
|
|
|
return addOperand(Inst, MCOperand::createImm(Imm));
|
2016-10-06 21:46:08 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 23:52:00 +08:00
|
|
|
#define DECODE_OPERAND(StaticDecoderName, DecoderName) \
|
|
|
|
static DecodeStatus StaticDecoderName(MCInst &Inst, \
|
|
|
|
unsigned Imm, \
|
|
|
|
uint64_t /*Addr*/, \
|
|
|
|
const void *Decoder) { \
|
2016-03-01 21:57:29 +08:00
|
|
|
auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder); \
|
2017-05-26 23:52:00 +08:00
|
|
|
return addOperand(Inst, DAsm->DecoderName(Imm)); \
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 23:52:00 +08:00
|
|
|
#define DECODE_OPERAND_REG(RegClass) \
|
|
|
|
DECODE_OPERAND(Decode##RegClass##RegisterClass, decodeOperand_##RegClass)
|
2016-02-18 11:42:32 +08:00
|
|
|
|
2017-05-26 23:52:00 +08:00
|
|
|
DECODE_OPERAND_REG(VGPR_32)
|
|
|
|
DECODE_OPERAND_REG(VS_32)
|
|
|
|
DECODE_OPERAND_REG(VS_64)
|
2017-07-18 21:12:48 +08:00
|
|
|
DECODE_OPERAND_REG(VS_128)
|
2016-02-18 11:42:32 +08:00
|
|
|
|
2017-05-26 23:52:00 +08:00
|
|
|
DECODE_OPERAND_REG(VReg_64)
|
|
|
|
DECODE_OPERAND_REG(VReg_96)
|
|
|
|
DECODE_OPERAND_REG(VReg_128)
|
2016-02-18 11:42:32 +08:00
|
|
|
|
2017-05-26 23:52:00 +08:00
|
|
|
DECODE_OPERAND_REG(SReg_32)
|
|
|
|
DECODE_OPERAND_REG(SReg_32_XM0_XEXEC)
|
2017-07-21 23:36:16 +08:00
|
|
|
DECODE_OPERAND_REG(SReg_32_XEXEC_HI)
|
2017-05-26 23:52:00 +08:00
|
|
|
DECODE_OPERAND_REG(SReg_64)
|
|
|
|
DECODE_OPERAND_REG(SReg_64_XEXEC)
|
|
|
|
DECODE_OPERAND_REG(SReg_128)
|
|
|
|
DECODE_OPERAND_REG(SReg_256)
|
|
|
|
DECODE_OPERAND_REG(SReg_512)
|
2016-02-18 11:42:32 +08:00
|
|
|
|
2016-12-10 08:39:12 +08:00
|
|
|
static DecodeStatus decodeOperand_VSrc16(MCInst &Inst,
|
|
|
|
unsigned Imm,
|
|
|
|
uint64_t Addr,
|
|
|
|
const void *Decoder) {
|
|
|
|
auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder);
|
|
|
|
return addOperand(Inst, DAsm->decodeOperand_VSrc16(Imm));
|
|
|
|
}
|
|
|
|
|
2017-02-28 02:49:11 +08:00
|
|
|
static DecodeStatus decodeOperand_VSrcV216(MCInst &Inst,
|
|
|
|
unsigned Imm,
|
|
|
|
uint64_t Addr,
|
|
|
|
const void *Decoder) {
|
|
|
|
auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder);
|
|
|
|
return addOperand(Inst, DAsm->decodeOperand_VSrcV216(Imm));
|
|
|
|
}
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
#define DECODE_SDWA(DecName) \
|
|
|
|
DECODE_OPERAND(decodeSDWA##DecName, decodeSDWA##DecName)
|
2017-05-26 23:52:00 +08:00
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
DECODE_SDWA(Src32)
|
|
|
|
DECODE_SDWA(Src16)
|
|
|
|
DECODE_SDWA(VopcDst)
|
2017-05-26 23:52:00 +08:00
|
|
|
|
2016-02-18 11:42:32 +08:00
|
|
|
#include "AMDGPUGenDisassemblerTables.inc"
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-31 22:15:04 +08:00
|
|
|
template <typename T> static inline T eatBytes(ArrayRef<uint8_t>& Bytes) {
|
|
|
|
assert(Bytes.size() >= sizeof(T));
|
|
|
|
const auto Res = support::endian::read<T, support::endianness::little>(Bytes.data());
|
|
|
|
Bytes = Bytes.slice(sizeof(T));
|
2016-03-01 21:57:29 +08:00
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecodeStatus AMDGPUDisassembler::tryDecodeInst(const uint8_t* Table,
|
|
|
|
MCInst &MI,
|
|
|
|
uint64_t Inst,
|
|
|
|
uint64_t Address) const {
|
|
|
|
assert(MI.getOpcode() == 0);
|
|
|
|
assert(MI.getNumOperands() == 0);
|
|
|
|
MCInst TmpInst;
|
2017-05-19 22:27:52 +08:00
|
|
|
HasLiteral = false;
|
2016-03-01 21:57:29 +08:00
|
|
|
const auto SavedBytes = Bytes;
|
|
|
|
if (decodeInstruction(Table, TmpInst, Inst, Address, this, STI)) {
|
|
|
|
MI = TmpInst;
|
|
|
|
return MCDisassembler::Success;
|
|
|
|
}
|
|
|
|
Bytes = SavedBytes;
|
|
|
|
return MCDisassembler::Fail;
|
|
|
|
}
|
|
|
|
|
2016-02-18 11:42:32 +08:00
|
|
|
DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
|
2016-03-01 21:57:29 +08:00
|
|
|
ArrayRef<uint8_t> Bytes_,
|
2016-02-26 00:09:14 +08:00
|
|
|
uint64_t Address,
|
2016-02-18 11:42:32 +08:00
|
|
|
raw_ostream &WS,
|
|
|
|
raw_ostream &CS) const {
|
|
|
|
CommentStream = &CS;
|
2017-06-21 16:53:38 +08:00
|
|
|
bool IsSDWA = false;
|
2016-02-18 11:42:32 +08:00
|
|
|
|
|
|
|
// ToDo: AMDGPUDisassembler supports only VI ISA.
|
2017-02-16 05:50:34 +08:00
|
|
|
if (!STI.getFeatureBits()[AMDGPU::FeatureGCN3Encoding])
|
|
|
|
report_fatal_error("Disassembly not yet supported for subtarget");
|
2016-02-18 11:42:32 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
const unsigned MaxInstBytesNum = (std::min)((size_t)8, Bytes_.size());
|
|
|
|
Bytes = Bytes_.slice(0, MaxInstBytesNum);
|
2016-02-26 00:09:14 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
DecodeStatus Res = MCDisassembler::Fail;
|
|
|
|
do {
|
2016-03-04 18:59:50 +08:00
|
|
|
// ToDo: better to switch encoding length using some bit predicate
|
2016-03-01 21:57:29 +08:00
|
|
|
// but it is unknown yet, so try all we can
|
2016-06-10 10:18:02 +08:00
|
|
|
|
2016-06-09 19:04:45 +08:00
|
|
|
// Try to decode DPP and SDWA first to solve conflict with VOP1 and VOP2
|
|
|
|
// encodings
|
2016-03-31 22:15:04 +08:00
|
|
|
if (Bytes.size() >= 8) {
|
|
|
|
const uint64_t QW = eatBytes<uint64_t>(Bytes);
|
|
|
|
Res = tryDecodeInst(DecoderTableDPP64, MI, QW, Address);
|
|
|
|
if (Res) break;
|
2016-06-09 19:04:45 +08:00
|
|
|
|
|
|
|
Res = tryDecodeInst(DecoderTableSDWA64, MI, QW, Address);
|
2017-06-21 16:53:38 +08:00
|
|
|
if (Res) { IsSDWA = true; break; }
|
2017-05-26 23:52:00 +08:00
|
|
|
|
|
|
|
Res = tryDecodeInst(DecoderTableSDWA964, MI, QW, Address);
|
2017-06-21 16:53:38 +08:00
|
|
|
if (Res) { IsSDWA = true; break; }
|
2016-03-31 22:15:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reinitialize Bytes as DPP64 could have eaten too much
|
|
|
|
Bytes = Bytes_.slice(0, MaxInstBytesNum);
|
|
|
|
|
|
|
|
// Try decode 32-bit instruction
|
2016-03-01 21:57:29 +08:00
|
|
|
if (Bytes.size() < 4) break;
|
2016-03-31 22:15:04 +08:00
|
|
|
const uint32_t DW = eatBytes<uint32_t>(Bytes);
|
2016-03-01 21:57:29 +08:00
|
|
|
Res = tryDecodeInst(DecoderTableVI32, MI, DW, Address);
|
|
|
|
if (Res) break;
|
2016-02-18 11:42:32 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
Res = tryDecodeInst(DecoderTableAMDGPU32, MI, DW, Address);
|
|
|
|
if (Res) break;
|
2016-02-18 11:42:32 +08:00
|
|
|
|
2017-11-21 02:24:21 +08:00
|
|
|
Res = tryDecodeInst(DecoderTableGFX932, MI, DW, Address);
|
|
|
|
if (Res) break;
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
if (Bytes.size() < 4) break;
|
2016-03-31 22:15:04 +08:00
|
|
|
const uint64_t QW = ((uint64_t)eatBytes<uint32_t>(Bytes) << 32) | DW;
|
2016-03-01 21:57:29 +08:00
|
|
|
Res = tryDecodeInst(DecoderTableVI64, MI, QW, Address);
|
|
|
|
if (Res) break;
|
|
|
|
|
|
|
|
Res = tryDecodeInst(DecoderTableAMDGPU64, MI, QW, Address);
|
2017-08-10 01:10:47 +08:00
|
|
|
if (Res) break;
|
|
|
|
|
|
|
|
Res = tryDecodeInst(DecoderTableGFX964, MI, QW, Address);
|
2016-03-01 21:57:29 +08:00
|
|
|
} while (false);
|
|
|
|
|
2017-04-11 01:58:06 +08:00
|
|
|
if (Res && (MI.getOpcode() == AMDGPU::V_MAC_F32_e64_vi ||
|
|
|
|
MI.getOpcode() == AMDGPU::V_MAC_F32_e64_si ||
|
|
|
|
MI.getOpcode() == AMDGPU::V_MAC_F16_e64_vi)) {
|
|
|
|
// Insert dummy unused src2_modifiers.
|
2017-06-21 16:53:38 +08:00
|
|
|
insertNamedMCOperand(MI, MCOperand::createImm(0),
|
|
|
|
AMDGPU::OpName::src2_modifiers);
|
2017-04-11 01:58:06 +08:00
|
|
|
}
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
if (Res && IsSDWA)
|
|
|
|
Res = convertSDWAInst(MI);
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
Size = Res ? (MaxInstBytesNum - Bytes.size()) : 0;
|
|
|
|
return Res;
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
DecodeStatus AMDGPUDisassembler::convertSDWAInst(MCInst &MI) const {
|
|
|
|
if (STI.getFeatureBits()[AMDGPU::FeatureGFX9]) {
|
|
|
|
if (AMDGPU::getNamedOperandIdx(MI.getOpcode(), AMDGPU::OpName::sdst) != -1)
|
|
|
|
// VOPC - insert clamp
|
|
|
|
insertNamedMCOperand(MI, MCOperand::createImm(0), AMDGPU::OpName::clamp);
|
|
|
|
} else if (STI.getFeatureBits()[AMDGPU::FeatureVolcanicIslands]) {
|
|
|
|
int SDst = AMDGPU::getNamedOperandIdx(MI.getOpcode(), AMDGPU::OpName::sdst);
|
|
|
|
if (SDst != -1) {
|
|
|
|
// VOPC - insert VCC register as sdst
|
|
|
|
insertNamedMCOperand(MI, MCOperand::createReg(AMDGPU::VCC),
|
|
|
|
AMDGPU::OpName::sdst);
|
|
|
|
} else {
|
|
|
|
// VOP1/2 - insert omod if present in instruction
|
|
|
|
insertNamedMCOperand(MI, MCOperand::createImm(0), AMDGPU::OpName::omod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MCDisassembler::Success;
|
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
const char* AMDGPUDisassembler::getRegClassName(unsigned RegClassID) const {
|
|
|
|
return getContext().getRegisterInfo()->
|
|
|
|
getRegClassName(&AMDGPUMCRegisterClasses[RegClassID]);
|
2016-02-26 00:09:14 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
inline
|
|
|
|
MCOperand AMDGPUDisassembler::errOperand(unsigned V,
|
|
|
|
const Twine& ErrMsg) const {
|
|
|
|
*CommentStream << "Error: " + ErrMsg;
|
|
|
|
|
|
|
|
// ToDo: add support for error operands to MCInst.h
|
|
|
|
// return MCOperand::createError(V);
|
|
|
|
return MCOperand();
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
inline
|
|
|
|
MCOperand AMDGPUDisassembler::createRegOperand(unsigned int RegId) const {
|
|
|
|
return MCOperand::createReg(RegId);
|
|
|
|
}
|
2016-02-26 00:09:14 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
inline
|
|
|
|
MCOperand AMDGPUDisassembler::createRegOperand(unsigned RegClassID,
|
|
|
|
unsigned Val) const {
|
|
|
|
const auto& RegCl = AMDGPUMCRegisterClasses[RegClassID];
|
|
|
|
if (Val >= RegCl.getNumRegs())
|
|
|
|
return errOperand(Val, Twine(getRegClassName(RegClassID)) +
|
|
|
|
": unknown register " + Twine(Val));
|
|
|
|
return createRegOperand(RegCl.getRegister(Val));
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
inline
|
|
|
|
MCOperand AMDGPUDisassembler::createSRegOperand(unsigned SRegClassID,
|
|
|
|
unsigned Val) const {
|
2016-02-18 11:42:32 +08:00
|
|
|
// ToDo: SI/CI have 104 SGPRs, VI - 102
|
2016-03-01 21:57:29 +08:00
|
|
|
// Valery: here we accepting as much as we can, let assembler sort it out
|
|
|
|
int shift = 0;
|
|
|
|
switch (SRegClassID) {
|
|
|
|
case AMDGPU::SGPR_32RegClassID:
|
2016-05-24 20:05:16 +08:00
|
|
|
case AMDGPU::TTMP_32RegClassID:
|
|
|
|
break;
|
2016-03-01 21:57:29 +08:00
|
|
|
case AMDGPU::SGPR_64RegClassID:
|
2016-05-24 20:05:16 +08:00
|
|
|
case AMDGPU::TTMP_64RegClassID:
|
|
|
|
shift = 1;
|
|
|
|
break;
|
|
|
|
case AMDGPU::SGPR_128RegClassID:
|
|
|
|
case AMDGPU::TTMP_128RegClassID:
|
2016-03-01 21:57:29 +08:00
|
|
|
// ToDo: unclear if s[100:104] is available on VI. Can we use VCC as SGPR in
|
|
|
|
// this bundle?
|
|
|
|
case AMDGPU::SReg_256RegClassID:
|
|
|
|
// ToDo: unclear if s[96:104] is available on VI. Can we use VCC as SGPR in
|
|
|
|
// this bundle?
|
2016-05-24 20:05:16 +08:00
|
|
|
case AMDGPU::SReg_512RegClassID:
|
|
|
|
shift = 2;
|
|
|
|
break;
|
2016-03-01 21:57:29 +08:00
|
|
|
// ToDo: unclear if s[88:104] is available on VI. Can we use VCC as SGPR in
|
|
|
|
// this bundle?
|
2016-05-24 20:05:16 +08:00
|
|
|
default:
|
2016-11-16 03:34:37 +08:00
|
|
|
llvm_unreachable("unhandled register class");
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
2016-11-16 03:34:37 +08:00
|
|
|
|
|
|
|
if (Val % (1 << shift)) {
|
2016-03-01 21:57:29 +08:00
|
|
|
*CommentStream << "Warning: " << getRegClassName(SRegClassID)
|
|
|
|
<< ": scalar reg isn't aligned " << Val;
|
2016-11-16 03:34:37 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
return createRegOperand(SRegClassID, Val >> shift);
|
|
|
|
}
|
2016-02-26 00:09:14 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VS_32(unsigned Val) const {
|
2016-05-24 20:05:16 +08:00
|
|
|
return decodeSrcOp(OPW32, Val);
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VS_64(unsigned Val) const {
|
2016-05-24 20:05:16 +08:00
|
|
|
return decodeSrcOp(OPW64, Val);
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
|
2017-07-18 21:12:48 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VS_128(unsigned Val) const {
|
|
|
|
return decodeSrcOp(OPW128, Val);
|
|
|
|
}
|
|
|
|
|
2016-12-10 08:39:12 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VSrc16(unsigned Val) const {
|
|
|
|
return decodeSrcOp(OPW16, Val);
|
|
|
|
}
|
|
|
|
|
2017-02-28 02:49:11 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VSrcV216(unsigned Val) const {
|
|
|
|
return decodeSrcOp(OPWV216, Val);
|
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VGPR_32(unsigned Val) const {
|
2016-07-19 08:35:03 +08:00
|
|
|
// Some instructions have operand restrictions beyond what the encoding
|
|
|
|
// allows. Some ordinarily VSrc_32 operands are VGPR_32, so clear the extra
|
|
|
|
// high bit.
|
|
|
|
Val &= 255;
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
return createRegOperand(AMDGPU::VGPR_32RegClassID, Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VReg_64(unsigned Val) const {
|
|
|
|
return createRegOperand(AMDGPU::VReg_64RegClassID, Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VReg_96(unsigned Val) const {
|
|
|
|
return createRegOperand(AMDGPU::VReg_96RegClassID, Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_VReg_128(unsigned Val) const {
|
|
|
|
return createRegOperand(AMDGPU::VReg_128RegClassID, Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_SReg_32(unsigned Val) const {
|
|
|
|
// table-gen generated disassembler doesn't care about operand types
|
|
|
|
// leaving only registry class so SSrc_32 operand turns into SReg_32
|
|
|
|
// and therefore we accept immediates and literals here as well
|
2016-05-24 20:05:16 +08:00
|
|
|
return decodeSrcOp(OPW32, Val);
|
2016-03-01 21:57:29 +08:00
|
|
|
}
|
|
|
|
|
2016-11-30 03:39:53 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_SReg_32_XM0_XEXEC(
|
|
|
|
unsigned Val) const {
|
|
|
|
// SReg_32_XM0 is SReg_32 without M0 or EXEC_LO/EXEC_HI
|
2016-04-30 01:04:50 +08:00
|
|
|
return decodeOperand_SReg_32(Val);
|
|
|
|
}
|
|
|
|
|
2017-07-21 23:36:16 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_SReg_32_XEXEC_HI(
|
|
|
|
unsigned Val) const {
|
|
|
|
// SReg_32_XM0 is SReg_32 without EXEC_HI
|
|
|
|
return decodeOperand_SReg_32(Val);
|
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_SReg_64(unsigned Val) const {
|
2016-11-30 03:39:53 +08:00
|
|
|
return decodeSrcOp(OPW64, Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_SReg_64_XEXEC(unsigned Val) const {
|
2016-05-24 20:05:16 +08:00
|
|
|
return decodeSrcOp(OPW64, Val);
|
2016-03-01 21:57:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_SReg_128(unsigned Val) const {
|
2016-05-24 20:05:16 +08:00
|
|
|
return decodeSrcOp(OPW128, Val);
|
2016-03-01 21:57:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_SReg_256(unsigned Val) const {
|
|
|
|
return createSRegOperand(AMDGPU::SReg_256RegClassID, Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeOperand_SReg_512(unsigned Val) const {
|
|
|
|
return createSRegOperand(AMDGPU::SReg_512RegClassID, Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeLiteralConstant() const {
|
2016-02-26 00:09:14 +08:00
|
|
|
// For now all literal constants are supposed to be unsigned integer
|
|
|
|
// ToDo: deal with signed/unsigned 64-bit integer constants
|
|
|
|
// ToDo: deal with float/double constants
|
2017-05-19 22:27:52 +08:00
|
|
|
if (!HasLiteral) {
|
|
|
|
if (Bytes.size() < 4) {
|
|
|
|
return errOperand(0, "cannot read literal, inst bytes left " +
|
|
|
|
Twine(Bytes.size()));
|
|
|
|
}
|
|
|
|
HasLiteral = true;
|
|
|
|
Literal = eatBytes<uint32_t>(Bytes);
|
|
|
|
}
|
|
|
|
return MCOperand::createImm(Literal);
|
2016-02-26 00:09:14 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeIntImmed(unsigned Imm) {
|
2016-05-24 20:05:16 +08:00
|
|
|
using namespace AMDGPU::EncValues;
|
2017-08-10 08:46:15 +08:00
|
|
|
|
2016-05-24 20:05:16 +08:00
|
|
|
assert(Imm >= INLINE_INTEGER_C_MIN && Imm <= INLINE_INTEGER_C_MAX);
|
|
|
|
return MCOperand::createImm((Imm <= INLINE_INTEGER_C_POSITIVE_MAX) ?
|
|
|
|
(static_cast<int64_t>(Imm) - INLINE_INTEGER_C_MIN) :
|
|
|
|
(INLINE_INTEGER_C_POSITIVE_MAX - static_cast<int64_t>(Imm)));
|
|
|
|
// Cast prevents negative overflow.
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
|
2016-12-10 08:39:12 +08:00
|
|
|
static int64_t getInlineImmVal32(unsigned Imm) {
|
|
|
|
switch (Imm) {
|
|
|
|
case 240:
|
|
|
|
return FloatToBits(0.5f);
|
|
|
|
case 241:
|
|
|
|
return FloatToBits(-0.5f);
|
|
|
|
case 242:
|
|
|
|
return FloatToBits(1.0f);
|
|
|
|
case 243:
|
|
|
|
return FloatToBits(-1.0f);
|
|
|
|
case 244:
|
|
|
|
return FloatToBits(2.0f);
|
|
|
|
case 245:
|
|
|
|
return FloatToBits(-2.0f);
|
|
|
|
case 246:
|
|
|
|
return FloatToBits(4.0f);
|
|
|
|
case 247:
|
|
|
|
return FloatToBits(-4.0f);
|
|
|
|
case 248: // 1 / (2 * PI)
|
|
|
|
return 0x3e22f983;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("invalid fp inline imm");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t getInlineImmVal64(unsigned Imm) {
|
|
|
|
switch (Imm) {
|
|
|
|
case 240:
|
|
|
|
return DoubleToBits(0.5);
|
|
|
|
case 241:
|
|
|
|
return DoubleToBits(-0.5);
|
|
|
|
case 242:
|
|
|
|
return DoubleToBits(1.0);
|
|
|
|
case 243:
|
|
|
|
return DoubleToBits(-1.0);
|
|
|
|
case 244:
|
|
|
|
return DoubleToBits(2.0);
|
|
|
|
case 245:
|
|
|
|
return DoubleToBits(-2.0);
|
|
|
|
case 246:
|
|
|
|
return DoubleToBits(4.0);
|
|
|
|
case 247:
|
|
|
|
return DoubleToBits(-4.0);
|
|
|
|
case 248: // 1 / (2 * PI)
|
|
|
|
return 0x3fc45f306dc9c882;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("invalid fp inline imm");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t getInlineImmVal16(unsigned Imm) {
|
|
|
|
switch (Imm) {
|
|
|
|
case 240:
|
|
|
|
return 0x3800;
|
|
|
|
case 241:
|
|
|
|
return 0xB800;
|
|
|
|
case 242:
|
|
|
|
return 0x3C00;
|
|
|
|
case 243:
|
|
|
|
return 0xBC00;
|
|
|
|
case 244:
|
|
|
|
return 0x4000;
|
|
|
|
case 245:
|
|
|
|
return 0xC000;
|
|
|
|
case 246:
|
|
|
|
return 0x4400;
|
|
|
|
case 247:
|
|
|
|
return 0xC400;
|
|
|
|
case 248: // 1 / (2 * PI)
|
|
|
|
return 0x3118;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("invalid fp inline imm");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeFPImmed(OpWidthTy Width, unsigned Imm) {
|
2016-05-24 20:05:16 +08:00
|
|
|
assert(Imm >= AMDGPU::EncValues::INLINE_FLOATING_C_MIN
|
|
|
|
&& Imm <= AMDGPU::EncValues::INLINE_FLOATING_C_MAX);
|
2016-12-10 08:39:12 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
// ToDo: case 248: 1/(2*PI) - is allowed only on VI
|
2016-12-10 08:39:12 +08:00
|
|
|
switch (Width) {
|
|
|
|
case OPW32:
|
|
|
|
return MCOperand::createImm(getInlineImmVal32(Imm));
|
|
|
|
case OPW64:
|
|
|
|
return MCOperand::createImm(getInlineImmVal64(Imm));
|
|
|
|
case OPW16:
|
2017-02-28 02:49:11 +08:00
|
|
|
case OPWV216:
|
2016-12-10 08:39:12 +08:00
|
|
|
return MCOperand::createImm(getInlineImmVal16(Imm));
|
|
|
|
default:
|
|
|
|
llvm_unreachable("implement me");
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-24 20:05:16 +08:00
|
|
|
unsigned AMDGPUDisassembler::getVgprClassId(const OpWidthTy Width) const {
|
2016-03-01 21:57:29 +08:00
|
|
|
using namespace AMDGPU;
|
2017-08-10 08:46:15 +08:00
|
|
|
|
2016-05-24 20:05:16 +08:00
|
|
|
assert(OPW_FIRST_ <= Width && Width < OPW_LAST_);
|
|
|
|
switch (Width) {
|
|
|
|
default: // fall
|
2016-12-10 08:39:12 +08:00
|
|
|
case OPW32:
|
|
|
|
case OPW16:
|
2017-02-28 02:49:11 +08:00
|
|
|
case OPWV216:
|
2016-12-10 08:39:12 +08:00
|
|
|
return VGPR_32RegClassID;
|
2016-05-24 20:05:16 +08:00
|
|
|
case OPW64: return VReg_64RegClassID;
|
|
|
|
case OPW128: return VReg_128RegClassID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned AMDGPUDisassembler::getSgprClassId(const OpWidthTy Width) const {
|
|
|
|
using namespace AMDGPU;
|
2017-08-10 08:46:15 +08:00
|
|
|
|
2016-05-24 20:05:16 +08:00
|
|
|
assert(OPW_FIRST_ <= Width && Width < OPW_LAST_);
|
|
|
|
switch (Width) {
|
|
|
|
default: // fall
|
2016-12-10 08:39:12 +08:00
|
|
|
case OPW32:
|
|
|
|
case OPW16:
|
2017-02-28 02:49:11 +08:00
|
|
|
case OPWV216:
|
2016-12-10 08:39:12 +08:00
|
|
|
return SGPR_32RegClassID;
|
2016-05-24 20:05:16 +08:00
|
|
|
case OPW64: return SGPR_64RegClassID;
|
|
|
|
case OPW128: return SGPR_128RegClassID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned AMDGPUDisassembler::getTtmpClassId(const OpWidthTy Width) const {
|
|
|
|
using namespace AMDGPU;
|
2017-08-10 08:46:15 +08:00
|
|
|
|
2016-05-24 20:05:16 +08:00
|
|
|
assert(OPW_FIRST_ <= Width && Width < OPW_LAST_);
|
|
|
|
switch (Width) {
|
|
|
|
default: // fall
|
2016-12-10 08:39:12 +08:00
|
|
|
case OPW32:
|
|
|
|
case OPW16:
|
2017-02-28 02:49:11 +08:00
|
|
|
case OPWV216:
|
2016-12-10 08:39:12 +08:00
|
|
|
return TTMP_32RegClassID;
|
2016-05-24 20:05:16 +08:00
|
|
|
case OPW64: return TTMP_64RegClassID;
|
|
|
|
case OPW128: return TTMP_128RegClassID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand AMDGPUDisassembler::decodeSrcOp(const OpWidthTy Width, unsigned Val) const {
|
|
|
|
using namespace AMDGPU::EncValues;
|
2017-08-10 08:46:15 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
assert(Val < 512); // enum9
|
|
|
|
|
2016-05-24 20:05:16 +08:00
|
|
|
if (VGPR_MIN <= Val && Val <= VGPR_MAX) {
|
|
|
|
return createRegOperand(getVgprClassId(Width), Val - VGPR_MIN);
|
|
|
|
}
|
2016-05-26 23:52:16 +08:00
|
|
|
if (Val <= SGPR_MAX) {
|
|
|
|
assert(SGPR_MIN == 0); // "SGPR_MIN <= Val" is always true and causes compilation warning.
|
2016-05-24 20:05:16 +08:00
|
|
|
return createSRegOperand(getSgprClassId(Width), Val - SGPR_MIN);
|
|
|
|
}
|
|
|
|
if (TTMP_MIN <= Val && Val <= TTMP_MAX) {
|
|
|
|
return createSRegOperand(getTtmpClassId(Width), Val - TTMP_MIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (INLINE_INTEGER_C_MIN <= Val && Val <= INLINE_INTEGER_C_MAX)
|
2016-03-01 21:57:29 +08:00
|
|
|
return decodeIntImmed(Val);
|
2016-02-26 00:09:14 +08:00
|
|
|
|
2016-05-24 20:05:16 +08:00
|
|
|
if (INLINE_FLOATING_C_MIN <= Val && Val <= INLINE_FLOATING_C_MAX)
|
2016-12-10 08:39:12 +08:00
|
|
|
return decodeFPImmed(Width, Val);
|
2016-03-01 21:57:29 +08:00
|
|
|
|
2016-05-24 20:05:16 +08:00
|
|
|
if (Val == LITERAL_CONST)
|
2016-03-01 21:57:29 +08:00
|
|
|
return decodeLiteralConstant();
|
|
|
|
|
2016-12-10 08:39:12 +08:00
|
|
|
switch (Width) {
|
|
|
|
case OPW32:
|
|
|
|
case OPW16:
|
2017-02-28 02:49:11 +08:00
|
|
|
case OPWV216:
|
2016-12-10 08:39:12 +08:00
|
|
|
return decodeSpecialReg32(Val);
|
|
|
|
case OPW64:
|
|
|
|
return decodeSpecialReg64(Val);
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unexpected immediate type");
|
|
|
|
}
|
2016-02-26 00:09:14 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeSpecialReg32(unsigned Val) const {
|
|
|
|
using namespace AMDGPU;
|
2017-08-10 08:46:15 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
switch (Val) {
|
|
|
|
case 102: return createRegOperand(getMCReg(FLAT_SCR_LO, STI));
|
|
|
|
case 103: return createRegOperand(getMCReg(FLAT_SCR_HI, STI));
|
|
|
|
// ToDo: no support for xnack_mask_lo/_hi register
|
|
|
|
case 104:
|
|
|
|
case 105: break;
|
|
|
|
case 106: return createRegOperand(VCC_LO);
|
|
|
|
case 107: return createRegOperand(VCC_HI);
|
2016-05-24 20:05:16 +08:00
|
|
|
case 108: return createRegOperand(TBA_LO);
|
|
|
|
case 109: return createRegOperand(TBA_HI);
|
|
|
|
case 110: return createRegOperand(TMA_LO);
|
|
|
|
case 111: return createRegOperand(TMA_HI);
|
2016-03-01 21:57:29 +08:00
|
|
|
case 124: return createRegOperand(M0);
|
|
|
|
case 126: return createRegOperand(EXEC_LO);
|
|
|
|
case 127: return createRegOperand(EXEC_HI);
|
2017-02-19 02:41:41 +08:00
|
|
|
case 235: return createRegOperand(SRC_SHARED_BASE);
|
|
|
|
case 236: return createRegOperand(SRC_SHARED_LIMIT);
|
|
|
|
case 237: return createRegOperand(SRC_PRIVATE_BASE);
|
|
|
|
case 238: return createRegOperand(SRC_PRIVATE_LIMIT);
|
|
|
|
// TODO: SRC_POPS_EXITING_WAVE_ID
|
2016-03-01 21:57:29 +08:00
|
|
|
// ToDo: no support for vccz register
|
|
|
|
case 251: break;
|
|
|
|
// ToDo: no support for execz register
|
|
|
|
case 252: break;
|
|
|
|
case 253: return createRegOperand(SCC);
|
|
|
|
default: break;
|
2016-02-26 00:09:14 +08:00
|
|
|
}
|
2016-03-01 21:57:29 +08:00
|
|
|
return errOperand(Val, "unknown operand encoding " + Twine(Val));
|
2016-02-26 00:09:14 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeSpecialReg64(unsigned Val) const {
|
|
|
|
using namespace AMDGPU;
|
2017-08-10 08:46:15 +08:00
|
|
|
|
2016-03-01 21:57:29 +08:00
|
|
|
switch (Val) {
|
|
|
|
case 102: return createRegOperand(getMCReg(FLAT_SCR, STI));
|
|
|
|
case 106: return createRegOperand(VCC);
|
2016-05-24 20:05:16 +08:00
|
|
|
case 108: return createRegOperand(TBA);
|
|
|
|
case 110: return createRegOperand(TMA);
|
2016-03-01 21:57:29 +08:00
|
|
|
case 126: return createRegOperand(EXEC);
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return errOperand(Val, "unknown operand encoding " + Twine(Val));
|
|
|
|
}
|
2016-02-26 00:09:14 +08:00
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeSDWASrc(const OpWidthTy Width,
|
|
|
|
unsigned Val) const {
|
2017-05-26 23:52:00 +08:00
|
|
|
using namespace AMDGPU::SDWA;
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
if (STI.getFeatureBits()[AMDGPU::FeatureGFX9]) {
|
[AMDGPU] SDWA: several fixes for V_CVT and VOPC instructions
Summary:
1. Instruction V_CVT_U32_F32 allow omod operand (see SIInstrInfo.td:1435). In fact this operand shouldn't be allowed here. This fix checks if SDWA pseudo instruction has OMod operand and then copy it.
2. There were several problems with support of VOPC instructions in SDWA peephole pass.
Reviewers: tstellar, arsenm, vpykhtin, airlied, kzhuravl
Subscribers: wdng, nhaehnle, yaxunl, dstuttard, tpr, sarnex, t-tye
Differential Revision: https://reviews.llvm.org/D34626
llvm-svn: 306413
2017-06-27 23:02:23 +08:00
|
|
|
// XXX: static_cast<int> is needed to avoid stupid warning:
|
|
|
|
// compare with unsigned is always true
|
|
|
|
if (SDWA9EncValues::SRC_VGPR_MIN <= static_cast<int>(Val) &&
|
2017-06-21 16:53:38 +08:00
|
|
|
Val <= SDWA9EncValues::SRC_VGPR_MAX) {
|
|
|
|
return createRegOperand(getVgprClassId(Width),
|
|
|
|
Val - SDWA9EncValues::SRC_VGPR_MIN);
|
|
|
|
}
|
|
|
|
if (SDWA9EncValues::SRC_SGPR_MIN <= Val &&
|
|
|
|
Val <= SDWA9EncValues::SRC_SGPR_MAX) {
|
|
|
|
return createSRegOperand(getSgprClassId(Width),
|
|
|
|
Val - SDWA9EncValues::SRC_SGPR_MIN);
|
|
|
|
}
|
2017-05-26 23:52:00 +08:00
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
return decodeSpecialReg32(Val - SDWA9EncValues::SRC_SGPR_MIN);
|
|
|
|
} else if (STI.getFeatureBits()[AMDGPU::FeatureVolcanicIslands]) {
|
|
|
|
return createRegOperand(getVgprClassId(Width), Val);
|
|
|
|
}
|
|
|
|
llvm_unreachable("unsupported target");
|
2017-05-26 23:52:00 +08:00
|
|
|
}
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeSDWASrc16(unsigned Val) const {
|
|
|
|
return decodeSDWASrc(OPW16, Val);
|
2017-05-26 23:52:00 +08:00
|
|
|
}
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeSDWASrc32(unsigned Val) const {
|
|
|
|
return decodeSDWASrc(OPW32, Val);
|
2017-05-26 23:52:00 +08:00
|
|
|
}
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
MCOperand AMDGPUDisassembler::decodeSDWAVopcDst(unsigned Val) const {
|
2017-05-26 23:52:00 +08:00
|
|
|
using namespace AMDGPU::SDWA;
|
|
|
|
|
2017-06-21 16:53:38 +08:00
|
|
|
assert(STI.getFeatureBits()[AMDGPU::FeatureGFX9] &&
|
|
|
|
"SDWAVopcDst should be present only on GFX9");
|
2017-05-26 23:52:00 +08:00
|
|
|
if (Val & SDWA9EncValues::VOPC_DST_VCC_MASK) {
|
|
|
|
Val &= SDWA9EncValues::VOPC_DST_SGPR_MASK;
|
|
|
|
if (Val > AMDGPU::EncValues::SGPR_MAX) {
|
|
|
|
return decodeSpecialReg64(Val);
|
|
|
|
} else {
|
|
|
|
return createSRegOperand(getSgprClassId(OPW64), Val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return createRegOperand(AMDGPU::VCC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 21:46:08 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AMDGPUSymbolizer
|
|
|
|
//===----------------------------------------------------------------------===//
|
2016-11-01 08:55:14 +08:00
|
|
|
|
2016-10-06 21:46:08 +08:00
|
|
|
// Try to find symbol name for specified label
|
|
|
|
bool AMDGPUSymbolizer::tryAddingSymbolicOperand(MCInst &Inst,
|
|
|
|
raw_ostream &/*cStream*/, int64_t Value,
|
|
|
|
uint64_t /*Address*/, bool IsBranch,
|
|
|
|
uint64_t /*Offset*/, uint64_t /*InstSize*/) {
|
2017-08-10 08:46:15 +08:00
|
|
|
using SymbolInfoTy = std::tuple<uint64_t, StringRef, uint8_t>;
|
|
|
|
using SectionSymbolsTy = std::vector<SymbolInfoTy>;
|
2016-10-06 21:46:08 +08:00
|
|
|
|
|
|
|
if (!IsBranch) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto *Symbols = static_cast<SectionSymbolsTy *>(DisInfo);
|
|
|
|
auto Result = std::find_if(Symbols->begin(), Symbols->end(),
|
|
|
|
[Value](const SymbolInfoTy& Val) {
|
|
|
|
return std::get<0>(Val) == static_cast<uint64_t>(Value)
|
|
|
|
&& std::get<2>(Val) == ELF::STT_NOTYPE;
|
|
|
|
});
|
|
|
|
if (Result != Symbols->end()) {
|
|
|
|
auto *Sym = Ctx.getOrCreateSymbol(std::get<1>(*Result));
|
|
|
|
const auto *Add = MCSymbolRefExpr::create(Sym, Ctx);
|
|
|
|
Inst.addOperand(MCOperand::createExpr(Add));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-16 03:34:37 +08:00
|
|
|
void AMDGPUSymbolizer::tryAddingPcLoadReferenceComment(raw_ostream &cStream,
|
|
|
|
int64_t Value,
|
|
|
|
uint64_t Address) {
|
|
|
|
llvm_unreachable("unimplemented");
|
|
|
|
}
|
|
|
|
|
2016-10-06 21:46:08 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Initialization
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static MCSymbolizer *createAMDGPUSymbolizer(const Triple &/*TT*/,
|
|
|
|
LLVMOpInfoCallback /*GetOpInfo*/,
|
|
|
|
LLVMSymbolLookupCallback /*SymbolLookUp*/,
|
2016-11-01 08:55:14 +08:00
|
|
|
void *DisInfo,
|
2016-10-06 21:46:08 +08:00
|
|
|
MCContext *Ctx,
|
|
|
|
std::unique_ptr<MCRelocationInfo> &&RelInfo) {
|
|
|
|
return new AMDGPUSymbolizer(*Ctx, std::move(RelInfo), DisInfo);
|
|
|
|
}
|
|
|
|
|
2016-02-18 11:42:32 +08:00
|
|
|
static MCDisassembler *createAMDGPUDisassembler(const Target &T,
|
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
MCContext &Ctx) {
|
|
|
|
return new AMDGPUDisassembler(STI, Ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void LLVMInitializeAMDGPUDisassembler() {
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCDisassembler(getTheGCNTarget(),
|
|
|
|
createAMDGPUDisassembler);
|
|
|
|
TargetRegistry::RegisterMCSymbolizer(getTheGCNTarget(),
|
|
|
|
createAMDGPUSymbolizer);
|
2016-02-18 11:42:32 +08:00
|
|
|
}
|