31 static const unsigned PCRelFlagVal =
36 AArch64AsmBackend(
const Target &
T,
const Triple &TT,
bool IsLittleEndian)
40 unsigned getNumFixupKinds()
const override {
50 {
"fixup_aarch64_pcrel_adr_imm21", 0, 32, PCRelFlagVal},
51 {
"fixup_aarch64_pcrel_adrp_imm21", 0, 32, PCRelFlagVal},
52 {
"fixup_aarch64_add_imm12", 10, 12, 0},
53 {
"fixup_aarch64_ldst_imm12_scale1", 10, 12, 0},
54 {
"fixup_aarch64_ldst_imm12_scale2", 10, 12, 0},
55 {
"fixup_aarch64_ldst_imm12_scale4", 10, 12, 0},
56 {
"fixup_aarch64_ldst_imm12_scale8", 10, 12, 0},
57 {
"fixup_aarch64_ldst_imm12_scale16", 10, 12, 0},
58 {
"fixup_aarch64_ldr_pcrel_imm19", 5, 19, PCRelFlagVal},
59 {
"fixup_aarch64_movw", 5, 16, 0},
60 {
"fixup_aarch64_pcrel_branch14", 5, 14, PCRelFlagVal},
61 {
"fixup_aarch64_pcrel_branch19", 5, 19, PCRelFlagVal},
62 {
"fixup_aarch64_pcrel_branch26", 0, 26, PCRelFlagVal},
63 {
"fixup_aarch64_pcrel_call26", 0, 26, PCRelFlagVal},
64 {
"fixup_aarch64_tlsdesc_call", 0, 0, 0}};
76 uint64_t
Value,
bool IsResolved,
79 bool mayNeedRelaxation(
const MCInst &Inst,
81 bool fixupNeedsRelaxation(
const MCFixup &Fixup, uint64_t
Value,
85 MCInst &Res)
const override;
86 bool writeNopData(
raw_ostream &OS, uint64_t Count)
const override;
92 unsigned getFixupKindContainereSizeInBytes(
unsigned Kind)
const;
142 unsigned lo2 = Value & 0x3;
143 unsigned hi19 = (Value & 0x1ffffc) >> 2;
144 return (hi19 << 5) | (lo2 << 29);
150 unsigned Kind = Fixup.
getKind();
151 int64_t SignedValue =
static_cast<int64_t
>(Value);
156 if (SignedValue > 2097151 || SignedValue < -2097152)
163 return AdrImmBits((Value & 0x1fffff000ULL) >> 12);
167 if (SignedValue > 2097151 || SignedValue < -2097152)
172 return (Value >> 2) & 0x7ffff;
212 if (Value >= 0x10000)
219 "no resolvable MOVZ/MOVK fixups supported yet");
223 if (SignedValue > 32767 || SignedValue < -32768)
228 return (Value >> 2) & 0x3fff;
232 if (SignedValue > 134217727 || SignedValue < -134217728)
237 return (Value >> 2) & 0x3ffffff;
250 unsigned AArch64AsmBackend::getFixupKindContainereSizeInBytes(
unsigned Kind)
const {
304 assert(Offset + NumBytes <= Data.
size() &&
"Invalid fixup offset!");
307 unsigned FulleSizeInBytes = getFixupKindContainereSizeInBytes(Fixup.
getKind());
311 if (FulleSizeInBytes == 0) {
313 for (
unsigned i = 0; i != NumBytes; ++i) {
314 Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
318 assert((Offset + FulleSizeInBytes) <= Data.
size() &&
"Invalid fixup size!");
319 assert(NumBytes <= FulleSizeInBytes &&
"Invalid fixup size!");
320 for (
unsigned i = 0; i != NumBytes; ++i) {
321 unsigned Idx = FulleSizeInBytes - 1 - i;
322 Data[Offset + Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
327 bool AArch64AsmBackend::mayNeedRelaxation(
const MCInst &Inst,
332 bool AArch64AsmBackend::fixupNeedsRelaxation(
const MCFixup &Fixup,
340 return int64_t(Value) != int64_t(int8_t(Value));
343 void AArch64AsmBackend::relaxInstruction(
const MCInst &Inst,
349 bool AArch64AsmBackend::writeNopData(
raw_ostream &OS, uint64_t Count)
const {
357 for (uint64_t i = 0; i != Count; ++i)
358 support::endian::write<uint32_t>(OS, 0xd503201f, Endian);
362 bool AArch64AsmBackend::shouldForceRelocation(
const MCAssembler &Asm,
390 UNWIND_ARM64_MODE_FRAMELESS = 0x02000000,
397 UNWIND_ARM64_MODE_DWARF = 0x03000000,
405 UNWIND_ARM64_MODE_FRAME = 0x04000000,
408 UNWIND_ARM64_FRAME_X19_X20_PAIR = 0x00000001,
409 UNWIND_ARM64_FRAME_X21_X22_PAIR = 0x00000002,
410 UNWIND_ARM64_FRAME_X23_X24_PAIR = 0x00000004,
411 UNWIND_ARM64_FRAME_X25_X26_PAIR = 0x00000008,
412 UNWIND_ARM64_FRAME_X27_X28_PAIR = 0x00000010,
413 UNWIND_ARM64_FRAME_D8_D9_PAIR = 0x00000100,
414 UNWIND_ARM64_FRAME_D10_D11_PAIR = 0x00000200,
415 UNWIND_ARM64_FRAME_D12_D13_PAIR = 0x00000400,
416 UNWIND_ARM64_FRAME_D14_D15_PAIR = 0x00000800
422 class DarwinAArch64AsmBackend :
public AArch64AsmBackend {
429 return (StackSize / 16) << 12;
433 DarwinAArch64AsmBackend(
const Target &
T,
const Triple &TT,
435 : AArch64AsmBackend(T, TT,
true),
MRI(MRI) {}
437 std::unique_ptr<MCObjectTargetWriter>
438 createObjectTargetWriter()
const override {
444 uint32_t generateCompactUnwindEncoding(
447 return CU::UNWIND_ARM64_MODE_FRAMELESS;
450 unsigned StackSize = 0;
453 for (
size_t i = 0, e = Instrs.
size(); i != e; ++i) {
459 return CU::UNWIND_ARM64_MODE_DWARF;
469 if (XReg != AArch64::FP)
470 return CU::UNWIND_ARM64_MODE_DWARF;
472 assert(XReg == AArch64::FP &&
"Invalid frame pointer!");
473 assert(i + 2 < e &&
"Insufficient CFI instructions to define a frame!");
477 "Link register not pushed!");
480 "Frame pointer not pushed!");
483 unsigned FPReg = MRI.
getLLVMRegNum(FPPush.getRegister(),
true);
488 assert(LRReg == AArch64::LR && FPReg == AArch64::FP &&
489 "Pushing invalid registers for frame!");
492 CompactUnwindEncoding |= CU::UNWIND_ARM64_MODE_FRAME;
497 assert(StackSize == 0 &&
"We already have the CFA offset!");
506 return CU::UNWIND_ARM64_MODE_DWARF;
510 return CU::UNWIND_ARM64_MODE_DWARF;
524 if (Reg1 == AArch64::X19 && Reg2 == AArch64::X20 &&
525 (CompactUnwindEncoding & 0xF1E) == 0)
526 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X19_X20_PAIR;
527 else if (Reg1 == AArch64::X21 && Reg2 == AArch64::X22 &&
528 (CompactUnwindEncoding & 0xF1C) == 0)
529 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X21_X22_PAIR;
530 else if (Reg1 == AArch64::X23 && Reg2 == AArch64::X24 &&
531 (CompactUnwindEncoding & 0xF18) == 0)
532 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X23_X24_PAIR;
533 else if (Reg1 == AArch64::X25 && Reg2 == AArch64::X26 &&
534 (CompactUnwindEncoding & 0xF10) == 0)
535 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X25_X26_PAIR;
536 else if (Reg1 == AArch64::X27 && Reg2 == AArch64::X28 &&
537 (CompactUnwindEncoding & 0xF00) == 0)
538 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X27_X28_PAIR;
547 if (Reg1 == AArch64::D8 && Reg2 == AArch64::D9 &&
548 (CompactUnwindEncoding & 0xE00) == 0)
549 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D8_D9_PAIR;
550 else if (Reg1 == AArch64::D10 && Reg2 == AArch64::D11 &&
551 (CompactUnwindEncoding & 0xC00) == 0)
552 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D10_D11_PAIR;
553 else if (Reg1 == AArch64::D12 && Reg2 == AArch64::D13 &&
554 (CompactUnwindEncoding & 0x800) == 0)
555 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D12_D13_PAIR;
556 else if (Reg1 == AArch64::D14 && Reg2 == AArch64::D15)
557 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D14_D15_PAIR;
560 return CU::UNWIND_ARM64_MODE_DWARF;
571 if (StackSize > 65520)
572 return CU::UNWIND_ARM64_MODE_DWARF;
574 CompactUnwindEncoding |= CU::UNWIND_ARM64_MODE_FRAMELESS;
575 CompactUnwindEncoding |= encodeStackAdjustment(StackSize);
578 return CompactUnwindEncoding;
586 class ELFAArch64AsmBackend :
public AArch64AsmBackend {
591 ELFAArch64AsmBackend(
const Target &
T,
const Triple &TT, uint8_t OSABI,
592 bool IsLittleEndian,
bool IsILP32)
593 : AArch64AsmBackend(T, TT, IsLittleEndian), OSABI(OSABI),
596 std::unique_ptr<MCObjectTargetWriter>
597 createObjectTargetWriter()
const override {
605 class COFFAArch64AsmBackend :
public AArch64AsmBackend {
607 COFFAArch64AsmBackend(
const Target &
T,
const Triple &TheTriple)
608 : AArch64AsmBackend(T, TheTriple,
true) {}
610 std::unique_ptr<MCObjectTargetWriter>
611 createObjectTargetWriter()
const override {
623 return new DarwinAArch64AsmBackend(T, TheTriple, MRI);
626 return new COFFAArch64AsmBackend(T, TheTriple);
631 bool IsILP32 = Options.
getABIName() ==
"ilp32";
632 return new ELFAArch64AsmBackend(T, TheTriple, OSABI,
true,
642 "Big endian is only supported for ELF targets!");
644 bool IsILP32 = Options.
getABIName() ==
"ilp32";
645 return new ELFAArch64AsmBackend(T, TheTriple, OSABI,
false,
Compute iterated dominance frontiers using a linear time algorithm.
This represents an "assembler immediate".
std::unique_ptr< MCObjectTargetWriter > createAArch64MachObjectWriter(uint32_t CPUType, uint32_t CPUSubtype)
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)
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.
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)...
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...
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.
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.
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.
PowerPC TLS Dynamic Call Fixup
unsigned getRegister() const
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()
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Generic base class for all target subtargets.
static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value, MCContext &Ctx, const Triple &TheTriple, bool IsResolved)
Target independent information on a fixup kind.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Generic interface to target specific assembler backends.
This class implements an extremely fast bulk output stream that can only output to a stream...
int getLLVMRegNum(unsigned RegNum, bool isEH) const
Map a dwarf register back to a target register.
MCFixupKind getKind() const
bool empty() const
empty - Check if the array is empty.