Skip to content

Commit dc88bdf

Browse files
Junliang YanV8 LUCI CQ
authored andcommitted
ppc/s390: [isolate-data] Split builtin tables into tiers
Port 06af754 Original Message: .. for more efficient access to builtins from generated code. Root-relative accesses tend to be faster and produce more compact code when the root-relative offset is small. IsolateData contains a few large tables (roots, external references, builtins), resulting in very large offsets in general. This CL starts by splitting the builtin table into tiers: tier 0 is a minimal set of perf-critical builtins that should be cheap to access. The offset to tier 0 builtins is guaranteed to be small. The full builtin table also remains in IsolateData for occasions in which we need to lookup builtins by index. In future work, we can also split external references and roots into tiers. On x64, this reduces deopt exit sizes from 7 to 4 bytes and from 12 to 9 bytes (dynamic map checks / EagerWithResume deopts). Change-Id: I021d60b20b783da170987ffcf0327b93206f7e5d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3172917 Reviewed-by: Milad Fa <[email protected]> Commit-Queue: Junliang Yan <[email protected]> Cr-Commit-Position: refs/heads/main@{#76967}
1 parent d7dde47 commit dc88bdf

File tree

6 files changed

+69
-33
lines changed

6 files changed

+69
-33
lines changed

src/codegen/ppc/macro-assembler-ppc.cc

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,14 @@ void TurboAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
187187
DCHECK_IMPLIES(options().isolate_independent_code,
188188
Builtins::IsIsolateIndependentBuiltin(*code));
189189

190-
Builtin builtin_index = Builtin::kNoBuiltinId;
190+
Builtin builtin = Builtin::kNoBuiltinId;
191191
bool target_is_builtin =
192-
isolate()->builtins()->IsBuiltinHandle(code, &builtin_index);
192+
isolate()->builtins()->IsBuiltinHandle(code, &builtin);
193193

194194
if (root_array_available_ && options().isolate_independent_code) {
195195
Label skip;
196196
Register scratch = ip;
197-
int offset = static_cast<int>(code->builtin_id()) * kSystemPointerSize +
198-
IsolateData::builtin_entry_table_offset();
197+
int offset = IsolateData::BuiltinEntrySlotOffset(code->builtin_id());
199198
LoadU64(scratch, MemOperand(kRootRegister, offset), r0);
200199
if (cond != al) b(NegateCondition(cond), &skip, cr);
201200
Jump(scratch);
@@ -204,10 +203,10 @@ void TurboAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
204203
} else if (options().inline_offheap_trampolines && target_is_builtin) {
205204
// Inline the trampoline.
206205
Label skip;
207-
RecordCommentForOffHeapTrampoline(builtin_index);
206+
RecordCommentForOffHeapTrampoline(builtin);
208207
// Use ip directly instead of using UseScratchRegisterScope, as we do
209208
// not preserve scratch registers across calls.
210-
mov(ip, Operand(BuiltinEntry(builtin_index), RelocInfo::OFF_HEAP_TARGET));
209+
mov(ip, Operand(BuiltinEntry(builtin), RelocInfo::OFF_HEAP_TARGET));
211210
if (cond != al) b(NegateCondition(cond), &skip, cr);
212211
Jump(ip);
213212
bind(&skip);
@@ -274,36 +273,40 @@ void TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
274273
DCHECK_IMPLIES(options().use_pc_relative_calls_and_jumps,
275274
Builtins::IsIsolateIndependentBuiltin(*code));
276275

277-
Builtin builtin_index = Builtin::kNoBuiltinId;
276+
Builtin builtin = Builtin::kNoBuiltinId;
278277
bool target_is_builtin =
279-
isolate()->builtins()->IsBuiltinHandle(code, &builtin_index);
278+
isolate()->builtins()->IsBuiltinHandle(code, &builtin);
280279

281280
if (root_array_available_ && options().isolate_independent_code) {
282281
Label skip;
283-
int offset = static_cast<int>(code->builtin_id()) * kSystemPointerSize +
284-
IsolateData::builtin_entry_table_offset();
282+
int offset = IsolateData::BuiltinEntrySlotOffset(code->builtin_id());
285283
LoadU64(ip, MemOperand(kRootRegister, offset));
286284
if (cond != al) b(NegateCondition(cond), &skip);
287285
Call(ip);
288286
bind(&skip);
289287
return;
290288
} else if (options().inline_offheap_trampolines && target_is_builtin) {
291289
// Inline the trampoline.
292-
RecordCommentForOffHeapTrampoline(builtin_index);
293-
// Use ip directly instead of using UseScratchRegisterScope, as we do
294-
// not preserve scratch registers across calls.
295-
mov(ip, Operand(BuiltinEntry(builtin_index), RelocInfo::OFF_HEAP_TARGET));
296-
Label skip;
297-
if (cond != al) b(NegateCondition(cond), &skip);
298-
Call(ip);
299-
bind(&skip);
290+
CallBuiltin(builtin, cond);
300291
return;
301292
}
302293
DCHECK(code->IsExecutable());
303294
int32_t target_index = AddCodeTarget(code);
304295
Call(static_cast<Address>(target_index), rmode, cond);
305296
}
306297

298+
void TurboAssembler::CallBuiltin(Builtin builtin, Condition cond) {
299+
ASM_CODE_COMMENT_STRING(this, CommentForOffHeapTrampoline("call", builtin));
300+
DCHECK(Builtins::IsBuiltinId(builtin));
301+
// Use ip directly instead of using UseScratchRegisterScope, as we do not
302+
// preserve scratch registers across calls.
303+
mov(ip, Operand(BuiltinEntry(builtin), RelocInfo::OFF_HEAP_TARGET));
304+
Label skip;
305+
if (cond != al) b(NegateCondition(cond), &skip);
306+
Call(ip);
307+
bind(&skip);
308+
}
309+
307310
void TurboAssembler::Drop(int count) {
308311
if (count > 0) {
309312
AddS64(sp, sp, Operand(count * kSystemPointerSize), r0);
@@ -3646,8 +3649,9 @@ void TurboAssembler::CallForDeoptimization(Builtin target, int, Label* exit,
36463649
DeoptimizeKind kind, Label* ret,
36473650
Label*) {
36483651
BlockTrampolinePoolScope block_trampoline_pool(this);
3652+
CHECK_LE(target, Builtins::kLastTier0);
36493653
LoadU64(ip, MemOperand(kRootRegister,
3650-
IsolateData::builtin_entry_slot_offset(target)));
3654+
IsolateData::BuiltinEntrySlotOffset(target)));
36513655
Call(ip);
36523656
DCHECK_EQ(SizeOfCodeGeneratedSince(exit),
36533657
(kind == DeoptimizeKind::kLazy)

src/codegen/ppc/macro-assembler-ppc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
4949
public:
5050
using TurboAssemblerBase::TurboAssemblerBase;
5151

52+
void CallBuiltin(Builtin builtin, Condition cond);
5253
void Popcnt32(Register dst, Register src);
5354
void Popcnt64(Register dst, Register src);
5455
// Converts the integer (untagged smi) in |src| to a double, storing

src/codegen/s390/macro-assembler-s390.cc

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,14 @@ void TurboAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
416416
DCHECK_IMPLIES(options().isolate_independent_code,
417417
Builtins::IsIsolateIndependentBuiltin(*code));
418418

419-
Builtin builtin_index = Builtin::kNoBuiltinId;
419+
Builtin builtin = Builtin::kNoBuiltinId;
420420
bool target_is_builtin =
421-
isolate()->builtins()->IsBuiltinHandle(code, &builtin_index);
421+
isolate()->builtins()->IsBuiltinHandle(code, &builtin);
422422

423423
if (options().inline_offheap_trampolines && target_is_builtin) {
424424
// Inline the trampoline.
425-
RecordCommentForOffHeapTrampoline(builtin_index);
426-
mov(ip, Operand(BuiltinEntry(builtin_index), RelocInfo::OFF_HEAP_TARGET));
425+
RecordCommentForOffHeapTrampoline(builtin);
426+
mov(ip, Operand(BuiltinEntry(builtin), RelocInfo::OFF_HEAP_TARGET));
427427
b(cond, ip);
428428
return;
429429
}
@@ -474,21 +474,28 @@ void TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
474474

475475
DCHECK_IMPLIES(options().isolate_independent_code,
476476
Builtins::IsIsolateIndependentBuiltin(*code));
477-
Builtin builtin_index = Builtin::kNoBuiltinId;
477+
Builtin builtin = Builtin::kNoBuiltinId;
478478
bool target_is_builtin =
479-
isolate()->builtins()->IsBuiltinHandle(code, &builtin_index);
479+
isolate()->builtins()->IsBuiltinHandle(code, &builtin);
480480

481481
if (target_is_builtin && options().inline_offheap_trampolines) {
482482
// Inline the trampoline.
483-
RecordCommentForOffHeapTrampoline(builtin_index);
484-
mov(ip, Operand(BuiltinEntry(builtin_index), RelocInfo::OFF_HEAP_TARGET));
485-
Call(ip);
483+
CallBuiltin(builtin);
486484
return;
487485
}
488486
DCHECK(code->IsExecutable());
489487
call(code, rmode);
490488
}
491489

490+
void TurboAssembler::CallBuiltin(Builtin builtin) {
491+
ASM_CODE_COMMENT_STRING(this, CommentForOffHeapTrampoline("call", builtin));
492+
DCHECK(Builtins::IsBuiltinId(builtin));
493+
// Use ip directly instead of using UseScratchRegisterScope, as we do not
494+
// preserve scratch registers across calls.
495+
mov(ip, Operand(BuiltinEntry(builtin), RelocInfo::OFF_HEAP_TARGET));
496+
Call(ip);
497+
}
498+
492499
void TurboAssembler::Drop(int count) {
493500
if (count > 0) {
494501
int total = count * kSystemPointerSize;
@@ -4779,8 +4786,9 @@ void TurboAssembler::StoreReturnAddressAndCall(Register target) {
47794786
void TurboAssembler::CallForDeoptimization(Builtin target, int, Label* exit,
47804787
DeoptimizeKind kind, Label* ret,
47814788
Label*) {
4789+
ASM_CODE_COMMENT(this);
47824790
LoadU64(ip, MemOperand(kRootRegister,
4783-
IsolateData::builtin_entry_slot_offset(target)));
4791+
IsolateData::BuiltinEntrySlotOffset(target)));
47844792
Call(ip);
47854793
DCHECK_EQ(SizeOfCodeGeneratedSince(exit),
47864794
(kind == DeoptimizeKind::kLazy)

src/codegen/s390/macro-assembler-s390.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
4444
public:
4545
using TurboAssemblerBase::TurboAssemblerBase;
4646

47+
void CallBuiltin(Builtin builtin);
4748
void AtomicCmpExchangeHelper(Register addr, Register output,
4849
Register old_value, Register new_value,
4950
int start, int end, int shift_amount, int offset,

src/deoptimizer/ppc/deoptimizer-ppc.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "src/codegen/assembler-inl.h"
6-
#include "src/codegen/macro-assembler.h"
7-
#include "src/codegen/register-configuration.h"
8-
#include "src/codegen/safepoint-table.h"
95
#include "src/deoptimizer/deoptimizer.h"
6+
#include "src/execution/isolate-data.h"
107

118
namespace v8 {
129
namespace internal {
1310

11+
// The deopt exit sizes below depend on the following IsolateData layout
12+
// guarantees:
13+
#define ASSERT_OFFSET(BuiltinName) \
14+
STATIC_ASSERT(IsolateData::builtin_tier0_entry_table_offset() + \
15+
Builtins::ToInt(BuiltinName) * kSystemPointerSize <= \
16+
0x1000)
17+
ASSERT_OFFSET(Builtin::kDeoptimizationEntry_Eager);
18+
ASSERT_OFFSET(Builtin::kDeoptimizationEntry_Lazy);
19+
ASSERT_OFFSET(Builtin::kDeoptimizationEntry_Soft);
20+
ASSERT_OFFSET(Builtin::kDeoptimizationEntry_Bailout);
21+
#undef ASSERT_OFFSET
22+
1423
const bool Deoptimizer::kSupportsFixedDeoptExitSizes = true;
1524
const int Deoptimizer::kNonLazyDeoptExitSize = 3 * kInstrSize;
1625
const int Deoptimizer::kLazyDeoptExitSize = 3 * kInstrSize;

src/deoptimizer/s390/deoptimizer-s390.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
// found in the LICENSE file.
44

55
#include "src/deoptimizer/deoptimizer.h"
6+
#include "src/execution/isolate-data.h"
67

78
namespace v8 {
89
namespace internal {
910

11+
// The deopt exit sizes below depend on the following IsolateData layout
12+
// guarantees:
13+
#define ASSERT_OFFSET(BuiltinName) \
14+
STATIC_ASSERT(IsolateData::builtin_tier0_entry_table_offset() + \
15+
Builtins::ToInt(BuiltinName) * kSystemPointerSize <= \
16+
0x1000)
17+
ASSERT_OFFSET(Builtin::kDeoptimizationEntry_Eager);
18+
ASSERT_OFFSET(Builtin::kDeoptimizationEntry_Lazy);
19+
ASSERT_OFFSET(Builtin::kDeoptimizationEntry_Soft);
20+
ASSERT_OFFSET(Builtin::kDeoptimizationEntry_Bailout);
21+
#undef ASSERT_OFFSET
22+
1023
const bool Deoptimizer::kSupportsFixedDeoptExitSizes = true;
1124
const int Deoptimizer::kNonLazyDeoptExitSize = 6 + 2;
1225
const int Deoptimizer::kLazyDeoptExitSize = 6 + 2;

0 commit comments

Comments
 (0)