• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BASELINE_ASSEMBLER_INL_H_
6 #define V8_BASELINE_BASELINE_ASSEMBLER_INL_H_
7 
8 #include "src/baseline/baseline-assembler.h"
9 
10 // TODO(v8:11421): Remove #if once baseline compiler is ported to other
11 // architectures.
12 #if ENABLE_SPARKPLUG
13 
14 #include <type_traits>
15 #include <unordered_map>
16 
17 #include "src/codegen/interface-descriptors-inl.h"
18 #include "src/interpreter/bytecode-register.h"
19 #include "src/objects/feedback-cell.h"
20 #include "src/objects/js-function.h"
21 #include "src/objects/map.h"
22 
23 #if V8_TARGET_ARCH_X64
24 #include "src/baseline/x64/baseline-assembler-x64-inl.h"
25 #elif V8_TARGET_ARCH_ARM64
26 #include "src/baseline/arm64/baseline-assembler-arm64-inl.h"
27 #elif V8_TARGET_ARCH_IA32
28 #include "src/baseline/ia32/baseline-assembler-ia32-inl.h"
29 #elif V8_TARGET_ARCH_ARM
30 #include "src/baseline/arm/baseline-assembler-arm-inl.h"
31 #elif V8_TARGET_ARCH_PPC64
32 #include "src/baseline/ppc/baseline-assembler-ppc-inl.h"
33 #elif V8_TARGET_ARCH_S390X
34 #include "src/baseline/s390/baseline-assembler-s390-inl.h"
35 #elif V8_TARGET_ARCH_RISCV64
36 #include "src/baseline/riscv64/baseline-assembler-riscv64-inl.h"
37 #elif V8_TARGET_ARCH_MIPS64
38 #include "src/baseline/mips64/baseline-assembler-mips64-inl.h"
39 #elif V8_TARGET_ARCH_MIPS
40 #include "src/baseline/mips/baseline-assembler-mips-inl.h"
41 #elif V8_TARGET_ARCH_LOONG64
42 #include "src/baseline/loong64/baseline-assembler-loong64-inl.h"
43 #else
44 #error Unsupported target architecture.
45 #endif
46 
47 namespace v8 {
48 namespace internal {
49 namespace baseline {
50 
51 #define __ masm_->
52 
GetCode(Isolate * isolate,CodeDesc * desc)53 void BaselineAssembler::GetCode(Isolate* isolate, CodeDesc* desc) {
54   __ GetCode(isolate, desc);
55 }
pc_offset()56 int BaselineAssembler::pc_offset() const { return __ pc_offset(); }
CodeEntry()57 void BaselineAssembler::CodeEntry() const { __ CodeEntry(); }
ExceptionHandler()58 void BaselineAssembler::ExceptionHandler() const { __ ExceptionHandler(); }
RecordComment(const char * string)59 void BaselineAssembler::RecordComment(const char* string) {
60   if (!FLAG_code_comments) return;
61   __ RecordComment(string);
62 }
Trap()63 void BaselineAssembler::Trap() { __ Trap(); }
DebugBreak()64 void BaselineAssembler::DebugBreak() { __ DebugBreak(); }
CallRuntime(Runtime::FunctionId function,int nargs)65 void BaselineAssembler::CallRuntime(Runtime::FunctionId function, int nargs) {
66   __ CallRuntime(function, nargs);
67 }
68 
ContextOperand()69 MemOperand BaselineAssembler::ContextOperand() {
70   return RegisterFrameOperand(interpreter::Register::current_context());
71 }
FunctionOperand()72 MemOperand BaselineAssembler::FunctionOperand() {
73   return RegisterFrameOperand(interpreter::Register::function_closure());
74 }
75 
LoadMap(Register output,Register value)76 void BaselineAssembler::LoadMap(Register output, Register value) {
77   __ LoadMap(output, value);
78 }
LoadRoot(Register output,RootIndex index)79 void BaselineAssembler::LoadRoot(Register output, RootIndex index) {
80   __ LoadRoot(output, index);
81 }
LoadNativeContextSlot(Register output,uint32_t index)82 void BaselineAssembler::LoadNativeContextSlot(Register output, uint32_t index) {
83   __ LoadNativeContextSlot(output, index);
84 }
85 
Move(Register output,interpreter::Register source)86 void BaselineAssembler::Move(Register output, interpreter::Register source) {
87   return __ Move(output, RegisterFrameOperand(source));
88 }
Move(Register output,RootIndex source)89 void BaselineAssembler::Move(Register output, RootIndex source) {
90   return __ LoadRoot(output, source);
91 }
Move(Register output,Register source)92 void BaselineAssembler::Move(Register output, Register source) {
93   __ Move(output, source);
94 }
Move(Register output,MemOperand operand)95 void BaselineAssembler::Move(Register output, MemOperand operand) {
96   __ Move(output, operand);
97 }
Move(Register output,Smi value)98 void BaselineAssembler::Move(Register output, Smi value) {
99   __ Move(output, value);
100 }
101 
SmiUntag(Register reg)102 void BaselineAssembler::SmiUntag(Register reg) { __ SmiUntag(reg); }
SmiUntag(Register output,Register value)103 void BaselineAssembler::SmiUntag(Register output, Register value) {
104   __ SmiUntag(output, value);
105 }
106 
LoadFixedArrayElement(Register output,Register array,int32_t index)107 void BaselineAssembler::LoadFixedArrayElement(Register output, Register array,
108                                               int32_t index) {
109   LoadTaggedAnyField(output, array,
110                      FixedArray::kHeaderSize + index * kTaggedSize);
111 }
112 
LoadPrototype(Register prototype,Register object)113 void BaselineAssembler::LoadPrototype(Register prototype, Register object) {
114   __ LoadMap(prototype, object);
115   LoadTaggedPointerField(prototype, prototype, Map::kPrototypeOffset);
116 }
LoadContext(Register output)117 void BaselineAssembler::LoadContext(Register output) {
118   LoadRegister(output, interpreter::Register::current_context());
119 }
LoadFunction(Register output)120 void BaselineAssembler::LoadFunction(Register output) {
121   LoadRegister(output, interpreter::Register::function_closure());
122 }
StoreContext(Register context)123 void BaselineAssembler::StoreContext(Register context) {
124   StoreRegister(interpreter::Register::current_context(), context);
125 }
LoadRegister(Register output,interpreter::Register source)126 void BaselineAssembler::LoadRegister(Register output,
127                                      interpreter::Register source) {
128   Move(output, source);
129 }
StoreRegister(interpreter::Register output,Register value)130 void BaselineAssembler::StoreRegister(interpreter::Register output,
131                                       Register value) {
132   Move(output, value);
133 }
134 
SaveAccumulatorScope(BaselineAssembler * assembler)135 SaveAccumulatorScope::SaveAccumulatorScope(BaselineAssembler* assembler)
136     : assembler_(assembler) {
137   assembler_->Push(kInterpreterAccumulatorRegister);
138 }
139 
~SaveAccumulatorScope()140 SaveAccumulatorScope::~SaveAccumulatorScope() {
141   assembler_->Pop(kInterpreterAccumulatorRegister);
142 }
143 
EnsureAccumulatorPreservedScope(BaselineAssembler * assembler)144 EnsureAccumulatorPreservedScope::EnsureAccumulatorPreservedScope(
145     BaselineAssembler* assembler)
146     : assembler_(assembler)
147 #ifdef V8_CODE_COMMENTS
148       ,
149       comment_(assembler->masm(), "EnsureAccumulatorPreservedScope")
150 #endif
151 {
152   assembler_->Push(kInterpreterAccumulatorRegister);
153 }
154 
~EnsureAccumulatorPreservedScope()155 EnsureAccumulatorPreservedScope::~EnsureAccumulatorPreservedScope() {
156   BaselineAssembler::ScratchRegisterScope scratch(assembler_);
157   Register reg = scratch.AcquireScratch();
158   assembler_->Pop(reg);
159   AssertEqualToAccumulator(reg);
160 }
161 
162 #undef __
163 
164 }  // namespace baseline
165 }  // namespace internal
166 }  // namespace v8
167 
168 #endif  // ENABLE_SPARKPLUG
169 
170 #endif  // V8_BASELINE_BASELINE_ASSEMBLER_INL_H_
171