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,
length_(ReadLength(safepoint_table_address)),
entry_size_(ReadEntrySize(safepoint_table_address)) {}
unsigned SafepointTable::find_return_pc(unsigned pc_offset) {
for (unsigned i = 0; i < length(); i++) {
int SafepointTable::find_return_pc(int pc_offset) {
for (int i = 0; i < length(); i++) {
if (GetTrampolinePcOffset(i) == static_cast<int>(pc_offset)) {
return GetPcOffset(i);
} else if (GetPcOffset(i) == pc_offset) {
......@@ -49,14 +49,13 @@ unsigned SafepointTable::find_return_pc(unsigned pc_offset) {
}
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.
DCHECK_NE(kMaxUInt32, pc_offset);
unsigned len = length();
CHECK_GT(len, 0);
// 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++) {
CHECK_LT(0, length_);
// A single entry with pc == -1 covers all call sites in the function.
if (length_ == 1 && GetPcOffset(0) == -1) return GetEntry(0);
for (int i = 0; i < length_; i++) {
// TODO(kasperl): Replace the linear search with binary search.
if (GetPcOffset(i) == pc_offset ||
(has_deopt_ &&
......@@ -67,17 +66,15 @@ SafepointEntry SafepointTable::FindEntry(Address pc) const {
UNREACHABLE();
}
void SafepointTable::PrintEntry(unsigned index, std::ostream& os) const {
void SafepointTable::PrintEntry(int index, std::ostream& os) const {
disasm::NameConverter converter;
SafepointEntry entry = GetEntry(index);
uint8_t* bits = entry.bits();
// Print the stack slot bits.
if (entry_size_ > 0) {
for (uint32_t i = 0; i < entry_size_; ++i) {
for (int bit = 0; bit < kBitsPerByte; ++bit) {
os << ((bits[i] & (1 << bit)) ? "1" : "0");
}
for (int i = 0; i < entry_size_; ++i) {
for (int bit = 0; bit < kBitsPerByte; ++bit) {
os << ((bits[i] & (1 << bit)) ? "1" : "0");
}
}
}
......@@ -89,18 +86,18 @@ Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler) {
return Safepoint(new_info.stack_indexes, &new_info.register_indexes);
}
unsigned SafepointTableBuilder::GetCodeOffset() const {
int SafepointTableBuilder::GetCodeOffset() const {
DCHECK(emitted_);
return offset_;
}
int SafepointTableBuilder::UpdateDeoptimizationInfo(int pc, int trampoline,
int start,
unsigned deopt_index) {
int deopt_index) {
int index = start;
for (auto it = deoptimization_info_.Find(start);
it != deoptimization_info_.end(); it++, index++) {
if (static_cast<int>(it->pc) == pc) {
if (it->pc == pc) {
it->trampoline = trampoline;
it->deopt_index = deopt_index;
return index;
......@@ -146,8 +143,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
if (info.register_indexes) {
// 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.
DCHECK_EQ(info.deopt_index,
static_cast<uint32_t>(Safepoint::kNoDeoptimizationIndex));
DCHECK_EQ(info.deopt_index, Safepoint::kNoDeoptimizationIndex);
assembler->dd(info.register_indexes);
} else {
assembler->dd(info.deopt_index);
......@@ -181,7 +177,7 @@ void SafepointTableBuilder::Emit(Assembler* assembler, int bits_per_entry) {
void SafepointTableBuilder::RemoveDuplicates() {
// 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 =
// 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.
if (deoptimization_info_.size() < 2) return;
......@@ -194,9 +190,9 @@ void SafepointTableBuilder::RemoveDuplicates() {
}
// 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_.front().pc = kMaxUInt32;
deoptimization_info_.front().pc = -1;
}
void SafepointTableBuilder::TrimEntries(int* bits_per_entry) {
......
......@@ -24,7 +24,7 @@ class SafepointEntry {
public:
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)
: deopt_index_(deopt_index),
bits_(bits),
......@@ -47,7 +47,7 @@ class SafepointEntry {
int trampoline_pc() { return trampoline_pc_; }
static const unsigned kNoDeoptIndex = kMaxUInt32;
static constexpr int kNoDeoptIndex = -1;
static constexpr int kNoTrampolinePC = -1;
int deoptimization_index() const {
......@@ -84,10 +84,9 @@ class SafepointEntry {
size_t entry_size() const { return bits_end_ - bits_; }
private:
uint32_t deopt_index_ = 0;
int deopt_index_ = 0;
uint8_t* bits_ = nullptr;
uint8_t* bits_end_ = nullptr;
// It needs to be an integer as it is -1 for eager deoptimizations.
int trampoline_pc_ = kNoTrampolinePC;
};
......@@ -106,25 +105,24 @@ class SafepointTable {
int size() const {
return kHeaderSize + (length_ * (kFixedEntrySize + entry_size_));
}
unsigned length() const { return length_; }
unsigned entry_size() const { return entry_size_; }
int length() const { return length_; }
int entry_size() const { return entry_size_; }
unsigned GetPcOffset(unsigned index) const {
DCHECK(index < length_);
return base::Memory<uint32_t>(GetPcOffsetLocation(index));
int GetPcOffset(int index) const {
DCHECK_GT(length_, index);
return base::Memory<int>(GetPcOffsetLocation(index));
}
int GetTrampolinePcOffset(unsigned index) const {
DCHECK(index < length_);
int GetTrampolinePcOffset(int index) const {
DCHECK_GT(length_, 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 {
DCHECK(index < length_);
unsigned deopt_index =
base::Memory<uint32_t>(GetEncodedInfoLocation(index));
SafepointEntry GetEntry(int index) const {
DCHECK_GT(length_, index);
int deopt_index = base::Memory<int>(GetEncodedInfoLocation(index));
uint8_t* bits = &base::Memory<uint8_t>(entries() + (index * entry_size_));
int trampoline_pc = has_deopt_
? base::Memory<int>(GetTrampolineLocation(index))
......@@ -135,7 +133,7 @@ class SafepointTable {
// Returns the entry for the given pc.
SafepointEntry FindEntry(Address pc) const;
void PrintEntry(unsigned index, std::ostream& os) const;
void PrintEntry(int index, std::ostream& os) const;
private:
SafepointTable(Address instruction_start, Address safepoint_table_address,
......@@ -152,11 +150,11 @@ class SafepointTable {
static const int kTrampolinePcOffset = kEncodedInfoOffset + kIntSize;
static const int kFixedEntrySize = kTrampolinePcOffset + kIntSize;
static uint32_t ReadLength(Address table) {
return base::Memory<uint32_t>(table + kLengthOffset);
static int ReadLength(Address table) {
return base::Memory<int>(table + kLengthOffset);
}
static uint32_t ReadEntrySize(Address table) {
return base::Memory<uint32_t>(table + kEntrySizeOffset);
static int ReadEntrySize(Address table) {
return base::Memory<int>(table + kEntrySizeOffset);
}
Address pc_and_deoptimization_indexes() const {
return safepoint_table_address_ + kHeaderSize;
......@@ -165,15 +163,15 @@ class SafepointTable {
return safepoint_table_address_ + kHeaderSize + (length_ * kFixedEntrySize);
}
Address GetPcOffsetLocation(unsigned index) const {
Address GetPcOffsetLocation(int index) const {
return pc_and_deoptimization_indexes() + (index * kFixedEntrySize);
}
Address GetEncodedInfoLocation(unsigned index) const {
Address GetEncodedInfoLocation(int index) const {
return GetPcOffsetLocation(index) + kEncodedInfoOffset;
}
Address GetTrampolineLocation(unsigned index) const {
Address GetTrampolineLocation(int index) const {
return GetPcOffsetLocation(index) + kTrampolinePcOffset;
}
......@@ -184,8 +182,8 @@ class SafepointTable {
// Safepoint table layout.
const Address safepoint_table_address_;
const uint32_t length_;
const uint32_t entry_size_;
const int length_;
const int entry_size_;
friend class SafepointTableBuilder;
friend class SafepointEntry;
......@@ -224,7 +222,7 @@ class SafepointTableBuilder {
SafepointTableBuilder& operator=(const SafepointTableBuilder&) = delete;
// 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.
Safepoint DefineSafepoint(Assembler* assembler);
......@@ -238,16 +236,16 @@ class SafepointTableBuilder {
// table contains the trampoline PC {trampoline} that replaced the
// return PC {pc} on the stack.
int UpdateDeoptimizationInfo(int pc, int trampoline, int start,
unsigned deopt_index);
int deopt_index);
private:
struct DeoptimizationInfo {
unsigned pc;
unsigned deopt_index;
int pc;
int deopt_index;
int trampoline;
ZoneChunkList<int>* stack_indexes;
uint32_t register_indexes;
DeoptimizationInfo(Zone* zone, unsigned pc)
DeoptimizationInfo(Zone* zone, int pc)
: pc(pc),
deopt_index(Safepoint::kNoDeoptimizationIndex),
trampoline(-1),
......@@ -269,7 +267,7 @@ class SafepointTableBuilder {
ZoneChunkList<DeoptimizationInfo> deoptimization_info_;
unsigned offset_;
int offset_;
bool emitted_;
Zone* zone_;
......
......@@ -586,8 +586,8 @@ void Code::Disassemble(const char* name, std::ostream& os, Isolate* isolate,
if (has_safepoint_info()) {
SafepointTable table(isolate, current_pc, *this);
os << "Safepoints (size = " << table.size() << ")\n";
for (unsigned i = 0; i < table.length(); i++) {
unsigned pc_offset = table.GetPcOffset(i);
for (int i = 0; i < table.length(); i++) {
int pc_offset = table.GetPcOffset(i);
os << reinterpret_cast<const void*>(InstructionStart() + pc_offset)
<< " ";
os << std::setw(6) << std::hex << pc_offset << " " << std::setw(4);
......
......@@ -437,8 +437,8 @@ void WasmCode::Disassemble(const char* name, std::ostream& os,
if (safepoint_table_offset_ > 0) {
SafepointTable table(this);
os << "Safepoints (size = " << table.size() << ")\n";
for (uint32_t i = 0; i < table.length(); i++) {
uintptr_t pc_offset = table.GetPcOffset(i);
for (int i = 0; i < table.length(); i++) {
int pc_offset = table.GetPcOffset(i);
os << reinterpret_cast<const void*>(instruction_start() + pc_offset);
os << std::setw(6) << std::hex << pc_offset << " " << std::dec;
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