13#ifndef LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H
14#define LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H
329 return Hi == 63 ? Val >>
Lo : (Val & ((((
uint64_t)1 << (
Hi + 1)) - 1))) >>
Lo;
334 using namespace support;
336 char *BlockWorkingMem =
B.getAlreadyMutableContent().data();
337 char *FixupPtr = BlockWorkingMem +
E.getOffset();
338 uint64_t FixupAddress = (
B.getAddress() +
E.getOffset()).getValue();
339 uint64_t TargetAddress =
E.getTarget().getAddress().getValue();
340 int64_t Addend =
E.getAddend();
342 switch (
E.getKind()) {
344 *(ulittle64_t *)FixupPtr = TargetAddress + Addend;
348 if (
Value > std::numeric_limits<uint32_t>::max())
350 *(ulittle32_t *)FixupPtr =
Value;
354 int64_t
Value = TargetAddress - FixupAddress + Addend;
356 if (!isInt<18>(
Value))
359 if (!isShiftedInt<16, 2>(
Value))
362 uint32_t RawInstr = *(little32_t *)FixupPtr;
365 *(little32_t *)FixupPtr = RawInstr | Imm15_0;
369 int64_t
Value = TargetAddress - FixupAddress + Addend;
371 if (!isInt<23>(
Value))
374 if (!isShiftedInt<21, 2>(
Value))
377 uint32_t RawInstr = *(little32_t *)FixupPtr;
381 *(little32_t *)FixupPtr = RawInstr | Imm15_0 | Imm20_16;
385 int64_t
Value = TargetAddress - FixupAddress + Addend;
387 if (!isInt<28>(
Value))
390 if (!isShiftedInt<26, 2>(
Value))
393 uint32_t RawInstr = *(little32_t *)FixupPtr;
397 *(little32_t *)FixupPtr = RawInstr | Imm15_0 | Imm25_16;
401 int64_t
Value = TargetAddress - FixupAddress + Addend;
403 if (!isInt<32>(
Value))
405 *(little32_t *)FixupPtr =
Value;
409 int64_t
Value = FixupAddress - TargetAddress + Addend;
410 if (!isInt<32>(
Value))
412 *(little32_t *)FixupPtr =
Value;
416 *(little64_t *)FixupPtr = TargetAddress - FixupAddress + Addend;
421 (
Target + (
Target & 0x800)) & ~static_cast<uint64_t>(0xfff);
422 uint64_t PCPage = FixupAddress & ~static_cast<uint64_t>(0xfff);
424 int64_t PageDelta = TargetPage - PCPage;
425 if (!isInt<32>(PageDelta))
428 uint32_t RawInstr = *(little32_t *)FixupPtr;
430 *(little32_t *)FixupPtr = RawInstr | Imm31_12;
434 uint64_t TargetOffset = (TargetAddress + Addend) & 0xfff;
436 uint32_t RawInstr = *(ulittle32_t *)FixupPtr;
437 uint32_t Imm11_0 = TargetOffset << 10;
438 *(ulittle32_t *)FixupPtr = RawInstr | Imm11_0;
442 int64_t
Value = TargetAddress - FixupAddress + Addend;
447 if (!isShiftedInt<36, 2>(
Value))
450 uint32_t Pcaddu18i = *(little32_t *)FixupPtr;
452 *(little32_t *)FixupPtr = Pcaddu18i | Hi20;
453 uint32_t Jirl = *(little32_t *)(FixupPtr + 4);
455 *(little32_t *)(FixupPtr + 4) = Jirl | Lo16;
459 int64_t
Value = *(
reinterpret_cast<const int8_t *
>(FixupPtr));
460 Value += ((TargetAddress + Addend) & 0x3f);
461 *FixupPtr = (*FixupPtr & 0xc0) | (
static_cast<int8_t
>(
Value) & 0x3f);
466 TargetAddress + *(
reinterpret_cast<const int8_t *
>(FixupPtr)) + Addend;
467 *FixupPtr =
static_cast<int8_t
>(
Value);
473 *(little16_t *)FixupPtr =
static_cast<int16_t
>(
Value);
479 *(little32_t *)FixupPtr =
static_cast<int32_t
>(
Value);
485 *(little64_t *)FixupPtr =
static_cast<int64_t
>(
Value);
489 const uint32_t Maxcount = 1 + 64 / 7;
491 const char *
Error =
nullptr;
493 &Count,
nullptr, &
Error);
495 if (Count > Maxcount || (Count == Maxcount &&
Error))
496 return make_error<JITLinkError>(
498 ": extra space for uleb128");
500 uint64_t Mask = Count < Maxcount ? (1ULL << 7 * Count) - 1 : -1ULL;
502 (
reinterpret_cast<uint8_t *
>(FixupPtr)), Count);
506 int64_t
Value = *(
reinterpret_cast<const int8_t *
>(FixupPtr));
507 Value -= ((TargetAddress + Addend) & 0x3f);
508 *FixupPtr = (*FixupPtr & 0xc0) | (
static_cast<int8_t
>(
Value) & 0x3f);
513 *(
reinterpret_cast<const int8_t *
>(FixupPtr)) - TargetAddress - Addend;
514 *FixupPtr =
static_cast<int8_t
>(
Value);
520 *(little16_t *)FixupPtr =
static_cast<int16_t
>(
Value);
526 *(little32_t *)FixupPtr =
static_cast<int32_t
>(
Value);
532 *(little64_t *)FixupPtr =
static_cast<int64_t
>(
Value);
536 const uint32_t Maxcount = 1 + 64 / 7;
538 const char *
Error =
nullptr;
540 &Count,
nullptr, &
Error);
542 if (Count > Maxcount || (Count == Maxcount &&
Error))
543 return make_error<JITLinkError>(
545 ": extra space for uleb128");
547 uint64_t Mask = Count < Maxcount ? (1ULL << 7 * Count) - 1 : -1ULL;
549 (
reinterpret_cast<uint8_t *
>(FixupPtr)), Count);
556 return make_error<JITLinkError>(
557 "In graph " +
G.getName() +
", section " +
B.getSection().getName() +
584 return {
reinterpret_cast<const char *
>(StubContent),
StubEntrySize};
597 Symbol *InitialTarget =
nullptr,
603 *InitialTarget, InitialAddend);
604 return G.addAnonymousSymbol(
B, 0,
G.getPointerSize(),
false,
false);
612 Block &StubContentBlock =
G.createContentBlock(
616 return G.addAnonymousSymbol(StubContentBlock, 0,
StubEntrySize,
true,
false);
626 switch (
E.getKind()) {
637 "Fell through switch, but no new kind to set");
639 dbgs() <<
" Fixing " <<
G.getEdgeKindName(
E.getKind()) <<
" edge at "
640 <<
B->getFixupAddress(
E) <<
" (" <<
B->getAddress() <<
" + "
641 <<
formatv(
"{0:x}",
E.getOffset()) <<
")\n";
643 E.setKind(KindToSet);
672 !
E.getTarget().isDefined()) {
674 dbgs() <<
" Fixing " <<
G.getEdgeKindName(
E.getKind()) <<
" edge at "
675 <<
B->getFixupAddress(
E) <<
" (" <<
B->getAddress() <<
" + "
676 <<
formatv(
"{0:x}",
E.getOffset()) <<
")\n";
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
LLVM Value Representation.
An Addressable with content and edges.
void addEdge(Edge::Kind K, Edge::OffsetT Offset, Symbol &Target, Edge::AddendT Addend)
Add an edge to this block.
Represents fixups and constraints in the LinkGraph.
Represents an object file section.
A CRTP base for tables that are built on demand, e.g.
Symbol & getEntryForTarget(LinkGraph &G, Symbol &Target)
Return the constructed entry.
Global Offset Table Builder.
Symbol & createEntry(LinkGraph &G, Symbol &Target)
bool visitEdge(LinkGraph &G, Block *B, Edge &E)
static StringRef getSectionName()
Procedure Linkage Table Builder.
static StringRef getSectionName()
PLTTableManager(GOTTableManager &GOT)
Section & getStubsSection(LinkGraph &G)
Symbol & createEntry(LinkGraph &G, Symbol &Target)
bool visitEdge(LinkGraph &G, Block *B, Edge &E)
Represents an address in the executor process.
Symbol & createAnonymousPointerJumpStub(LinkGraph &G, Section &StubSection, Symbol &PointerSymbol)
Create a jump stub that jumps via the pointer at the given symbol and an anonymous symbol pointing to...
Symbol & createAnonymousPointer(LinkGraph &G, Section &PointerSection, Symbol *InitialTarget=nullptr, uint64_t InitialAddend=0)
Creates a new pointer block in the given section and returns an Anonymous symbol pointing to it.
ArrayRef< char > getStubBlockContent(LinkGraph &G)
const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given loongarch edge.
ArrayRef< char > getGOTEntryBlockContent(LinkGraph &G)
EdgeKind_loongarch
Represents loongarch fixups.
@ Branch16PCRel
A 16-bit PC-relative branch.
@ Add16
16 bits label addition
@ AddUleb128
ULEB128 bits label addition.
@ RequestGOTAndTransformToPage20
A GOT entry getter/constructor, transformed to Page20 pointing at the GOT entry for the original targ...
@ Sub16
16 bits label subtraction
@ NegDelta32
A 32-bit negative delta.
@ SubUleb128
ULEB128 bits label subtraction.
@ Sub8
8 bits label subtraction
@ PageOffset12
The 12-bit offset of the target within its page.
@ Sub32
32 bits label subtraction
@ Add64
64 bits label addition
@ Sub6
low 6 bits label subtraction
@ Add8
8 bits label addition
@ Page20
The signed 20-bit delta from the fixup page to the page containing the target.
@ Pointer64
A plain 64-bit pointer value relocation.
@ RequestGOTAndTransformToPageOffset12
A GOT entry getter/constructor, transformed to Pageoffset12 pointing at the GOT entry for the origina...
@ Call36PCRel
A 36-bit PC-relative call.
@ Add6
low 6 bits label addition
@ Branch21PCRel
A 21-bit PC-relative branch.
@ Branch26PCRel
A 26-bit PC-relative branch.
@ Add32
32 bits label addition
@ Pointer32
A plain 32-bit pointer value relocation.
@ AlignRelaxable
Alignment requirement used by linker relaxation.
@ Sub64
64 bits label subtraction
Error applyFixup(LinkGraph &G, Block &B, const Edge &E)
Apply fixup expression for edge to block content.
const uint8_t LA32StubContent[StubEntrySize]
const uint8_t LA64StubContent[StubEntrySize]
const char NullPointerContent[8]
loongarch null pointer content.
uint32_t extractBits(uint64_t Val, unsigned Hi, unsigned Lo)
constexpr size_t StubEntrySize
loongarch stub content.
Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B, const Edge &E)
Create an out of range error for the given edge in the given block.
Error makeAlignmentError(llvm::orc::ExecutorAddr Loc, uint64_t Value, int N, const Edge &E)
uint64_t read64le(const void *P)
uint16_t read16le(const void *P)
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.