Debian Codegraph @

js/src/jit/riscv64/SharedICHelpers-riscv64.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_riscv64_SharedICHelpers_riscv64_h
8 #define jit_riscv64_SharedICHelpers_riscv64_h
9 #include "jit/BaselineIC.h"
10 #include "jit/JitFrames.h"
11 #include "jit/MacroAssembler.h"
12 #include "jit/SharedICRegisters.h"
13 namespace js {
14 namespace jit {
15
16 static const size_t ICStackValueOffset = 0;
17
18 inline void EmitRestoreTailCallReg(MacroAssembler& masm) {
19 // No-op on RISC-V because ra register is always holding the return address.
20 }
21
22 inline void EmitRepushTailCallReg(MacroAssembler& masm) {
23 // No-op on RISC-V because ra register is always holding the return address.
24 }
25 inline void EmitCallIC(MacroAssembler& masm, CodeOffset* callOffset) {
26 // The stub pointer must already be in ICStubReg.
27 // Load stubcode pointer from the ICStub.
28 // R2 won't be active when we call ICs, so we can use it as scratch.
29 masm.loadPtr(Address(ICStubReg, ICStub::offsetOfStubCode()), R2.scratchReg());
30
31 // Call the stubcode via a direct jump-and-link
32 masm.call(R2.scratchReg());
33 *callOffset = CodeOffset(masm.currentOffset());
34 }
35 inline void EmitReturnFromIC(MacroAssembler& masm) { masm.branch(ra); }
36 inline void EmitBaselineLeaveStubFrame(MacroAssembler& masm) {
37 masm.loadPtr(
38 Address(FramePointer, BaselineStubFrameLayout::ICStubOffsetFromFP),
39 ICStubReg);
40
41 masm.movePtr(FramePointer, StackPointer);
42 masm.Pop(FramePointer);
43
44 // Load the return address.
45 masm.Pop(ICTailCallReg);
46
47 // Discard the frame descriptor.
48 {
49 UseScratchRegisterScope temps(&masm);
50 Register scratch2 = temps.Acquire();
51 masm.Pop(scratch2);
52 }
53
54 masm.checkStackAlignment();
55 }
56
57 inline void EmitStubGuardFailure(MacroAssembler& masm) {
58 // Load next stub into ICStubReg
59 masm.loadPtr(Address(ICStubReg, ICCacheIRStub::offsetOfNext()), ICStubReg);
60
61 // Return address is already loaded, just jump to the next stubcode.
62 MOZ_ASSERT(ICTailCallReg == ra);
63 masm.jump(Address(ICStubReg, ICStub::offsetOfStubCode()));
64 }
65 template <typename AddrType>
66 inline void EmitPreBarrier(MacroAssembler& masm, const AddrType& addr,
67 MIRType type) {
68 // On RISC-V, $ra is clobbered by guardedCallPreBarrier. Save it first.
69 masm.push(ra);
70 masm.guardedCallPreBarrier(addr, type);
71 masm.pop(ra);
72 }
73
74 } // namespace jit
75 } // namespace js
76
77 #endif /* jit_riscv64_SharedICHelpers_riscv64_h */