Skip to content

Commit cae7aad

Browse files
zjiazV8 LUCI CQ
authored andcommitted
[loong64][compiler] Add bottleneck for static roots check in MacroAssembler
Port commit 6a8fa0d Besides, port a missed commit 0523061 - [masm] Add quick check for RO values to write barrier Change-Id: I8c7ac524290203df0e95d90188a89aff8931de8f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6994010 Auto-Submit: Zhao Jiazhong <[email protected]> Reviewed-by: Michael Lippautz <[email protected]> Commit-Queue: Zhao Jiazhong <[email protected]> Cr-Commit-Position: refs/heads/main@{#103126}
1 parent 84bc340 commit cae7aad

3 files changed

Lines changed: 47 additions & 16 deletions

File tree

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,34 @@ void MacroAssembler::PreCheckSkippedWriteBarrier(Register object,
194194
bind(&not_ok);
195195
}
196196

197+
void MacroAssembler::MaybeJumpIfReadOnlyOrSmallSmi(Register value,
198+
Label* dest) {
199+
#if V8_STATIC_ROOTS_BOOL
200+
// Quick check for Read-only and small Smi values.
201+
static_assert(StaticReadOnlyRoot::kLastAllocatedRoot < kRegularPageSize);
202+
JumpIfUnsignedLessThan(value, kRegularPageSize, dest);
203+
#endif // V8_STATIC_ROOTS_BOOL
204+
}
205+
197206
// Clobbers object, dst, value, and ra, if (ra_status == kRAHasBeenSaved)
198207
// The register 'object' contains a heap object pointer. The heap object
199208
// tag is shifted away.
200209
void MacroAssembler::RecordWriteField(Register object, int offset,
201210
Register value, RAStatus ra_status,
202211
SaveFPRegsMode save_fp,
203-
SmiCheck smi_check, SlotDescriptor slot) {
212+
SmiCheck smi_check,
213+
ReadOnlyCheck ro_check,
214+
SlotDescriptor slot) {
204215
ASM_CODE_COMMENT(this);
216+
DCHECK(!AreAliased(object, value));
205217
// First, check if a write barrier is even needed. The tests below
206-
// catch stores of Smis.
218+
// catch stores of Smis and read-only objects.
207219
Label done;
208220

221+
if (ro_check == ReadOnlyCheck::kInline) {
222+
MaybeJumpIfReadOnlyOrSmallSmi(value, &done);
223+
}
224+
209225
// Skip barrier if writing a smi.
210226
if (smi_check == SmiCheck::kInline) {
211227
JumpIfSmi(value, &done);
@@ -228,7 +244,7 @@ void MacroAssembler::RecordWriteField(Register object, int offset,
228244
}
229245

230246
RecordWrite(object, Operand(offset - kHeapObjectTag), value, ra_status,
231-
save_fp, SmiCheck::kOmit, slot);
247+
save_fp, SmiCheck::kOmit, ReadOnlyCheck::kOmit, slot);
232248

233249
bind(&done);
234250
}
@@ -703,7 +719,7 @@ void MacroAssembler::MoveObjectAndSlot(Register dst_object, Register dst_slot,
703719
void MacroAssembler::RecordWrite(Register object, Operand offset,
704720
Register value, RAStatus ra_status,
705721
SaveFPRegsMode fp_mode, SmiCheck smi_check,
706-
SlotDescriptor slot) {
722+
ReadOnlyCheck ro_check, SlotDescriptor slot) {
707723
DCHECK(!AreAliased(object, value));
708724

709725
if (v8_flags.slow_debug_code) {
@@ -726,9 +742,14 @@ void MacroAssembler::RecordWrite(Register object, Operand offset,
726742
}
727743

728744
// First, check if a write barrier is even needed. The tests below
729-
// catch stores of smis and stores into the young generation.
745+
// catch stores of smis and read-only objects, as well as stores into the
746+
// young generation.
730747
Label done;
731748

749+
if (ro_check == ReadOnlyCheck::kInline) {
750+
MaybeJumpIfReadOnlyOrSmallSmi(value, &done);
751+
}
752+
732753
if (smi_check == SmiCheck::kInline) {
733754
DCHECK_EQ(0, kSmiTag);
734755
JumpIfSmi(value, &done);
@@ -5312,7 +5333,7 @@ void MacroAssembler::ReplaceClosureCodeWithOptimizedCode(
53125333
FieldMemOperand(closure, JSFunction::kCodeOffset));
53135334
RecordWriteField(closure, JSFunction::kCodeOffset, optimized_code,
53145335
kRAHasNotBeenSaved, SaveFPRegsMode::kIgnore, SmiCheck::kOmit,
5315-
SlotDescriptor::ForCodePointerSlot());
5336+
ReadOnlyCheck::kOmit, SlotDescriptor::ForCodePointerSlot());
53165337
}
53175338

53185339
// Read off the flags in the feedback vector and check if there

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -817,18 +817,20 @@ class V8_EXPORT_PRIVATE MacroAssembler : public MacroAssemblerBase {
817817
// Jump the register contains a smi.
818818
void JumpIfSmi(Register value, Label* smi_label);
819819

820-
void JumpIfEqual(Register a, int32_t b, Label* dest) {
821-
UseScratchRegisterScope temps(this);
822-
Register scratch = temps.Acquire();
823-
li(scratch, Operand(b));
824-
Branch(dest, eq, a, Operand(scratch));
820+
inline void JumpIf(Condition cond, Register x, int32_t y, Label* dest) {
821+
Branch(dest, cond, x, Operand(y));
825822
}
826823

827-
void JumpIfLessThan(Register a, int32_t b, Label* dest) {
828-
UseScratchRegisterScope temps(this);
829-
Register scratch = temps.Acquire();
830-
li(scratch, Operand(b));
831-
Branch(dest, lt, a, Operand(scratch));
824+
inline void JumpIfEqual(Register x, int32_t y, Label* dest) {
825+
Branch(dest, eq, x, Operand(y));
826+
}
827+
828+
inline void JumpIfLessThan(Register x, int32_t y, Label* dest) {
829+
Branch(dest, lt, x, Operand(y));
830+
}
831+
832+
inline void JumpIfUnsignedLessThan(Register x, int32_t y, Label* dest) {
833+
Branch(dest, lo, x, Operand(y));
832834
}
833835

834836
// Push a standard frame, consisting of ra, fp, context and JS function.
@@ -1058,6 +1060,10 @@ class V8_EXPORT_PRIVATE MacroAssembler : public MacroAssemblerBase {
10581060
// ---------------------------------------------------------------------------
10591061
// GC Support
10601062

1063+
// Performs a fast check for whether `value` is a read-only object or a small
1064+
// Smi. Only enabled in some configurations.
1065+
void MaybeJumpIfReadOnlyOrSmallSmi(Register value, Label* dest);
1066+
10611067
// Notify the garbage collector that we wrote a pointer into an object.
10621068
// |object| is the object being stored into, |value| is the object being
10631069
// stored.
@@ -1066,13 +1072,15 @@ class V8_EXPORT_PRIVATE MacroAssembler : public MacroAssemblerBase {
10661072
void RecordWriteField(
10671073
Register object, int offset, Register value, RAStatus ra_status,
10681074
SaveFPRegsMode save_fp, SmiCheck smi_check = SmiCheck::kInline,
1075+
ReadOnlyCheck ro_check = ReadOnlyCheck::kInline,
10691076
SlotDescriptor slot = SlotDescriptor::ForDirectPointerSlot());
10701077

10711078
// For a given |object| notify the garbage collector that the slot at |offset|
10721079
// has been written. |value| is the object being stored.
10731080
void RecordWrite(
10741081
Register object, Operand offset, Register value, RAStatus ra_status,
10751082
SaveFPRegsMode save_fp, SmiCheck smi_check = SmiCheck::kInline,
1083+
ReadOnlyCheck ro_check = ReadOnlyCheck::kInline,
10761084
SlotDescriptor slot = SlotDescriptor::ForDirectPointerSlot());
10771085

10781086
// ---------------------------------------------------------------------------

src/compiler/backend/loong64/code-generator-loong64.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
10681068
Register scratch = i.TempRegister(0);
10691069
auto ool = zone()->New<OutOfLineVerifySkippedWriteBarrier>(
10701070
this, object, value, scratch);
1071+
__ MaybeJumpIfReadOnlyOrSmallSmi(value, ool->exit());
10711072
__ JumpIfNotSmi(value, ool->entry());
10721073
__ bind(ool->exit());
10731074

@@ -1128,6 +1129,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
11281129
Register scratch = i.TempRegister(1);
11291130
auto ool = zone()->New<OutOfLineVerifySkippedWriteBarrier>(
11301131
this, object, value, scratch);
1132+
__ MaybeJumpIfReadOnlyOrSmallSmi(value, ool->exit());
11311133
__ JumpIfNotSmi(value, ool->entry());
11321134
__ bind(ool->exit());
11331135

0 commit comments

Comments
 (0)