Skip to content

Commit 7e50fa6

Browse files
LiuYu396V8 LUCI CQ
authored andcommitted
[loong64][mips][wasm] Fix return value of lazy compile runtime function
Port commit 22a16bd Bug: chromium:1311960 Change-Id: Id06b901e5290a0c7d2c01f4fabbb98d0f47eb570 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3665938 Auto-Submit: Liu Yu <[email protected]> Reviewed-by: Zhao Jiazhong <[email protected]> Commit-Queue: Zhao Jiazhong <[email protected]> Cr-Commit-Position: refs/heads/main@{#80737}
1 parent c2dadb6 commit 7e50fa6

3 files changed

Lines changed: 147 additions & 70 deletions

File tree

src/builtins/loong64/builtins-loong64.cc

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,37 +2678,50 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
26782678
// The function index was put in t0 by the jump table trampoline.
26792679
// Convert to Smi for the runtime call
26802680
__ SmiTag(kWasmCompileLazyFuncIndexRegister);
2681-
{
2682-
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
2683-
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
26842681

2685-
// Save all parameter registers (see wasm-linkage.h). They might be
2686-
// overwritten in the runtime call below. We don't have any callee-saved
2687-
// registers in wasm, so no need to store anything else.
2688-
RegList gp_regs;
2682+
// Compute register lists for parameters to be saved. We save all parameter
2683+
// registers (see wasm-linkage.h). They might be overwritten in the runtime
2684+
// call below. We don't have any callee-saved registers in wasm, so no need to
2685+
// store anything else.
2686+
constexpr RegList kSavedGpRegs = ([]() constexpr {
2687+
RegList saved_gp_regs;
26892688
for (Register gp_param_reg : wasm::kGpParamRegisters) {
2690-
gp_regs.set(gp_param_reg);
2689+
saved_gp_regs.set(gp_param_reg);
26912690
}
26922691

2693-
DoubleRegList fp_regs;
2692+
// All set registers were unique.
2693+
CHECK_EQ(saved_gp_regs.Count(), arraysize(wasm::kGpParamRegisters));
2694+
// The Wasm instance must be part of the saved registers.
2695+
CHECK(saved_gp_regs.has(kWasmInstanceRegister));
2696+
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
2697+
saved_gp_regs.Count());
2698+
return saved_gp_regs;
2699+
})();
2700+
2701+
constexpr DoubleRegList kSavedFpRegs = ([]() constexpr {
2702+
DoubleRegList saved_fp_regs;
26942703
for (DoubleRegister fp_param_reg : wasm::kFpParamRegisters) {
2695-
fp_regs.set(fp_param_reg);
2704+
saved_fp_regs.set(fp_param_reg);
26962705
}
26972706

2698-
CHECK_EQ(gp_regs.Count(), arraysize(wasm::kGpParamRegisters));
2699-
CHECK_EQ(fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
2700-
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
2701-
gp_regs.Count());
2707+
CHECK_EQ(saved_fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
27022708
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedFpParamRegs,
2703-
fp_regs.Count());
2709+
saved_fp_regs.Count());
2710+
return saved_fp_regs;
2711+
})();
2712+
2713+
{
2714+
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
2715+
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
27042716

2705-
__ MultiPush(gp_regs);
2706-
__ MultiPushFPU(fp_regs);
2717+
// Save registers that we need to keep alive across the runtime call.
2718+
__ MultiPush(kSavedGpRegs);
2719+
__ MultiPushFPU(kSavedFpRegs);
27072720

27082721
// kFixedFrameSizeFromFp is hard coded to include space for Simd
27092722
// registers, so we still need to allocate extra (unused) space on the stack
27102723
// as if they were saved.
2711-
__ Sub_d(sp, sp, fp_regs.Count() * kDoubleSize);
2724+
__ Sub_d(sp, sp, kSavedFpRegs.Count() * kDoubleSize);
27122725

27132726
// Pass instance and function index as an explicit arguments to the runtime
27142727
// function.
@@ -2717,15 +2730,27 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
27172730
// set the current context on the isolate.
27182731
__ Move(kContextRegister, Smi::zero());
27192732
__ CallRuntime(Runtime::kWasmCompileLazy, 2);
2720-
__ mov(t8, a0);
27212733

2722-
__ Add_d(sp, sp, fp_regs.Count() * kDoubleSize);
2734+
// Untag the returned Smi into into t7, for later use.
2735+
static_assert(!kSavedGpRegs.has(t7));
2736+
__ SmiUntag(t7, a0);
2737+
2738+
__ Add_d(sp, sp, kSavedFpRegs.Count() * kDoubleSize);
27232739
// Restore registers.
2724-
__ MultiPopFPU(fp_regs);
2725-
__ MultiPop(gp_regs);
2740+
__ MultiPopFPU(kSavedFpRegs);
2741+
__ MultiPop(kSavedGpRegs);
27262742
}
2727-
// Finally, jump to the entrypoint.
2728-
__ Jump(t8);
2743+
2744+
// The runtime function returned the jump table slot offset as a Smi (now in
2745+
// t7). Use that to compute the jump target.
2746+
static_assert(!kSavedGpRegs.has(t8));
2747+
__ Ld_d(t8, MemOperand(
2748+
kWasmInstanceRegister,
2749+
WasmInstanceObject::kJumpTableStartOffset - kHeapObjectTag));
2750+
__ Add_d(t7, t8, Operand(t7));
2751+
2752+
// Finally, jump to the jump table slot for the function.
2753+
__ Jump(t7);
27292754
}
27302755

27312756
void Builtins::Generate_WasmDebugBreak(MacroAssembler* masm) {

src/builtins/mips/builtins-mips.cc

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,32 +2623,45 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
26232623
// The function index was put in t0 by the jump table trampoline.
26242624
// Convert to Smi for the runtime call.
26252625
__ SmiTag(kWasmCompileLazyFuncIndexRegister);
2626-
{
2627-
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
2628-
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
26292626

2630-
// Save all parameter registers (see wasm-linkage.h). They might be
2631-
// overwritten in the runtime call below. We don't have any callee-saved
2632-
// registers in wasm, so no need to store anything else.
2633-
RegList gp_regs;
2627+
// Compute register lists for parameters to be saved. We save all parameter
2628+
// registers (see wasm-linkage.h). They might be overwritten in the runtime
2629+
// call below. We don't have any callee-saved registers in wasm, so no need to
2630+
// store anything else.
2631+
constexpr RegList kSavedGpRegs = ([]() constexpr {
2632+
RegList saved_gp_regs;
26342633
for (Register gp_param_reg : wasm::kGpParamRegisters) {
2635-
gp_regs.set(gp_param_reg);
2634+
saved_gp_regs.set(gp_param_reg);
26362635
}
26372636

2638-
DoubleRegList fp_regs;
2637+
// All set registers were unique.
2638+
CHECK_EQ(saved_gp_regs.Count(), arraysize(wasm::kGpParamRegisters));
2639+
// The Wasm instance must be part of the saved registers.
2640+
CHECK(saved_gp_regs.has(kWasmInstanceRegister));
2641+
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
2642+
saved_gp_regs.Count());
2643+
return saved_gp_regs;
2644+
})();
2645+
2646+
constexpr DoubleRegList kSavedFpRegs = ([]() constexpr {
2647+
DoubleRegList saved_fp_regs;
26392648
for (DoubleRegister fp_param_reg : wasm::kFpParamRegisters) {
2640-
fp_regs.set(fp_param_reg);
2649+
saved_fp_regs.set(fp_param_reg);
26412650
}
26422651

2643-
CHECK_EQ(gp_regs.Count(), arraysize(wasm::kGpParamRegisters));
2644-
CHECK_EQ(fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
2645-
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
2646-
gp_regs.Count());
2652+
CHECK_EQ(saved_fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
26472653
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedFpParamRegs,
2648-
fp_regs.Count());
2654+
saved_fp_regs.Count());
2655+
return saved_fp_regs;
2656+
})();
26492657

2650-
__ MultiPush(gp_regs);
2651-
__ MultiPushFPU(fp_regs);
2658+
{
2659+
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
2660+
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
2661+
2662+
// Save registers that we need to keep alive across the runtime call.
2663+
__ MultiPush(kSavedGpRegs);
2664+
__ MultiPushFPU(kSavedFpRegs);
26522665

26532666
// Pass instance and function index as an explicit arguments to the runtime
26542667
// function.
@@ -2659,11 +2672,24 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
26592672
__ CallRuntime(Runtime::kWasmCompileLazy, 2);
26602673

26612674
// Restore registers.
2662-
__ MultiPopFPU(fp_regs);
2663-
__ MultiPop(gp_regs);
2675+
__ MultiPopFPU(kSavedFpRegs);
2676+
__ MultiPop(kSavedGpRegs);
26642677
}
2665-
// Finally, jump to the entrypoint.
2666-
__ Jump(kScratchReg, v0, 0);
2678+
2679+
// Untag the returned Smi, for later use.
2680+
static_assert(!kSavedGpRegs.has(v0));
2681+
__ SmiUntag(v0);
2682+
2683+
// The runtime function returned the jump table slot offset as a Smi (now in
2684+
// t8). Use that to compute the jump target.
2685+
static_assert(!kSavedGpRegs.has(t8));
2686+
__ Lw(t8,
2687+
MemOperand(kWasmInstanceRegister,
2688+
WasmInstanceObject::kJumpTableStartOffset - kHeapObjectTag));
2689+
__ Addu(t8, v0, t8);
2690+
2691+
// Finally, jump to the jump table slot for the function.
2692+
__ Jump(t8);
26672693
}
26682694

26692695
void Builtins::Generate_WasmDebugBreak(MacroAssembler* masm) {

src/builtins/mips64/builtins-mips64.cc

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,31 +2672,44 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
26722672
// The function index was put in t0 by the jump table trampoline.
26732673
// Convert to Smi for the runtime call
26742674
__ SmiTag(kWasmCompileLazyFuncIndexRegister);
2675-
{
2676-
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
2677-
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
26782675

2679-
// Save all parameter registers (see wasm-linkage.h). They might be
2680-
// overwritten in the runtime call below. We don't have any callee-saved
2681-
// registers in wasm, so no need to store anything else.
2682-
RegList gp_regs;
2676+
// Compute register lists for parameters to be saved. We save all parameter
2677+
// registers (see wasm-linkage.h). They might be overwritten in the runtime
2678+
// call below. We don't have any callee-saved registers in wasm, so no need to
2679+
// store anything else.
2680+
constexpr RegList kSavedGpRegs = ([]() constexpr {
2681+
RegList saved_gp_regs;
26832682
for (Register gp_param_reg : wasm::kGpParamRegisters) {
2684-
gp_regs.set(gp_param_reg);
2683+
saved_gp_regs.set(gp_param_reg);
26852684
}
26862685

2687-
DoubleRegList fp_regs;
2686+
// All set registers were unique.
2687+
CHECK_EQ(saved_gp_regs.Count(), arraysize(wasm::kGpParamRegisters));
2688+
// The Wasm instance must be part of the saved registers.
2689+
CHECK(saved_gp_regs.has(kWasmInstanceRegister));
2690+
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
2691+
saved_gp_regs.Count());
2692+
return saved_gp_regs;
2693+
})();
2694+
2695+
constexpr DoubleRegList kSavedFpRegs = ([]() constexpr {
2696+
DoubleRegList saved_fp_regs;
26882697
for (DoubleRegister fp_param_reg : wasm::kFpParamRegisters) {
2689-
fp_regs.set(fp_param_reg);
2698+
saved_fp_regs.set(fp_param_reg);
26902699
}
26912700

2692-
CHECK_EQ(gp_regs.Count(), arraysize(wasm::kGpParamRegisters));
2693-
CHECK_EQ(fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
2694-
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedGpParamRegs,
2695-
gp_regs.Count());
2701+
CHECK_EQ(saved_fp_regs.Count(), arraysize(wasm::kFpParamRegisters));
26962702
CHECK_EQ(WasmCompileLazyFrameConstants::kNumberOfSavedFpParamRegs,
2697-
fp_regs.Count());
2703+
saved_fp_regs.Count());
2704+
return saved_fp_regs;
2705+
})();
26982706

2699-
__ MultiPush(gp_regs);
2707+
{
2708+
HardAbortScope hard_abort(masm); // Avoid calls to Abort.
2709+
FrameScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
2710+
2711+
// Save registers that we need to keep alive across the runtime call.
2712+
__ MultiPush(kSavedGpRegs);
27002713
// Check if machine has simd enabled, if so push vector registers. If not
27012714
// then only push double registers.
27022715
Label push_doubles, simd_pushed;
@@ -2708,15 +2721,15 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
27082721
{
27092722
CpuFeatureScope msa_scope(
27102723
masm, MIPS_SIMD, CpuFeatureScope::CheckPolicy::kDontCheckSupported);
2711-
__ MultiPushMSA(fp_regs);
2724+
__ MultiPushMSA(kSavedFpRegs);
27122725
}
27132726
__ Branch(&simd_pushed);
27142727
__ bind(&push_doubles);
2715-
__ MultiPushFPU(fp_regs);
2728+
__ MultiPushFPU(kSavedFpRegs);
27162729
// kFixedFrameSizeFromFp is hard coded to include space for Simd
27172730
// registers, so we still need to allocate extra (unused) space on the stack
27182731
// as if they were saved.
2719-
__ Dsubu(sp, sp, fp_regs.Count() * kDoubleSize);
2732+
__ Dsubu(sp, sp, kSavedFpRegs.Count() * kDoubleSize);
27202733
__ bind(&simd_pushed);
27212734
// Pass instance and function index as an explicit arguments to the runtime
27222735
// function.
@@ -2736,17 +2749,30 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
27362749
{
27372750
CpuFeatureScope msa_scope(
27382751
masm, MIPS_SIMD, CpuFeatureScope::CheckPolicy::kDontCheckSupported);
2739-
__ MultiPopMSA(fp_regs);
2752+
__ MultiPopMSA(kSavedFpRegs);
27402753
}
27412754
__ Branch(&simd_popped);
27422755
__ bind(&pop_doubles);
2743-
__ Daddu(sp, sp, fp_regs.Count() * kDoubleSize);
2744-
__ MultiPopFPU(fp_regs);
2756+
__ Daddu(sp, sp, kSavedFpRegs.Count() * kDoubleSize);
2757+
__ MultiPopFPU(kSavedFpRegs);
27452758
__ bind(&simd_popped);
2746-
__ MultiPop(gp_regs);
2759+
__ MultiPop(kSavedGpRegs);
27472760
}
2748-
// Finally, jump to the entrypoint.
2749-
__ Jump(v0);
2761+
2762+
// Untag the returned Smi, for later use.
2763+
static_assert(!kSavedGpRegs.has(v0));
2764+
__ SmiUntag(v0);
2765+
2766+
// The runtime function returned the jump table slot offset as a Smi (now in
2767+
// t8). Use that to compute the jump target.
2768+
static_assert(!kSavedGpRegs.has(t8));
2769+
__ Ld(t8,
2770+
MemOperand(kWasmInstanceRegister,
2771+
WasmInstanceObject::kJumpTableStartOffset - kHeapObjectTag));
2772+
__ Daddu(t8, v0, t8);
2773+
2774+
// Finally, jump to the jump table slot for the function.
2775+
__ Jump(t8);
27502776
}
27512777

27522778
void Builtins::Generate_WasmDebugBreak(MacroAssembler* masm) {

0 commit comments

Comments
 (0)