baseline-compiler-riscv64-inl.h 2.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_BASELINE_RISCV64_BASELINE_COMPILER_RISCV64_INL_H_
#define V8_BASELINE_RISCV64_BASELINE_COMPILER_RISCV64_INL_H_

#include "src/baseline/baseline-compiler.h"

namespace v8 {
namespace internal {
namespace baseline {

#define __ basm_.

void BaselineCompiler::Prologue() {
17
  ASM_CODE_COMMENT(&masm_);
18
  // Enter the frame here, since CallBuiltin will override lr.
19 20
  __ masm()->EnterFrame(StackFrame::BASELINE);
  DCHECK_EQ(kJSFunctionRegister, kJavaScriptCallTargetRegister);
21 22
  int max_frame_size =
      bytecode_->frame_size() + max_call_args_ * kSystemPointerSize;
23
  CallBuiltin<Builtin::kBaselineOutOfLinePrologue>(
24 25
      kContextRegister, kJSFunctionRegister, kJavaScriptCallArgCountRegister,
      max_frame_size, kJavaScriptCallNewTargetRegister, bytecode_);
26 27 28 29
  PrologueFillFrame();
}

void BaselineCompiler::PrologueFillFrame() {
30
  ASM_CODE_COMMENT(&masm_);
31 32 33 34 35 36 37 38 39 40
  // Inlined register frame fill
  interpreter::Register new_target_or_generator_register =
      bytecode_->incoming_new_target_or_generator_register();
  __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kUndefinedValue);
  int register_count = bytecode_->register_count();
  // Magic value
  const int kLoopUnrollSize = 8;
  const int new_target_index = new_target_or_generator_register.index();
  const bool has_new_target = new_target_index != kMaxInt;
  if (has_new_target) {
41 42 43 44
    DCHECK_LE(new_target_index, register_count);
    __ masm()->Add64(sp, sp, Operand(-(kPointerSize * new_target_index)));
    for (int i = 0; i < new_target_index; i++) {
      __ masm()->Sd(kInterpreterAccumulatorRegister, MemOperand(sp, i * 8));
45
    }
46 47 48
    // Push new_target_or_generator.
    __ Push(kJavaScriptCallNewTargetRegister);
    register_count -= new_target_index + 1;
49 50 51
  }
  if (register_count < 2 * kLoopUnrollSize) {
    // If the frame is small enough, just unroll the frame fill completely.
52 53 54
    __ masm()->Add64(sp, sp, Operand(-(kPointerSize * register_count)));
    for (int i = 0; i < register_count; ++i) {
      __ masm()->Sd(kInterpreterAccumulatorRegister, MemOperand(sp, i * 8));
55 56
    }
  } else {
57 58 59
    __ masm()->Add64(sp, sp, Operand(-(kPointerSize * register_count)));
    for (int i = 0; i < register_count; ++i) {
      __ masm()->Sd(kInterpreterAccumulatorRegister, MemOperand(sp, i * 8));
60 61 62 63 64
    }
  }
}

void BaselineCompiler::VerifyFrameSize() {
65
  ASM_CODE_COMMENT(&masm_);
66
  __ masm()->Add64(kScratchReg, sp,
67 68
                   Operand(InterpreterFrameConstants::kFixedFrameSizeFromFp +
                           bytecode_->frame_size()));
69 70 71 72 73 74 75 76 77 78 79
  __ masm()->Assert(eq, AbortReason::kUnexpectedStackPointer, kScratchReg,
                    Operand(fp));
}

#undef __

}  // namespace baseline
}  // namespace internal
}  // namespace v8

#endif  // V8_BASELINE_RISCV64_BASELINE_COMPILER_RISCV64_INL_H_