34 static const unsigned PCRelFlagVal =
39 AArch64AsmBackend(
const Target &
T,
const Triple &
TT,
bool IsLittleEndian)
43 unsigned getNumFixupKinds()
const override {
55 {
"fixup_aarch64_pcrel_adr_imm21", 0, 32, PCRelFlagVal},
56 {
"fixup_aarch64_pcrel_adrp_imm21", 0, 32, PCRelFlagVal},
57 {
"fixup_aarch64_add_imm12", 10, 12, 0},
58 {
"fixup_aarch64_ldst_imm12_scale1", 10, 12, 0},
59 {
"fixup_aarch64_ldst_imm12_scale2", 10, 12, 0},
60 {
"fixup_aarch64_ldst_imm12_scale4", 10, 12, 0},
61 {
"fixup_aarch64_ldst_imm12_scale8", 10, 12, 0},
62 {
"fixup_aarch64_ldst_imm12_scale16", 10, 12, 0},
63 {
"fixup_aarch64_ldr_pcrel_imm19", 5, 19, PCRelFlagVal},
64 {
"fixup_aarch64_movw", 5, 16, 0},
65 {
"fixup_aarch64_pcrel_branch14", 5, 14, PCRelFlagVal},
66 {
"fixup_aarch64_pcrel_branch19", 5, 19, PCRelFlagVal},
67 {
"fixup_aarch64_pcrel_branch26", 0, 26, PCRelFlagVal},
68 {
"fixup_aarch64_pcrel_call26", 0, 26, PCRelFlagVal},
69 {
"fixup_aarch64_tlsdesc_call", 0, 0, 0}};
81 uint64_t
Value,
bool IsResolved,
84 bool mayNeedRelaxation(
const MCInst &Inst,
86 bool fixupNeedsRelaxation(
const MCFixup &Fixup, uint64_t
Value,
90 MCInst &Res)
const override;
91 bool writeNopData(
raw_ostream &OS, uint64_t Count)
const override;
97 unsigned getFixupKindContainereSizeInBytes(
unsigned Kind)
const;
148 unsigned lo2 = Value & 0x3;
149 unsigned hi19 = (Value & 0x1ffffc) >> 2;
150 return (hi19 << 5) | (lo2 << 29);
160 default:
return true;
162 return isUIntN(NumBits, Value) ||
163 isIntN(NumBits, static_cast<int64_t>(Value));
168 const Triple &TheTriple,
bool IsResolved) {
169 int64_t SignedValue =
static_cast<int64_t
>(
Value);
174 if (SignedValue > 2097151 || SignedValue < -2097152)
181 return AdrImmBits((Value & 0x1fffff000ULL) >> 12);
185 if (SignedValue > 2097151 || SignedValue < -2097152)
190 return (Value >> 2) & 0x7ffff;
230 if (Value >= 0x10000)
243 "relocation for a thread-local variable points to an " 261 SignedValue = SignedValue >> 16;
264 SignedValue = SignedValue >> 32;
267 SignedValue = SignedValue >> 48;
295 if (SignedValue > 0xFFFF || SignedValue < -0xFFFF)
300 SignedValue = ~SignedValue;
301 Value =
static_cast<uint64_t
>(SignedValue);
303 else if (Value > 0xFFFF) {
310 if (SignedValue > 32767 || SignedValue < -32768)
315 return (Value >> 2) & 0x3fff;
319 if (SignedValue > 134217727 || SignedValue < -134217728)
324 return (Value >> 2) & 0x3ffffff;
347 unsigned AArch64AsmBackend::getFixupKindContainereSizeInBytes(
unsigned Kind)
const {
394 int64_t SignedValue =
static_cast<int64_t
>(
Value);
402 assert(Offset + NumBytes <= Data.
size() &&
"Invalid fixup offset!");
405 unsigned FulleSizeInBytes = getFixupKindContainereSizeInBytes(Fixup.
getKind());
409 if (FulleSizeInBytes == 0) {
411 for (
unsigned i = 0; i != NumBytes; ++i) {
412 Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
416 assert((Offset + FulleSizeInBytes) <= Data.
size() &&
"Invalid fixup size!");
417 assert(NumBytes <= FulleSizeInBytes &&
"Invalid fixup size!");
418 for (
unsigned i = 0; i != NumBytes; ++i) {
419 unsigned Idx = FulleSizeInBytes - 1 - i;
420 Data[Offset + Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
432 Data[Offset + 3] &= ~(1 << 6);
434 Data[Offset + 3] |= (1 << 6);
438 bool AArch64AsmBackend::mayNeedRelaxation(
const MCInst &Inst,
443 bool AArch64AsmBackend::fixupNeedsRelaxation(
const MCFixup &Fixup,
451 return int64_t(Value) != int64_t(int8_t(Value));
454 void AArch64AsmBackend::relaxInstruction(
const MCInst &Inst,
460 bool AArch64AsmBackend::writeNopData(
raw_ostream &OS, uint64_t Count)
const {
468 for (uint64_t i = 0; i != Count; ++i)
469 support::endian::write<uint32_t>(OS, 0xd503201f, Endian);
473 bool AArch64AsmBackend::shouldForceRelocation(
const MCAssembler &Asm,
476 unsigned Kind = Fixup.
getKind();
513 UNWIND_ARM64_MODE_FRAMELESS = 0x02000000,
520 UNWIND_ARM64_MODE_DWARF = 0x03000000,
528 UNWIND_ARM64_MODE_FRAME = 0x04000000,
531 UNWIND_ARM64_FRAME_X19_X20_PAIR = 0x00000001,
532 UNWIND_ARM64_FRAME_X21_X22_PAIR = 0x00000002,
533 UNWIND_ARM64_FRAME_X23_X24_PAIR = 0x00000004,
534 UNWIND_ARM64_FRAME_X25_X26_PAIR = 0x00000008,
535 UNWIND_ARM64_FRAME_X27_X28_PAIR = 0x00000010,
536 UNWIND_ARM64_FRAME_D8_D9_PAIR = 0x00000100,
537 UNWIND_ARM64_FRAME_D10_D11_PAIR = 0x00000200,
538 UNWIND_ARM64_FRAME_D12_D13_PAIR = 0x00000400,
539 UNWIND_ARM64_FRAME_D14_D15_PAIR = 0x00000800
545 class DarwinAArch64AsmBackend :
public AArch64AsmBackend {
553 return (StackSize / 16) << 12;
557 DarwinAArch64AsmBackend(
const Target &
T,
const Triple &
TT,
559 : AArch64AsmBackend(T, TT,
true),
MRI(MRI),
562 std::unique_ptr<MCObjectTargetWriter>
563 createObjectTargetWriter()
const override {
573 uint32_t generateCompactUnwindEncoding(
576 return CU::UNWIND_ARM64_MODE_FRAMELESS;
579 unsigned StackSize = 0;
582 for (
size_t i = 0,
e = Instrs.
size(); i !=
e; ++i) {
588 return CU::UNWIND_ARM64_MODE_DWARF;
598 if (XReg != AArch64::FP)
599 return CU::UNWIND_ARM64_MODE_DWARF;
601 assert(XReg == AArch64::FP &&
"Invalid frame pointer!");
602 assert(i + 2 <
e &&
"Insufficient CFI instructions to define a frame!");
606 "Link register not pushed!");
609 "Frame pointer not pushed!");
612 unsigned FPReg = *MRI.
getLLVMRegNum(FPPush.getRegister(),
true);
617 assert(LRReg == AArch64::LR && FPReg == AArch64::FP &&
618 "Pushing invalid registers for frame!");
621 CompactUnwindEncoding |= CU::UNWIND_ARM64_MODE_FRAME;
626 assert(StackSize == 0 &&
"We already have the CFA offset!");
635 return CU::UNWIND_ARM64_MODE_DWARF;
639 return CU::UNWIND_ARM64_MODE_DWARF;
653 if (Reg1 == AArch64::X19 && Reg2 == AArch64::X20 &&
654 (CompactUnwindEncoding & 0xF1E) == 0)
655 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X19_X20_PAIR;
656 else if (Reg1 == AArch64::X21 && Reg2 == AArch64::X22 &&
657 (CompactUnwindEncoding & 0xF1C) == 0)
658 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X21_X22_PAIR;
659 else if (Reg1 == AArch64::X23 && Reg2 == AArch64::X24 &&
660 (CompactUnwindEncoding & 0xF18) == 0)
661 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X23_X24_PAIR;
662 else if (Reg1 == AArch64::X25 && Reg2 == AArch64::X26 &&
663 (CompactUnwindEncoding & 0xF10) == 0)
664 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X25_X26_PAIR;
665 else if (Reg1 == AArch64::X27 && Reg2 == AArch64::X28 &&
666 (CompactUnwindEncoding & 0xF00) == 0)
667 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X27_X28_PAIR;
676 if (Reg1 == AArch64::D8 && Reg2 == AArch64::D9 &&
677 (CompactUnwindEncoding & 0xE00) == 0)
678 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D8_D9_PAIR;
679 else if (Reg1 == AArch64::D10 && Reg2 == AArch64::D11 &&
680 (CompactUnwindEncoding & 0xC00) == 0)
681 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D10_D11_PAIR;
682 else if (Reg1 == AArch64::D12 && Reg2 == AArch64::D13 &&
683 (CompactUnwindEncoding & 0x800) == 0)
684 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D12_D13_PAIR;
685 else if (Reg1 == AArch64::D14 && Reg2 == AArch64::D15)
686 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D14_D15_PAIR;
689 return CU::UNWIND_ARM64_MODE_DWARF;
700 if (StackSize > 65520)
701 return CU::UNWIND_ARM64_MODE_DWARF;
703 CompactUnwindEncoding |= CU::UNWIND_ARM64_MODE_FRAMELESS;
704 CompactUnwindEncoding |= encodeStackAdjustment(StackSize);
707 return CompactUnwindEncoding;
715 class ELFAArch64AsmBackend :
public AArch64AsmBackend {
720 ELFAArch64AsmBackend(
const Target &
T,
const Triple &
TT, uint8_t OSABI,
721 bool IsLittleEndian,
bool IsILP32)
722 : AArch64AsmBackend(T, TT, IsLittleEndian), OSABI(OSABI),
725 std::unique_ptr<MCObjectTargetWriter>
726 createObjectTargetWriter()
const override {
734 class COFFAArch64AsmBackend :
public AArch64AsmBackend {
736 COFFAArch64AsmBackend(
const Target &
T,
const Triple &TheTriple)
737 : AArch64AsmBackend(T, TheTriple,
true) {}
739 std::unique_ptr<MCObjectTargetWriter>
740 createObjectTargetWriter()
const override {
753 return new DarwinAArch64AsmBackend(T, TheTriple, MRI, IsILP32);
757 return new COFFAArch64AsmBackend(T, TheTriple);
762 bool IsILP32 = Options.
getABIName() ==
"ilp32";
763 return new ELFAArch64AsmBackend(T, TheTriple, OSABI,
true,
773 "Big endian is only supported for ELF targets!");
775 bool IsILP32 = Options.
getABIName() ==
"ilp32";
776 return new ELFAArch64AsmBackend(T, TheTriple, OSABI,
false,
This class represents lattice values for constants.
This represents an "assembler immediate".
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
static unsigned getXRegFromWReg(unsigned Reg)
std::unique_ptr< MCObjectTargetWriter > createAArch64MachObjectWriter(uint32_t CPUType, uint32_t CPUSubtype, bool IsILP32)
unsigned TargetOffset
The bit offset to write the relocation into.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
const Triple & getTargetTriple() const
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
MCContext & getContext() const
Encapsulates the layout of an assembly file at a particular point in time.
MCAsmBackend * createAArch64leAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
A four-byte section relative fixup.
Context object for machine code objects.
A two-byte section relative fixup.
bool isArch32Bit() const
Test whether the architecture is 32-bit.
CompactUnwindEncodings
Compact unwind encoding values.
static uint64_t getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI, const Function *F)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static VariantKind getAddressFrag(VariantKind Kind)
Analysis containing CSE Info
Instances of this class represent a single low-level machine instruction.
static unsigned getFixupKindNumBytes(unsigned Kind)
The number of bytes the fixup may change.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Optional< unsigned > getLLVMRegNum(unsigned RegNum, bool isEH) const
Map a dwarf register back to a target register.
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
unsigned const MachineRegisterInfo * MRI
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
size_t size() const
size - Get the array size.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target, uint64_t Value, MCContext &Ctx, const Triple &TheTriple, bool IsResolved)
OpType getOperation() const
void reportError(SMLoc L, const Twine &Msg)
Should this fixup kind force a 4-byte aligned effective PC value?
std::unique_ptr< MCObjectTargetWriter > createAArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32)
uint32_t getOffset() const
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
static unsigned AdrImmBits(unsigned Value)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
PowerPC TLS Dynamic Call Fixup
unsigned getRegister() const
virtual Optional< MCFixupKind > getFixupKind(StringRef Name) const
Map a relocation name used in .reloc to a fixup kind.
Target - Wrapper for Target specific information.
MCAsmBackend * createAArch64beAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
static unsigned getDRegFromBReg(unsigned Reg)
StringRef getABIName() const
getABIName - If this returns a non-empty string this represents the textual name of the ABI that we w...
std::unique_ptr< MCObjectTargetWriter > createAArch64WinCOFFObjectWriter()
static bool valueFitsIntoFixupKind(unsigned Kind, uint64_t Value)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Generic base class for all target subtargets.
Target independent information on a fixup kind.
uint32_t getRefKind() const
static VariantKind getSymbolLoc(VariantKind Kind)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Generic interface to target specific assembler backends.
unsigned getTargetKind() const
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
MCFixupKind getKind() const
bool empty() const
empty - Check if the array is empty.