5 #include "src/turbo-assembler.h" 7 #include "src/builtins/builtins.h" 8 #include "src/builtins/constants-table-builder.h" 9 #include "src/isolate-data.h" 10 #include "src/isolate-inl.h" 12 #include "src/snapshot/serializer-common.h" 17 TurboAssemblerBase::TurboAssemblerBase(Isolate* isolate,
18 const AssemblerOptions& options,
19 void* buffer,
int buffer_size,
20 CodeObjectRequired create_code_object)
21 : Assembler(options, buffer, buffer_size), isolate_(isolate) {
22 if (create_code_object == CodeObjectRequired::kYes) {
23 code_object_ = Handle<HeapObject>::New(
24 ReadOnlyRoots(isolate).self_reference_marker(), isolate);
28 void TurboAssemblerBase::IndirectLoadConstant(Register destination,
29 Handle<HeapObject>
object) {
30 CHECK(root_array_available_);
37 if (isolate()->roots_table().IsRootHandle(
object, &root_index)) {
39 LoadRoot(destination, root_index);
40 }
else if (isolate()->builtins()->IsBuiltinHandle(
object, &builtin_index)) {
42 LoadRootRelative(destination,
43 RootRegisterOffsetForBuiltinIndex(builtin_index));
44 }
else if (
object.is_identical_to(code_object_) &&
45 Builtins::IsBuiltinId(maybe_builtin_index_)) {
48 LoadRootRelative(destination,
49 RootRegisterOffsetForBuiltinIndex(maybe_builtin_index_));
51 CHECK(isolate()->ShouldLoadConstantsFromRootList());
54 BuiltinsConstantsTableBuilder* builder =
55 isolate()->builtins_constants_table_builder();
56 uint32_t index = builder->AddObject(
object);
59 LoadFromConstantsTable(destination, index);
63 void TurboAssemblerBase::IndirectLoadExternalReference(
64 Register destination, ExternalReference reference) {
65 CHECK(root_array_available_);
67 if (IsAddressableThroughRootRegister(isolate(), reference)) {
71 RootRegisterOffsetForExternalReference(isolate(), reference);
72 LoadRootRegisterOffset(destination, offset);
77 RootRegisterOffsetForExternalReferenceTableEntry(isolate(), reference));
82 int32_t TurboAssemblerBase::RootRegisterOffsetForRootIndex(
83 RootIndex root_index) {
84 return IsolateData::root_slot_offset(root_index);
88 int32_t TurboAssemblerBase::RootRegisterOffsetForBuiltinIndex(
90 return IsolateData::builtin_slot_offset(builtin_index);
94 intptr_t TurboAssemblerBase::RootRegisterOffsetForExternalReference(
95 Isolate* isolate,
const ExternalReference& reference) {
96 return static_cast<intptr_t
>(reference.address() - isolate->isolate_root());
100 int32_t TurboAssemblerBase::RootRegisterOffsetForExternalReferenceTableEntry(
101 Isolate* isolate,
const ExternalReference& reference) {
104 ExternalReferenceEncoder encoder(isolate);
105 ExternalReferenceEncoder::Value v = encoder.Encode(reference.address());
106 CHECK(!v.is_from_api());
108 return IsolateData::external_reference_table_offset() +
109 ExternalReferenceTable::OffsetOfEntry(v.index());
113 bool TurboAssemblerBase::IsAddressableThroughRootRegister(
114 Isolate* isolate,
const ExternalReference& reference) {
115 Address address = reference.address();
116 return isolate->root_register_addressable_region().contains(address);
119 void TurboAssemblerBase::RecordCommentForOffHeapTrampoline(
int builtin_index) {
120 if (!FLAG_code_comments)
return;
121 size_t len = strlen(
"-- Inlined Trampoline to --") +
122 strlen(Builtins::name(builtin_index)) + 1;
123 Vector<char> buffer = Vector<char>::New(static_cast<int>(len));
124 char* buffer_start = buffer.start();
125 LSAN_IGNORE_OBJECT(buffer_start);
126 SNPrintF(buffer,
"-- Inlined Trampoline to %s --",
127 Builtins::name(builtin_index));
128 RecordComment(buffer_start);