forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacro-assembler-base.cc
More file actions
156 lines (134 loc) · 5.82 KB
/
Copy pathmacro-assembler-base.cc
File metadata and controls
156 lines (134 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright 2018 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.
#include "src/codegen/macro-assembler-base.h"
#include "src/builtins/builtins.h"
#include "src/builtins/constants-table-builder.h"
#include "src/codegen/external-reference-encoder.h"
#include "src/common/globals.h"
#include "src/execution/isolate-data.h"
#include "src/execution/isolate-inl.h"
#include "src/snapshot/embedded/embedded-data-inl.h"
namespace v8 {
namespace internal {
MacroAssemblerBase::MacroAssemblerBase(Isolate* isolate,
const AssemblerOptions& options,
CodeObjectRequired create_code_object,
std::unique_ptr<AssemblerBuffer> buffer)
: MacroAssemblerBase(isolate, isolate->allocator(), options,
create_code_object, std::move(buffer)) {}
MacroAssemblerBase::MacroAssemblerBase(Isolate* isolate,
MaybeAssemblerZone zone,
AssemblerOptions options,
CodeObjectRequired create_code_object,
std::unique_ptr<AssemblerBuffer> buffer)
: Assembler(zone, options, std::move(buffer)), isolate_(isolate) {
if (create_code_object == CodeObjectRequired::kYes) {
code_object_ = IndirectHandle<HeapObject>::New(
ReadOnlyRoots(isolate).self_reference_marker(), isolate);
}
}
Address MacroAssemblerBase::BuiltinEntry(Builtin builtin) {
DCHECK(Builtins::IsBuiltinId(builtin));
if (isolate_ != nullptr) {
Address entry = isolate_->builtin_entry_table()[Builtins::ToInt(builtin)];
DCHECK_EQ(entry,
EmbeddedData::FromBlob(isolate_).InstructionStartOf(builtin));
return entry;
}
EmbeddedData d = EmbeddedData::FromBlob();
return d.InstructionStartOf(builtin);
}
void MacroAssemblerBase::IndirectLoadConstant(Register destination,
Handle<HeapObject> object) {
CHECK(root_array_available_);
// Before falling back to the (fairly slow) lookup from the constants table,
// check if any of the fast paths can be applied.
Builtin builtin;
RootIndex root_index;
if (isolate()->roots_table().IsRootHandle(object, &root_index)) {
// Roots are loaded relative to the root register.
LoadRoot(destination, root_index);
} else if (isolate()->builtins()->IsBuiltinHandle(object, &builtin)) {
// Similar to roots, builtins may be loaded from the builtins table.
LoadRootRelative(destination, RootRegisterOffsetForBuiltin(builtin));
} else if (object.is_identical_to(code_object_) &&
Builtins::IsBuiltinId(maybe_builtin_)) {
// The self-reference loaded through Codevalue() may also be a builtin
// and thus viable for a fast load.
LoadRootRelative(destination, RootRegisterOffsetForBuiltin(maybe_builtin_));
} else {
CHECK(isolate()->IsGeneratingEmbeddedBuiltins());
// Ensure the given object is in the builtins constants table and fetch its
// index.
BuiltinsConstantsTableBuilder* builder =
isolate()->builtins_constants_table_builder();
uint32_t index = builder->AddObject(object);
// Slow load from the constants table.
LoadFromConstantsTable(destination, index);
}
}
void MacroAssemblerBase::IndirectLoadExternalReference(
Register destination, ExternalReference reference) {
CHECK(root_array_available_);
if (IsAddressableThroughRootRegister(isolate(), reference)) {
// Some external references can be efficiently loaded as an offset from
// kRootRegister.
intptr_t offset =
RootRegisterOffsetForExternalReference(isolate(), reference);
LoadRootRegisterOffset(destination, offset);
} else {
// Otherwise, do a memory load from the external reference table.
LoadRootRelative(
destination,
RootRegisterOffsetForExternalReferenceTableEntry(isolate(), reference));
}
}
// static
int32_t MacroAssemblerBase::RootRegisterOffsetForRootIndex(
RootIndex root_index) {
return IsolateData::root_slot_offset(root_index);
}
// static
int32_t MacroAssemblerBase::RootRegisterOffsetForBuiltin(Builtin builtin) {
return IsolateData::BuiltinSlotOffset(builtin);
}
// static
intptr_t MacroAssemblerBase::RootRegisterOffsetForExternalReference(
Isolate* isolate, const ExternalReference& reference) {
if (reference.IsIsolateFieldId()) {
return reference.offset_from_root_register();
}
return static_cast<intptr_t>(reference.address() - isolate->isolate_root());
}
// static
int32_t MacroAssemblerBase::RootRegisterOffsetForExternalReferenceTableEntry(
Isolate* isolate, const ExternalReference& reference) {
// Encode as an index into the external reference table stored on the
// isolate.
ExternalReferenceEncoder encoder(isolate);
ExternalReferenceEncoder::Value v = encoder.Encode(reference.address());
CHECK(!v.is_from_api());
return IsolateData::external_reference_table_offset() +
ExternalReferenceTable::OffsetOfEntry(v.index());
}
// static
bool MacroAssemblerBase::IsAddressableThroughRootRegister(
Isolate* isolate, const ExternalReference& reference) {
if (reference.IsIsolateFieldId()) return true;
Address address = reference.address();
return isolate->root_register_addressable_region().contains(address);
}
// static
Tagged_t MacroAssemblerBase::ReadOnlyRootPtr(RootIndex index,
Isolate* isolate) {
DCHECK(CanBeImmediate(index));
Tagged<Object> obj = isolate->root(index);
CHECK(IsHeapObject(obj));
return V8HeapCompressionScheme::CompressObject(obj.ptr());
}
Tagged_t MacroAssemblerBase::ReadOnlyRootPtr(RootIndex index) {
return ReadOnlyRootPtr(index, isolate_);
}
} // namespace internal
} // namespace v8