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_MIPS_BASELINE_COMPILER_MIPS_INL_H_ 6#define V8_BASELINE_MIPS_BASELINE_COMPILER_MIPS_INL_H_ 7 8#include "src/base/logging.h" 9#include "src/baseline/baseline-compiler.h" 10 11namespace v8 { 12namespace internal { 13namespace baseline { 14 15#define __ basm_. 16 17void 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 30void 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()->Addu(sp, sp, Operand(-(kPointerSize * new_target_index))); 44 for (int i = 0; i < new_target_index; i++) { 45 __ masm()->Sw(kInterpreterAccumulatorRegister, MemOperand(sp, i * 4)); 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()->Addu(sp, sp, Operand(-(kPointerSize * register_count))); 54 for (int i = 0; i < register_count; ++i) { 55 __ masm()->Sw(kInterpreterAccumulatorRegister, MemOperand(sp, i * 4)); 56 } 57 } else { 58 __ masm()->Addu(sp, sp, Operand(-(kPointerSize * register_count))); 59 for (int i = 0; i < register_count; ++i) { 60 __ masm()->Sw(kInterpreterAccumulatorRegister, MemOperand(sp, i * 4)); 61 } 62 } 63} 64 65void BaselineCompiler::VerifyFrameSize() { 66 ASM_CODE_COMMENT(&masm_); 67 __ masm()->Addu(kScratchReg, sp, 68 Operand(InterpreterFrameConstants::kFixedFrameSizeFromFp + 69 bytecode_->frame_size())); 70 __ masm()->Assert(eq, AbortReason::kUnexpectedStackPointer, kScratchReg, 71 Operand(fp)); 72} 73 74} // namespace baseline 75} // namespace internal 76} // namespace v8 77 78#endif // V8_BASELINE_MIPS_BASELINE_COMPILER_MIPS_INL_H_ 79