LLVM 19.0.0git
LoongArchAsmBackend.cpp
Go to the documentation of this file.
1//===-- LoongArchAsmBackend.cpp - LoongArch Assembler Backend -*- C++ -*---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the LoongArchAsmBackend class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "LoongArchAsmBackend.h"
14#include "LoongArchFixupKinds.h"
15#include "llvm/MC/MCAsmInfo.h"
16#include "llvm/MC/MCAsmLayout.h"
17#include "llvm/MC/MCAssembler.h"
18#include "llvm/MC/MCContext.h"
20#include "llvm/MC/MCExpr.h"
21#include "llvm/MC/MCSection.h"
22#include "llvm/MC/MCValue.h"
24#include "llvm/Support/LEB128.h"
26
27#define DEBUG_TYPE "loongarch-asmbackend"
28
29using namespace llvm;
30
31std::optional<MCFixupKind>
35#define ELF_RELOC(X, Y) .Case(#X, Y)
36#include "llvm/BinaryFormat/ELFRelocs/LoongArch.def"
37#undef ELF_RELOC
38 .Case("BFD_RELOC_NONE", ELF::R_LARCH_NONE)
39 .Case("BFD_RELOC_32", ELF::R_LARCH_32)
40 .Case("BFD_RELOC_64", ELF::R_LARCH_64)
41 .Default(-1u);
42 if (Type != -1u)
43 return static_cast<MCFixupKind>(FirstLiteralRelocationKind + Type);
44 }
45 return std::nullopt;
46}
47
48const MCFixupKindInfo &
50 const static MCFixupKindInfo Infos[] = {
51 // This table *must* be in the order that the fixup_* kinds are defined in
52 // LoongArchFixupKinds.h.
53 //
54 // {name, offset, bits, flags}
55 {"fixup_loongarch_b16", 10, 16, MCFixupKindInfo::FKF_IsPCRel},
56 {"fixup_loongarch_b21", 0, 26, MCFixupKindInfo::FKF_IsPCRel},
57 {"fixup_loongarch_b26", 0, 26, MCFixupKindInfo::FKF_IsPCRel},
58 {"fixup_loongarch_abs_hi20", 5, 20, 0},
59 {"fixup_loongarch_abs_lo12", 10, 12, 0},
60 {"fixup_loongarch_abs64_lo20", 5, 20, 0},
61 {"fixup_loongarch_abs64_hi12", 10, 12, 0},
62 {"fixup_loongarch_tls_le_hi20", 5, 20, 0},
63 {"fixup_loongarch_tls_le_lo12", 10, 12, 0},
64 {"fixup_loongarch_tls_le64_lo20", 5, 20, 0},
65 {"fixup_loongarch_tls_le64_hi12", 10, 12, 0},
66 // TODO: Add more fixup kinds.
67 };
68
69 static_assert((std::size(Infos)) == LoongArch::NumTargetFixupKinds,
70 "Not all fixup kinds added to Infos array");
71
72 // Fixup kinds from .reloc directive are like R_LARCH_NONE. They
73 // do not require any extra processing.
76
77 if (Kind < FirstTargetFixupKind)
79
80 assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
81 "Invalid kind!");
82 return Infos[Kind - FirstTargetFixupKind];
83}
84
85static void reportOutOfRangeError(MCContext &Ctx, SMLoc Loc, unsigned N) {
86 Ctx.reportError(Loc, "fixup value out of range [" + Twine(llvm::minIntN(N)) +
87 ", " + Twine(llvm::maxIntN(N)) + "]");
88}
89
91 MCContext &Ctx) {
92 switch (Fixup.getTargetKind()) {
93 default:
94 llvm_unreachable("Unknown fixup kind");
95 case FK_Data_1:
96 case FK_Data_2:
97 case FK_Data_4:
98 case FK_Data_8:
99 case FK_Data_leb128:
100 return Value;
102 if (!isInt<18>(Value))
103 reportOutOfRangeError(Ctx, Fixup.getLoc(), 18);
104 if (Value % 4)
105 Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
106 return (Value >> 2) & 0xffff;
107 }
109 if (!isInt<23>(Value))
110 reportOutOfRangeError(Ctx, Fixup.getLoc(), 23);
111 if (Value % 4)
112 Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
113 return ((Value & 0x3fffc) << 8) | ((Value >> 18) & 0x1f);
114 }
116 if (!isInt<28>(Value))
117 reportOutOfRangeError(Ctx, Fixup.getLoc(), 28);
118 if (Value % 4)
119 Ctx.reportError(Fixup.getLoc(), "fixup value must be 4-byte aligned");
120 return ((Value & 0x3fffc) << 8) | ((Value >> 18) & 0x3ff);
121 }
124 return (Value >> 12) & 0xfffff;
127 return Value & 0xfff;
130 return (Value >> 32) & 0xfffff;
133 return (Value >> 52) & 0xfff;
134 }
135}
136
137static void fixupLeb128(MCContext &Ctx, const MCFixup &Fixup,
139 unsigned I;
140 for (I = 0; I != Data.size() && Value; ++I, Value >>= 7)
141 Data[I] |= uint8_t(Value & 0x7f);
142 if (Value)
143 Ctx.reportError(Fixup.getLoc(), "Invalid uleb128 value!");
144}
145
147 const MCFixup &Fixup,
148 const MCValue &Target,
150 bool IsResolved,
151 const MCSubtargetInfo *STI) const {
152 if (!Value)
153 return; // Doesn't change encoding.
154
155 MCFixupKind Kind = Fixup.getKind();
156 if (Kind >= FirstLiteralRelocationKind)
157 return;
159 MCContext &Ctx = Asm.getContext();
160
161 // Fixup leb128 separately.
162 if (Fixup.getTargetKind() == FK_Data_leb128)
163 return fixupLeb128(Ctx, Fixup, Data, Value);
164
165 // Apply any target-specific value adjustments.
167
168 // Shift the value into position.
169 Value <<= Info.TargetOffset;
170
171 unsigned Offset = Fixup.getOffset();
172 unsigned NumBytes = alignTo(Info.TargetSize + Info.TargetOffset, 8) / 8;
173
174 assert(Offset + NumBytes <= Data.size() && "Invalid fixup offset!");
175 // For each byte of the fragment that the fixup touches, mask in the
176 // bits from the fixup value.
177 for (unsigned I = 0; I != NumBytes; ++I) {
178 Data[Offset + I] |= uint8_t((Value >> (I * 8)) & 0xff);
179 }
180}
181
182// Linker relaxation may change code size. We have to insert Nops
183// for .align directive when linker relaxation enabled. So then Linker
184// could satisfy alignment by removing Nops.
185// The function returns the total Nops Size we need to insert.
187 const MCAlignFragment &AF, unsigned &Size) {
188 // Calculate Nops Size only when linker relaxation enabled.
189 if (!AF.getSubtargetInfo()->hasFeature(LoongArch::FeatureRelax))
190 return false;
191
192 // Ignore alignment if MaxBytesToEmit is less than the minimum Nop size.
193 const unsigned MinNopLen = 4;
194 if (AF.getMaxBytesToEmit() < MinNopLen)
195 return false;
196 Size = AF.getAlignment().value() - MinNopLen;
197 return AF.getAlignment() > MinNopLen;
198}
199
200// We need to insert R_LARCH_ALIGN relocation type to indicate the
201// position of Nops and the total bytes of the Nops have been inserted
202// when linker relaxation enabled.
203// The function inserts fixup_loongarch_align fixup which eventually will
204// transfer to R_LARCH_ALIGN relocation type.
205// The improved R_LARCH_ALIGN requires symbol index. The lowest 8 bits of
206// addend represent alignment and the other bits of addend represent the
207// maximum number of bytes to emit. The maximum number of bytes is zero
208// means ignore the emit limit.
210 MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF) {
211 // Insert the fixup only when linker relaxation enabled.
212 if (!AF.getSubtargetInfo()->hasFeature(LoongArch::FeatureRelax))
213 return false;
214
215 // Calculate total Nops we need to insert. If there are none to insert
216 // then simply return.
217 unsigned InsertedNopBytes;
218 if (!shouldInsertExtraNopBytesForCodeAlign(AF, InsertedNopBytes))
219 return false;
220
221 MCSection *Sec = AF.getParent();
222 MCContext &Ctx = Asm.getContext();
223 const MCExpr *Dummy = MCConstantExpr::create(0, Ctx);
224 // Create fixup_loongarch_align fixup.
225 MCFixup Fixup =
227 unsigned MaxBytesToEmit = AF.getMaxBytesToEmit();
228
229 auto createExtendedValue = [&]() {
230 const MCSymbolRefExpr *MCSym = getSecToAlignSym()[Sec];
231 if (MCSym == nullptr) {
232 // Define a marker symbol at the section with an offset of 0.
233 MCSymbol *Sym = Ctx.createNamedTempSymbol("la-relax-align");
234 Sym->setFragment(&*Sec->getBeginSymbol()->getFragment());
235 Asm.registerSymbol(*Sym);
236 MCSym = MCSymbolRefExpr::create(Sym, Ctx);
237 getSecToAlignSym()[Sec] = MCSym;
238 }
239 return MCValue::get(MCSym, nullptr,
240 MaxBytesToEmit << 8 | Log2(AF.getAlignment()));
241 };
242
243 uint64_t FixedValue = 0;
244 MCValue Value = MaxBytesToEmit >= InsertedNopBytes
245 ? MCValue::get(InsertedNopBytes)
246 : createExtendedValue();
247 Asm.getWriter().recordRelocation(Asm, Layout, &AF, Fixup, Value, FixedValue);
248
249 return true;
250}
251
253 const MCFixup &Fixup,
254 const MCValue &Target,
255 const MCSubtargetInfo *STI) {
256 if (Fixup.getKind() >= FirstLiteralRelocationKind)
257 return true;
258 switch (Fixup.getTargetKind()) {
259 default:
260 return STI->hasFeature(LoongArch::FeatureRelax);
261 case FK_Data_1:
262 case FK_Data_2:
263 case FK_Data_4:
264 case FK_Data_8:
265 case FK_Data_leb128:
266 return !Target.isAbsolute();
267 }
268}
269
270static inline std::pair<MCFixupKind, MCFixupKind>
272 switch (Size) {
273 default:
274 llvm_unreachable("unsupported fixup size");
275 case 6:
276 return std::make_pair(
277 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_ADD6),
278 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_SUB6));
279 case 8:
280 return std::make_pair(
281 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_ADD8),
282 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_SUB8));
283 case 16:
284 return std::make_pair(
285 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_ADD16),
286 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_SUB16));
287 case 32:
288 return std::make_pair(
289 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_ADD32),
290 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_SUB32));
291 case 64:
292 return std::make_pair(
293 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_ADD64),
294 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_SUB64));
295 case 128:
296 return std::make_pair(
297 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_ADD_ULEB128),
298 MCFixupKind(FirstLiteralRelocationKind + ELF::R_LARCH_SUB_ULEB128));
299 }
300}
301
303 MCAsmLayout &Layout,
304 int64_t &Value) const {
305 const MCExpr &Expr = LF.getValue();
306 if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, Layout))
307 return std::make_pair(false, false);
308 LF.getFixups().push_back(
309 MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
310 return std::make_pair(true, true);
311}
312
314 MCAsmLayout &Layout,
315 bool &WasRelaxed) const {
316 MCContext &C = Layout.getAssembler().getContext();
317
318 int64_t LineDelta = DF.getLineDelta();
319 const MCExpr &AddrDelta = DF.getAddrDelta();
320 SmallVectorImpl<char> &Data = DF.getContents();
321 SmallVectorImpl<MCFixup> &Fixups = DF.getFixups();
322 size_t OldSize = Data.size();
323
324 int64_t Value;
325 if (AddrDelta.evaluateAsAbsolute(Value, Layout))
326 return false;
327 bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout);
328 assert(IsAbsolute && "CFA with invalid expression");
329 (void)IsAbsolute;
330
331 Data.clear();
332 Fixups.clear();
334
335 // INT64_MAX is a signal that this is actually a DW_LNE_end_sequence.
336 if (LineDelta != INT64_MAX) {
337 OS << uint8_t(dwarf::DW_LNS_advance_line);
338 encodeSLEB128(LineDelta, OS);
339 }
340
341 unsigned Offset;
342 std::pair<MCFixupKind, MCFixupKind> FK;
343
344 // According to the DWARF specification, the `DW_LNS_fixed_advance_pc` opcode
345 // takes a single unsigned half (unencoded) operand. The maximum encodable
346 // value is therefore 65535. Set a conservative upper bound for relaxation.
347 if (Value > 60000) {
348 unsigned PtrSize = C.getAsmInfo()->getCodePointerSize();
349
350 OS << uint8_t(dwarf::DW_LNS_extended_op);
351 encodeULEB128(PtrSize + 1, OS);
352
353 OS << uint8_t(dwarf::DW_LNE_set_address);
354 Offset = OS.tell();
355 assert((PtrSize == 4 || PtrSize == 8) && "Unexpected pointer size");
356 FK = getRelocPairForSize(PtrSize == 4 ? 32 : 64);
357 OS.write_zeros(PtrSize);
358 } else {
359 OS << uint8_t(dwarf::DW_LNS_fixed_advance_pc);
360 Offset = OS.tell();
361 FK = getRelocPairForSize(16);
362 support::endian::write<uint16_t>(OS, 0, llvm::endianness::little);
363 }
364
365 const MCBinaryExpr &MBE = cast<MCBinaryExpr>(AddrDelta);
366 Fixups.push_back(MCFixup::create(Offset, MBE.getLHS(), std::get<0>(FK)));
367 Fixups.push_back(MCFixup::create(Offset, MBE.getRHS(), std::get<1>(FK)));
368
369 if (LineDelta == INT64_MAX) {
370 OS << uint8_t(dwarf::DW_LNS_extended_op);
371 OS << uint8_t(1);
372 OS << uint8_t(dwarf::DW_LNE_end_sequence);
373 } else {
374 OS << uint8_t(dwarf::DW_LNS_copy);
375 }
376
377 WasRelaxed = OldSize != Data.size();
378 return true;
379}
380
382 MCAsmLayout &Layout,
383 bool &WasRelaxed) const {
384 const MCExpr &AddrDelta = DF.getAddrDelta();
385 SmallVectorImpl<char> &Data = DF.getContents();
386 SmallVectorImpl<MCFixup> &Fixups = DF.getFixups();
387 size_t OldSize = Data.size();
388
389 int64_t Value;
390 if (AddrDelta.evaluateAsAbsolute(Value, Layout))
391 return false;
392 bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout);
393 assert(IsAbsolute && "CFA with invalid expression");
394 (void)IsAbsolute;
395
396 Data.clear();
397 Fixups.clear();
399
400 assert(
402 1 &&
403 "expected 1-byte alignment");
404 if (Value == 0) {
405 WasRelaxed = OldSize != Data.size();
406 return true;
407 }
408
409 auto AddFixups = [&Fixups,
410 &AddrDelta](unsigned Offset,
411 std::pair<MCFixupKind, MCFixupKind> FK) {
412 const MCBinaryExpr &MBE = cast<MCBinaryExpr>(AddrDelta);
413 Fixups.push_back(MCFixup::create(Offset, MBE.getLHS(), std::get<0>(FK)));
414 Fixups.push_back(MCFixup::create(Offset, MBE.getRHS(), std::get<1>(FK)));
415 };
416
417 if (isUIntN(6, Value)) {
418 OS << uint8_t(dwarf::DW_CFA_advance_loc);
419 AddFixups(0, getRelocPairForSize(6));
420 } else if (isUInt<8>(Value)) {
421 OS << uint8_t(dwarf::DW_CFA_advance_loc1);
422 support::endian::write<uint8_t>(OS, 0, llvm::endianness::little);
423 AddFixups(1, getRelocPairForSize(8));
424 } else if (isUInt<16>(Value)) {
425 OS << uint8_t(dwarf::DW_CFA_advance_loc2);
426 support::endian::write<uint16_t>(OS, 0, llvm::endianness::little);
427 AddFixups(1, getRelocPairForSize(16));
428 } else if (isUInt<32>(Value)) {
429 OS << uint8_t(dwarf::DW_CFA_advance_loc4);
430 support::endian::write<uint32_t>(OS, 0, llvm::endianness::little);
431 AddFixups(1, getRelocPairForSize(32));
432 } else {
433 llvm_unreachable("unsupported CFA encoding");
434 }
435
436 WasRelaxed = OldSize != Data.size();
437 return true;
438}
439
441 const MCSubtargetInfo *STI) const {
442 // We mostly follow binutils' convention here: align to 4-byte boundary with a
443 // 0-fill padding.
444 OS.write_zeros(Count % 4);
445
446 // The remainder is now padded with 4-byte nops.
447 // nop: andi r0, r0, 0
448 for (; Count >= 4; Count -= 4)
449 OS.write("\0\0\x40\x03", 4);
450
451 return true;
452}
453
455 const MCFragment &F,
456 const MCFixup &Fixup,
457 const MCValue &Target,
458 uint64_t &FixedValue) const {
459 std::pair<MCFixupKind, MCFixupKind> FK;
460 uint64_t FixedValueA, FixedValueB;
461 const MCSymbol &SA = Target.getSymA()->getSymbol();
462 const MCSymbol &SB = Target.getSymB()->getSymbol();
463
464 bool force = !SA.isInSection() || !SB.isInSection();
465 if (!force) {
466 const MCSection &SecA = SA.getSection();
467 const MCSection &SecB = SB.getSection();
468
469 // We need record relocation if SecA != SecB. Usually SecB is same as the
470 // section of Fixup, which will be record the relocation as PCRel. If SecB
471 // is not same as the section of Fixup, it will report error. Just return
472 // false and then this work can be finished by handleFixup.
473 if (&SecA != &SecB)
474 return false;
475
476 // In SecA == SecB case. If the linker relaxation is enabled, we need record
477 // the ADD, SUB relocations. Otherwise the FixedValue has already been calc-
478 // ulated out in evaluateFixup, return true and avoid record relocations.
479 if (!STI.hasFeature(LoongArch::FeatureRelax))
480 return true;
481 }
482
483 switch (Fixup.getKind()) {
484 case llvm::FK_Data_1:
485 FK = getRelocPairForSize(8);
486 break;
487 case llvm::FK_Data_2:
488 FK = getRelocPairForSize(16);
489 break;
490 case llvm::FK_Data_4:
491 FK = getRelocPairForSize(32);
492 break;
493 case llvm::FK_Data_8:
494 FK = getRelocPairForSize(64);
495 break;
497 FK = getRelocPairForSize(128);
498 break;
499 default:
500 llvm_unreachable("unsupported fixup size");
501 }
502 MCValue A = MCValue::get(Target.getSymA(), nullptr, Target.getConstant());
503 MCValue B = MCValue::get(Target.getSymB());
504 auto FA = MCFixup::create(Fixup.getOffset(), nullptr, std::get<0>(FK));
505 auto FB = MCFixup::create(Fixup.getOffset(), nullptr, std::get<1>(FK));
506 auto &Asm = Layout.getAssembler();
507 Asm.getWriter().recordRelocation(Asm, Layout, &F, FA, A, FixedValueA);
508 Asm.getWriter().recordRelocation(Asm, Layout, &F, FB, B, FixedValueB);
509 FixedValue = FixedValueA - FixedValueB;
510 return true;
511}
512
513std::unique_ptr<MCObjectTargetWriter>
516 OSABI, Is64Bit, STI.hasFeature(LoongArch::FeatureRelax));
517}
518
520 const MCSubtargetInfo &STI,
521 const MCRegisterInfo &MRI,
522 const MCTargetOptions &Options) {
523 const Triple &TT = STI.getTargetTriple();
524 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
525 return new LoongArchAsmBackend(STI, OSABI, TT.isArch64Bit(), Options);
526}
unsigned const MachineRegisterInfo * MRI
static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target, uint64_t Value, MCContext &Ctx, const Triple &TheTriple, bool IsResolved)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
static LVOptions Options
Definition: LVOptions.cpp:25
static std::pair< MCFixupKind, MCFixupKind > getRelocPairForSize(unsigned Size)
static void reportOutOfRangeError(MCContext &Ctx, SMLoc Loc, unsigned N)
static void fixupLeb128(MCContext &Ctx, const MCFixup &Fixup, MutableArrayRef< char > Data, uint64_t Value)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const override
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
std::unique_ptr< MCObjectTargetWriter > createObjectTargetWriter() const override
bool relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF, MCAsmLayout &Layout, bool &WasRelaxed) const override
std::optional< MCFixupKind > getFixupKind(StringRef Name) const override
Map a relocation name used in .reloc to a fixup kind.
bool handleAddSubRelocations(const MCAsmLayout &Layout, const MCFragment &F, const MCFixup &Fixup, const MCValue &Target, uint64_t &FixedValue) const override
DenseMap< MCSection *, const MCSymbolRefExpr * > & getSecToAlignSym()
bool relaxDwarfCFA(MCDwarfCallFrameFragment &DF, MCAsmLayout &Layout, bool &WasRelaxed) const override
bool shouldInsertFixupForCodeAlign(MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF) override
Hook which indicates if the target requires a fixup to be generated when handling an align directive ...
const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const override
Get information on a fixup kind.
bool shouldInsertExtraNopBytesForCodeAlign(const MCAlignFragment &AF, unsigned &Size) override
Hook to check if extra nop bytes must be inserted for alignment directive.
unsigned getNumFixupKinds() const override
Get the number of target specific fixup kinds.
bool writeNopData(raw_ostream &OS, uint64_t Count, const MCSubtargetInfo *STI) const override
Write an (optimal) nop sequence of Count bytes to the given output.
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, const MCSubtargetInfo *STI) override
Hook to check if a relocation is needed for some target specific reason.
std::pair< bool, bool > relaxLEB128(MCLEBFragment &LF, MCAsmLayout &Layout, int64_t &Value) const override
Align getAlignment() const
Definition: MCFragment.h:314
unsigned getMaxBytesToEmit() const
Definition: MCFragment.h:320
const MCSubtargetInfo * getSubtargetInfo() const
Definition: MCFragment.h:328
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:43
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
unsigned getMinInstAlignment() const
Definition: MCAsmInfo.h:641
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:41
MCContext & getContext() const
Definition: MCAssembler.h:322
Binary assembler expressions.
Definition: MCExpr.h:492
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:639
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:642
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
Context object for machine code objects.
Definition: MCContext.h:83
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:412
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1070
MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
Definition: MCContext.cpp:347
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:213
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
Definition: MCExpr.cpp:572
SMLoc getLoc() const
Definition: MCExpr.h:82
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Definition: MCFixup.h:87
MCSection * getParent() const
Definition: MCFragment.h:94
bool isSigned() const
Definition: MCFragment.h:434
const MCExpr & getValue() const
Definition: MCFragment.h:431
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
MCSymbol * getBeginSymbol()
Definition: MCSection.h:147
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:397
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
Definition: MCSymbol.h:254
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:269
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:397
This represents an "assembler immediate".
Definition: MCValue.h:36
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
Definition: MCValue.h:59
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
Represents a location in source code.
Definition: SMLoc.h:23
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:719
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:151
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:691
#define INT64_MAX
Definition: DataTypes.h:71
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
int64_t maxIntN(int64_t N)
Gets the maximum value for a N-bit signed integer.
Definition: MathExtras.h:228
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:239
std::unique_ptr< MCObjectTargetWriter > createLoongArchELFObjectWriter(uint8_t OSABI, bool Is64Bit, bool Relax)
MCAsmBackend * createLoongArchAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:21
@ FirstTargetFixupKind
Definition: MCFixup.h:45
@ FirstLiteralRelocationKind
The range [FirstLiteralRelocationKind, MaxTargetFixupKind) is used for relocations coming from ....
Definition: MCFixup.h:50
@ FK_Data_8
A eight-byte fixup.
Definition: MCFixup.h:26
@ FK_Data_1
A one-byte fixup.
Definition: MCFixup.h:23
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:25
@ FK_NONE
A no-op fixup.
Definition: MCFixup.h:22
@ FK_Data_leb128
A leb128 fixup.
Definition: MCFixup.h:27
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:24
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
int64_t minIntN(int64_t N)
Gets the minimum value for a N-bit signed integer.
Definition: MathExtras.h:219
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition: LEB128.h:23
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:80
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:208
#define N
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
Target independent information on a fixup kind.
@ FKF_IsPCRel
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...