Commit 2c4d1b4c authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[maglev] Properly use MachineRepresentation in RegAlloc

We need to use MachineRepresentation to properly distinguish
the types in compiler::UnallocatedOperand.

Bug: v8:7700
Change-Id: I4273512a00290bb85b09aeb3788643e346be03f7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3602515Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80140}
parent fe12d2d1
...@@ -774,6 +774,17 @@ class ValueNode : public Node { ...@@ -774,6 +774,17 @@ class ValueNode : public Node {
ValueRepresentation::kFloat64); ValueRepresentation::kFloat64);
} }
constexpr MachineRepresentation GetMachineRepresentation() const {
switch (properties().value_representation()) {
case ValueRepresentation::kTagged:
return MachineRepresentation::kTagged;
case ValueRepresentation::kInt32:
return MachineRepresentation::kWord32;
case ValueRepresentation::kFloat64:
return MachineRepresentation::kFloat64;
}
}
void AddRegister(Register reg) { void AddRegister(Register reg) {
DCHECK(!use_double_register()); DCHECK(!use_double_register());
registers_with_result_.set(reg); registers_with_result_.set(reg);
...@@ -811,8 +822,8 @@ class ValueNode : public Node { ...@@ -811,8 +822,8 @@ class ValueNode : public Node {
compiler::AllocatedOperand allocation() const { compiler::AllocatedOperand allocation() const {
if (has_register()) { if (has_register()) {
return compiler::AllocatedOperand(compiler::LocationOperand::REGISTER, return compiler::AllocatedOperand(compiler::LocationOperand::REGISTER,
MachineRepresentation::kTagged, GetMachineRepresentation(),
registers_with_result_.first().code()); FirstRegisterCode());
} }
DCHECK(is_spilled()); DCHECK(is_spilled());
return compiler::AllocatedOperand::cast(spill_or_hint_); return compiler::AllocatedOperand::cast(spill_or_hint_);
...@@ -834,6 +845,13 @@ class ValueNode : public Node { ...@@ -834,6 +845,13 @@ class ValueNode : public Node {
} }
} }
int FirstRegisterCode() const {
if (use_double_register()) {
return double_registers_with_result_.first().code();
}
return registers_with_result_.first().code();
}
// Rename for better pairing with `end_id`. // Rename for better pairing with `end_id`.
NodeIdT start_id() const { return id(); } NodeIdT start_id() const { return id(); }
......
...@@ -417,7 +417,7 @@ void StraightForwardRegisterAllocator::AllocateNodeResult(ValueNode* node) { ...@@ -417,7 +417,7 @@ void StraightForwardRegisterAllocator::AllocateNodeResult(ValueNode* node) {
DCHECK_LT(operand.fixed_slot_index(), 0); DCHECK_LT(operand.fixed_slot_index(), 0);
// Set the stack slot to exactly where the value is. // Set the stack slot to exactly where the value is.
compiler::AllocatedOperand location(compiler::AllocatedOperand::STACK_SLOT, compiler::AllocatedOperand location(compiler::AllocatedOperand::STACK_SLOT,
MachineRepresentation::kTagged, node->GetMachineRepresentation(),
operand.fixed_slot_index()); operand.fixed_slot_index());
node->result().SetAllocated(location); node->result().SetAllocated(location);
node->Spill(location); node->Spill(location);
...@@ -469,6 +469,7 @@ void StraightForwardRegisterAllocator::DropRegisterValue( ...@@ -469,6 +469,7 @@ void StraightForwardRegisterAllocator::DropRegisterValue(
DCHECK(!registers.free().has(reg)); DCHECK(!registers.free().has(reg));
ValueNode* node = registers.GetValue(reg); ValueNode* node = registers.GetValue(reg);
MachineRepresentation mach_repr = node->GetMachineRepresentation();
// Remove the register from the node's list. // Remove the register from the node's list.
node->RemoveRegister(reg); node->RemoveRegister(reg);
...@@ -482,11 +483,9 @@ void StraightForwardRegisterAllocator::DropRegisterValue( ...@@ -482,11 +483,9 @@ void StraightForwardRegisterAllocator::DropRegisterValue(
registers.SetValue(target_reg, node); registers.SetValue(target_reg, node);
// Emit a gapmove. // Emit a gapmove.
compiler::AllocatedOperand source(compiler::LocationOperand::REGISTER, compiler::AllocatedOperand source(compiler::LocationOperand::REGISTER,
MachineRepresentation::kTagged, mach_repr, reg.code());
reg.code());
compiler::AllocatedOperand target(compiler::LocationOperand::REGISTER, compiler::AllocatedOperand target(compiler::LocationOperand::REGISTER,
MachineRepresentation::kTagged, mach_repr, target_reg.code());
target_reg.code());
if (FLAG_trace_maglev_regalloc) { if (FLAG_trace_maglev_regalloc) {
printing_visitor_->os() printing_visitor_->os()
...@@ -773,7 +772,7 @@ compiler::AllocatedOperand StraightForwardRegisterAllocator::ForceAllocate( ...@@ -773,7 +772,7 @@ compiler::AllocatedOperand StraightForwardRegisterAllocator::ForceAllocate(
registers.RemoveFromFree(reg); registers.RemoveFromFree(reg);
} else if (registers.GetValue(reg) == node) { } else if (registers.GetValue(reg) == node) {
return compiler::AllocatedOperand(compiler::LocationOperand::REGISTER, return compiler::AllocatedOperand(compiler::LocationOperand::REGISTER,
MachineRepresentation::kTagged, node->GetMachineRepresentation(),
reg.code()); reg.code());
} else { } else {
DropRegisterValue(registers, reg); DropRegisterValue(registers, reg);
...@@ -783,7 +782,8 @@ compiler::AllocatedOperand StraightForwardRegisterAllocator::ForceAllocate( ...@@ -783,7 +782,8 @@ compiler::AllocatedOperand StraightForwardRegisterAllocator::ForceAllocate(
#endif #endif
registers.SetValue(reg, node); registers.SetValue(reg, node);
return compiler::AllocatedOperand(compiler::LocationOperand::REGISTER, return compiler::AllocatedOperand(compiler::LocationOperand::REGISTER,
MachineRepresentation::kTagged, reg.code()); node->GetMachineRepresentation(),
reg.code());
} }
compiler::AllocatedOperand StraightForwardRegisterAllocator::ForceAllocate( compiler::AllocatedOperand StraightForwardRegisterAllocator::ForceAllocate(
...@@ -808,7 +808,8 @@ compiler::InstructionOperand RegisterFrameState<RegisterT>::TryAllocateRegister( ...@@ -808,7 +808,8 @@ compiler::InstructionOperand RegisterFrameState<RegisterT>::TryAllocateRegister(
// Simply update the state anyway. // Simply update the state anyway.
SetValue(reg, node); SetValue(reg, node);
return compiler::AllocatedOperand(compiler::LocationOperand::REGISTER, return compiler::AllocatedOperand(compiler::LocationOperand::REGISTER,
MachineRepresentation::kTagged, reg.code()); node->GetMachineRepresentation(),
reg.code());
} }
void StraightForwardRegisterAllocator::AssignTemporaries(NodeBase* node) { void StraightForwardRegisterAllocator::AssignTemporaries(NodeBase* node) {
...@@ -895,9 +896,11 @@ void StraightForwardRegisterAllocator::MergeRegisterValues(ControlNode* control, ...@@ -895,9 +896,11 @@ void StraightForwardRegisterAllocator::MergeRegisterValues(ControlNode* control,
RegisterMerge* merge; RegisterMerge* merge;
LoadMergeState(state, &node, &merge); LoadMergeState(state, &node, &merge);
MachineRepresentation mach_repr = node == nullptr
? MachineRepresentation::kTagged
: node->GetMachineRepresentation();
compiler::AllocatedOperand register_info = { compiler::AllocatedOperand register_info = {
compiler::LocationOperand::REGISTER, MachineRepresentation::kTagged, compiler::LocationOperand::REGISTER, mach_repr, reg.code()};
reg.code()};
ValueNode* incoming = nullptr; ValueNode* incoming = nullptr;
if (!general_registers_.free().has(reg)) { if (!general_registers_.free().has(reg)) {
......
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