Commit 9ab8422d authored by Liu Yu's avatar Liu Yu Committed by V8 LUCI CQ

[mips][baseline] Remove initial relocation when compiling on heap

And fallback to handle references on heap compilation.

Port 7ac3b55a
Port 642a4673

Bug: v8:11872

Change-Id: Ia371c53d32c0f1f4496fee1a7c72461ea291191f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3066946
Auto-Submit: Liu yu <liuyu@loongson.cn>
Reviewed-by: 's avatarZhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Commit-Queue: Zhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Cr-Commit-Position: refs/heads/master@{#76045}
parent d2db7fa7
...@@ -3537,7 +3537,16 @@ void Assembler::RelocateRelativeReference(RelocInfo::Mode rmode, Address pc, ...@@ -3537,7 +3537,16 @@ void Assembler::RelocateRelativeReference(RelocInfo::Mode rmode, Address pc,
} }
} }
void Assembler::FixOnHeapReferences() {
for (auto p : saved_handles_for_raw_object_ptr_) {
Address base = reinterpret_cast<Address>(buffer_->start() + p.first);
set_target_value_at(base, p.second);
}
}
void Assembler::GrowBuffer() { void Assembler::GrowBuffer() {
bool previously_on_heap = buffer_->IsOnHeap();
// Compute new buffer size. // Compute new buffer size.
int old_size = buffer_->size(); int old_size = buffer_->size();
int new_size = std::min(2 * old_size, old_size + 1 * MB); int new_size = std::min(2 * old_size, old_size + 1 * MB);
...@@ -3580,6 +3589,8 @@ void Assembler::GrowBuffer() { ...@@ -3580,6 +3589,8 @@ void Assembler::GrowBuffer() {
RelocateInternalReference(rmode, it.rinfo()->pc(), pc_delta); RelocateInternalReference(rmode, it.rinfo()->pc(), pc_delta);
} }
} }
// Patch on-heap references to handles.
if (previously_on_heap && !buffer_->IsOnHeap()) FixOnHeapReferences();
DCHECK(!overflow()); DCHECK(!overflow());
} }
......
...@@ -167,6 +167,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase { ...@@ -167,6 +167,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
GetCode(isolate, desc, kNoSafepointTable, kNoHandlerTable); GetCode(isolate, desc, kNoSafepointTable, kNoHandlerTable);
} }
void FixOnHeapReferences();
// Unused on this architecture. // Unused on this architecture.
void MaybeEmitOutOfLineConstantPool() {} void MaybeEmitOutOfLineConstantPool() {}
......
...@@ -1394,6 +1394,15 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) { ...@@ -1394,6 +1394,15 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) {
ori(rd, rd, (j.immediate() & kImm16Mask)); ori(rd, rd, (j.immediate() & kImm16Mask));
} }
} }
} else if (IsOnHeap() && RelocInfo::IsEmbeddedObjectMode(j.rmode())) {
BlockGrowBufferScope block_growbuffer(this);
saved_handles_for_raw_object_ptr_.push_back(
std::make_pair(pc_offset(), j.immediate()));
Handle<HeapObject> handle(reinterpret_cast<Address*>(j.immediate()));
int32_t immediate = handle->ptr();
RecordRelocInfo(j.rmode(), immediate);
lui(rd, (immediate >> kLuiShift) & kImm16Mask);
ori(rd, rd, (immediate & kImm16Mask));
} else { } else {
int32_t immediate; int32_t immediate;
if (j.IsHeapObjectRequest()) { if (j.IsHeapObjectRequest()) {
......
...@@ -3736,7 +3736,16 @@ int Assembler::RelocateInternalReference(RelocInfo::Mode rmode, Address pc, ...@@ -3736,7 +3736,16 @@ int Assembler::RelocateInternalReference(RelocInfo::Mode rmode, Address pc,
} }
} }
void Assembler::FixOnHeapReferences() {
for (auto p : saved_handles_for_raw_object_ptr_) {
Address base = reinterpret_cast<Address>(buffer_->start() + p.first);
set_target_value_at(base, p.second);
}
}
void Assembler::GrowBuffer() { void Assembler::GrowBuffer() {
bool previously_on_heap = buffer_->IsOnHeap();
// Compute new buffer size. // Compute new buffer size.
int old_size = buffer_->size(); int old_size = buffer_->size();
int new_size = std::min(2 * old_size, old_size + 1 * MB); int new_size = std::min(2 * old_size, old_size + 1 * MB);
...@@ -3778,6 +3787,8 @@ void Assembler::GrowBuffer() { ...@@ -3778,6 +3787,8 @@ void Assembler::GrowBuffer() {
RelocateInternalReference(rmode, it.rinfo()->pc(), pc_delta); RelocateInternalReference(rmode, it.rinfo()->pc(), pc_delta);
} }
} }
// Patch on-heap references to handles.
if (previously_on_heap && !buffer_->IsOnHeap()) FixOnHeapReferences();
DCHECK(!overflow()); DCHECK(!overflow());
} }
......
...@@ -167,6 +167,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase { ...@@ -167,6 +167,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
GetCode(isolate, desc, kNoSafepointTable, kNoHandlerTable); GetCode(isolate, desc, kNoSafepointTable, kNoHandlerTable);
} }
void FixOnHeapReferences();
// Unused on this architecture. // Unused on this architecture.
void MaybeEmitOutOfLineConstantPool() {} void MaybeEmitOutOfLineConstantPool() {}
......
...@@ -1914,6 +1914,17 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) { ...@@ -1914,6 +1914,17 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) {
} else { } else {
li_optimized(rd, j, mode); li_optimized(rd, j, mode);
} }
} else if (IsOnHeap() && RelocInfo::IsEmbeddedObjectMode(j.rmode())) {
BlockGrowBufferScope block_growbuffer(this);
saved_handles_for_raw_object_ptr_.push_back(
std::make_pair(pc_offset(), j.immediate()));
Handle<HeapObject> handle(reinterpret_cast<Address*>(j.immediate()));
int64_t immediate = handle->ptr();
RecordRelocInfo(j.rmode(), immediate);
lui(rd, (immediate >> 32) & kImm16Mask);
ori(rd, rd, (immediate >> 16) & kImm16Mask);
dsll(rd, rd, 16);
ori(rd, rd, immediate & kImm16Mask);
} else if (MustUseReg(j.rmode())) { } else if (MustUseReg(j.rmode())) {
int64_t immediate; int64_t immediate;
if (j.IsHeapObjectRequest()) { if (j.IsHeapObjectRequest()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment