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

Avoid emitting redundant safepoint info

Before emitting the safepoint table, remove consecutive identical
entries (idential except for the pc of course). The lookup then
searches for the last entry whose pc is <= the wanted pc.
The lookup procedure can still be optimized to use binary search
laster.

This change decreases code size for wasm by 27.6% (on the unity
benchmark).

BUG=v8:6434

Change-Id: I03481721fe666cd2c50a383380c74b06edf39106
Reviewed-on: https://chromium-review.googlesource.com/512542
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45491}
parent 6128f2cf
......@@ -52,7 +52,12 @@ SafepointTable::SafepointTable(Code* code) {
SafepointEntry SafepointTable::FindEntry(Address pc) const {
unsigned pc_offset = static_cast<unsigned>(pc - code_->instruction_start());
for (unsigned i = 0; i < length(); i++) {
// We use kMaxUInt32 as sentinel value, so check that we don't hit that.
DCHECK_NE(kMaxUInt32, pc_offset);
unsigned len = length();
// If pc == kMaxUInt32, then this entry covers all call sites in the function.
if (len == 1 && GetPcOffset(0) == kMaxUInt32) return GetEntry(0);
for (unsigned i = 0; i < len; i++) {
// TODO(kasperl): Replace the linear search with binary search.
if (GetPcOffset(i) == pc_offset) return GetEntry(i);
}
......@@ -137,6 +142,8 @@ unsigned SafepointTableBuilder::GetCodeOffset() const {
void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
RemoveDuplicates();
// Make sure the safepoint table is properly aligned. Pad with nops.
assembler->Align(kIntSize);
assembler->RecordComment(";;; Safepoint table.");
......@@ -211,6 +218,56 @@ uint32_t SafepointTableBuilder::EncodeExceptPC(const DeoptimizationInfo& info,
return encoding;
}
void SafepointTableBuilder::RemoveDuplicates() {
int length = deoptimization_info_.length();
DCHECK_EQ(length, deopt_index_list_.length());
DCHECK_EQ(length, indexes_.length());
DCHECK_EQ(length, registers_.length());
if (length < 2) return;
for (int i = 1; i < length; ++i) {
if (!IsIdenticalExceptForPc(0, i)) return;
}
// If we get here, all entries were identical. Rewind all lists to just one
// entry, and set the pc to kMaxUInt32.
deoptimization_info_.Rewind(1);
deopt_index_list_.Rewind(1);
indexes_.Rewind(1);
registers_.Rewind(1);
deoptimization_info_[0].pc = kMaxUInt32;
}
bool SafepointTableBuilder::IsIdenticalExceptForPc(int index1,
int index2) const {
DeoptimizationInfo& deopt_info_1 = deoptimization_info_[index1];
DeoptimizationInfo& deopt_info_2 = deoptimization_info_[index2];
if (deopt_info_1.arguments != deopt_info_2.arguments) return false;
if (deopt_info_1.has_doubles != deopt_info_2.has_doubles) return false;
if (deopt_index_list_[index1] != deopt_index_list_[index2]) return false;
ZoneList<int>* indexes1 = indexes_[index1];
ZoneList<int>* indexes2 = indexes_[index2];
if (indexes1->length() != indexes2->length()) return false;
for (int i = 0; i < indexes1->length(); ++i) {
if (indexes1->at(i) != indexes2->at(i)) return false;
}
ZoneList<int>* registers1 = registers_[index1];
ZoneList<int>* registers2 = registers_[index2];
if (registers1) {
if (registers1->length() != registers2->length()) return false;
for (int i = 0; i < registers1->length(); ++i) {
if (registers1->at(i) != registers2->at(i)) return false;
}
} else if (registers2) {
return false;
}
return true;
}
} // namespace internal
} // namespace v8
......@@ -217,6 +217,10 @@ class SafepointTableBuilder BASE_EMBEDDED {
uint32_t EncodeExceptPC(const DeoptimizationInfo& info, unsigned index);
bool IsIdenticalExceptForPc(int index1, int index2) const;
// If all entries are identical, replace them by 1 entry with pc = kMaxUInt32.
void RemoveDuplicates();
ZoneList<DeoptimizationInfo> deoptimization_info_;
ZoneList<unsigned> deopt_index_list_;
ZoneList<ZoneList<int>*> indexes_;
......
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