1 // Copyright 2021 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_BASELINE_LOONG64_BASELINE_COMPILER_LOONG64_INL_H_
6 #define V8_BASELINE_LOONG64_BASELINE_COMPILER_LOONG64_INL_H_
7
8 #include "src/base/logging.h"
9 #include "src/baseline/baseline-compiler.h"
10
11 namespace v8 {
12 namespace internal {
13 namespace baseline {
14
15 #define __ basm_.
16
Prologue()17 void BaselineCompiler::Prologue() {
18 ASM_CODE_COMMENT(&masm_);
19 __ masm()->EnterFrame(StackFrame::BASELINE);
20 DCHECK_EQ(kJSFunctionRegister, kJavaScriptCallTargetRegister);
21 int max_frame_size =
22 bytecode_->frame_size() + max_call_args_ * kSystemPointerSize;
23 CallBuiltin<Builtin::kBaselineOutOfLinePrologue>(
24 kContextRegister, kJSFunctionRegister, kJavaScriptCallArgCountRegister,
25 max_frame_size, kJavaScriptCallNewTargetRegister, bytecode_);
26
27 PrologueFillFrame();
28 }
29
PrologueFillFrame()30 void BaselineCompiler::PrologueFillFrame() {
31 ASM_CODE_COMMENT(&masm_);
32 // Inlined register frame fill
33 interpreter::Register new_target_or_generator_register =
34 bytecode_->incoming_new_target_or_generator_register();
35 __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kUndefinedValue);
36 int register_count = bytecode_->register_count();
37 // Magic value
38 const int kLoopUnrollSize = 8;
39 const int new_target_index = new_target_or_generator_register.index();
40 const bool has_new_target = new_target_index != kMaxInt;
41 if (has_new_target) {
42 DCHECK_LE(new_target_index, register_count);
43 __ masm()->Add_d(sp, sp, Operand(-(kPointerSize * new_target_index)));
44 for (int i = 0; i < new_target_index; i++) {
45 __ masm()->St_d(kInterpreterAccumulatorRegister, MemOperand(sp, i * 8));
46 }
47 // Push new_target_or_generator.
48 __ Push(kJavaScriptCallNewTargetRegister);
49 register_count -= new_target_index + 1;
50 }
51 if (register_count < 2 * kLoopUnrollSize) {
52 // If the frame is small enough, just unroll the frame fill completely.
53 __ masm()->Add_d(sp, sp, Operand(-(kPointerSize * register_count)));
54 for (int i = 0; i < register_count; ++i) {
55 __ masm()->St_d(kInterpreterAccumulatorRegister, MemOperand(sp, i * 8));
56 }
57 } else {
58 __ masm()->Add_d(sp, sp, Operand(-(kPointerSize * register_count)));
59 for (int i = 0; i < register_count; ++i) {
60 __ masm()->St_d(kInterpreterAccumulatorRegister, MemOperand(sp, i * 8));
61 }
62 }
63 }
64
VerifyFrameSize()65 void BaselineCompiler::VerifyFrameSize() {
66 ASM_CODE_COMMENT(&masm_);
67 __ masm()->Add_d(t0, sp,
68 Operand(InterpreterFrameConstants::kFixedFrameSizeFromFp +
69 bytecode_->frame_size()));
70 __ masm()->Assert(eq, AbortReason::kUnexpectedStackPointer, t0, Operand(fp));
71 }
72
73 } // namespace baseline
74 } // namespace internal
75 } // namespace v8
76
77 #endif // V8_BASELINE_LOONG64_BASELINE_COMPILER_LOONG64_INL_H_
78