@@ -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}
0 commit comments