Commit cc2a4461 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[codegen] Trim safepoints by removing trailing zeros

This saves quite some code space on wasm functions, which often do not
spill any tagged values (hence the safepoints will just be empty). It
also often saves a few bytes on code that actually spills tagged values,
but not to the highest frame slots.

R=jkummerow@chromium.org

Bug: v8:11630
Change-Id: I3bd77b3afcd2cf86a92ce5b302b5aa06ec0ed223
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2831873Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74043}
parent b681c309
......@@ -111,6 +111,7 @@ int SafepointTableBuilder::UpdateDeoptimizationInfo(int pc, int trampoline,
void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
RemoveDuplicates();
TrimEntries(&bits_per_entry);
// Make sure the safepoint table is properly aligned. Pad with nops.
assembler->Align(Code::kMetadataAlignment);
......@@ -157,6 +158,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
// Run through the indexes and build a bitmap.
for (int idx : *indexes) {
DCHECK_GT(bits_per_entry, idx);
int index = bits_per_entry - 1 - idx;
int byte_index = index >> kBitsPerByteLog2;
int bit_index = index & (kBitsPerByte - 1);
......@@ -192,6 +194,28 @@ void SafepointTableBuilder::RemoveDuplicates() {
deoptimization_info_.front().pc = kMaxUInt32;
}
void SafepointTableBuilder::TrimEntries(int* bits_per_entry) {
int min_index = *bits_per_entry;
if (min_index == 0) return; // Early exit: nothing to trim.
for (auto& info : deoptimization_info_) {
for (int idx : *info.stack_indexes) {
DCHECK_GT(*bits_per_entry, idx); // Validity check.
if (idx >= min_index) continue;
if (idx == 0) return; // Early exit: nothing to trim.
min_index = idx;
}
}
DCHECK_LT(0, min_index);
*bits_per_entry -= min_index;
for (auto& info : deoptimization_info_) {
for (int& idx : *info.stack_indexes) {
idx -= min_index;
}
}
}
bool SafepointTableBuilder::IsIdenticalExceptForPc(
const DeoptimizationInfo& info1, const DeoptimizationInfo& info2) const {
if (info1.deopt_index != info2.deopt_index) return false;
......
......@@ -263,6 +263,10 @@ class SafepointTableBuilder {
// If all entries are identical, replace them by 1 entry with pc = kMaxUInt32.
void RemoveDuplicates();
// Try to trim entries by removing trailing zeros (and shrinking
// {bits_per_entry}).
void TrimEntries(int* bits_per_entry);
ZoneChunkList<DeoptimizationInfo> deoptimization_info_;
unsigned offset_;
......
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