Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Unified Diff: src/compiler/register-allocator.cc

Issue 803493002: revert r25736 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/register-allocator.h ('k') | src/compiler/register-allocator-verifier.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/register-allocator.cc
diff --git a/src/compiler/register-allocator.cc b/src/compiler/register-allocator.cc
index a4f3c6ef0ad5d8372ce99e18058b6f1cf0521710..3b933af1c70f801da753d9509ebe4a558afc5fdf 100644
--- a/src/compiler/register-allocator.cc
+++ b/src/compiler/register-allocator.cc
@@ -74,16 +74,6 @@ void UseInterval::SplitAt(LifetimePosition pos, Zone* zone) {
}
-struct LiveRange::SpillAtDefinitionList : ZoneObject {
- SpillAtDefinitionList(int gap_index, InstructionOperand* operand,
- SpillAtDefinitionList* next)
- : gap_index(gap_index), operand(operand), next(next) {}
- const int gap_index;
- InstructionOperand* const operand;
- SpillAtDefinitionList* const next;
-};
-
-
#ifdef DEBUG
@@ -129,72 +119,53 @@ LiveRange::LiveRange(int id, Zone* zone)
current_interval_(nullptr),
last_processed_use_(nullptr),
current_hint_operand_(nullptr),
+ spill_operand_(new (zone) InstructionOperand()),
spill_start_index_(kMaxInt),
- spill_type_(SpillType::kNoSpillType),
- spill_operand_(nullptr),
- spills_at_definition_(nullptr) {}
+ spill_range_(nullptr) {}
void LiveRange::set_assigned_register(int reg, Zone* zone) {
DCHECK(!HasRegisterAssigned() && !IsSpilled());
assigned_register_ = reg;
- // TODO(dcarney): stop aliasing hint operands.
- ConvertUsesToOperand(CreateAssignedOperand(zone));
+ if (spill_range_ == nullptr) {
+ ConvertOperands(zone);
+ }
}
-void LiveRange::MakeSpilled() {
+void LiveRange::MakeSpilled(Zone* zone) {
DCHECK(!IsSpilled());
- DCHECK(!TopLevel()->HasNoSpillType());
+ DCHECK(TopLevel()->HasAllocatedSpillOperand());
spilled_ = true;
assigned_register_ = kInvalidAssignment;
+ ConvertOperands(zone);
}
-void LiveRange::SpillAtDefinition(Zone* zone, int gap_index,
- InstructionOperand* operand) {
- DCHECK(HasNoSpillType());
- spills_at_definition_ = new (zone)
- SpillAtDefinitionList(gap_index, operand, spills_at_definition_);
-}
-
-
-void LiveRange::CommitSpillsAtDefinition(InstructionSequence* sequence,
- InstructionOperand* op) {
- auto to_spill = TopLevel()->spills_at_definition_;
- if (to_spill == nullptr) return;
- auto zone = sequence->zone();
- for (; to_spill != nullptr; to_spill = to_spill->next) {
- auto gap = sequence->GapAt(to_spill->gap_index);
- auto move = gap->GetOrCreateParallelMove(GapInstruction::START, zone);
- move->AddMove(to_spill->operand, op, zone);
- }
- TopLevel()->spills_at_definition_ = nullptr;
+bool LiveRange::HasAllocatedSpillOperand() const {
+ DCHECK(spill_operand_ != nullptr);
+ return !spill_operand_->IsIgnored() || spill_range_ != nullptr;
}
void LiveRange::SetSpillOperand(InstructionOperand* operand) {
- DCHECK(HasNoSpillType());
DCHECK(!operand->IsUnallocated());
- spill_type_ = SpillType::kSpillOperand;
- spill_operand_ = operand;
-}
-
-
-void LiveRange::SetSpillRange(SpillRange* spill_range) {
- DCHECK(HasNoSpillType() || HasSpillRange());
- DCHECK_NE(spill_range, nullptr);
- spill_type_ = SpillType::kSpillRange;
- spill_range_ = spill_range;
+ DCHECK(spill_operand_ != nullptr);
+ DCHECK(spill_operand_->IsIgnored());
+ spill_operand_->ConvertTo(operand->kind(), operand->index());
}
void LiveRange::CommitSpillOperand(InstructionOperand* operand) {
- DCHECK(HasSpillRange());
- DCHECK(!operand->IsUnallocated());
+ DCHECK(spill_range_ != nullptr);
DCHECK(!IsChild());
- spill_type_ = SpillType::kSpillOperand;
- spill_operand_ = operand;
+ spill_range_ = nullptr;
+ SetSpillOperand(operand);
+ for (auto range = this; range != nullptr; range = range->next()) {
+ if (range->IsSpilled()) {
+ range->ConvertUsesToOperand(operand);
+ }
+ }
}
@@ -264,11 +235,15 @@ InstructionOperand* LiveRange::CreateAssignedOperand(Zone* zone) const {
default:
UNREACHABLE();
}
- } else {
- DCHECK(IsSpilled());
+ } else if (IsSpilled()) {
DCHECK(!HasRegisterAssigned());
op = TopLevel()->GetSpillOperand();
DCHECK(!op->IsUnallocated());
+ } else {
+ UnallocatedOperand* unalloc =
+ new (zone) UnallocatedOperand(UnallocatedOperand::NONE);
+ unalloc->set_virtual_register(id_);
+ op = unalloc;
}
return op;
}
@@ -507,6 +482,11 @@ void LiveRange::ConvertUsesToOperand(InstructionOperand* op) {
}
+void LiveRange::ConvertOperands(Zone* zone) {
+ ConvertUsesToOperand(CreateAssignedOperand(zone));
+}
+
+
bool LiveRange::CanCover(LifetimePosition position) const {
if (IsEmpty()) return false;
return Start().Value() <= position.Value() &&
@@ -837,7 +817,7 @@ SpillRange::SpillRange(LiveRange* range, Zone* zone) : live_ranges_(zone) {
use_interval_ = result;
live_ranges().push_back(range);
end_position_ = node->end();
- DCHECK(!range->HasSpillRange());
+ DCHECK(range->GetSpillRange() == nullptr);
range->SetSpillRange(this);
}
@@ -941,20 +921,6 @@ void RegisterAllocator::ReuseSpillSlots() {
}
-void RegisterAllocator::CommitAssignment() {
- for (auto range : live_ranges()) {
- if (range == nullptr || range->IsEmpty()) continue;
- // Register assignments were committed in set_assigned_register.
- if (range->HasRegisterAssigned()) continue;
- auto assigned = range->CreateAssignedOperand(code_zone());
- range->ConvertUsesToOperand(assigned);
- if (range->IsSpilled()) {
- range->CommitSpillsAtDefinition(code(), assigned);
- }
- }
-}
-
-
SpillRange* RegisterAllocator::AssignSpillRangeToLiveRange(LiveRange* range) {
DCHECK(FLAG_turbo_reuse_spill_slots);
auto spill_range = new (local_zone()) SpillRange(range, local_zone());
@@ -965,7 +931,7 @@ SpillRange* RegisterAllocator::AssignSpillRangeToLiveRange(LiveRange* range) {
bool RegisterAllocator::TryReuseSpillForPhi(LiveRange* range) {
DCHECK(FLAG_turbo_reuse_spill_slots);
- DCHECK(range->HasNoSpillType());
+ DCHECK(!range->HasAllocatedSpillOperand());
if (range->IsChild() || !range->is_phi()) return false;
auto lookup = phi_map_.find(range->id());
@@ -1109,8 +1075,16 @@ void RegisterAllocator::MeetRegisterConstraintsForLastInstructionInBlock(
const InstructionBlock* successor = code()->InstructionBlockAt(succ);
DCHECK(successor->PredecessorCount() == 1);
int gap_index = successor->first_instruction_index() + 1;
- range->SpillAtDefinition(local_zone(), gap_index, output);
range->SetSpillStartIndex(gap_index);
+
+ // This move to spill operand is not a real use. Liveness analysis
+ // and splitting of live ranges do not account for it.
+ // Thus it should be inserted to a lifetime position corresponding to
+ // the instruction end.
+ auto gap = code()->GapAt(gap_index);
+ auto move =
+ gap->GetOrCreateParallelMove(GapInstruction::BEFORE, code_zone());
+ move->AddMove(output, range->GetSpillOperand(), code_zone());
}
}
}
@@ -1159,8 +1133,16 @@ void RegisterAllocator::MeetConstraintsBetween(Instruction* first,
// Make sure we add a gap move for spilling (if we have not done
// so already).
if (!assigned) {
- range->SpillAtDefinition(local_zone(), gap_index, first_output);
range->SetSpillStartIndex(gap_index);
+
+ // This move to spill operand is not a real use. Liveness analysis
+ // and splitting of live ranges do not account for it.
+ // Thus it should be inserted to a lifetime position corresponding to
+ // the instruction end.
+ auto gap = code()->GapAt(gap_index);
+ auto move =
+ gap->GetOrCreateParallelMove(GapInstruction::BEFORE, code_zone());
+ move->AddMove(first_output, range->GetSpillOperand(), code_zone());
}
}
}
@@ -1256,6 +1238,7 @@ void RegisterAllocator::ProcessInstructions(const InstructionBlock* block,
const ZoneList<MoveOperands>* move_operands = move->move_operands();
for (int i = 0; i < move_operands->length(); ++i) {
auto cur = &move_operands->at(i);
+ if (cur->IsIgnored()) continue;
auto from = cur->source();
auto to = cur->destination();
auto hint = to;
@@ -1378,9 +1361,10 @@ void RegisterAllocator::ResolvePhis(const InstructionBlock* block) {
}
}
auto live_range = LiveRangeFor(phi_vreg);
- int gap_index = block->first_instruction_index();
- live_range->SpillAtDefinition(local_zone(), gap_index, output);
- live_range->SetSpillStartIndex(gap_index);
+ auto block_start = code()->GetBlockStart(block->rpo_number());
+ block_start->GetOrCreateParallelMove(GapInstruction::BEFORE, code_zone())
+ ->AddMove(output, live_range->GetSpillOperand(), code_zone());
+ live_range->SetSpillStartIndex(block->first_instruction_index());
// We use the phi-ness of some nodes in some later heuristics.
live_range->set_is_phi(true);
live_range->set_is_non_loop_phi(!block->IsLoopHeader());
@@ -1739,7 +1723,8 @@ void RegisterAllocator::BuildLiveRanges() {
// live ranges, every use requires the constant to be in a register.
// Without this hack, all uses with "any" policy would get the constant
// operand assigned.
- if (range->HasSpillOperand() && range->GetSpillOperand()->IsConstant()) {
+ if (range->HasAllocatedSpillOperand() &&
+ range->GetSpillOperand()->IsConstant()) {
for (auto pos = range->first_pos(); pos != nullptr; pos = pos->next_) {
pos->register_beneficial_ = true;
// TODO(dcarney): should the else case assert requires_reg_ == false?
@@ -1843,7 +1828,7 @@ void RegisterAllocator::PopulatePointerMaps() {
// Check if the live range is spilled and the safe point is after
// the spill position.
- if (range->HasSpillOperand() &&
+ if (range->HasAllocatedSpillOperand() &&
safe_point >= range->spill_start_index() &&
!range->GetSpillOperand()->IsConstant()) {
TraceAlloc("Pointer for range %d (spilled at %d) at safe point %d\n",
@@ -1923,7 +1908,7 @@ void RegisterAllocator::AllocateRegisters() {
TraceAlloc("Processing interval %d start=%d\n", current->id(),
position.Value());
- if (!current->HasNoSpillType()) {
+ if (current->HasAllocatedSpillOperand()) {
TraceAlloc("Live range %d already has a spill operand\n", current->id());
auto next_pos = position;
if (code()->IsGapAt(next_pos.InstructionIndex())) {
@@ -2088,7 +2073,7 @@ void RegisterAllocator::FreeSpillSlot(LiveRange* range) {
DCHECK(!FLAG_turbo_reuse_spill_slots);
// Check that we are the last range.
if (range->next() != nullptr) return;
- if (!range->TopLevel()->HasSpillOperand()) return;
+ if (!range->TopLevel()->HasAllocatedSpillOperand()) return;
auto spill_operand = range->TopLevel()->GetSpillOperand();
if (spill_operand->IsConstant()) return;
if (spill_operand->index() >= 0) {
@@ -2503,7 +2488,7 @@ void RegisterAllocator::Spill(LiveRange* range) {
DCHECK(!range->IsSpilled());
TraceAlloc("Spilling live range %d\n", range->id());
auto first = range->TopLevel();
- if (first->HasNoSpillType()) {
+ if (!first->HasAllocatedSpillOperand()) {
if (FLAG_turbo_reuse_spill_slots) {
AssignSpillRangeToLiveRange(first);
} else {
@@ -2512,15 +2497,17 @@ void RegisterAllocator::Spill(LiveRange* range) {
// Allocate a new operand referring to the spill slot.
RegisterKind kind = range->Kind();
int index = frame()->AllocateSpillSlot(kind == DOUBLE_REGISTERS);
- auto op_kind = kind == DOUBLE_REGISTERS
- ? InstructionOperand::DOUBLE_STACK_SLOT
- : InstructionOperand::STACK_SLOT;
- op = new (code_zone()) InstructionOperand(op_kind, index);
+ if (kind == DOUBLE_REGISTERS) {
+ op = DoubleStackSlotOperand::Create(index, local_zone());
+ } else {
+ DCHECK(kind == GENERAL_REGISTERS);
+ op = StackSlotOperand::Create(index, local_zone());
+ }
}
first->SetSpillOperand(op);
}
}
- range->MakeSpilled();
+ range->MakeSpilled(code_zone());
}
« no previous file with comments | « src/compiler/register-allocator.h ('k') | src/compiler/register-allocator-verifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698