35 void applyFixup(
const MCFragment &,
const MCFixup &,
const MCValue &Target,
36 uint8_t *
Data, uint64_t
Value,
bool IsResolved)
override;
37 bool fixupNeedsRelaxationAdvanced(
const MCFragment &,
const MCFixup &,
38 const MCValue &, uint64_t,
41 void relaxInstruction(MCInst &Inst,
42 const MCSubtargetInfo &STI)
const override;
45 const MCSubtargetInfo &STI)
const override;
47 unsigned getMinimumNopSize()
const override;
48 bool writeNopData(raw_ostream &OS, uint64_t
Count,
49 const MCSubtargetInfo *STI)
const override;
51 std::optional<MCFixupKind>
getFixupKind(StringRef Name)
const override;
52 MCFixupKindInfo getFixupKindInfo(
MCFixupKind Kind)
const override;
57void AMDGPUAsmBackend::relaxInstruction(
MCInst &Inst,
63 Inst = std::move(Res);
66bool AMDGPUAsmBackend::fixupNeedsRelaxationAdvanced(
const MCFragment &,
70 bool Resolved)
const {
76 return (((int64_t(
Value)/4)-1) == 0x3f);
79bool AMDGPUAsmBackend::mayNeedRelaxation(
unsigned Opcode,
81 const MCSubtargetInfo &STI)
const {
82 if (!STI.
hasFeature(AMDGPU::FeatureOffset3fBug))
114 int64_t SignedValue =
static_cast<int64_t
>(
Value);
116 switch (
Fixup.getKind()) {
118 int64_t BrImm = (SignedValue - 4) / 4;
121 Ctx->reportError(
Fixup.getLoc(),
"branch size exceeds simm16");
136void AMDGPUAsmBackend::applyFixup(
const MCFragment &
F,
const MCFixup &
Fixup,
137 const MCValue &Target, uint8_t *
Data,
138 uint64_t
Value,
bool IsResolved) {
139 if (
Target.getSpecifier())
141 maybeAddReloc(
F,
Fixup, Target,
Value, IsResolved);
149 MCFixupKindInfo
Info = getFixupKindInfo(
Fixup.getKind());
156 "Invalid fixup offset!");
160 for (
unsigned i = 0; i != NumBytes; ++i)
161 Data[i] |=
static_cast<uint8_t
>((
Value >> (i * 8)) & 0xff);
164std::optional<MCFixupKind>
165AMDGPUAsmBackend::getFixupKind(StringRef Name)
const {
166 auto Type = StringSwitch<unsigned>(Name)
167#define ELF_RELOC(Name, Value) .Case(#Name, Value)
168#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
170 .Case(
"BFD_RELOC_NONE", ELF::R_AMDGPU_NONE)
171 .Case(
"BFD_RELOC_32", ELF::R_AMDGPU_ABS32)
172 .Case(
"BFD_RELOC_64", ELF::R_AMDGPU_ABS64)
179MCFixupKindInfo AMDGPUAsmBackend::getFixupKindInfo(
MCFixupKind Kind)
const {
182 {
"fixup_si_sopp_br", 0, 16, 0},
196unsigned AMDGPUAsmBackend::getMinimumNopSize()
const {
200bool AMDGPUAsmBackend::writeNopData(raw_ostream &OS, uint64_t
Count,
201 const MCSubtargetInfo *STI)
const {
206 unsigned MinInstAlignment =
getContext().getAsmInfo()->getMinInstAlignment();
210 Count /= MinInstAlignment;
214 const uint32_t Encoded_S_NOP_0 = 0xbf800000;
216 assert(MinInstAlignment ==
sizeof(Encoded_S_NOP_0));
217 for (uint64_t
I = 0;
I !=
Count; ++
I)
229class ELFAMDGPUAsmBackend :
public AMDGPUAsmBackend {
231 bool HasRelocationAddend;
235 ELFAMDGPUAsmBackend(
const Target &
T,
const Triple &TT)
236 : AMDGPUAsmBackend(
T), Is64Bit(
TT.isAMDGCN()),
237 HasRelocationAddend(
TT.getOS() == Triple::AMDHSA) {
238 switch (
TT.getOS()) {
240 OSABI = ELF::ELFOSABI_AMDGPU_HSA;
243 OSABI = ELF::ELFOSABI_AMDGPU_PAL;
246 OSABI = ELF::ELFOSABI_AMDGPU_MESA3D;
253 std::unique_ptr<MCObjectTargetWriter>
254 createObjectTargetWriter()
const override {
static unsigned getFixupKindNumBytes(unsigned Kind)
The number of bytes the fixup may change.
static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target, uint64_t Value, MCContext &Ctx, const Triple &TheTriple, bool IsResolved)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
PowerPC TLS Dynamic Call Fixup
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Generic interface to target specific assembler backends.
virtual MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Context object for machine code objects.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
Target - Wrapper for Target specific information.
LLVM Value Representation.
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ fixup_si_sopp_br
16-bit PC relative fixup for SOPP branch instructions.
LLVM_READONLY int32_t getSOPPWithRelaxation(uint32_t Opcode)
VE::Fixups getFixupKind(uint8_t S)
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const ArmConfig &ArmCfg)
Apply fixup expression for edge to block content.
bool isRelocation(MCFixupKind FixupKind)
Context & getContext() const
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
MCAsmBackend * createAMDGPUAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
std::unique_ptr< MCObjectTargetWriter > createAMDGPUELFObjectWriter(bool Is64Bit, uint8_t OSABI, bool HasRelocationAddend)
uint16_t MCFixupKind
Extensible enumeration to represent the type of a fixup.
FunctionAddr VTableAddr Count
@ FK_SecRel_2
A two-byte section relative fixup.
@ FirstLiteralRelocationKind
@ FK_Data_8
A eight-byte fixup.
@ FK_Data_1
A one-byte fixup.
@ FK_Data_4
A four-byte fixup.
@ FK_SecRel_8
A eight-byte section relative fixup.
@ FK_SecRel_4
A four-byte section relative fixup.
@ FK_SecRel_1
A one-byte section relative fixup.
@ FK_Data_2
A two-byte fixup.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
ArrayRef(const T &OneElt) -> ArrayRef< T >