Commit bdb20626 authored by Lu Yahan's avatar Lu Yahan Committed by V8 LUCI CQ

[riscv64] Fix return value of lazy compile runtime function

Port commit 22a16bda

Change-Id: I1a6815ca22f4b931ffd2468d8aeb82dc7a1e2bc5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3669661
Commit-Queue: ji qiu <qiuji@iscas.ac.cn>
Reviewed-by: 's avatarji qiu <qiuji@iscas.ac.cn>
Auto-Submit: Yahan Lu <yahan@iscas.ac.cn>
Cr-Commit-Position: refs/heads/main@{#80759}
parent 7e5b7ad1
...@@ -2772,37 +2772,40 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) { ...@@ -2772,37 +2772,40 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
// The function index was put in t0 by the jump table trampoline. // The function index was put in t0 by the jump table trampoline.
// Convert to Smi for the runtime call // Convert to Smi for the runtime call
__ SmiTag(kWasmCompileLazyFuncIndexRegister); __ SmiTag(kWasmCompileLazyFuncIndexRegister);
{
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
// Save all parameter registers (see kGpParamRegisters in wasm-linkage.cc). RegList kSavedGpRegs = ([]() constexpr {
// They might be overwritten in the runtime call below. We don't have any RegList saved_gp_regs;
// callee-saved registers in wasm, so no need to store anything else.
RegList gp_regs;
for (Register gp_param_reg : wasm::kGpParamRegisters) { for (Register gp_param_reg : wasm::kGpParamRegisters) {
gp_regs.set(gp_param_reg); saved_gp_regs.set(gp_param_reg);
} }
// Also push a1, because we must push multiples of 16 bytes (see
// {TurboAssembler::PushCPURegList}. // All set registers were unique.
CHECK_EQ(1, gp_regs.Count() % 2); CHECK_EQ(saved_gp_regs.Count(), arraysize(wasm::kGpParamRegisters));
gp_regs.set(a1); // The Wasm instance must be part of the saved registers.
// Ensure that A1 will not be repeated. CHECK(saved_gp_regs.has(kWasmInstanceRegister));
CHECK_EQ(0, gp_regs.Count() % 2); CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
saved_gp_regs.Count());
DoubleRegList fp_regs; return saved_gp_regs;
})();
DoubleRegList kSavedFpRegs = ([]() constexpr {
DoubleRegList saved_fp_regs;
for (DoubleRegister fp_param_reg : wasm::kFpParamRegisters) { for (DoubleRegister fp_param_reg : wasm::kFpParamRegisters) {
fp_regs.set(fp_param_reg); saved_fp_regs.set(fp_param_reg);
} }
CHECK_EQ(gp_regs.Count(), arraysize(wasm::kGpParamRegisters) + 1); CHECK_EQ(saved_fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
CHECK_EQ(fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
gp_regs.Count());
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedFpParamRegs, CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedFpParamRegs,
fp_regs.Count()); saved_fp_regs.Count());
__ MultiPush(gp_regs); return saved_fp_regs;
__ MultiPushFPU(fp_regs); })();
{
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
__ MultiPush(kSavedGpRegs);
__ MultiPushFPU(kSavedFpRegs);
// Pass instance and function index as an explicit arguments to the runtime // Pass instance and function index as an explicit arguments to the runtime
// function. // function.
...@@ -2812,13 +2815,21 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) { ...@@ -2812,13 +2815,21 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
__ Move(kContextRegister, Smi::zero()); __ Move(kContextRegister, Smi::zero());
__ CallRuntime(Runtime::kWasmCompileLazy, 2); __ CallRuntime(Runtime::kWasmCompileLazy, 2);
__ Move(s1, a0); // move return value to s1 since a0 will be restored to __ SmiUntag(s1, a0); // move return value to s1 since a0 will be restored
// the value before the call // to the value before the call
CHECK(!kSavedGpRegs.has(s1));
// Restore registers. // Restore registers.
__ MultiPopFPU(fp_regs); __ MultiPopFPU(kSavedFpRegs);
__ MultiPop(gp_regs); __ MultiPop(kSavedGpRegs);
} }
// The runtime function returned the jump table slot offset as a Smi (now in
// x17). Use that to compute the jump target.
__ Ld(kScratchReg,
MemOperand(kWasmInstanceRegister,
WasmInstanceObject::kJumpTableStartOffset - kHeapObjectTag));
__ Add64(s1, s1, Operand(kScratchReg));
// Finally, jump to the entrypoint. // Finally, jump to the entrypoint.
__ Jump(s1); __ Jump(s1);
} }
......
...@@ -24,14 +24,15 @@ class EntryFrameConstants : public AllStatic { ...@@ -24,14 +24,15 @@ class EntryFrameConstants : public AllStatic {
class WasmCompileLazyFrameConstants : public TypedFrameConstants { class WasmCompileLazyFrameConstants : public TypedFrameConstants {
public: public:
static constexpr int kNumberOfSavedGpParamRegs = static constexpr int kNumberOfSavedGpParamRegs =
arraysize(wasm::kGpParamRegisters) + 1; arraysize(wasm::kGpParamRegisters);
static constexpr int kNumberOfSavedFpParamRegs = static constexpr int kNumberOfSavedFpParamRegs =
arraysize(wasm::kFpParamRegisters); arraysize(wasm::kFpParamRegisters);
static constexpr int kNumberOfSavedAllParamRegs = static constexpr int kNumberOfSavedAllParamRegs =
kNumberOfSavedGpParamRegs + kNumberOfSavedFpParamRegs; kNumberOfSavedGpParamRegs + kNumberOfSavedFpParamRegs;
// FP-relative. // FP-relative.
// See Generate_WasmCompileLazy in builtins-mips64.cc. // See Generate_WasmCompileLazy in builtins-riscv64.cc.
// TODO(riscv): add rvv v reg save
static constexpr int kWasmInstanceOffset = static constexpr int kWasmInstanceOffset =
TYPED_FRAME_PUSHED_VALUE_OFFSET(kNumberOfSavedAllParamRegs); TYPED_FRAME_PUSHED_VALUE_OFFSET(kNumberOfSavedAllParamRegs);
static constexpr int kFixedFrameSizeFromFp = static constexpr int kFixedFrameSizeFromFp =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment