v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
macro-assembler-base.h
Go to the documentation of this file.
1// Copyright 2018 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_BASE_H_
6#define V8_CODEGEN_MACRO_ASSEMBLER_BASE_H_
7
8#include <memory>
9
13#include "src/roots/roots.h"
14
15namespace v8 {
16namespace internal {
17
18// Common base class for platform-specific MacroAssemblers containing
19// platform-independent bits.
20// TODO(victorgomes): We should use LocalIsolate instead of Isolate in the
21// methods of this class.
23 public:
24 // Constructors are declared public to inherit them in derived classes
25 // with `using` directive.
26 MacroAssemblerBase(Isolate* isolate, CodeObjectRequired create_code_object,
27 std::unique_ptr<AssemblerBuffer> buffer = {})
28 : MacroAssemblerBase(isolate, AssemblerOptions::Default(isolate),
29 create_code_object, std::move(buffer)) {}
31 CodeObjectRequired create_code_object,
32 std::unique_ptr<AssemblerBuffer> buffer = {})
33 : MacroAssemblerBase(isolate, zone, AssemblerOptions::Default(isolate),
34 create_code_object, std::move(buffer)) {}
35
36 MacroAssemblerBase(Isolate* isolate, const AssemblerOptions& options,
37 CodeObjectRequired create_code_object,
38 std::unique_ptr<AssemblerBuffer> buffer = {});
39 MacroAssemblerBase(Isolate* isolate, MaybeAssemblerZone zone,
40 AssemblerOptions options,
41 CodeObjectRequired create_code_object,
42 std::unique_ptr<AssemblerBuffer> buffer = {});
43 // For isolate-less users.
45 CodeObjectRequired create_code_object,
46 std::unique_ptr<AssemblerBuffer> buffer = {})
47 : MacroAssemblerBase(nullptr, zone, options, create_code_object,
48 std::move(buffer)) {}
49
50 Isolate* isolate() const { return isolate_; }
51
53 DCHECK(!code_object_.is_null());
54 return code_object_;
55 }
56
57 bool root_array_available() const { return root_array_available_; }
58 void set_root_array_available(bool v) { root_array_available_ = v; }
59
60 bool should_abort_hard() const { return hard_abort_; }
61 void set_abort_hard(bool v) { hard_abort_ = v; }
62
63 void set_builtin(Builtin builtin) { maybe_builtin_ = builtin; }
64 Builtin builtin() const { return maybe_builtin_; }
65
66 void set_has_frame(bool v) { has_frame_ = v; }
67 bool has_frame() const { return has_frame_; }
68
69 // Loads the given constant or external reference without embedding its direct
70 // pointer. The produced code is isolate-independent.
71 void IndirectLoadConstant(Register destination, Handle<HeapObject> object);
72 void IndirectLoadExternalReference(Register destination,
73 ExternalReference reference);
74
75 Address BuiltinEntry(Builtin builtin);
76
78 int constant_index) = 0;
79
80 // Corresponds to: destination = kRootRegister + offset.
82 intptr_t offset) = 0;
83
84 // Corresponds to: destination = [kRootRegister + offset].
85 virtual void LoadRootRelative(Register destination, int32_t offset) = 0;
86 virtual void StoreRootRelative(int32_t offset, Register value) = 0;
87
88 static constexpr bool CanBeImmediate(RootIndex index) {
89 return V8_STATIC_ROOTS_BOOL && RootsTable::IsReadOnly(index);
90 }
91 Tagged_t ReadOnlyRootPtr(RootIndex index);
92 static Tagged_t ReadOnlyRootPtr(RootIndex index, Isolate* isolate);
93 virtual void LoadRoot(Register destination, RootIndex index) = 0;
94
95 static int32_t RootRegisterOffsetForRootIndex(RootIndex root_index);
96 static int32_t RootRegisterOffsetForBuiltin(Builtin builtin);
97
98 // Returns the root-relative offset to reference.address().
99 static intptr_t RootRegisterOffsetForExternalReference(
100 Isolate* isolate, const ExternalReference& reference);
101
102 // Returns the root-relative offset to the external reference table entry,
103 // which itself contains reference.address().
104 static int32_t RootRegisterOffsetForExternalReferenceTableEntry(
105 Isolate* isolate, const ExternalReference& reference);
106
107 // An address is addressable through kRootRegister if it is located within
108 // isolate->root_register_addressable_region().
109 static bool IsAddressableThroughRootRegister(
110 Isolate* isolate, const ExternalReference& reference);
111
112#if defined(V8_TARGET_OS_WIN) || defined(V8_TARGET_OS_MACOS)
113 // Minimum page size. We must touch memory once per page when expanding the
114 // stack, to avoid access violations.
115 static constexpr int kStackPageSize = 4 * KB;
116#endif
117
118 V8_INLINE std::string CommentForOffHeapTrampoline(const char* prefix,
119 Builtin builtin) {
120 if (!v8_flags.code_comments) return "";
121 std::ostringstream str;
122 str << "Inlined Trampoline for " << prefix << " to "
123 << Builtins::name(builtin);
124 return str.str();
125 }
126
127 enum class RecordWriteCallMode { kDefault, kWasm };
128
129 protected:
130 Isolate* const isolate_ = nullptr;
131
132 // This handle will be patched with the code object on installation.
134
135 // Whether kRootRegister has been initialized.
136 bool root_array_available_ = true;
137
138 // Emit a C call to abort instead of a runtime call.
139 bool hard_abort_ = false;
140
141 // May be set while generating builtins.
142 Builtin maybe_builtin_ = Builtin::kNoBuiltinId;
143
144 bool has_frame_ = false;
145
146 int comment_depth_ = 0;
147
149};
150
151// Avoids emitting calls to the {Builtin::kAbort} builtin when emitting
152// debug code during the lifetime of this scope object.
154 public:
156 : assembler_(assembler), old_value_(assembler->should_abort_hard()) {
157 assembler_->set_abort_hard(true);
158 }
159 ~HardAbortScope() { assembler_->set_abort_hard(old_value_); }
160
161 private:
164};
165
166} // namespace internal
167} // namespace v8
168
169#endif // V8_CODEGEN_MACRO_ASSEMBLER_BASE_H_
Isolate * isolate_
HardAbortScope(MacroAssemblerBase *assembler)
virtual void LoadRoot(Register destination, RootIndex index)=0
virtual void LoadRootRelative(Register destination, int32_t offset)=0
MacroAssemblerBase(Isolate *isolate, MaybeAssemblerZone zone, CodeObjectRequired create_code_object, std::unique_ptr< AssemblerBuffer > buffer={})
IndirectHandle< HeapObject > CodeObject() const
static constexpr bool CanBeImmediate(RootIndex index)
virtual void LoadRootRegisterOffset(Register destination, intptr_t offset)=0
V8_INLINE std::string CommentForOffHeapTrampoline(const char *prefix, Builtin builtin)
virtual void StoreRootRelative(int32_t offset, Register value)=0
MacroAssemblerBase(Isolate *isolate, CodeObjectRequired create_code_object, std::unique_ptr< AssemblerBuffer > buffer={})
DISALLOW_IMPLICIT_CONSTRUCTORS(MacroAssemblerBase)
virtual void LoadFromConstantsTable(Register destination, int constant_index)=0
IndirectHandle< HeapObject > code_object_
MacroAssemblerBase(MaybeAssemblerZone zone, AssemblerOptions options, CodeObjectRequired create_code_object, std::unique_ptr< AssemblerBuffer > buffer={})
BytecodeAssembler & assembler_
refactor address components for immediate indexing make OptimizeMaglevOnNextCall optimize to turbofan instead of maglev filter for tracing turbofan compilation trace turbo cfg trace TurboFan s graph trimmer trace TurboFan s control equivalence trace TurboFan s register allocator trace stack load store counters for optimized code in run fuzzing &&concurrent_recompilation trace_turbo trace_turbo_scheduled trace_turbo_stack_accesses verify TurboFan machine graph of code stubs enable FixedArray bounds checks print TurboFan statistics of wasm compilations maximum cumulative size of bytecode considered for inlining scale factor of bytecode size used to calculate the inlining budget * KB
int32_t offset
Builtin builtin
InstructionOperand destination
STL namespace.
std::variant< Zone *, AccountingAllocator * > MaybeAssemblerZone
Definition assembler.h:262
Address Tagged_t
Definition globals.h:547
V8_EXPORT_PRIVATE FlagValues v8_flags
#define DCHECK(condition)
Definition logging.h:482
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_STATIC_ROOTS_BOOL
Definition v8config.h:1001
#define V8_INLINE
Definition v8config.h:500
#define V8_NODISCARD
Definition v8config.h:693