13#ifndef LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H
14#define LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H
169 return (Val & (((1UL << (
Hi + 1)) - 1))) >>
Lo;
174 using namespace support;
176 char *BlockWorkingMem =
B.getAlreadyMutableContent().data();
177 char *FixupPtr = BlockWorkingMem +
E.getOffset();
178 uint64_t FixupAddress = (
B.getAddress() +
E.getOffset()).getValue();
179 uint64_t TargetAddress =
E.getTarget().getAddress().getValue();
180 int64_t Addend =
E.getAddend();
182 switch (
E.getKind()) {
184 *(ulittle64_t *)FixupPtr = TargetAddress + Addend;
188 if (
Value > std::numeric_limits<uint32_t>::max())
190 *(ulittle32_t *)FixupPtr =
Value;
194 int64_t
Value = TargetAddress - FixupAddress + Addend;
196 if (!isInt<28>(
Value))
199 if (!isShiftedInt<26, 2>(
Value))
202 uint32_t RawInstr = *(little32_t *)FixupPtr;
206 *(little32_t *)FixupPtr = RawInstr | Imm15_0 | Imm25_16;
210 int64_t
Value = TargetAddress - FixupAddress + Addend;
212 if (!isInt<32>(
Value))
214 *(little32_t *)FixupPtr =
Value;
218 int64_t
Value = FixupAddress - TargetAddress + Addend;
219 if (!isInt<32>(
Value))
221 *(little32_t *)FixupPtr =
Value;
225 *(little64_t *)FixupPtr = TargetAddress - FixupAddress + Addend;
230 (
Target + (
Target & 0x800)) & ~static_cast<uint64_t>(0xfff);
231 uint64_t PCPage = FixupAddress & ~static_cast<uint64_t>(0xfff);
233 int64_t PageDelta = TargetPage - PCPage;
234 if (!isInt<32>(PageDelta))
237 uint32_t RawInstr = *(little32_t *)FixupPtr;
239 *(little32_t *)FixupPtr = RawInstr | Imm31_12;
243 uint64_t TargetOffset = (TargetAddress + Addend) & 0xfff;
245 uint32_t RawInstr = *(ulittle32_t *)FixupPtr;
246 uint32_t Imm11_0 = TargetOffset << 10;
247 *(ulittle32_t *)FixupPtr = RawInstr | Imm11_0;
251 return make_error<JITLinkError>(
252 "In graph " +
G.getName() +
", section " +
B.getSection().getName() +
279 return {
reinterpret_cast<const char *
>(StubContent),
StubEntrySize};
292 Symbol *InitialTarget =
nullptr,
298 *InitialTarget, InitialAddend);
299 return G.addAnonymousSymbol(
B, 0,
G.getPointerSize(),
false,
false);
307 Block &StubContentBlock =
G.createContentBlock(
311 return G.addAnonymousSymbol(StubContentBlock, 0,
StubEntrySize,
true,
false);
321 switch (
E.getKind()) {
332 "Fell through switch, but no new kind to set");
334 dbgs() <<
" Fixing " <<
G.getEdgeKindName(
E.getKind()) <<
" edge at "
335 <<
B->getFixupAddress(
E) <<
" (" <<
B->getAddress() <<
" + "
336 <<
formatv(
"{0:x}",
E.getOffset()) <<
")\n";
338 E.setKind(KindToSet);
368 dbgs() <<
" Fixing " <<
G.getEdgeKindName(
E.getKind()) <<
" edge at "
369 <<
B->getFixupAddress(
E) <<
" (" <<
B->getAddress() <<
" + "
370 <<
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, X)
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)
uint32_t extractBits(uint32_t Val, unsigned Hi, unsigned Lo)
EdgeKind_loongarch
Represents loongarch fixups.
@ 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...
@ 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.
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(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< Ts >(Vals))...))>
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.