Debian Codegraph @

js/src/jit/loong64/SharedICHelpers-loong64.h

raw
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 SecondScratchRegisterScope scratch2(masm);
64 masm.Pop(scratch2);
65 }
66 }
67
68 template <typename AddrType>
69 inline void EmitPreBarrier(MacroAssembler& masm, const AddrType& addr,
70 MIRType type) {
71 // On LoongArch, $ra is clobbered by guardedCallPreBarrier. Save it first.
72 masm.push(ra);
73 masm.guardedCallPreBarrier(addr, type);
74 masm.pop(ra);
75 }
76
77 inline void EmitStubGuardFailure(MacroAssembler& masm) {
78 // Load next stub into ICStubReg
79 masm.loadPtr(Address(ICStubReg, ICCacheIRStub::offsetOfNext()), ICStubReg);
80
81 // Return address is already loaded, just jump to the next stubcode.
82 MOZ_ASSERT(ICTailCallReg == ra);
83 masm.jump(Address(ICStubReg, ICStub::offsetOfStubCode()));
84 }
85
86 } // namespace jit
87 } // namespace js
88
89 #endif /* jit_loong64_SharedICHelpers_loong64_h */