Skip to content

Commit

Permalink
[JITLink][x86-64] Rename *Relaxable edges to *REXRelaxable.
Browse files Browse the repository at this point in the history
The existing relaxable edges all assume a REX prefix. ELF includes non-REX
relaxations, so rename these edges to make room for the new kinds.
  • Loading branch information
lhames committed Aug 14, 2021
1 parent 632135a commit 27ea3f1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 43 deletions.
41 changes: 21 additions & 20 deletions llvm/include/llvm/ExecutionEngine/JITLink/x86_64.h
Expand Up @@ -221,7 +221,7 @@ enum EdgeKind_x86_64 : Edge::Kind {
/// phase will result in an assert/unreachable during the fixup phase
RequestGOTAndTransformToDelta64FromGOT,

/// A PC-relative reference to a GOT entry, relaxable if GOT entry target
/// A PC-relative REX load of a GOT entry, relaxable if GOT entry target
/// is in-range of the fixup.
///
/// If the GOT entry target is in-range of the fixup then the load from the
Expand All @@ -234,17 +234,18 @@ enum EdgeKind_x86_64 : Edge::Kind {
/// - The result of the fixup expression must fit into an int32, otherwise
/// an out-of-range error will be returned.
///
PCRel32GOTLoadRelaxable,
PCRel32GOTLoadREXRelaxable,

/// A GOT entry getter/constructor, transformed to PCRel32ToGOTLoadRelaxable
/// pointing at the GOT entry for the original target.
/// A GOT entry getter/constructor, transformed to
/// PCRel32ToGOTLoadREXRelaxable pointing at the GOT entry for the original
/// target.
///
/// Indicates that this edge should be transformed into a
/// PC32ToGOTLoadRelaxable targeting the GOT entry for the edge's current
/// target, maintaining the same addend. A GOT entry for the target should be
/// created if one does not already exist.
/// Indicates that this edge should be lowered to a PC32ToGOTLoadREXRelaxable
/// targeting the GOT entry for the edge's current target, maintaining the
/// same addend. A GOT entry for the target should be created if one does not
/// already exist.
///
/// Edges of this kind are usually handled by a GOT builder pass inserted by
/// Edges of this kind are usually lowered by a GOT builder pass inserted by
/// default.
///
/// Fixup expression:
Expand All @@ -254,12 +255,12 @@ enum EdgeKind_x86_64 : Edge::Kind {
/// - *ASSERTION* Failure to handle edges of this kind prior to the fixup
/// phase will result in an assert/unreachable during the fixup phase.
///
RequestGOTAndTransformToPCRel32GOTLoadRelaxable,
RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable,

/// A PC-relative reference to a Thread Local Variable Pointer (TLVP) entry,
/// A PC-relative REX load of a Thread Local Variable Pointer (TLVP) entry,
/// relaxable if the TLVP entry target is in-range of the fixup.
///
/// If the TLVP entry target is in-range of the fixup then the load frmo the
/// If the TLVP entry target is in-range of the fixup then the load from the
/// TLVP may be replaced with a direct memory address calculation.
///
/// The target of this edge must be a thread local variable entry of the form
Expand All @@ -276,15 +277,15 @@ enum EdgeKind_x86_64 : Edge::Kind {
/// - The target must be either external, or a TLV entry of the required
/// form, otherwise a malformed TLV entry error will be returned.
///
PCRel32TLVPLoadRelaxable,
PCRel32TLVPLoadREXRelaxable,

/// A TLVP entry getter/constructor, transformed to
/// Delta32ToTLVPLoadRelaxable.
/// Delta32ToTLVPLoadREXRelaxable.
///
/// Indicates that this edge should be transformed into a
/// Delta32ToTLVPLoadRelaxable targeting the TLVP entry for the edge's current
/// target. A TLVP entry for the target should be created if one does not
/// already exist.
/// Delta32ToTLVPLoadREXRelaxable targeting the TLVP entry for the edge's
/// current target. A TLVP entry for the target should be created if one does
/// not already exist.
///
/// Fixup expression:
/// NONE
Expand All @@ -293,7 +294,7 @@ enum EdgeKind_x86_64 : Edge::Kind {
/// - *ASSERTION* Failure to handle edges of this kind prior to the fixup
/// phase will result in an assert/unreachable during the fixup phase.
///
RequestTLVPAndTransformToPCRel32TLVPLoadRelaxable
RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable
};

/// Returns a string name for the given x86-64 edge. For debugging purposes
Expand Down Expand Up @@ -340,8 +341,8 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E,
case BranchPCRel32:
case BranchPCRel32ToPtrJumpStub:
case BranchPCRel32ToPtrJumpStubBypassable:
case PCRel32GOTLoadRelaxable:
case PCRel32TLVPLoadRelaxable: {
case PCRel32GOTLoadREXRelaxable:
case PCRel32TLVPLoadREXRelaxable: {
int64_t Value =
E.getTarget().getAddress() - (FixupAddress + 4) + E.getAddend();
if (LLVM_LIKELY(isInRangeForImmS32(Value)))
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
Expand Up @@ -53,7 +53,7 @@ class PerGraphGOTAndPLTStubsBuilder_ELF_x86_64
return E.getKind() == x86_64::RequestGOTAndTransformToDelta32 ||
E.getKind() == x86_64::RequestGOTAndTransformToDelta64 ||
E.getKind() ==
x86_64::RequestGOTAndTransformToPCRel32GOTLoadRelaxable ||
x86_64::RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable ||
E.getKind() == x86_64::RequestGOTAndTransformToDelta64FromGOT;
}

Expand All @@ -71,8 +71,8 @@ class PerGraphGOTAndPLTStubsBuilder_ELF_x86_64
// optimizeMachO_x86_64_GOTAndStubs pass below.
// If it's a GOT64 leave it as is.
switch (E.getKind()) {
case x86_64::RequestGOTAndTransformToPCRel32GOTLoadRelaxable:
E.setKind(x86_64::PCRel32GOTLoadRelaxable);
case x86_64::RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable:
E.setKind(x86_64::PCRel32GOTLoadREXRelaxable);
break;
case x86_64::RequestGOTAndTransformToDelta64:
E.setKind(x86_64::Delta64);
Expand Down Expand Up @@ -107,7 +107,7 @@ class PerGraphGOTAndPLTStubsBuilder_ELF_x86_64
void fixPLTEdge(Edge &E, Symbol &Stub) {
assert(E.getKind() == x86_64::BranchPCRel32 && "Not a Branch32 edge?");

// Set the edge kind to Branch32ToPtrJumpStubRelaxable to enable it to be
// Set the edge kind to Branch32ToPtrJumpStubBypassable to enable it to be
// optimized when the target is in-range.
E.setKind(x86_64::BranchPCRel32ToPtrJumpStubBypassable);
E.setTarget(Stub);
Expand Down Expand Up @@ -154,7 +154,7 @@ static Error optimizeELF_x86_64_GOTAndStubs(LinkGraph &G) {

for (auto *B : G.blocks())
for (auto &E : B->edges())
if (E.getKind() == x86_64::PCRel32GOTLoadRelaxable) {
if (E.getKind() == x86_64::PCRel32GOTLoadREXRelaxable) {
// Replace GOT load with LEA only for MOVQ instructions.
constexpr uint8_t MOVQRIPRel[] = {0x48, 0x8b};
if (E.getOffset() < 3 ||
Expand Down Expand Up @@ -371,7 +371,7 @@ class ELFLinkGraphBuilder_x86_64 : public ELFLinkGraphBuilder<object::ELF64LE> {
Kind = x86_64::Pointer64;
break;
case PCRel32GOTLoad: {
Kind = x86_64::RequestGOTAndTransformToPCRel32GOTLoadRelaxable;
Kind = x86_64::RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable;
Addend = 0;
break;
}
Expand Down
15 changes: 9 additions & 6 deletions llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp
Expand Up @@ -300,7 +300,7 @@ class MachOLinkGraphBuilder_x86_64 : public MachOLinkGraphBuilder {
else
return TargetSymbolOrErr.takeError();
Addend = *(const little32_t *)FixupContent;
Kind = x86_64::RequestGOTAndTransformToPCRel32GOTLoadRelaxable;
Kind = x86_64::RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable;
if (FixupOffset < 3)
return make_error<JITLinkError>("GOTLD at invalid offset " +
formatv("{0}", FixupOffset));
Expand All @@ -319,7 +319,10 @@ class MachOLinkGraphBuilder_x86_64 : public MachOLinkGraphBuilder {
else
return TargetSymbolOrErr.takeError();
Addend = *(const little32_t *)FixupContent;
Kind = x86_64::RequestTLVPAndTransformToPCRel32TLVPLoadRelaxable;
Kind = x86_64::RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable;
if (FixupOffset < 3)
return make_error<JITLinkError>("TLV at invalid offset " +
formatv("{0}", FixupOffset));
break;
case MachOPointer32:
if (auto TargetSymbolOrErr = findSymbolByIndex(RI.r_symbolnum))
Expand Down Expand Up @@ -429,7 +432,7 @@ class PerGraphGOTAndPLTStubsBuilder_MachO_x86_64
bool isGOTEdgeToFix(Edge &E) const {
return E.getKind() == x86_64::RequestGOTAndTransformToDelta32 ||
E.getKind() ==
x86_64::RequestGOTAndTransformToPCRel32GOTLoadRelaxable;
x86_64::RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable;
}

Symbol &createGOTEntry(Symbol &Target) {
Expand All @@ -442,8 +445,8 @@ class PerGraphGOTAndPLTStubsBuilder_MachO_x86_64
case x86_64::RequestGOTAndTransformToDelta32:
E.setKind(x86_64::Delta32);
break;
case x86_64::RequestGOTAndTransformToPCRel32GOTLoadRelaxable:
E.setKind(x86_64::PCRel32GOTLoadRelaxable);
case x86_64::RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable:
E.setKind(x86_64::PCRel32GOTLoadREXRelaxable);
break;
default:
llvm_unreachable("Not a GOT transform edge");
Expand Down Expand Up @@ -500,7 +503,7 @@ static Error optimizeMachO_x86_64_GOTAndStubs(LinkGraph &G) {

for (auto *B : G.blocks())
for (auto &E : B->edges())
if (E.getKind() == x86_64::PCRel32GOTLoadRelaxable) {
if (E.getKind() == x86_64::PCRel32GOTLoadREXRelaxable) {
assert(E.getOffset() >= 3 && "GOT edge occurs too early in block");

// Optimize GOT references.
Expand Down
16 changes: 8 additions & 8 deletions llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
Expand Up @@ -46,14 +46,14 @@ const char *getEdgeKindName(Edge::Kind K) {
return "RequestGOTAndTransformToDelta64";
case RequestGOTAndTransformToDelta64FromGOT:
return "RequestGOTAndTransformToDelta64FromGOT";
case PCRel32GOTLoadRelaxable:
return "PCRel32GOTLoadRelaxable";
case RequestGOTAndTransformToPCRel32GOTLoadRelaxable:
return "RequestGOTAndTransformToPCRel32GOTLoadRelaxable";
case PCRel32TLVPLoadRelaxable:
return "PCRel32TLVPLoadRelaxable";
case RequestTLVPAndTransformToPCRel32TLVPLoadRelaxable:
return "RequestTLVPAndTransformToPCRel32TLVPLoadRelaxable";
case PCRel32GOTLoadREXRelaxable:
return "PCRel32GOTLoadREXRelaxable";
case RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable:
return "RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable";
case PCRel32TLVPLoadREXRelaxable:
return "PCRel32TLVPLoadREXRelaxable";
case RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable:
return "RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable";
default:
return getGenericEdgeKindName(static_cast<Edge::Kind>(K));
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
Expand Up @@ -950,9 +950,9 @@ Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges(
for (auto *B : G.blocks())
for (auto &E : B->edges())
if (E.getKind() ==
jitlink::x86_64::RequestTLVPAndTransformToPCRel32TLVPLoadRelaxable)
E.setKind(
jitlink::x86_64::RequestGOTAndTransformToPCRel32GOTLoadRelaxable);
jitlink::x86_64::RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable)
E.setKind(jitlink::x86_64::
RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable);

return Error::success();
}
Expand Down

0 comments on commit 27ea3f1

Please sign in to comment.