Skip to content

Commit

Permalink
JIT: Switch remaining offsetof(Runtime) to RuntimeOffsets
Browse files Browse the repository at this point in the history
Summary:
This keeps all the warnings in one place, making it compilable
with `-Werror`.

Reviewed By: neildhar

Differential Revision: D68655679

fbshipit-source-id: 831de77b37ec3d4c3714793be93abdbe8c0205e5
  • Loading branch information
avp authored and facebook-github-bot committed Jan 27, 2025
1 parent c908a05 commit befb93e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/VM/JIT/RuntimeOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ namespace vm {

struct RuntimeOffsets {
static constexpr uint32_t stackPointer = offsetof(Runtime, stackPointer_);
static constexpr uint32_t registerStackEnd =
offsetof(Runtime, registerStackEnd_);
static constexpr uint32_t currentFrame = offsetof(Runtime, currentFrame_);
static constexpr uint32_t currentIP = offsetof(Runtime, currentIP_);
static constexpr uint32_t globalObject = offsetof(Runtime, global_);
static constexpr uint32_t thrownValue = offsetof(Runtime, thrownValue_);
static constexpr uint32_t shLocals = offsetof(Runtime, shLocals);
Expand Down
14 changes: 7 additions & 7 deletions lib/VM/JIT/arm64/JitEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ void Emitter::frameSetup(
}});

comment("// xFrame");
a.ldr(xFrame, a64::Mem(xRuntime, offsetof(Runtime, stackPointer_)));
a.ldr(xFrame, a64::Mem(xRuntime, RuntimeOffsets::stackPointer));

// If the function has a prohibitInvoke flag, we need to check if it has been
// called correctly.
Expand Down Expand Up @@ -771,7 +771,7 @@ void Emitter::frameSetup(

// Compute the remaining available stack space:
// runtime.registerStackEnd_ - runtime.stackPointer_
a.ldr(a64::x0, a64::Mem(xRuntime, offsetof(Runtime, registerStackEnd_)));
a.ldr(a64::x0, a64::Mem(xRuntime, RuntimeOffsets::registerStackEnd));
a.sub(a64::x0, a64::x0, xFrame);
// Check if we need more registers than remain.
size_t totalRegsToAlloc = numFrameRegs + hbc::StackFrameLayout::FirstLocal;
Expand All @@ -790,8 +790,8 @@ void Emitter::frameSetup(
}

// Advance the register stack.
a.str(a64::x0, a64::Mem(xRuntime, offsetof(Runtime, stackPointer_)));
a.str(xFrame, a64::Mem(xRuntime, offsetof(Runtime, currentFrame_)));
a.str(a64::x0, a64::Mem(xRuntime, RuntimeOffsets::stackPointer));
a.str(xFrame, a64::Mem(xRuntime, RuntimeOffsets::currentFrame));

// Fill it with undefined.
a.mov(a64::x0, _sh_ljs_undefined().raw);
Expand Down Expand Up @@ -945,15 +945,15 @@ void Emitter::callThunk(void *fn, const char *name) {
void Emitter::callThunkWithSavedIP(void *fn, const char *name) {
// Save the current IP in the runtime.
getBytecodeIP(a64::x16);
a.str(a64::x16, a64::Mem(xRuntime, offsetof(Runtime, currentIP_)));
a.str(a64::x16, a64::Mem(xRuntime, RuntimeOffsets::currentIP));

// Call the passed function.
callThunk(fn, name);

if (emitAsserts_) {
// Invalidate the current IP to make sure it is set before the next call.
a.mov(a64::x16, Runtime::kInvalidCurrentIP);
a.str(a64::x16, a64::Mem(xRuntime, offsetof(Runtime, currentIP_)));
a.str(a64::x16, a64::Mem(xRuntime, RuntimeOffsets::currentIP));
}
}

Expand Down Expand Up @@ -4291,7 +4291,7 @@ void Emitter::callImpl(FR frRes, FR frCallee) {
// Save the current IP in both the SavedIP slot and the runtime.
getBytecodeIP(savedIPReg.a64GpX());
frUpdatedWithHW(savedIPArg, savedIPReg, FRType::OtherNonPtr);
a.str(savedIPReg.a64GpX(), a64::Mem(xRuntime, offsetof(Runtime, currentIP_)));
a.str(savedIPReg.a64GpX(), a64::Mem(xRuntime, RuntimeOffsets::currentIP));

FR savedCodeBlockArg = FR{nRegs + hbc::StackFrameLayout::SavedCodeBlock};
// TODO: We should be able to directly store xzr.
Expand Down

0 comments on commit befb93e

Please sign in to comment.