11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_BASELINE_BASELINE_ASSEMBLER_INL_H_
61cb0ef41Sopenharmony_ci#define V8_BASELINE_BASELINE_ASSEMBLER_INL_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/baseline/baseline-assembler.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// TODO(v8:11421): Remove #if once baseline compiler is ported to other
111cb0ef41Sopenharmony_ci// architectures.
121cb0ef41Sopenharmony_ci#if ENABLE_SPARKPLUG
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci#include <type_traits>
151cb0ef41Sopenharmony_ci#include <unordered_map>
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci#include "src/codegen/interface-descriptors-inl.h"
181cb0ef41Sopenharmony_ci#include "src/interpreter/bytecode-register.h"
191cb0ef41Sopenharmony_ci#include "src/objects/feedback-cell.h"
201cb0ef41Sopenharmony_ci#include "src/objects/js-function.h"
211cb0ef41Sopenharmony_ci#include "src/objects/map.h"
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_X64
241cb0ef41Sopenharmony_ci#include "src/baseline/x64/baseline-assembler-x64-inl.h"
251cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_ARM64
261cb0ef41Sopenharmony_ci#include "src/baseline/arm64/baseline-assembler-arm64-inl.h"
271cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_IA32
281cb0ef41Sopenharmony_ci#include "src/baseline/ia32/baseline-assembler-ia32-inl.h"
291cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_ARM
301cb0ef41Sopenharmony_ci#include "src/baseline/arm/baseline-assembler-arm-inl.h"
311cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_PPC64
321cb0ef41Sopenharmony_ci#include "src/baseline/ppc/baseline-assembler-ppc-inl.h"
331cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_S390X
341cb0ef41Sopenharmony_ci#include "src/baseline/s390/baseline-assembler-s390-inl.h"
351cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_RISCV64
361cb0ef41Sopenharmony_ci#include "src/baseline/riscv64/baseline-assembler-riscv64-inl.h"
371cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_MIPS64
381cb0ef41Sopenharmony_ci#include "src/baseline/mips64/baseline-assembler-mips64-inl.h"
391cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_MIPS
401cb0ef41Sopenharmony_ci#include "src/baseline/mips/baseline-assembler-mips-inl.h"
411cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_LOONG64
421cb0ef41Sopenharmony_ci#include "src/baseline/loong64/baseline-assembler-loong64-inl.h"
431cb0ef41Sopenharmony_ci#else
441cb0ef41Sopenharmony_ci#error Unsupported target architecture.
451cb0ef41Sopenharmony_ci#endif
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_cinamespace v8 {
481cb0ef41Sopenharmony_cinamespace internal {
491cb0ef41Sopenharmony_cinamespace baseline {
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci#define __ masm_->
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_civoid BaselineAssembler::GetCode(Isolate* isolate, CodeDesc* desc) {
541cb0ef41Sopenharmony_ci  __ GetCode(isolate, desc);
551cb0ef41Sopenharmony_ci}
561cb0ef41Sopenharmony_ciint BaselineAssembler::pc_offset() const { return __ pc_offset(); }
571cb0ef41Sopenharmony_civoid BaselineAssembler::CodeEntry() const { __ CodeEntry(); }
581cb0ef41Sopenharmony_civoid BaselineAssembler::ExceptionHandler() const { __ ExceptionHandler(); }
591cb0ef41Sopenharmony_civoid BaselineAssembler::RecordComment(const char* string) {
601cb0ef41Sopenharmony_ci  if (!FLAG_code_comments) return;
611cb0ef41Sopenharmony_ci  __ RecordComment(string);
621cb0ef41Sopenharmony_ci}
631cb0ef41Sopenharmony_civoid BaselineAssembler::Trap() { __ Trap(); }
641cb0ef41Sopenharmony_civoid BaselineAssembler::DebugBreak() { __ DebugBreak(); }
651cb0ef41Sopenharmony_civoid BaselineAssembler::CallRuntime(Runtime::FunctionId function, int nargs) {
661cb0ef41Sopenharmony_ci  __ CallRuntime(function, nargs);
671cb0ef41Sopenharmony_ci}
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ciMemOperand BaselineAssembler::ContextOperand() {
701cb0ef41Sopenharmony_ci  return RegisterFrameOperand(interpreter::Register::current_context());
711cb0ef41Sopenharmony_ci}
721cb0ef41Sopenharmony_ciMemOperand BaselineAssembler::FunctionOperand() {
731cb0ef41Sopenharmony_ci  return RegisterFrameOperand(interpreter::Register::function_closure());
741cb0ef41Sopenharmony_ci}
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_civoid BaselineAssembler::LoadMap(Register output, Register value) {
771cb0ef41Sopenharmony_ci  __ LoadMap(output, value);
781cb0ef41Sopenharmony_ci}
791cb0ef41Sopenharmony_civoid BaselineAssembler::LoadRoot(Register output, RootIndex index) {
801cb0ef41Sopenharmony_ci  __ LoadRoot(output, index);
811cb0ef41Sopenharmony_ci}
821cb0ef41Sopenharmony_civoid BaselineAssembler::LoadNativeContextSlot(Register output, uint32_t index) {
831cb0ef41Sopenharmony_ci  __ LoadNativeContextSlot(output, index);
841cb0ef41Sopenharmony_ci}
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_civoid BaselineAssembler::Move(Register output, interpreter::Register source) {
871cb0ef41Sopenharmony_ci  return __ Move(output, RegisterFrameOperand(source));
881cb0ef41Sopenharmony_ci}
891cb0ef41Sopenharmony_civoid BaselineAssembler::Move(Register output, RootIndex source) {
901cb0ef41Sopenharmony_ci  return __ LoadRoot(output, source);
911cb0ef41Sopenharmony_ci}
921cb0ef41Sopenharmony_civoid BaselineAssembler::Move(Register output, Register source) {
931cb0ef41Sopenharmony_ci  __ Move(output, source);
941cb0ef41Sopenharmony_ci}
951cb0ef41Sopenharmony_civoid BaselineAssembler::Move(Register output, MemOperand operand) {
961cb0ef41Sopenharmony_ci  __ Move(output, operand);
971cb0ef41Sopenharmony_ci}
981cb0ef41Sopenharmony_civoid BaselineAssembler::Move(Register output, Smi value) {
991cb0ef41Sopenharmony_ci  __ Move(output, value);
1001cb0ef41Sopenharmony_ci}
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_civoid BaselineAssembler::SmiUntag(Register reg) { __ SmiUntag(reg); }
1031cb0ef41Sopenharmony_civoid BaselineAssembler::SmiUntag(Register output, Register value) {
1041cb0ef41Sopenharmony_ci  __ SmiUntag(output, value);
1051cb0ef41Sopenharmony_ci}
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_civoid BaselineAssembler::LoadFixedArrayElement(Register output, Register array,
1081cb0ef41Sopenharmony_ci                                              int32_t index) {
1091cb0ef41Sopenharmony_ci  LoadTaggedAnyField(output, array,
1101cb0ef41Sopenharmony_ci                     FixedArray::kHeaderSize + index * kTaggedSize);
1111cb0ef41Sopenharmony_ci}
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_civoid BaselineAssembler::LoadPrototype(Register prototype, Register object) {
1141cb0ef41Sopenharmony_ci  __ LoadMap(prototype, object);
1151cb0ef41Sopenharmony_ci  LoadTaggedPointerField(prototype, prototype, Map::kPrototypeOffset);
1161cb0ef41Sopenharmony_ci}
1171cb0ef41Sopenharmony_civoid BaselineAssembler::LoadContext(Register output) {
1181cb0ef41Sopenharmony_ci  LoadRegister(output, interpreter::Register::current_context());
1191cb0ef41Sopenharmony_ci}
1201cb0ef41Sopenharmony_civoid BaselineAssembler::LoadFunction(Register output) {
1211cb0ef41Sopenharmony_ci  LoadRegister(output, interpreter::Register::function_closure());
1221cb0ef41Sopenharmony_ci}
1231cb0ef41Sopenharmony_civoid BaselineAssembler::StoreContext(Register context) {
1241cb0ef41Sopenharmony_ci  StoreRegister(interpreter::Register::current_context(), context);
1251cb0ef41Sopenharmony_ci}
1261cb0ef41Sopenharmony_civoid BaselineAssembler::LoadRegister(Register output,
1271cb0ef41Sopenharmony_ci                                     interpreter::Register source) {
1281cb0ef41Sopenharmony_ci  Move(output, source);
1291cb0ef41Sopenharmony_ci}
1301cb0ef41Sopenharmony_civoid BaselineAssembler::StoreRegister(interpreter::Register output,
1311cb0ef41Sopenharmony_ci                                      Register value) {
1321cb0ef41Sopenharmony_ci  Move(output, value);
1331cb0ef41Sopenharmony_ci}
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ciSaveAccumulatorScope::SaveAccumulatorScope(BaselineAssembler* assembler)
1361cb0ef41Sopenharmony_ci    : assembler_(assembler) {
1371cb0ef41Sopenharmony_ci  assembler_->Push(kInterpreterAccumulatorRegister);
1381cb0ef41Sopenharmony_ci}
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ciSaveAccumulatorScope::~SaveAccumulatorScope() {
1411cb0ef41Sopenharmony_ci  assembler_->Pop(kInterpreterAccumulatorRegister);
1421cb0ef41Sopenharmony_ci}
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ciEnsureAccumulatorPreservedScope::EnsureAccumulatorPreservedScope(
1451cb0ef41Sopenharmony_ci    BaselineAssembler* assembler)
1461cb0ef41Sopenharmony_ci    : assembler_(assembler)
1471cb0ef41Sopenharmony_ci#ifdef V8_CODE_COMMENTS
1481cb0ef41Sopenharmony_ci      ,
1491cb0ef41Sopenharmony_ci      comment_(assembler->masm(), "EnsureAccumulatorPreservedScope")
1501cb0ef41Sopenharmony_ci#endif
1511cb0ef41Sopenharmony_ci{
1521cb0ef41Sopenharmony_ci  assembler_->Push(kInterpreterAccumulatorRegister);
1531cb0ef41Sopenharmony_ci}
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ciEnsureAccumulatorPreservedScope::~EnsureAccumulatorPreservedScope() {
1561cb0ef41Sopenharmony_ci  BaselineAssembler::ScratchRegisterScope scratch(assembler_);
1571cb0ef41Sopenharmony_ci  Register reg = scratch.AcquireScratch();
1581cb0ef41Sopenharmony_ci  assembler_->Pop(reg);
1591cb0ef41Sopenharmony_ci  AssertEqualToAccumulator(reg);
1601cb0ef41Sopenharmony_ci}
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci#undef __
1631cb0ef41Sopenharmony_ci
1641cb0ef41Sopenharmony_ci}  // namespace baseline
1651cb0ef41Sopenharmony_ci}  // namespace internal
1661cb0ef41Sopenharmony_ci}  // namespace v8
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_ci#endif  // ENABLE_SPARKPLUG
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ci#endif  // V8_BASELINE_BASELINE_ASSEMBLER_INL_H_
171