v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
macro-assembler.h
Go to the documentation of this file.
1// Copyright 2012 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_CODEGEN_MACRO_ASSEMBLER_H_
6#define V8_CODEGEN_MACRO_ASSEMBLER_H_
7
10#include "src/heap/heap.h"
11
12// Helper types to make boolean flag easier to read at call-site.
13enum class InvokeType { kCall, kJump };
14
15// Flags used for the AllocateInNewSpace functions.
17 // No special flags.
19 // The content of the result register already contains the allocation top in
20 // new space.
22 // Specify that the requested size of the space to allocate is specified in
23 // words instead of bytes.
24 SIZE_IN_WORDS = 1 << 1,
25 // Align the allocation to a multiple of kDoubleSize
27 // Directly allocate in old space
28 PRETENURE = 1 << 3,
29};
30
31enum class JumpMode {
32 kJump, // Does a direct jump to the given address
33 kPushAndReturn // Pushes the given address as the current return address and
34 // does a return
35};
36
37enum class SmiCheck { kOmit, kInline };
38enum class ReadOnlyCheck { kOmit, kInline };
39
40enum class ComparisonMode {
41 // The default compare mode will use a 32-bit comparison when pointer
42 // compression is enabled and the root is a tagged value.
44 // This mode can be used when the value to compare may not be located inside
45 // the main pointer compression cage.
47};
48
50 kNo,
51 kYes,
52};
53
55
56// This is the only place allowed to include the platform-specific headers.
57#define INCLUDED_FROM_MACRO_ASSEMBLER_H
58#if V8_TARGET_ARCH_IA32
60#elif V8_TARGET_ARCH_X64
62#elif V8_TARGET_ARCH_ARM64
65#elif V8_TARGET_ARCH_ARM
68#elif V8_TARGET_ARCH_PPC64
71#elif V8_TARGET_ARCH_MIPS64
74#elif V8_TARGET_ARCH_LOONG64
77#elif V8_TARGET_ARCH_S390X
80#elif V8_TARGET_ARCH_RISCV32 || V8_TARGET_ARCH_RISCV64
83#else
84#error Unsupported target architecture.
85#endif
86#undef INCLUDED_FROM_MACRO_ASSEMBLER_H
87
88namespace v8 {
89namespace internal {
90
91// Maximum number of parameters supported in calls to C/C++. The C++ standard
92// defines a limit of 256 parameters but in simulator builds we provide only
93// limited support.
94#ifdef USE_SIMULATOR
95static constexpr int kMaxCParameters = 20;
96#else
97static constexpr int kMaxCParameters = 256;
98#endif
99
101 public:
103 const SourceLocation& loc = SourceLocation())
104 :
105#ifdef V8_CODE_COMMENTS
106 comment_(masm, frame_name(type), loc),
107#endif
108 masm_(masm),
109 type_(type),
110 old_has_frame_(masm->has_frame()) {
111 masm->set_has_frame(true);
112 if (type != StackFrame::MANUAL && type_ != StackFrame::NO_FRAME_TYPE) {
113 masm->EnterFrame(type);
114 }
115 }
116
118 if (type_ != StackFrame::MANUAL && type_ != StackFrame::NO_FRAME_TYPE) {
119 masm_->LeaveFrame(type_);
120 }
121 masm_->set_has_frame(old_has_frame_);
122 }
123
124 private:
125#ifdef V8_CODE_COMMENTS
126 const char* frame_name(StackFrame::Type type) {
127 switch (type) {
128 case StackFrame::NO_FRAME_TYPE:
129 return "Frame: NO_FRAME_TYPE";
130 case StackFrame::MANUAL:
131 return "Frame: MANUAL";
132#define FRAME_TYPE_CASE(type, field) \
133 case StackFrame::type: \
134 return "Frame: " #type;
136#undef FRAME_TYPE_CASE
137 case StackFrame::NUMBER_OF_TYPES:
138 break;
139 }
140 return "Frame";
141 }
142
143 Assembler::CodeComment comment_;
144#endif // V8_CODE_COMMENTS
145
148 bool const old_has_frame_;
149};
150
152 public:
154 : masm_(masm),
155 type_(type),
156 old_has_frame_(masm->has_frame()),
157 old_constant_pool_available_(V8_EMBEDDED_CONSTANT_POOL_BOOL &&
158 masm->is_constant_pool_available()) {
159 masm->set_has_frame(true);
161 masm->set_constant_pool_available(true);
162 }
163 if (type_ != StackFrame::MANUAL && type_ != StackFrame::NO_FRAME_TYPE) {
164 masm->EnterFrame(type, !old_constant_pool_available_);
165 }
166 }
167
169 masm_->LeaveFrame(type_);
170 masm_->set_has_frame(old_has_frame_);
172 masm_->set_constant_pool_available(old_constant_pool_available_);
173 }
174 }
175
176 private:
181
183};
184
185// Class for scoping the the unavailability of constant pool access.
187 public:
189 : assembler_(assembler),
190 old_constant_pool_available_(V8_EMBEDDED_CONSTANT_POOL_BOOL &&
191 assembler->is_constant_pool_available()) {
193 assembler->set_constant_pool_available(false);
194 }
195 }
198 assembler_->set_constant_pool_available(old_constant_pool_available_);
199 }
200 }
201
202 private:
205
207};
208
210 public:
212 : FrameScope(masm, StackFrame::NO_FRAME_TYPE) {}
213};
214
215// Prevent the use of the RootArray during the lifetime of this
216// scope object.
218 public:
220 : masm_(masm), old_value_(masm->root_array_available()) {
221 masm->set_root_array_available(false);
222 }
223
224 ~NoRootArrayScope() { masm_->set_root_array_available(old_value_); }
225
226 private:
229};
230
231} // namespace internal
232} // namespace v8
233
234#endif // V8_CODEGEN_MACRO_ASSEMBLER_H_
void set_constant_pool_available(bool available)
Definition assembler.h:512
DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolUnavailableScope)
DISALLOW_IMPLICIT_CONSTRUCTORS(FrameAndConstantPoolScope)
FrameAndConstantPoolScope(MacroAssembler *masm, StackFrame::Type type)
StackFrame::Type const type_
FrameScope(MacroAssembler *masm, StackFrame::Type type, const SourceLocation &loc=SourceLocation())
void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg=false)
NoRootArrayScope(MacroAssembler *masm)
#define V8_EMBEDDED_CONSTANT_POOL_BOOL
Definition globals.h:81
const ObjectRef type_
BytecodeAssembler & assembler_
#define FRAME_TYPE_CASE(type, class)
#define STACK_FRAME_TYPE_LIST(V)
Definition frames.h:115
ReadOnlyCheck
SmiCheck
ComparisonMode
ArgumentAdaptionMode
InvokeType
AllocationFlags
@ RESULT_CONTAINS_TOP
@ DOUBLE_ALIGNMENT
@ PRETENURE
@ SIZE_IN_WORDS
@ NO_ALLOCATION_FLAGS
SetIsolateDataSlots
JumpMode
@ kPushAndReturn
MaglevAssembler *const masm_
static constexpr int kMaxCParameters
#define V8_NODISCARD
Definition v8config.h:693