SharedICHelpers-loong64.h (2828B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef jit_loong64_SharedICHelpers_loong64_h 8 #define jit_loong64_SharedICHelpers_loong64_h 9 10 #include "jit/BaselineIC.h" 11 #include "jit/JitFrames.h" 12 #include "jit/MacroAssembler.h" 13 #include "jit/SharedICRegisters.h" 14 15 namespace js { 16 namespace jit { 17 18 // Distance from sp to the top Value inside an IC stub (no return address on 19 // the stack on LoongArch). 20 static const size_t ICStackValueOffset = 0; 21 22 struct BaselineStubFrame { 23 uintptr_t savedFrame; 24 uintptr_t savedStub; 25 uintptr_t returnAddress; 26 uintptr_t descriptor; 27 }; 28 29 inline void EmitRestoreTailCallReg(MacroAssembler& masm) { 30 // No-op on LA because ra register is always holding the return address. 31 } 32 33 inline void EmitRepushTailCallReg(MacroAssembler& masm) { 34 // No-op on LA because ra register is always holding the return address. 35 } 36 37 inline void EmitCallIC(MacroAssembler& masm, CodeOffset* callOffset) { 38 // The stub pointer must already be in ICStubReg. 39 // Load stubcode pointer from the ICStub. 40 // R2 won't be active when we call ICs, so we can use it as scratch. 41 masm.loadPtr(Address(ICStubReg, ICStub::offsetOfStubCode()), R2.scratchReg()); 42 43 // Call the stubcode via a direct jump-and-link 44 masm.call(R2.scratchReg()); 45 *callOffset = CodeOffset(masm.currentOffset()); 46 } 47 48 inline void EmitReturnFromIC(MacroAssembler& masm) { masm.branch(ra); } 49 50 inline void EmitBaselineLeaveStubFrame(MacroAssembler& masm) { 51 masm.loadPtr( 52 Address(FramePointer, BaselineStubFrameLayout::ICStubOffsetFromFP), 53 ICStubReg); 54 55 masm.movePtr(FramePointer, StackPointer); 56 masm.Pop(FramePointer); 57 58 // Load the return address. 59 masm.Pop(ICTailCallReg); 60 61 // Discard the frame descriptor. 62 { 63 UseScratchRegisterScope temps(masm); 64 Register scratch = temps.Acquire(); 65 masm.Pop(scratch); 66 } 67 } 68 69 template <typename AddrType> 70 inline void EmitPreBarrier(MacroAssembler& masm, const AddrType& addr, 71 MIRType type) { 72 // On LoongArch, $ra is clobbered by guardedCallPreBarrier. Save it first. 73 masm.push(ra); 74 masm.guardedCallPreBarrier(addr, type); 75 masm.pop(ra); 76 } 77 78 inline void EmitStubGuardFailure(MacroAssembler& masm) { 79 // Load next stub into ICStubReg 80 masm.loadPtr(Address(ICStubReg, ICCacheIRStub::offsetOfNext()), ICStubReg); 81 82 // Return address is already loaded, just jump to the next stubcode. 83 MOZ_ASSERT(ICTailCallReg == ra); 84 masm.jump(Address(ICStubReg, ICStub::offsetOfStubCode())); 85 } 86 87 } // namespace jit 88 } // namespace js 89 90 #endif /* jit_loong64_SharedICHelpers_loong64_h */