Skip to content

Commit bdb2062

Browse files
luyahanV8 LUCI CQ
authored andcommitted
[riscv64] Fix return value of lazy compile runtime function
Port commit 22a16bd Change-Id: I1a6815ca22f4b931ffd2468d8aeb82dc7a1e2bc5 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3669661 Commit-Queue: ji qiu <[email protected]> Reviewed-by: ji qiu <[email protected]> Auto-Submit: Yahan Lu <[email protected]> Cr-Commit-Position: refs/heads/main@{#80759}
1 parent 7e5b7ad commit bdb2062

2 files changed

Lines changed: 42 additions & 30 deletions

File tree

src/builtins/riscv64/builtins-riscv64.cc

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,37 +2772,40 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
27722772
// The function index was put in t0 by the jump table trampoline.
27732773
// Convert to Smi for the runtime call
27742774
__ SmiTag(kWasmCompileLazyFuncIndexRegister);
2775-
{
2776-
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
2777-
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
27782775

2779-
// Save all parameter registers (see kGpParamRegisters in wasm-linkage.cc).
2780-
// They might be overwritten in the runtime call below. We don't have any
2781-
// callee-saved registers in wasm, so no need to store anything else.
2782-
RegList gp_regs;
2776+
RegList kSavedGpRegs = ([]() constexpr {
2777+
RegList saved_gp_regs;
27832778
for (Register gp_param_reg : wasm::kGpParamRegisters) {
2784-
gp_regs.set(gp_param_reg);
2779+
saved_gp_regs.set(gp_param_reg);
27852780
}
2786-
// Also push a1, because we must push multiples of 16 bytes (see
2787-
// {TurboAssembler::PushCPURegList}.
2788-
CHECK_EQ(1, gp_regs.Count() % 2);
2789-
gp_regs.set(a1);
2790-
// Ensure that A1 will not be repeated.
2791-
CHECK_EQ(0, gp_regs.Count() % 2);
2792-
2793-
DoubleRegList fp_regs;
2781+
2782+
// All set registers were unique.
2783+
CHECK_EQ(saved_gp_regs.Count(), arraysize(wasm::kGpParamRegisters));
2784+
// The Wasm instance must be part of the saved registers.
2785+
CHECK(saved_gp_regs.has(kWasmInstanceRegister));
2786+
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
2787+
saved_gp_regs.Count());
2788+
return saved_gp_regs;
2789+
})();
2790+
2791+
DoubleRegList kSavedFpRegs = ([]() constexpr {
2792+
DoubleRegList saved_fp_regs;
27942793
for (DoubleRegister fp_param_reg : wasm::kFpParamRegisters) {
2795-
fp_regs.set(fp_param_reg);
2794+
saved_fp_regs.set(fp_param_reg);
27962795
}
27972796

2798-
CHECK_EQ(gp_regs.Count(), arraysize(wasm::kGpParamRegisters) + 1);
2799-
CHECK_EQ(fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
2800-
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
2801-
gp_regs.Count());
2797+
CHECK_EQ(saved_fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
28022798
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedFpParamRegs,
2803-
fp_regs.Count());
2804-
__ MultiPush(gp_regs);
2805-
__ MultiPushFPU(fp_regs);
2799+
saved_fp_regs.Count());
2800+
return saved_fp_regs;
2801+
})();
2802+
2803+
{
2804+
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
2805+
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
2806+
2807+
__ MultiPush(kSavedGpRegs);
2808+
__ MultiPushFPU(kSavedFpRegs);
28062809

28072810
// Pass instance and function index as an explicit arguments to the runtime
28082811
// function.
@@ -2812,13 +2815,21 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
28122815
__ Move(kContextRegister, Smi::zero());
28132816
__ CallRuntime(Runtime::kWasmCompileLazy, 2);
28142817

2815-
__ Move(s1, a0); // move return value to s1 since a0 will be restored to
2816-
// the value before the call
2818+
__ SmiUntag(s1, a0); // move return value to s1 since a0 will be restored
2819+
// to the value before the call
2820+
CHECK(!kSavedGpRegs.has(s1));
28172821

28182822
// Restore registers.
2819-
__ MultiPopFPU(fp_regs);
2820-
__ MultiPop(gp_regs);
2823+
__ MultiPopFPU(kSavedFpRegs);
2824+
__ MultiPop(kSavedGpRegs);
28212825
}
2826+
2827+
// The runtime function returned the jump table slot offset as a Smi (now in
2828+
// x17). Use that to compute the jump target.
2829+
__ Ld(kScratchReg,
2830+
MemOperand(kWasmInstanceRegister,
2831+
WasmInstanceObject::kJumpTableStartOffset - kHeapObjectTag));
2832+
__ Add64(s1, s1, Operand(kScratchReg));
28222833
// Finally, jump to the entrypoint.
28232834
__ Jump(s1);
28242835
}

src/execution/riscv64/frame-constants-riscv64.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ class EntryFrameConstants : public AllStatic {
2424
class WasmCompileLazyFrameConstants : public TypedFrameConstants {
2525
public:
2626
static constexpr int kNumberOfSavedGpParamRegs =
27-
arraysize(wasm::kGpParamRegisters) + 1;
27+
arraysize(wasm::kGpParamRegisters);
2828
static constexpr int kNumberOfSavedFpParamRegs =
2929
arraysize(wasm::kFpParamRegisters);
3030
static constexpr int kNumberOfSavedAllParamRegs =
3131
kNumberOfSavedGpParamRegs + kNumberOfSavedFpParamRegs;
3232

3333
// FP-relative.
34-
// See Generate_WasmCompileLazy in builtins-mips64.cc.
34+
// See Generate_WasmCompileLazy in builtins-riscv64.cc.
35+
// TODO(riscv): add rvv v reg save
3536
static constexpr int kWasmInstanceOffset =
3637
TYPED_FRAME_PUSHED_VALUE_OFFSET(kNumberOfSavedAllParamRegs);
3738
static constexpr int kFixedFrameSizeFromFp =

0 commit comments

Comments
 (0)