31 static const unsigned PCRelFlagVal =
37 AArch64AsmBackend(
const Target &
T,
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)
const override;
78 bool mayNeedRelaxation(
const MCInst &Inst)
const override;
79 bool fixupNeedsRelaxation(
const MCFixup &Fixup, uint64_t
Value,
83 MCInst &Res)
const override;
84 bool writeNopData(uint64_t Count,
MCObjectWriter *OW)
const override;
90 unsigned getFixupKindContainereSizeInBytes(
unsigned Kind)
const;
137 unsigned lo2 = Value & 0x3;
138 unsigned hi19 = (Value & 0x1ffffc) >> 2;
139 return (hi19 << 5) | (lo2 << 29);
144 unsigned Kind = Fixup.
getKind();
145 int64_t SignedValue =
static_cast<int64_t
>(Value);
150 if (SignedValue > 2097151 || SignedValue < -2097152)
154 return AdrImmBits((Value & 0x1fffff000ULL) >> 12);
158 if (SignedValue > 2097151 || SignedValue < -2097152)
163 return (Value >> 2) & 0x7ffff;
193 if (Value >= 0x10000)
200 "no resolvable MOVZ/MOVK fixups supported yet");
204 if (SignedValue > 32767 || SignedValue < -32768)
209 return (Value >> 2) & 0x3fff;
213 if (SignedValue > 134217727 || SignedValue < -134217728)
218 return (Value >> 2) & 0x3ffffff;
231 unsigned AArch64AsmBackend::getFixupKindContainereSizeInBytes(
unsigned Kind)
const {
271 bool IsResolved)
const {
284 assert(Offset + NumBytes <= Data.
size() &&
"Invalid fixup offset!");
287 unsigned FulleSizeInBytes = getFixupKindContainereSizeInBytes(Fixup.
getKind());
291 if (FulleSizeInBytes == 0) {
293 for (
unsigned i = 0; i != NumBytes; ++i) {
294 Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
298 assert((Offset + FulleSizeInBytes) <= Data.
size() &&
"Invalid fixup size!");
299 assert(NumBytes <= FulleSizeInBytes &&
"Invalid fixup size!");
300 for (
unsigned i = 0; i != NumBytes; ++i) {
301 unsigned Idx = FulleSizeInBytes - 1 - i;
302 Data[Offset + Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
307 bool AArch64AsmBackend::mayNeedRelaxation(
const MCInst &Inst)
const {
311 bool AArch64AsmBackend::fixupNeedsRelaxation(
const MCFixup &Fixup,
319 return int64_t(Value) != int64_t(int8_t(Value));
322 void AArch64AsmBackend::relaxInstruction(
const MCInst &Inst,
328 bool AArch64AsmBackend::writeNopData(uint64_t Count,
MCObjectWriter *OW)
const {
336 for (uint64_t i = 0; i != Count; ++i)
349 UNWIND_ARM64_MODE_FRAMELESS = 0x02000000,
356 UNWIND_ARM64_MODE_DWARF = 0x03000000,
364 UNWIND_ARM64_MODE_FRAME = 0x04000000,
367 UNWIND_ARM64_FRAME_X19_X20_PAIR = 0x00000001,
368 UNWIND_ARM64_FRAME_X21_X22_PAIR = 0x00000002,
369 UNWIND_ARM64_FRAME_X23_X24_PAIR = 0x00000004,
370 UNWIND_ARM64_FRAME_X25_X26_PAIR = 0x00000008,
371 UNWIND_ARM64_FRAME_X27_X28_PAIR = 0x00000010,
372 UNWIND_ARM64_FRAME_D8_D9_PAIR = 0x00000100,
373 UNWIND_ARM64_FRAME_D10_D11_PAIR = 0x00000200,
374 UNWIND_ARM64_FRAME_D12_D13_PAIR = 0x00000400,
375 UNWIND_ARM64_FRAME_D14_D15_PAIR = 0x00000800
381 class DarwinAArch64AsmBackend :
public AArch64AsmBackend {
388 return (StackSize / 16) << 12;
393 : AArch64AsmBackend(T,
true), MRI(MRI) {}
401 uint32_t generateCompactUnwindEncoding(
404 return CU::UNWIND_ARM64_MODE_FRAMELESS;
407 unsigned StackSize = 0;
410 for (
size_t i = 0, e = Instrs.
size(); i != e; ++i) {
416 return CU::UNWIND_ARM64_MODE_DWARF;
421 "Invalid frame pointer!");
422 assert(i + 2 < e &&
"Insufficient CFI instructions to define a frame!");
426 "Link register not pushed!");
429 "Frame pointer not pushed!");
432 unsigned FPReg =
MRI.getLLVMRegNum(FPPush.getRegister(),
true);
437 assert(LRReg == AArch64::LR && FPReg == AArch64::FP &&
438 "Pushing invalid registers for frame!");
441 CompactUnwindEncoding |= CU::UNWIND_ARM64_MODE_FRAME;
446 assert(StackSize == 0 &&
"We already have the CFA offset!");
455 return CU::UNWIND_ARM64_MODE_DWARF;
459 return CU::UNWIND_ARM64_MODE_DWARF;
473 if (Reg1 == AArch64::X19 && Reg2 == AArch64::X20 &&
474 (CompactUnwindEncoding & 0xF1E) == 0)
475 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X19_X20_PAIR;
476 else if (Reg1 == AArch64::X21 && Reg2 == AArch64::X22 &&
477 (CompactUnwindEncoding & 0xF1C) == 0)
478 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X21_X22_PAIR;
479 else if (Reg1 == AArch64::X23 && Reg2 == AArch64::X24 &&
480 (CompactUnwindEncoding & 0xF18) == 0)
481 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X23_X24_PAIR;
482 else if (Reg1 == AArch64::X25 && Reg2 == AArch64::X26 &&
483 (CompactUnwindEncoding & 0xF10) == 0)
484 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X25_X26_PAIR;
485 else if (Reg1 == AArch64::X27 && Reg2 == AArch64::X28 &&
486 (CompactUnwindEncoding & 0xF00) == 0)
487 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_X27_X28_PAIR;
496 if (Reg1 == AArch64::D8 && Reg2 == AArch64::D9 &&
497 (CompactUnwindEncoding & 0xE00) == 0)
498 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D8_D9_PAIR;
499 else if (Reg1 == AArch64::D10 && Reg2 == AArch64::D11 &&
500 (CompactUnwindEncoding & 0xC00) == 0)
501 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D10_D11_PAIR;
502 else if (Reg1 == AArch64::D12 && Reg2 == AArch64::D13 &&
503 (CompactUnwindEncoding & 0x800) == 0)
504 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D12_D13_PAIR;
505 else if (Reg1 == AArch64::D14 && Reg2 == AArch64::D15)
506 CompactUnwindEncoding |= CU::UNWIND_ARM64_FRAME_D14_D15_PAIR;
509 return CU::UNWIND_ARM64_MODE_DWARF;
520 if (StackSize > 65520)
521 return CU::UNWIND_ARM64_MODE_DWARF;
523 CompactUnwindEncoding |= CU::UNWIND_ARM64_MODE_FRAMELESS;
524 CompactUnwindEncoding |= encodeStackAdjustment(StackSize);
527 return CompactUnwindEncoding;
535 class ELFAArch64AsmBackend :
public AArch64AsmBackend {
540 ELFAArch64AsmBackend(
const Target &
T, uint8_t OSABI,
bool IsLittleEndian,
542 : AArch64AsmBackend(T, IsLittleEndian), OSABI(OSABI), IsILP32(IsILP32) {}
549 const MCValue &Target)
override;
552 bool ELFAArch64AsmBackend::shouldForceRelocation(
const MCAssembler &Asm,
575 class COFFAArch64AsmBackend :
public AArch64AsmBackend {
577 COFFAArch64AsmBackend(
const Target &
T,
const Triple &TheTriple)
578 : AArch64AsmBackend(T,
true) {}
592 return new DarwinAArch64AsmBackend(T, MRI);
595 return new COFFAArch64AsmBackend(T, TheTriple);
600 bool IsILP32 = Options.
getABIName() ==
"ilp32";
601 return new ELFAArch64AsmBackend(T, OSABI,
true, IsILP32);
610 "Big endian is only supported for ELF targets!");
612 bool IsILP32 = Options.
getABIName() ==
"ilp32";
613 return new ELFAArch64AsmBackend(T, OSABI,
false, IsILP32);
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
void WriteZeros(unsigned N)
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
This represents an "assembler immediate".
static unsigned getXRegFromWReg(unsigned Reg)
MCContext & getContext() const
Defines the object file and target independent interfaces used by the assembler backend to write nati...
unsigned getRegister() const
unsigned TargetOffset
The bit offset to write the relocation into.
MCObjectWriter * createAArch64WinCOFFObjectWriter(raw_pwrite_stream &OS)
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
Encapsulates the layout of an assembly file at a particular point in time.
static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value, MCContext &Ctx)
A four-byte section relative fixup.
Context object for machine code objects.
A two-byte section relative fixup.
CompactUnwindEncodings
Compact unwind encoding values.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
uint32_t getOffset() const
size_t size() const
size - Get the array size.
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...
void write32(uint32_t Value)
unsigned const MachineRegisterInfo * MRI
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
MCFixupKind
Extensible enumeration to represent the type of a fixup.
void reportError(SMLoc L, const Twine &Msg)
Should this fixup kind force a 4-byte aligned effective PC value?
bool empty() const
empty - Check if the array is empty.
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
MCObjectWriter * createAArch64MachObjectWriter(raw_pwrite_stream &OS, uint32_t CPUType, uint32_t CPUSubtype)
MCFixupKind getKind() const
static unsigned AdrImmBits(unsigned Value)
Triple - Helper class for working with autoconf configuration names.
MCObjectWriter * createAArch64ELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI, bool IsLittleEndian, bool IsILP32)
OpType getOperation() const
StringRef getABIName() const
getABIName - If this returns a non-empty string this represents the textual name of the ABI that we w...
Target - Wrapper for Target specific information.
llvm_unreachable("Unknown RegBank!")
static unsigned getDRegFromBReg(unsigned Reg)
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
MCAsmBackend * createAArch64leAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
MCSubtargetInfo - Generic base class for all target subtargets.
MCAsmBackend * createAArch64beAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
Target independent information on a fixup kind.
An abstract base class for streams implementations that also support a pwrite operation.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Generic interface to target specific assembler backends.
StringRef - Represent a constant reference to a string, i.e.
static uint64_t getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI)
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.