Commit 581b7c88 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[codegen][cleanup] Switch safepoint fields to int

Many callers already pass an int, so there is no point in storing as an
uint32_t internally. The style guide also recommends int as the general
data type for integers, even if it's statically known that only positive
values will occur.

R=jkummerow@chromium.org

Bug: v8:12401
Change-Id: I6067139f514895f925d1c536112b4cb5c2c24a36
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3289157
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77975}
parent ff05fe59
...@@ -37,8 +37,8 @@ SafepointTable::SafepointTable(Address instruction_start, ...@@ -37,8 +37,8 @@ SafepointTable::SafepointTable(Address instruction_start,
length_(ReadLength(safepoint_table_address)), length_(ReadLength(safepoint_table_address)),
entry_size_(ReadEntrySize(safepoint_table_address)) {} entry_size_(ReadEntrySize(safepoint_table_address)) {}
unsigned SafepointTable::find_return_pc(unsigned pc_offset) { int SafepointTable::find_return_pc(int pc_offset) {
for (unsigned i = 0; i < length(); i++) { for (int i = 0; i < length(); i++) {
if (GetTrampolinePcOffset(i) == static_cast<int>(pc_offset)) { if (GetTrampolinePcOffset(i) == static_cast<int>(pc_offset)) {
return GetPcOffset(i); return GetPcOffset(i);
} else if (GetPcOffset(i) == pc_offset) { } else if (GetPcOffset(i) == pc_offset) {
...@@ -49,14 +49,13 @@ unsigned SafepointTable::find_return_pc(unsigned pc_offset) { ...@@ -49,14 +49,13 @@ unsigned SafepointTable::find_return_pc(unsigned pc_offset) {
} }
SafepointEntry SafepointTable::FindEntry(Address pc) const { SafepointEntry SafepointTable::FindEntry(Address pc) const {
unsigned pc_offset = static_cast<unsigned>(pc - instruction_start_); int pc_offset = static_cast<int>(pc - instruction_start_);
// We use kMaxUInt32 as sentinel value, so check that we don't hit that. // We use kMaxUInt32 as sentinel value, so check that we don't hit that.
DCHECK_NE(kMaxUInt32, pc_offset); DCHECK_NE(kMaxUInt32, pc_offset);
unsigned len = length(); CHECK_LT(0, length_);
CHECK_GT(len, 0); // A single entry with pc == -1 covers all call sites in the function.
// If pc == kMaxUInt32, then this entry covers all call sites in the function. if (length_ == 1 && GetPcOffset(0) == -1) return GetEntry(0);
if (len == 1 && GetPcOffset(0) == kMaxUInt32) return GetEntry(0); for (int i = 0; i < length_; i++) {
for (unsigned i = 0; i < len; i++) {
// TODO(kasperl): Replace the linear search with binary search. // TODO(kasperl): Replace the linear search with binary search.
if (GetPcOffset(i) == pc_offset || if (GetPcOffset(i) == pc_offset ||
(has_deopt_ && (has_deopt_ &&
...@@ -67,17 +66,15 @@ SafepointEntry SafepointTable::FindEntry(Address pc) const { ...@@ -67,17 +66,15 @@ SafepointEntry SafepointTable::FindEntry(Address pc) const {
UNREACHABLE(); UNREACHABLE();
} }
void SafepointTable::PrintEntry(unsigned index, std::ostream& os) const { void SafepointTable::PrintEntry(int index, std::ostream& os) const {
disasm::NameConverter converter; disasm::NameConverter converter;
SafepointEntry entry = GetEntry(index); SafepointEntry entry = GetEntry(index);
uint8_t* bits = entry.bits(); uint8_t* bits = entry.bits();
// Print the stack slot bits. // Print the stack slot bits.
if (entry_size_ > 0) { for (int i = 0; i < entry_size_; ++i) {
for (uint32_t i = 0; i < entry_size_; ++i) { for (int bit = 0; bit < kBitsPerByte; ++bit) {
for (int bit = 0; bit < kBitsPerByte; ++bit) { os << ((bits[i] & (1 << bit)) ? "1" : "0");
os << ((bits[i] & (1 << bit)) ? "1" : "0");
}
} }
} }
} }
...@@ -89,18 +86,18 @@ Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler) { ...@@ -89,18 +86,18 @@ Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler) {
return Safepoint(new_info.stack_indexes, &new_info.register_indexes); return Safepoint(new_info.stack_indexes, &new_info.register_indexes);
} }
unsigned SafepointTableBuilder::GetCodeOffset() const { int SafepointTableBuilder::GetCodeOffset() const {
DCHECK(emitted_); DCHECK(emitted_);
return offset_; return offset_;
} }
int SafepointTableBuilder::UpdateDeoptimizationInfo(int pc, int trampoline, int SafepointTableBuilder::UpdateDeoptimizationInfo(int pc, int trampoline,
int start, int start,
unsigned deopt_index) { int deopt_index) {
int index = start; int index = start;
for (auto it = deoptimization_info_.Find(start); for (auto it = deoptimization_info_.Find(start);
it != deoptimization_info_.end(); it++, index++) { it != deoptimization_info_.end(); it++, index++) {
if (static_cast<int>(it->pc) == pc) { if (it->pc == pc) {
it->trampoline = trampoline; it->trampoline = trampoline;
it->deopt_index = deopt_index; it->deopt_index = deopt_index;
return index; return index;
...@@ -146,8 +143,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) { ...@@ -146,8 +143,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
if (info.register_indexes) { if (info.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, DCHECK_EQ(info.deopt_index, Safepoint::kNoDeoptimizationIndex);
static_cast<uint32_t>(Safepoint::kNoDeoptimizationIndex));
assembler->dd(info.register_indexes); assembler->dd(info.register_indexes);
} else { } else {
assembler->dd(info.deopt_index); assembler->dd(info.deopt_index);
...@@ -181,7 +177,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) { ...@@ -181,7 +177,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
void SafepointTableBuilder::RemoveDuplicates() { void SafepointTableBuilder::RemoveDuplicates() {
// If the table contains more than one entry, and all entries are identical // If the table contains more than one entry, and all entries are identical
// (except for the pc), replace the whole table by a single entry with pc = // (except for the pc), replace the whole table by a single entry with pc =
// kMaxUInt32. 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 (deoptimization_info_.size() < 2) return;
...@@ -194,9 +190,9 @@ void SafepointTableBuilder::RemoveDuplicates() { ...@@ -194,9 +190,9 @@ void SafepointTableBuilder::RemoveDuplicates() {
} }
// If we get here, all entries were identical. Rewind the list to just one // If we get here, all entries were identical. Rewind the list to just one
// entry, and set the pc to kMaxUInt32. // entry, and set the pc to -1.
deoptimization_info_.Rewind(1); deoptimization_info_.Rewind(1);
deoptimization_info_.front().pc = kMaxUInt32; deoptimization_info_.front().pc = -1;
} }
void SafepointTableBuilder::TrimEntries(int* bits_per_entry) { void SafepointTableBuilder::TrimEntries(int* bits_per_entry) {
......
...@@ -24,7 +24,7 @@ class SafepointEntry { ...@@ -24,7 +24,7 @@ class SafepointEntry {
public: public:
SafepointEntry() = default; SafepointEntry() = default;
SafepointEntry(unsigned deopt_index, uint8_t* bits, uint8_t* bits_end, SafepointEntry(int deopt_index, uint8_t* bits, uint8_t* bits_end,
int trampoline_pc) int trampoline_pc)
: deopt_index_(deopt_index), : deopt_index_(deopt_index),
bits_(bits), bits_(bits),
...@@ -47,7 +47,7 @@ class SafepointEntry { ...@@ -47,7 +47,7 @@ class SafepointEntry {
int trampoline_pc() { return trampoline_pc_; } int trampoline_pc() { return trampoline_pc_; }
static const unsigned kNoDeoptIndex = kMaxUInt32; static constexpr int kNoDeoptIndex = -1;
static constexpr int kNoTrampolinePC = -1; static constexpr int kNoTrampolinePC = -1;
int deoptimization_index() const { int deoptimization_index() const {
...@@ -84,10 +84,9 @@ class SafepointEntry { ...@@ -84,10 +84,9 @@ class SafepointEntry {
size_t entry_size() const { return bits_end_ - bits_; } size_t entry_size() const { return bits_end_ - bits_; }
private: private:
uint32_t deopt_index_ = 0; int deopt_index_ = 0;
uint8_t* bits_ = nullptr; uint8_t* bits_ = nullptr;
uint8_t* bits_end_ = nullptr; uint8_t* bits_end_ = nullptr;
// It needs to be an integer as it is -1 for eager deoptimizations.
int trampoline_pc_ = kNoTrampolinePC; int trampoline_pc_ = kNoTrampolinePC;
}; };
...@@ -106,25 +105,24 @@ class SafepointTable { ...@@ -106,25 +105,24 @@ class SafepointTable {
int size() const { int size() const {
return kHeaderSize + (length_ * (kFixedEntrySize + entry_size_)); return kHeaderSize + (length_ * (kFixedEntrySize + entry_size_));
} }
unsigned length() const { return length_; } int length() const { return length_; }
unsigned entry_size() const { return entry_size_; } int entry_size() const { return entry_size_; }
unsigned GetPcOffset(unsigned index) const { int GetPcOffset(int index) const {
DCHECK(index < length_); DCHECK_GT(length_, index);
return base::Memory<uint32_t>(GetPcOffsetLocation(index)); return base::Memory<int>(GetPcOffsetLocation(index));
} }
int GetTrampolinePcOffset(unsigned index) const { int GetTrampolinePcOffset(int index) const {
DCHECK(index < length_); DCHECK_GT(length_, index);
return base::Memory<int>(GetTrampolineLocation(index)); return base::Memory<int>(GetTrampolineLocation(index));
} }
unsigned find_return_pc(unsigned pc_offset); int find_return_pc(int pc_offset);
SafepointEntry GetEntry(unsigned index) const { SafepointEntry GetEntry(int index) const {
DCHECK(index < length_); DCHECK_GT(length_, index);
unsigned deopt_index = int deopt_index = base::Memory<int>(GetEncodedInfoLocation(index));
base::Memory<uint32_t>(GetEncodedInfoLocation(index));
uint8_t* bits = &base::Memory<uint8_t>(entries() + (index * entry_size_)); uint8_t* bits = &base::Memory<uint8_t>(entries() + (index * entry_size_));
int trampoline_pc = has_deopt_ int trampoline_pc = has_deopt_
? base::Memory<int>(GetTrampolineLocation(index)) ? base::Memory<int>(GetTrampolineLocation(index))
...@@ -135,7 +133,7 @@ class SafepointTable { ...@@ -135,7 +133,7 @@ class SafepointTable {
// Returns the entry for the given pc. // Returns the entry for the given pc.
SafepointEntry FindEntry(Address pc) const; SafepointEntry FindEntry(Address pc) const;
void PrintEntry(unsigned index, std::ostream& os) const; void PrintEntry(int index, std::ostream& os) const;
private: private:
SafepointTable(Address instruction_start, Address safepoint_table_address, SafepointTable(Address instruction_start, Address safepoint_table_address,
...@@ -152,11 +150,11 @@ class SafepointTable { ...@@ -152,11 +150,11 @@ class SafepointTable {
static const int kTrampolinePcOffset = kEncodedInfoOffset + kIntSize; static const int kTrampolinePcOffset = kEncodedInfoOffset + kIntSize;
static const int kFixedEntrySize = kTrampolinePcOffset + kIntSize; static const int kFixedEntrySize = kTrampolinePcOffset + kIntSize;
static uint32_t ReadLength(Address table) { static int ReadLength(Address table) {
return base::Memory<uint32_t>(table + kLengthOffset); return base::Memory<int>(table + kLengthOffset);
} }
static uint32_t ReadEntrySize(Address table) { static int ReadEntrySize(Address table) {
return base::Memory<uint32_t>(table + kEntrySizeOffset); return base::Memory<int>(table + kEntrySizeOffset);
} }
Address pc_and_deoptimization_indexes() const { Address pc_and_deoptimization_indexes() const {
return safepoint_table_address_ + kHeaderSize; return safepoint_table_address_ + kHeaderSize;
...@@ -165,15 +163,15 @@ class SafepointTable { ...@@ -165,15 +163,15 @@ class SafepointTable {
return safepoint_table_address_ + kHeaderSize + (length_ * kFixedEntrySize); return safepoint_table_address_ + kHeaderSize + (length_ * kFixedEntrySize);
} }
Address GetPcOffsetLocation(unsigned index) const { Address GetPcOffsetLocation(int index) const {
return pc_and_deoptimization_indexes() + (index * kFixedEntrySize); return pc_and_deoptimization_indexes() + (index * kFixedEntrySize);
} }
Address GetEncodedInfoLocation(unsigned index) const { Address GetEncodedInfoLocation(int index) const {
return GetPcOffsetLocation(index) + kEncodedInfoOffset; return GetPcOffsetLocation(index) + kEncodedInfoOffset;
} }
Address GetTrampolineLocation(unsigned index) const { Address GetTrampolineLocation(int index) const {
return GetPcOffsetLocation(index) + kTrampolinePcOffset; return GetPcOffsetLocation(index) + kTrampolinePcOffset;
} }
...@@ -184,8 +182,8 @@ class SafepointTable { ...@@ -184,8 +182,8 @@ class SafepointTable {
// Safepoint table layout. // Safepoint table layout.
const Address safepoint_table_address_; const Address safepoint_table_address_;
const uint32_t length_; const int length_;
const uint32_t entry_size_; const int entry_size_;
friend class SafepointTableBuilder; friend class SafepointTableBuilder;
friend class SafepointEntry; friend class SafepointEntry;
...@@ -224,7 +222,7 @@ class SafepointTableBuilder { ...@@ -224,7 +222,7 @@ class SafepointTableBuilder {
SafepointTableBuilder& operator=(const SafepointTableBuilder&) = delete; SafepointTableBuilder& operator=(const SafepointTableBuilder&) = delete;
// Get the offset of the emitted safepoint table in the code. // Get the offset of the emitted safepoint table in the code.
unsigned GetCodeOffset() const; int GetCodeOffset() const;
// 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);
...@@ -238,16 +236,16 @@ class SafepointTableBuilder { ...@@ -238,16 +236,16 @@ class SafepointTableBuilder {
// table contains the trampoline PC {trampoline} that replaced the // table contains the trampoline PC {trampoline} that replaced the
// return PC {pc} on the stack. // return PC {pc} on the stack.
int UpdateDeoptimizationInfo(int pc, int trampoline, int start, int UpdateDeoptimizationInfo(int pc, int trampoline, int start,
unsigned deopt_index); int deopt_index);
private: private:
struct DeoptimizationInfo { struct DeoptimizationInfo {
unsigned pc; int pc;
unsigned 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, unsigned pc) DeoptimizationInfo(Zone* zone, int pc)
: pc(pc), : pc(pc),
deopt_index(Safepoint::kNoDeoptimizationIndex), deopt_index(Safepoint::kNoDeoptimizationIndex),
trampoline(-1), trampoline(-1),
...@@ -269,7 +267,7 @@ class SafepointTableBuilder { ...@@ -269,7 +267,7 @@ class SafepointTableBuilder {
ZoneChunkList<DeoptimizationInfo> deoptimization_info_; ZoneChunkList<DeoptimizationInfo> deoptimization_info_;
unsigned offset_; int offset_;
bool emitted_; bool emitted_;
Zone* zone_; Zone* zone_;
......
...@@ -586,8 +586,8 @@ void Code::Disassemble(const char* name, std::ostream& os, Isolate* isolate, ...@@ -586,8 +586,8 @@ void Code::Disassemble(const char* name, std::ostream& os, Isolate* isolate,
if (has_safepoint_info()) { if (has_safepoint_info()) {
SafepointTable table(isolate, current_pc, *this); SafepointTable table(isolate, current_pc, *this);
os << "Safepoints (size = " << table.size() << ")\n"; os << "Safepoints (size = " << table.size() << ")\n";
for (unsigned i = 0; i < table.length(); i++) { for (int i = 0; i < table.length(); i++) {
unsigned pc_offset = table.GetPcOffset(i); int pc_offset = table.GetPcOffset(i);
os << reinterpret_cast<const void*>(InstructionStart() + pc_offset) os << reinterpret_cast<const void*>(InstructionStart() + pc_offset)
<< " "; << " ";
os << std::setw(6) << std::hex << pc_offset << " " << std::setw(4); os << std::setw(6) << std::hex << pc_offset << " " << std::setw(4);
......
...@@ -437,8 +437,8 @@ void WasmCode::Disassemble(const char* name, std::ostream& os, ...@@ -437,8 +437,8 @@ void WasmCode::Disassemble(const char* name, std::ostream& os,
if (safepoint_table_offset_ > 0) { if (safepoint_table_offset_ > 0) {
SafepointTable table(this); SafepointTable table(this);
os << "Safepoints (size = " << table.size() << ")\n"; os << "Safepoints (size = " << table.size() << ")\n";
for (uint32_t i = 0; i < table.length(); i++) { for (int i = 0; i < table.length(); i++) {
uintptr_t pc_offset = table.GetPcOffset(i); int pc_offset = table.GetPcOffset(i);
os << reinterpret_cast<const void*>(instruction_start() + pc_offset); os << reinterpret_cast<const void*>(instruction_start() + pc_offset);
os << std::setw(6) << std::hex << pc_offset << " " << std::dec; os << std::setw(6) << std::hex << pc_offset << " " << std::dec;
table.PrintEntry(i, os); table.PrintEntry(i, os);
......
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