Commit dad405a2 authored by dcarney's avatar dcarney Committed by Commit bot

[turbofan] put spill slot reuse behind a flag

BUG=

Review URL: https://codereview.chromium.org/748773002

Cr-Commit-Position: refs/heads/master@{#25461}
parent 132871a6
......@@ -724,7 +724,8 @@ void GraphC1Visualizer::PrintLiveRange(LiveRange* range, const char* type) {
}
} else if (range->IsSpilled()) {
int index = -1;
if (range->TopLevel()->GetSpillRange()->id() != -1) {
if (range->TopLevel()->GetSpillRange() != nullptr &&
range->TopLevel()->GetSpillRange()->id() != -1) {
index = range->TopLevel()->GetSpillRange()->id();
} else {
index = range->TopLevel()->GetSpillOperand()->index();
......
......@@ -944,7 +944,9 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config,
data->set_compilation_failed();
return;
}
Run<ReuseSpillSlotsPhase>();
if (FLAG_turbo_reuse_spill_slots) {
Run<ReuseSpillSlotsPhase>();
}
Run<PopulatePointerMapsPhase>();
Run<ConnectRangesPhase>();
Run<ResolveControlFlowPhase>();
......
......@@ -881,6 +881,8 @@ void SpillRange::MergeDisjointIntervals(UseInterval* other, Zone* zone) {
void RegisterAllocator::ReuseSpillSlots() {
DCHECK(FLAG_turbo_reuse_spill_slots);
// Merge disjoint spill ranges
for (int i = 0; i < spill_ranges_.length(); i++) {
SpillRange* range = spill_ranges_.at(i);
......@@ -915,6 +917,7 @@ void RegisterAllocator::ReuseSpillSlots() {
SpillRange* RegisterAllocator::AssignSpillRangeToLiveRange(LiveRange* range) {
DCHECK(FLAG_turbo_reuse_spill_slots);
int spill_id = spill_ranges_.length();
SpillRange* spill_range =
new (local_zone()) SpillRange(range, spill_id, local_zone());
......@@ -1932,10 +1935,40 @@ bool RegisterAllocator::UnhandledIsSorted() {
}
void RegisterAllocator::FreeSpillSlot(LiveRange* range) {
DCHECK(!FLAG_turbo_reuse_spill_slots);
// Check that we are the last range.
if (range->next() != NULL) return;
if (!range->TopLevel()->HasAllocatedSpillOperand()) return;
InstructionOperand* spill_operand = range->TopLevel()->GetSpillOperand();
if (spill_operand->IsConstant()) return;
if (spill_operand->index() >= 0) {
reusable_slots_.Add(range, local_zone());
}
}
InstructionOperand* RegisterAllocator::TryReuseSpillSlot(LiveRange* range) {
DCHECK(!FLAG_turbo_reuse_spill_slots);
if (reusable_slots_.is_empty()) return NULL;
if (reusable_slots_.first()->End().Value() >
range->TopLevel()->Start().Value()) {
return NULL;
}
InstructionOperand* result =
reusable_slots_.first()->TopLevel()->GetSpillOperand();
reusable_slots_.Remove(0);
return result;
}
void RegisterAllocator::ActiveToHandled(LiveRange* range) {
DCHECK(active_live_ranges_.Contains(range));
active_live_ranges_.RemoveElement(range);
TraceAlloc("Moving live range %d from active to handled\n", range->id());
if (!FLAG_turbo_reuse_spill_slots) FreeSpillSlot(range);
}
......@@ -1951,6 +1984,7 @@ void RegisterAllocator::InactiveToHandled(LiveRange* range) {
DCHECK(inactive_live_ranges_.Contains(range));
inactive_live_ranges_.RemoveElement(range);
TraceAlloc("Moving live range %d from inactive to handled\n", range->id());
if (!FLAG_turbo_reuse_spill_slots) FreeSpillSlot(range);
}
......@@ -2335,7 +2369,23 @@ void RegisterAllocator::Spill(LiveRange* range) {
LiveRange* first = range->TopLevel();
if (!first->HasAllocatedSpillOperand()) {
AssignSpillRangeToLiveRange(first);
if (FLAG_turbo_reuse_spill_slots) {
AssignSpillRangeToLiveRange(first);
} else {
InstructionOperand* op = TryReuseSpillSlot(range);
if (op == NULL) {
// Allocate a new operand referring to the spill slot.
RegisterKind kind = range->Kind();
int index = frame()->AllocateSpillSlot(kind == DOUBLE_REGISTERS);
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(code_zone());
}
......
......@@ -457,6 +457,8 @@ class RegisterAllocator FINAL : public ZoneObject {
bool TryAllocateFreeReg(LiveRange* range);
void AllocateBlockedReg(LiveRange* range);
SpillRange* AssignSpillRangeToLiveRange(LiveRange* range);
void FreeSpillSlot(LiveRange* range);
InstructionOperand* TryReuseSpillSlot(LiveRange* range);
// Live range splitting helpers.
......
......@@ -388,6 +388,8 @@ DEFINE_BOOL(loop_assignment_analysis, true, "perform loop assignment analysis")
DEFINE_IMPLICATION(turbo_inlining_intrinsics, turbo_inlining)
DEFINE_IMPLICATION(turbo_inlining, turbo_types)
DEFINE_BOOL(turbo_profiling, false, "enable profiling in TurboFan")
// TODO(dcarney): this is just for experimentation, remove when default.
DEFINE_BOOL(turbo_reuse_spill_slots, false, "reuse spill slots in TurboFan")
DEFINE_INT(typed_array_max_size_in_heap, 64,
"threshold for in-heap typed array")
......
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