13#ifndef LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H
14#define LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H
236 return Hi == 63 ? Val >>
Lo : (Val & (((1UL << (
Hi + 1)) - 1))) >>
Lo;
241 using namespace support;
243 char *BlockWorkingMem =
B.getAlreadyMutableContent().data();
244 char *FixupPtr = BlockWorkingMem +
E.getOffset();
245 uint64_t FixupAddress = (
B.getAddress() +
E.getOffset()).getValue();
246 uint64_t TargetAddress =
E.getTarget().getAddress().getValue();
247 int64_t Addend =
E.getAddend();
249 switch (
E.getKind()) {
251 *(ulittle64_t *)FixupPtr = TargetAddress + Addend;
255 if (
Value > std::numeric_limits<uint32_t>::max())
257 *(ulittle32_t *)FixupPtr =
Value;
261 int64_t
Value = TargetAddress - FixupAddress + Addend;
263 if (!isInt<18>(
Value))
266 if (!isShiftedInt<16, 2>(
Value))
269 uint32_t RawInstr = *(little32_t *)FixupPtr;
272 *(little32_t *)FixupPtr = RawInstr | Imm15_0;
276 int64_t
Value = TargetAddress - FixupAddress + Addend;
278 if (!isInt<23>(
Value))
281 if (!isShiftedInt<21, 2>(
Value))
284 uint32_t RawInstr = *(little32_t *)FixupPtr;
288 *(little32_t *)FixupPtr = RawInstr | Imm15_0 | Imm20_16;
292 int64_t
Value = TargetAddress - FixupAddress + Addend;
294 if (!isInt<28>(
Value))
297 if (!isShiftedInt<26, 2>(
Value))
300 uint32_t RawInstr = *(little32_t *)FixupPtr;
304 *(little32_t *)FixupPtr = RawInstr | Imm15_0 | Imm25_16;
308 int64_t
Value = TargetAddress - FixupAddress + Addend;
310 if (!isInt<32>(
Value))
312 *(little32_t *)FixupPtr =
Value;
316 int64_t
Value = FixupAddress - TargetAddress + Addend;
317 if (!isInt<32>(
Value))
319 *(little32_t *)FixupPtr =
Value;
323 *(little64_t *)FixupPtr = TargetAddress - FixupAddress + Addend;
328 (
Target + (
Target & 0x800)) & ~static_cast<uint64_t>(0xfff);
329 uint64_t PCPage = FixupAddress & ~static_cast<uint64_t>(0xfff);
331 int64_t PageDelta = TargetPage - PCPage;
332 if (!isInt<32>(PageDelta))
335 uint32_t RawInstr = *(little32_t *)FixupPtr;
337 *(little32_t *)FixupPtr = RawInstr | Imm31_12;
341 uint64_t TargetOffset = (TargetAddress + Addend) & 0xfff;
343 uint32_t RawInstr = *(ulittle32_t *)FixupPtr;
344 uint32_t Imm11_0 = TargetOffset << 10;
345 *(ulittle32_t *)FixupPtr = RawInstr | Imm11_0;
349 int64_t
Value = TargetAddress - FixupAddress + Addend;
354 if (!isShiftedInt<36, 2>(
Value))
357 uint32_t Pcaddu18i = *(little32_t *)FixupPtr;
359 *(little32_t *)FixupPtr = Pcaddu18i | Hi20;
360 uint32_t Jirl = *(little32_t *)(FixupPtr + 4);
362 *(little32_t *)(FixupPtr + 4) = Jirl | Lo16;
366 return make_error<JITLinkError>(
367 "In graph " +
G.getName() +
", section " +
B.getSection().getName() +
394 return {
reinterpret_cast<const char *
>(StubContent),
StubEntrySize};
407 Symbol *InitialTarget =
nullptr,
413 *InitialTarget, InitialAddend);
414 return G.addAnonymousSymbol(
B, 0,
G.getPointerSize(),
false,
false);
422 Block &StubContentBlock =
G.createContentBlock(
426 return G.addAnonymousSymbol(StubContentBlock, 0,
StubEntrySize,
true,
false);
436 switch (
E.getKind()) {
447 "Fell through switch, but no new kind to set");
449 dbgs() <<
" Fixing " <<
G.getEdgeKindName(
E.getKind()) <<
" edge at "
450 <<
B->getFixupAddress(
E) <<
" (" <<
B->getAddress() <<
" + "
451 <<
formatv(
"{0:x}",
E.getOffset()) <<
")\n";
453 E.setKind(KindToSet);
482 !
E.getTarget().isDefined()) {
484 dbgs() <<
" Fixing " <<
G.getEdgeKindName(
E.getKind()) <<
" edge at "
485 <<
B->getFixupAddress(
E) <<
" (" <<
B->getAddress() <<
" + "
486 <<
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.
@ RequestGOTAndTransformToPage20
A GOT entry getter/constructor, transformed to Page20 pointing at the GOT entry for the original targ...
@ NegDelta32
A 32-bit negative delta.
@ PageOffset12
The 12-bit offset of the target within its page.
@ 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.
@ Branch21PCRel
A 21-bit PC-relative branch.
@ Branch26PCRel
A 26-bit PC-relative branch.
@ Pointer32
A plain 32-bit pointer value relocation.
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)
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.