Commit e39cba6b authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[assembler] Unify reloc info recording

This removes duplication in the platform-dependent assemblers by
introducing {AssemblerBase::ShouldRecordRelocInfo}.
On arm64, we also remove a bool and replace it by an early exit.

R=mstarzinger@chromium.org

Bug: v8:8238
Change-Id: I08c623a19167a358c3188dc9008f045120da82b1
Reviewed-on: https://chromium-review.googlesource.com/1251085Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56319}
parent 82be80aa
...@@ -1433,7 +1433,7 @@ int Assembler::branch_offset(Label* L) { ...@@ -1433,7 +1433,7 @@ int Assembler::branch_offset(Label* L) {
// Branch instructions. // Branch instructions.
void Assembler::b(int branch_offset, Condition cond, RelocInfo::Mode rmode) { void Assembler::b(int branch_offset, Condition cond, RelocInfo::Mode rmode) {
RecordRelocInfo(rmode); if (!RelocInfo::IsNone(rmode)) RecordRelocInfo(rmode);
DCHECK_EQ(branch_offset & 3, 0); DCHECK_EQ(branch_offset & 3, 0);
int imm24 = branch_offset >> 2; int imm24 = branch_offset >> 2;
const bool b_imm_check = is_int24(imm24); const bool b_imm_check = is_int24(imm24);
...@@ -1447,7 +1447,7 @@ void Assembler::b(int branch_offset, Condition cond, RelocInfo::Mode rmode) { ...@@ -1447,7 +1447,7 @@ void Assembler::b(int branch_offset, Condition cond, RelocInfo::Mode rmode) {
} }
void Assembler::bl(int branch_offset, Condition cond, RelocInfo::Mode rmode) { void Assembler::bl(int branch_offset, Condition cond, RelocInfo::Mode rmode) {
RecordRelocInfo(rmode); if (!RelocInfo::IsNone(rmode)) RecordRelocInfo(rmode);
DCHECK_EQ(branch_offset & 3, 0); DCHECK_EQ(branch_offset & 3, 0);
int imm24 = branch_offset >> 2; int imm24 = branch_offset >> 2;
const bool bl_imm_check = is_int24(imm24); const bool bl_imm_check = is_int24(imm24);
...@@ -5118,13 +5118,7 @@ void Assembler::dq(uint64_t value) { ...@@ -5118,13 +5118,7 @@ void Assembler::dq(uint64_t value) {
} }
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
if (options().disable_reloc_info_for_patching) return; if (!ShouldRecordRelocInfo(rmode)) return;
if (RelocInfo::IsNone(rmode) ||
// Don't record external references unless the heap will be serialized.
(RelocInfo::IsOnlyForSerializer(rmode) &&
!options().record_reloc_info_for_serialization && !emit_debug_code())) {
return;
}
DCHECK_GE(buffer_space(), kMaxRelocSize); // too late to grow buffer here DCHECK_GE(buffer_space(), kMaxRelocSize); // too late to grow buffer here
RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr); RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr);
reloc_info_writer.Write(&rinfo); reloc_info_writer.Write(&rinfo);
......
...@@ -4767,14 +4767,6 @@ void Assembler::GrowBuffer() { ...@@ -4767,14 +4767,6 @@ void Assembler::GrowBuffer() {
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data, void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data,
ConstantPoolMode constant_pool_mode) { ConstantPoolMode constant_pool_mode) {
// Non-relocatable constants should not end up in the literal pool.
DCHECK(!RelocInfo::IsNone(rmode));
if (options().disable_reloc_info_for_patching) return;
// We do not try to reuse pool constants.
RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr);
bool write_reloc_info = true;
if ((rmode == RelocInfo::COMMENT) || if ((rmode == RelocInfo::COMMENT) ||
(rmode == RelocInfo::INTERNAL_REFERENCE) || (rmode == RelocInfo::INTERNAL_REFERENCE) ||
(rmode == RelocInfo::CONST_POOL) || (rmode == RelocInfo::VENEER_POOL) || (rmode == RelocInfo::CONST_POOL) || (rmode == RelocInfo::VENEER_POOL) ||
...@@ -4788,23 +4780,22 @@ void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data, ...@@ -4788,23 +4780,22 @@ void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data,
RelocInfo::IsConstPool(rmode) || RelocInfo::IsVeneerPool(rmode)); RelocInfo::IsConstPool(rmode) || RelocInfo::IsVeneerPool(rmode));
// These modes do not need an entry in the constant pool. // These modes do not need an entry in the constant pool.
} else if (constant_pool_mode == NEEDS_POOL_ENTRY) { } else if (constant_pool_mode == NEEDS_POOL_ENTRY) {
write_reloc_info = constpool_.RecordEntry(data, rmode); bool new_constpool_entry = constpool_.RecordEntry(data, rmode);
// Make sure the constant pool is not emitted in place of the next // Make sure the constant pool is not emitted in place of the next
// instruction for which we just recorded relocation info. // instruction for which we just recorded relocation info.
BlockConstPoolFor(1); BlockConstPoolFor(1);
if (!new_constpool_entry) return;
} }
// For modes that cannot use the constant pool, a different sequence of // For modes that cannot use the constant pool, a different sequence of
// instructions will be emitted by this function's caller. // instructions will be emitted by this function's caller.
if (write_reloc_info) { if (!ShouldRecordRelocInfo(rmode)) return;
// Don't record external references unless the heap will be serialized.
if (RelocInfo::IsOnlyForSerializer(rmode) && // We do not try to reuse pool constants.
!options().record_reloc_info_for_serialization && !emit_debug_code()) { RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr);
return;
} DCHECK_GE(buffer_space(), kMaxRelocSize); // too late to grow buffer here
DCHECK_GE(buffer_space(), kMaxRelocSize); // too late to grow buffer here reloc_info_writer.Write(&rinfo);
reloc_info_writer.Write(&rinfo);
}
} }
void Assembler::near_jump(int offset, RelocInfo::Mode rmode) { void Assembler::near_jump(int offset, RelocInfo::Mode rmode) {
......
...@@ -289,6 +289,16 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced { ...@@ -289,6 +289,16 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced {
// by the pc offset associated with each request). // by the pc offset associated with each request).
void RequestHeapObject(HeapObjectRequest request); void RequestHeapObject(HeapObjectRequest request);
bool ShouldRecordRelocInfo(RelocInfo::Mode rmode) const {
DCHECK(!RelocInfo::IsNone(rmode));
if (options().disable_reloc_info_for_patching) return false;
if (RelocInfo::IsOnlyForSerializer(rmode) &&
!options().record_reloc_info_for_serialization && !emit_debug_code()) {
return false;
}
return true;
}
private: private:
// Before we copy code into the code space, we sometimes cannot encode // Before we copy code into the code space, we sometimes cannot encode
// call/jump code targets as we normally would, as the difference between the // call/jump code targets as we normally would, as the difference between the
......
...@@ -3405,13 +3405,7 @@ void Assembler::dd(Label* label) { ...@@ -3405,13 +3405,7 @@ void Assembler::dd(Label* label) {
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
DCHECK(!RelocInfo::IsNone(rmode)); if (!ShouldRecordRelocInfo(rmode)) return;
if (options().disable_reloc_info_for_patching) return;
// Don't record external references unless the heap will be serialized.
if (RelocInfo::IsOnlyForSerializer(rmode) &&
!options().record_reloc_info_for_serialization && !emit_debug_code()) {
return;
}
RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr); RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr);
reloc_info_writer.Write(&rinfo); reloc_info_writer.Write(&rinfo);
} }
......
...@@ -3887,17 +3887,11 @@ void Assembler::dd(Label* label) { ...@@ -3887,17 +3887,11 @@ void Assembler::dd(Label* label) {
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
if (!ShouldRecordRelocInfo(rmode)) return;
// We do not try to reuse pool constants. // We do not try to reuse pool constants.
RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr); RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr);
if (!RelocInfo::IsNone(rinfo.rmode())) { DCHECK_GE(buffer_space(), kMaxRelocSize); // Too late to grow buffer here.
if (options().disable_reloc_info_for_patching) return; reloc_info_writer.Write(&rinfo);
if (RelocInfo::IsOnlyForSerializer(rmode) &&
!options().record_reloc_info_for_serialization && !emit_debug_code()) {
return;
}
DCHECK_GE(buffer_space(), kMaxRelocSize); // Too late to grow buffer here.
reloc_info_writer.Write(&rinfo);
}
} }
void Assembler::BlockTrampolinePoolFor(int instructions) { void Assembler::BlockTrampolinePoolFor(int instructions) {
......
...@@ -4215,18 +4215,11 @@ void Assembler::dd(Label* label) { ...@@ -4215,18 +4215,11 @@ void Assembler::dd(Label* label) {
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
if (!ShouldRecordRelocInfo(rmode)) return;
// We do not try to reuse pool constants. // We do not try to reuse pool constants.
RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr); RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr);
if (!RelocInfo::IsNone(rinfo.rmode())) { DCHECK_GE(buffer_space(), kMaxRelocSize); // Too late to grow buffer here.
if (options().disable_reloc_info_for_patching) return; reloc_info_writer.Write(&rinfo);
// Don't record external references unless the heap will be serialized.
if (RelocInfo::IsOnlyForSerializer(rmode) &&
!options().record_reloc_info_for_serialization && !emit_debug_code()) {
return;
}
DCHECK_GE(buffer_space(), kMaxRelocSize); // Too late to grow buffer here.
reloc_info_writer.Write(&rinfo);
}
} }
......
...@@ -2086,13 +2086,7 @@ void Assembler::dp(uintptr_t data) { ...@@ -2086,13 +2086,7 @@ void Assembler::dp(uintptr_t data) {
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
if (options().disable_reloc_info_for_patching) return; if (!ShouldRecordRelocInfo(rmode)) return;
if (RelocInfo::IsNone(rmode) ||
// Don't record external references unless the heap will be serialized.
(RelocInfo::IsOnlyForSerializer(rmode) &&
!options().record_reloc_info_for_serialization && !emit_debug_code())) {
return;
}
DeferredRelocInfo rinfo(pc_offset(), rmode, data); DeferredRelocInfo rinfo(pc_offset(), rmode, data);
relocations_.push_back(rinfo); relocations_.push_back(rinfo);
} }
......
...@@ -812,13 +812,7 @@ void Assembler::dp(uintptr_t data) { ...@@ -812,13 +812,7 @@ void Assembler::dp(uintptr_t data) {
} }
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
if (options().disable_reloc_info_for_patching) return; if (!ShouldRecordRelocInfo(rmode)) return;
if (RelocInfo::IsNone(rmode) ||
// Don't record external references unless the heap will be serialized.
(RelocInfo::IsOnlyForSerializer(rmode) &&
!options().record_reloc_info_for_serialization && !emit_debug_code())) {
return;
}
DeferredRelocInfo rinfo(pc_offset(), rmode, data); DeferredRelocInfo rinfo(pc_offset(), rmode, data);
relocations_.push_back(rinfo); relocations_.push_back(rinfo);
} }
......
...@@ -5002,12 +5002,7 @@ void Assembler::dq(Label* label) { ...@@ -5002,12 +5002,7 @@ void Assembler::dq(Label* label) {
// Relocation information implementations. // Relocation information implementations.
void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
DCHECK(!RelocInfo::IsNone(rmode)); if (!ShouldRecordRelocInfo(rmode)) return;
if (options().disable_reloc_info_for_patching) return;
if (RelocInfo::IsOnlyForSerializer(rmode) &&
!options().record_reloc_info_for_serialization && !emit_debug_code()) {
return;
}
RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr); RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, nullptr);
reloc_info_writer.Write(&rinfo); reloc_info_writer.Write(&rinfo);
} }
......
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