Commit 55d2c08c authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[codegen] Rename deoptimization info in safepoints

The entries contain more than just deoptimization info. Thus rename them
to "entries" and use "EntryBuilder" instead of "DeoptimizationInfo".

Drive-by: Remove the redundant {emitted_} field, just check if
{offset_} was initialized.

R=jkummerow@chromium.org

Bug: v8:12401
Change-Id: Ifedc265dc27dd6817b731d9e24a1d8654edc99de
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3291310
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77985}
parent a302ee47
...@@ -80,15 +80,9 @@ void SafepointTable::PrintEntry(int index, std::ostream& os) const { ...@@ -80,15 +80,9 @@ void SafepointTable::PrintEntry(int index, std::ostream& os) const {
} }
Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler) { Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler) {
deoptimization_info_.push_back( entries_.push_back(EntryBuilder(zone_, assembler->pc_offset_for_safepoint()));
DeoptimizationInfo(zone_, assembler->pc_offset_for_safepoint())); EntryBuilder& new_entry = entries_.back();
DeoptimizationInfo& new_info = deoptimization_info_.back(); return Safepoint(new_entry.stack_indexes, &new_entry.register_indexes);
return Safepoint(new_info.stack_indexes, &new_info.register_indexes);
}
int SafepointTableBuilder::GetCodeOffset() const {
DCHECK(emitted_);
return offset_;
} }
int SafepointTableBuilder::UpdateDeoptimizationInfo(int pc, int trampoline, int SafepointTableBuilder::UpdateDeoptimizationInfo(int pc, int trampoline,
...@@ -96,9 +90,9 @@ int SafepointTableBuilder::UpdateDeoptimizationInfo(int pc, int trampoline, ...@@ -96,9 +90,9 @@ int SafepointTableBuilder::UpdateDeoptimizationInfo(int pc, int trampoline,
int deopt_index) { int deopt_index) {
DCHECK_NE(SafepointEntry::kNoTrampolinePC, trampoline); DCHECK_NE(SafepointEntry::kNoTrampolinePC, trampoline);
DCHECK_NE(SafepointEntry::kNoDeoptIndex, deopt_index); DCHECK_NE(SafepointEntry::kNoDeoptIndex, deopt_index);
auto it = deoptimization_info_.Find(start); auto it = entries_.Find(start);
DCHECK(std::any_of(it, deoptimization_info_.end(), DCHECK(std::any_of(it, entries_.end(),
[pc](auto& info) { return info.pc == pc; })); [pc](auto& entry) { return entry.pc == pc; }));
int index = start; int index = start;
while (it->pc != pc) ++it, ++index; while (it->pc != pc) ++it, ++index;
it->trampoline = trampoline; it->trampoline = trampoline;
...@@ -110,19 +104,19 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) { ...@@ -110,19 +104,19 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
#ifdef DEBUG #ifdef DEBUG
int last_pc = -1; int last_pc = -1;
int last_trampoline = -1; int last_trampoline = -1;
for (const DeoptimizationInfo& info : deoptimization_info_) { for (const EntryBuilder& entry : entries_) {
// Entries are ordered by PC. // Entries are ordered by PC.
DCHECK_LT(last_pc, info.pc); DCHECK_LT(last_pc, entry.pc);
last_pc = info.pc; last_pc = entry.pc;
// Trampoline PCs are increasing, and larger than regular PCs. // Trampoline PCs are increasing, and larger than regular PCs.
if (info.trampoline != SafepointEntry::kNoTrampolinePC) { if (entry.trampoline != SafepointEntry::kNoTrampolinePC) {
DCHECK_LT(last_trampoline, info.trampoline); DCHECK_LT(last_trampoline, entry.trampoline);
DCHECK_LT(deoptimization_info_.back().pc, info.trampoline); DCHECK_LT(entries_.back().pc, entry.trampoline);
last_trampoline = info.trampoline; last_trampoline = entry.trampoline;
} }
// An entry either has trampoline and deopt index, or none of the two. // An entry either has trampoline and deopt index, or none of the two.
DCHECK_EQ(info.trampoline == SafepointEntry::kNoTrampolinePC, DCHECK_EQ(entry.trampoline == SafepointEntry::kNoTrampolinePC,
info.deopt_index == SafepointEntry::kNoDeoptIndex); entry.deopt_index == SafepointEntry::kNoDeoptIndex);
} }
#endif // DEBUG #endif // DEBUG
...@@ -147,7 +141,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) { ...@@ -147,7 +141,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
STATIC_ASSERT(SafepointTable::kLengthOffset == 0 * kIntSize); STATIC_ASSERT(SafepointTable::kLengthOffset == 0 * kIntSize);
STATIC_ASSERT(SafepointTable::kEntrySizeOffset == 1 * kIntSize); STATIC_ASSERT(SafepointTable::kEntrySizeOffset == 1 * kIntSize);
STATIC_ASSERT(SafepointTable::kHeaderSize == 2 * kIntSize); STATIC_ASSERT(SafepointTable::kHeaderSize == 2 * kIntSize);
int length = static_cast<int>(deoptimization_info_.size()); int length = static_cast<int>(entries_.size());
assembler->dd(length); assembler->dd(length);
assembler->dd(bytes_per_entry); assembler->dd(bytes_per_entry);
...@@ -157,23 +151,23 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) { ...@@ -157,23 +151,23 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
STATIC_ASSERT(SafepointTable::kEncodedInfoOffset == 1 * kIntSize); STATIC_ASSERT(SafepointTable::kEncodedInfoOffset == 1 * kIntSize);
STATIC_ASSERT(SafepointTable::kTrampolinePcOffset == 2 * kIntSize); STATIC_ASSERT(SafepointTable::kTrampolinePcOffset == 2 * kIntSize);
STATIC_ASSERT(SafepointTable::kFixedEntrySize == 3 * kIntSize); STATIC_ASSERT(SafepointTable::kFixedEntrySize == 3 * kIntSize);
for (const DeoptimizationInfo& info : deoptimization_info_) { for (const EntryBuilder& entry : entries_) {
assembler->dd(info.pc); assembler->dd(entry.pc);
if (info.register_indexes) { if (entry.register_indexes) {
// We emit the register indexes in the same bits as the deopt_index. // We emit the register indexes in the same bits as the deopt_index.
// Register indexes and deopt_index should not exist at the same time. // Register indexes and deopt_index should not exist at the same time.
DCHECK_EQ(info.deopt_index, SafepointEntry::kNoDeoptIndex); DCHECK_EQ(entry.deopt_index, SafepointEntry::kNoDeoptIndex);
assembler->dd(info.register_indexes); assembler->dd(entry.register_indexes);
} else { } else {
assembler->dd(info.deopt_index); assembler->dd(entry.deopt_index);
} }
assembler->dd(info.trampoline); assembler->dd(entry.trampoline);
} }
// Emit table of bitmaps. // Emit table of bitmaps.
ZoneVector<uint8_t> bits(bytes_per_entry, 0, zone_); ZoneVector<uint8_t> bits(bytes_per_entry, 0, zone_);
for (const DeoptimizationInfo& info : deoptimization_info_) { for (const EntryBuilder& entry : entries_) {
ZoneChunkList<int>* indexes = info.stack_indexes; ZoneChunkList<int>* indexes = entry.stack_indexes;
std::fill(bits.begin(), bits.end(), 0); std::fill(bits.begin(), bits.end(), 0);
// Run through the indexes and build a bitmap. // Run through the indexes and build a bitmap.
...@@ -190,7 +184,6 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) { ...@@ -190,7 +184,6 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
assembler->db(bits[k]); assembler->db(bits[k]);
} }
} }
emitted_ = true;
} }
void SafepointTableBuilder::RemoveDuplicates() { void SafepointTableBuilder::RemoveDuplicates() {
...@@ -199,35 +192,35 @@ void SafepointTableBuilder::RemoveDuplicates() { ...@@ -199,35 +192,35 @@ void SafepointTableBuilder::RemoveDuplicates() {
// -1. This especially compacts the table for wasm code without tagged // -1. This especially compacts the table for wasm code without tagged
// pointers and without deoptimization info. // pointers and without deoptimization info.
if (deoptimization_info_.size() < 2) return; if (entries_.size() < 2) return;
// Check that all entries (1, size] are identical to entry 0. // Check that all entries (1, size] are identical to entry 0.
const DeoptimizationInfo& first_info = deoptimization_info_.front(); const EntryBuilder& first_entry = entries_.front();
auto is_identical_except_for_pc = [](const DeoptimizationInfo& info1, auto is_identical_except_for_pc = [](const EntryBuilder& entry1,
const DeoptimizationInfo& info2) { const EntryBuilder& entry2) {
if (info1.deopt_index != info2.deopt_index) return false; if (entry1.deopt_index != entry2.deopt_index) return false;
DCHECK_EQ(info1.trampoline, info2.trampoline); DCHECK_EQ(entry1.trampoline, entry2.trampoline);
ZoneChunkList<int>* indexes1 = info1.stack_indexes; ZoneChunkList<int>* indexes1 = entry1.stack_indexes;
ZoneChunkList<int>* indexes2 = info2.stack_indexes; ZoneChunkList<int>* indexes2 = entry2.stack_indexes;
if (indexes1->size() != indexes2->size()) return false; if (indexes1->size() != indexes2->size()) return false;
if (!std::equal(indexes1->begin(), indexes1->end(), indexes2->begin())) { if (!std::equal(indexes1->begin(), indexes1->end(), indexes2->begin())) {
return false; return false;
} }
if (info1.register_indexes != info2.register_indexes) return false; if (entry1.register_indexes != entry2.register_indexes) return false;
return true; return true;
}; };
if (std::all_of(deoptimization_info_.Find(1), deoptimization_info_.end(), if (std::all_of(entries_.Find(1), entries_.end(),
[&](const DeoptimizationInfo& info) { [&](const EntryBuilder& entry) {
return is_identical_except_for_pc(first_info, info); return is_identical_except_for_pc(first_entry, entry);
})) { })) {
// All entries were identical. Rewind the list to just one // All entries were identical. Rewind the list to just one
// entry, and set the pc to -1. // entry, and set the pc to -1.
deoptimization_info_.Rewind(1); entries_.Rewind(1);
deoptimization_info_.front().pc = -1; entries_.front().pc = -1;
} }
} }
...@@ -235,8 +228,8 @@ void SafepointTableBuilder::TrimEntries(int* bits_per_entry) { ...@@ -235,8 +228,8 @@ void SafepointTableBuilder::TrimEntries(int* bits_per_entry) {
int min_index = *bits_per_entry; int min_index = *bits_per_entry;
if (min_index == 0) return; // Early exit: nothing to trim. if (min_index == 0) return; // Early exit: nothing to trim.
for (auto& info : deoptimization_info_) { for (auto& entry : entries_) {
for (int idx : *info.stack_indexes) { for (int idx : *entry.stack_indexes) {
DCHECK_GT(*bits_per_entry, idx); // Validity check. DCHECK_GT(*bits_per_entry, idx); // Validity check.
if (idx >= min_index) continue; if (idx >= min_index) continue;
if (idx == 0) return; // Early exit: nothing to trim. if (idx == 0) return; // Early exit: nothing to trim.
...@@ -246,8 +239,8 @@ void SafepointTableBuilder::TrimEntries(int* bits_per_entry) { ...@@ -246,8 +239,8 @@ void SafepointTableBuilder::TrimEntries(int* bits_per_entry) {
DCHECK_LT(0, min_index); DCHECK_LT(0, min_index);
*bits_per_entry -= min_index; *bits_per_entry -= min_index;
for (auto& info : deoptimization_info_) { for (auto& entry : entries_) {
for (int& idx : *info.stack_indexes) { for (int& idx : *entry.stack_indexes) {
idx -= min_index; idx -= min_index;
} }
} }
......
...@@ -211,16 +211,18 @@ class Safepoint { ...@@ -211,16 +211,18 @@ class Safepoint {
class SafepointTableBuilder { class SafepointTableBuilder {
public: public:
explicit SafepointTableBuilder(Zone* zone) explicit SafepointTableBuilder(Zone* zone) : entries_(zone), zone_(zone) {}
: deoptimization_info_(zone),
emitted_(false),
zone_(zone) {}
SafepointTableBuilder(const SafepointTableBuilder&) = delete; SafepointTableBuilder(const SafepointTableBuilder&) = delete;
SafepointTableBuilder& operator=(const SafepointTableBuilder&) = delete; SafepointTableBuilder& operator=(const SafepointTableBuilder&) = delete;
bool emitted() const { return offset_ != -1; }
// Get the offset of the emitted safepoint table in the code. // Get the offset of the emitted safepoint table in the code.
int GetCodeOffset() const; int GetCodeOffset() const {
DCHECK(emitted());
return offset_;
}
// Define a new safepoint for the current position in the body. // Define a new safepoint for the current position in the body.
Safepoint DefineSafepoint(Assembler* assembler); Safepoint DefineSafepoint(Assembler* assembler);
...@@ -237,13 +239,13 @@ class SafepointTableBuilder { ...@@ -237,13 +239,13 @@ class SafepointTableBuilder {
int deopt_index); int deopt_index);
private: private:
struct DeoptimizationInfo { struct EntryBuilder {
int pc; int pc;
int deopt_index; int deopt_index;
int trampoline; int trampoline;
ZoneChunkList<int>* stack_indexes; ZoneChunkList<int>* stack_indexes;
uint32_t register_indexes; uint32_t register_indexes;
DeoptimizationInfo(Zone* zone, int pc) EntryBuilder(Zone* zone, int pc)
: pc(pc), : pc(pc),
deopt_index(SafepointEntry::kNoDeoptIndex), deopt_index(SafepointEntry::kNoDeoptIndex),
trampoline(SafepointEntry::kNoTrampolinePC), trampoline(SafepointEntry::kNoTrampolinePC),
...@@ -259,10 +261,9 @@ class SafepointTableBuilder { ...@@ -259,10 +261,9 @@ class SafepointTableBuilder {
// {bits_per_entry}). // {bits_per_entry}).
void TrimEntries(int* bits_per_entry); void TrimEntries(int* bits_per_entry);
ZoneChunkList<DeoptimizationInfo> deoptimization_info_; ZoneChunkList<EntryBuilder> entries_;
int offset_; int offset_ = -1;
bool emitted_;
Zone* zone_; Zone* zone_;
}; };
......
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