[static-roots] Use static roots in CSA

Like in https://chromium-review.googlesource.com/c/v8/v8/+/4130075
we add the same optimizations to non-C++ builtins.

Bug: v8:13466
Change-Id: I20600f01c6966ef5b3e66cdf934cf895d60d6847
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4151195
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Olivier Flückiger <olivf@chromium.org>
Reviewed-by: Darius Mercadier <dmercadier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85183}
This commit is contained in:
Olivier Flückiger 2023-01-10 13:07:55 +00:00 committed by V8 LUCI CQ
parent 50a20711c7
commit 643b458b07
8 changed files with 68 additions and 5 deletions

View File

@ -1819,10 +1819,22 @@ void TurboAssembler::CanonicalizeNaN(const VRegister& dst,
Fsub(dst, src, fp_zero);
}
void TurboAssembler::LoadTaggedRoot(Register destination, RootIndex index) {
ASM_CODE_COMMENT(this);
if (V8_STATIC_ROOTS_BOOL && RootsTable::IsReadOnly(index)) {
Mov(destination,
Immediate(ReadOnlyRootPtr(index), RelocInfo::Mode::NO_INFO));
return;
}
LoadRoot(destination, index);
}
void TurboAssembler::LoadRoot(Register destination, RootIndex index) {
ASM_CODE_COMMENT(this);
// TODO(jbramley): Most root values are constants, and can be synthesized
// without a load. Refer to the ARM back end for details.
if (V8_STATIC_ROOTS_BOOL && RootsTable::IsReadOnly(index)) {
DecompressTaggedPointer(destination, ReadOnlyRootPtr(index));
return;
}
Ldr(destination,
MemOperand(kRootRegister, RootRegisterOffsetForRootIndex(index)));
}
@ -3144,7 +3156,11 @@ void MacroAssembler::CompareRoot(const Register& obj, RootIndex index) {
UseScratchRegisterScope temps(this);
Register temp = temps.AcquireX();
DCHECK(!AreAliased(obj, temp));
LoadRoot(temp, index);
if (V8_STATIC_ROOTS_BOOL && RootsTable::IsReadOnly(index)) {
LoadTaggedRoot(temp, index);
} else {
LoadRoot(temp, index);
}
CmpTagged(obj, temp);
}
@ -3253,6 +3269,13 @@ void TurboAssembler::DecompressTaggedPointer(const Register& destination,
Add(destination, kPtrComprCageBaseRegister, Operand(source, UXTW));
}
void TurboAssembler::DecompressTaggedPointer(const Register& destination,
Tagged_t immediate) {
ASM_CODE_COMMENT(this);
Add(destination, kPtrComprCageBaseRegister,
Immediate(immediate, RelocInfo::Mode::NO_INFO));
}
void TurboAssembler::DecompressAnyTagged(const Register& destination,
const MemOperand& field_operand) {
ASM_CODE_COMMENT(this);

View File

@ -1335,6 +1335,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
// Load an object from the root table.
void LoadRoot(Register destination, RootIndex index) final;
void LoadTaggedRoot(Register destination, RootIndex index);
void PushRoot(RootIndex index);
inline void Ret(const Register& xn = lr);
@ -1445,6 +1446,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
const MemOperand& field_operand);
void DecompressTaggedPointer(const Register& destination,
const Register& source);
void DecompressTaggedPointer(const Register& destination, Tagged_t immediate);
void DecompressAnyTagged(const Register& destination,
const MemOperand& field_operand);

View File

@ -126,5 +126,12 @@ bool TurboAssemblerBase::IsAddressableThroughRootRegister(
return isolate->root_register_addressable_region().contains(address);
}
Tagged_t TurboAssemblerBase::ReadOnlyRootPtr(RootIndex index) {
DCHECK(RootsTable::IsReadOnly(index));
CHECK(V8_STATIC_ROOTS_BOOL);
CHECK(isolate_->root(index).IsHeapObject());
return V8HeapCompressionScheme::CompressTagged(isolate_->root(index).ptr());
}
} // namespace internal
} // namespace v8

View File

@ -76,6 +76,7 @@ class V8_EXPORT_PRIVATE TurboAssemblerBase : public Assembler {
// Corresponds to: destination = [kRootRegister + offset].
virtual void LoadRootRelative(Register destination, int32_t offset) = 0;
Tagged_t ReadOnlyRootPtr(RootIndex index);
virtual void LoadRoot(Register destination, RootIndex index) = 0;
static int32_t RootRegisterOffsetForRootIndex(RootIndex root_index);

View File

@ -163,7 +163,20 @@ Operand TurboAssembler::RootAsOperand(RootIndex index) {
return Operand(kRootRegister, RootRegisterOffsetForRootIndex(index));
}
void TurboAssembler::LoadTaggedRoot(Register destination, RootIndex index) {
if (V8_STATIC_ROOTS_BOOL && RootsTable::IsReadOnly(index)) {
mov_tagged(destination, Immediate(ReadOnlyRootPtr(index)));
return;
}
DCHECK(root_array_available_);
movq(destination, RootAsOperand(index));
}
void TurboAssembler::LoadRoot(Register destination, RootIndex index) {
if (V8_STATIC_ROOTS_BOOL && RootsTable::IsReadOnly(index)) {
DecompressTaggedPointer(destination, ReadOnlyRootPtr(index));
return;
}
DCHECK(root_array_available_);
movq(destination, RootAsOperand(index));
}
@ -174,6 +187,10 @@ void MacroAssembler::PushRoot(RootIndex index) {
}
void TurboAssembler::CompareRoot(Register with, RootIndex index) {
if (V8_STATIC_ROOTS_BOOL && RootsTable::IsReadOnly(index)) {
cmp_tagged(with, Immediate(ReadOnlyRootPtr(index)));
return;
}
DCHECK(root_array_available_);
if (base::IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
RootIndex::kLastStrongOrReadOnlyRoot)) {
@ -185,6 +202,10 @@ void TurboAssembler::CompareRoot(Register with, RootIndex index) {
}
void TurboAssembler::CompareRoot(Operand with, RootIndex index) {
if (V8_STATIC_ROOTS_BOOL && RootsTable::IsReadOnly(index)) {
cmp_tagged(with, Immediate(ReadOnlyRootPtr(index)));
return;
}
DCHECK(root_array_available_);
DCHECK(!with.AddressUsesRegister(kScratchRegister));
if (base::IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
@ -357,6 +378,13 @@ void TurboAssembler::DecompressAnyTagged(Register destination,
addq(destination, kPtrComprCageBaseRegister);
}
void TurboAssembler::DecompressTaggedPointer(Register destination,
Tagged_t immediate) {
ASM_CODE_COMMENT(this);
leaq(destination,
Operand(kPtrComprCageBaseRegister, static_cast<int32_t>(immediate)));
}
void MacroAssembler::RecordWriteField(Register object, int offset,
Register value, Register slot_address,
SaveFPRegsMode save_fp,

View File

@ -76,6 +76,7 @@ class V8_EXPORT_PRIVATE TurboAssembler
// Operations on roots in the root-array.
Operand RootAsOperand(RootIndex index);
void LoadTaggedRoot(Register destination, RootIndex index);
void LoadRoot(Register destination, RootIndex index) final;
void LoadRoot(Operand destination, RootIndex index) {
LoadRoot(kScratchRegister, index);
@ -628,6 +629,7 @@ class V8_EXPORT_PRIVATE TurboAssembler
void DecompressTaggedSigned(Register destination, Operand field_operand);
void DecompressTaggedPointer(Register destination, Operand field_operand);
void DecompressTaggedPointer(Register destination, Register source);
void DecompressTaggedPointer(Register destination, Tagged_t immediate);
void DecompressAnyTagged(Register destination, Operand field_operand);
// ---------------------------------------------------------------------------

View File

@ -3587,7 +3587,7 @@ void CodeGenerator::AssembleMove(InstructionOperand* source,
Handle<HeapObject> src_object = src.ToHeapObject();
RootIndex index;
if (IsMaterializableFromRoot(src_object, &index)) {
__ LoadRoot(dst, index);
__ LoadTaggedRoot(dst, index);
} else {
// TODO(v8:8977): Even though this mov happens on 32 bits (Note the
// .W()) and we are passing along the RelocInfo, we still haven't made

View File

@ -5263,7 +5263,7 @@ void CodeGenerator::AssembleMove(InstructionOperand* source,
Handle<HeapObject> src_object = src.ToHeapObject();
RootIndex index;
if (IsMaterializableFromRoot(src_object, &index)) {
__ LoadRoot(dst, index);
__ LoadTaggedRoot(dst, index);
} else {
__ Move(dst, src_object, RelocInfo::COMPRESSED_EMBEDDED_OBJECT);
}