Commit a44db052 authored by mtrofin's avatar mtrofin Committed by Commit bot

Drop 'auto' from register-allocator.cc

Pretty much everywhere except for a few places where we use
iterators.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#32962}
parent 2376296c
......@@ -49,7 +49,7 @@ const int* GetAllocatableRegisterCodes(const RegisterConfiguration* cfg,
const InstructionBlock* GetContainingLoop(const InstructionSequence* sequence,
const InstructionBlock* block) {
auto index = block->loop_header();
RpoNumber index = block->loop_header();
if (!index.IsValid()) return nullptr;
return sequence->InstructionBlockAt(index);
}
......@@ -69,7 +69,7 @@ Instruction* GetLastInstruction(InstructionSequence* code,
bool IsOutputRegisterOf(Instruction* instr, Register reg) {
for (size_t i = 0; i < instr->OutputCount(); i++) {
auto output = instr->OutputAt(i);
InstructionOperand* output = instr->OutputAt(i);
if (output->IsRegister() &&
LocationOperand::cast(output)->GetRegister().is(reg)) {
return true;
......@@ -81,7 +81,7 @@ bool IsOutputRegisterOf(Instruction* instr, Register reg) {
bool IsOutputDoubleRegisterOf(Instruction* instr, DoubleRegister reg) {
for (size_t i = 0; i < instr->OutputCount(); i++) {
auto output = instr->OutputAt(i);
InstructionOperand* output = instr->OutputAt(i);
if (output->IsDoubleRegister() &&
LocationOperand::cast(output)->GetDoubleRegister().is(reg)) {
return true;
......@@ -150,14 +150,15 @@ bool UsePosition::HintRegister(int* register_code) const {
case UsePositionHintType::kUnresolved:
return false;
case UsePositionHintType::kUsePos: {
auto use_pos = reinterpret_cast<UsePosition*>(hint_);
UsePosition* use_pos = reinterpret_cast<UsePosition*>(hint_);
int assigned_register = AssignedRegisterField::decode(use_pos->flags_);
if (assigned_register == kUnassignedRegister) return false;
*register_code = assigned_register;
return true;
}
case UsePositionHintType::kOperand: {
auto operand = reinterpret_cast<InstructionOperand*>(hint_);
InstructionOperand* operand =
reinterpret_cast<InstructionOperand*>(hint_);
int assigned_register =
operand->IsRegister()
? LocationOperand::cast(operand)->GetRegister().code()
......@@ -166,7 +167,8 @@ bool UsePosition::HintRegister(int* register_code) const {
return true;
}
case UsePositionHintType::kPhi: {
auto phi = reinterpret_cast<RegisterAllocationData::PhiMapValue*>(hint_);
RegisterAllocationData::PhiMapValue* phi =
reinterpret_cast<RegisterAllocationData::PhiMapValue*>(hint_);
int assigned_register = phi->assigned_register();
if (assigned_register == kUnassignedRegister) return false;
*register_code = assigned_register;
......@@ -222,7 +224,7 @@ void UsePosition::set_type(UsePositionType type, bool register_beneficial) {
UseInterval* UseInterval::SplitAt(LifetimePosition pos, Zone* zone) {
DCHECK(Contains(pos) && pos != start());
auto after = new (zone) UseInterval(pos, end_);
UseInterval* after = new (zone) UseInterval(pos, end_);
after->next_ = next_;
next_ = nullptr;
end_ = pos;
......@@ -280,8 +282,8 @@ LiveRange::LiveRange(int relative_id, MachineRepresentation rep,
void LiveRange::VerifyPositions() const {
// Walk the positions, verifying that each is in an interval.
auto interval = first_interval_;
for (auto pos = first_pos_; pos != nullptr; pos = pos->next()) {
UseInterval* interval = first_interval_;
for (UsePosition* pos = first_pos_; pos != nullptr; pos = pos->next()) {
CHECK(Start() <= pos->pos());
CHECK(pos->pos() <= End());
CHECK(interval != nullptr);
......@@ -332,7 +334,7 @@ RegisterKind LiveRange::kind() const {
UsePosition* LiveRange::FirstHintPosition(int* register_index) const {
for (auto pos = first_pos_; pos != nullptr; pos = pos->next()) {
for (UsePosition* pos = first_pos_; pos != nullptr; pos = pos->next()) {
if (pos->HintRegister(register_index)) return pos;
}
return nullptr;
......@@ -364,7 +366,7 @@ UsePosition* LiveRange::NextUsePositionRegisterIsBeneficial(
UsePosition* LiveRange::PreviousUsePositionRegisterIsBeneficial(
LifetimePosition start) const {
auto pos = first_pos();
UsePosition* pos = first_pos();
UsePosition* prev = nullptr;
while (pos != nullptr && pos->pos() < start) {
if (pos->RegisterIsBeneficial()) prev = pos;
......@@ -396,7 +398,7 @@ UsePosition* LiveRange::NextSlotPosition(LifetimePosition start) const {
bool LiveRange::CanBeSpilled(LifetimePosition pos) const {
// We cannot spill a live range that has a use requiring a register
// at the current or the immediate next position.
auto use_pos = NextRegisterPosition(pos);
UsePosition* use_pos = NextRegisterPosition(pos);
if (use_pos == nullptr) return true;
return use_pos->pos() > pos.NextStart().End();
}
......@@ -414,7 +416,7 @@ InstructionOperand LiveRange::GetAssignedOperand() const {
DCHECK(spilled());
DCHECK(!HasRegisterAssigned());
if (TopLevel()->HasSpillOperand()) {
auto op = TopLevel()->GetSpillOperand();
InstructionOperand* op = TopLevel()->GetSpillOperand();
DCHECK(!op->IsUnallocated());
return *op;
}
......@@ -437,7 +439,8 @@ void LiveRange::AdvanceLastProcessedMarker(
UseInterval* to_start_of, LifetimePosition but_not_past) const {
if (to_start_of == nullptr) return;
if (to_start_of->start() > but_not_past) return;
auto start = current_interval_ == nullptr ? LifetimePosition::Invalid()
LifetimePosition start = current_interval_ == nullptr
? LifetimePosition::Invalid()
: current_interval_->start();
if (to_start_of->start() > start) {
current_interval_ = to_start_of;
......@@ -465,7 +468,7 @@ UsePosition* LiveRange::DetachAt(LifetimePosition position, LiveRange* result,
// Find the last interval that ends before the position. If the
// position is contained in one of the intervals in the chain, we
// split that interval and use the first part.
auto current = FirstSearchIntervalForPosition(position);
UseInterval* current = FirstSearchIntervalForPosition(position);
// If the split position coincides with the beginning of a use interval
// we need to split use positons in a special way.
......@@ -482,7 +485,7 @@ UsePosition* LiveRange::DetachAt(LifetimePosition position, LiveRange* result,
after = current->SplitAt(position, zone);
break;
}
auto next = current->next();
UseInterval* next = current->next();
if (next->start() >= position) {
split_at_start = (next->start() == position);
after = next;
......@@ -494,7 +497,7 @@ UsePosition* LiveRange::DetachAt(LifetimePosition position, LiveRange* result,
DCHECK(nullptr != after);
// Partition original use intervals to the two live ranges.
auto before = current;
UseInterval* before = current;
result->last_interval_ =
(last_interval_ == before)
? after // Only interval in the range after split.
......@@ -504,7 +507,7 @@ UsePosition* LiveRange::DetachAt(LifetimePosition position, LiveRange* result,
// Find the last use position before the split and the first use
// position after it.
auto use_after =
UsePosition* use_after =
splitting_pointer_ == nullptr || splitting_pointer_->pos() > position
? first_pos()
: splitting_pointer_;
......@@ -559,7 +562,7 @@ void LiveRange::UpdateParentForAllChildren(TopLevelLiveRange* new_top_level) {
void LiveRange::ConvertUsesToOperand(const InstructionOperand& op,
const InstructionOperand& spill_op) {
for (auto pos = first_pos(); pos != nullptr; pos = pos->next()) {
for (UsePosition* pos = first_pos(); pos != nullptr; pos = pos->next()) {
DCHECK(Start() <= pos->pos() && pos->pos() <= End());
if (!pos->HasOperand()) continue;
switch (pos->type()) {
......@@ -598,7 +601,7 @@ bool LiveRange::ShouldBeAllocatedBefore(const LiveRange* other) const {
void LiveRange::SetUseHints(int register_index) {
for (auto pos = first_pos(); pos != nullptr; pos = pos->next()) {
for (UsePosition* pos = first_pos(); pos != nullptr; pos = pos->next()) {
if (!pos->HasOperand()) continue;
switch (pos->type()) {
case UsePositionType::kRequiresSlot:
......@@ -620,8 +623,8 @@ bool LiveRange::CanCover(LifetimePosition position) const {
bool LiveRange::Covers(LifetimePosition position) const {
if (!CanCover(position)) return false;
auto start_search = FirstSearchIntervalForPosition(position);
for (auto interval = start_search; interval != nullptr;
UseInterval* start_search = FirstSearchIntervalForPosition(position);
for (UseInterval* interval = start_search; interval != nullptr;
interval = interval->next()) {
DCHECK(interval->next() == nullptr ||
interval->next()->start() >= interval->start());
......@@ -634,14 +637,14 @@ bool LiveRange::Covers(LifetimePosition position) const {
LifetimePosition LiveRange::FirstIntersection(LiveRange* other) const {
auto b = other->first_interval();
UseInterval* b = other->first_interval();
if (b == nullptr) return LifetimePosition::Invalid();
auto advance_last_processed_up_to = b->start();
auto a = FirstSearchIntervalForPosition(b->start());
LifetimePosition advance_last_processed_up_to = b->start();
UseInterval* a = FirstSearchIntervalForPosition(b->start());
while (a != nullptr && b != nullptr) {
if (a->start() > other->End()) break;
if (b->start() > End()) break;
auto cur_intersection = a->Intersect(b);
LifetimePosition cur_intersection = a->Intersect(b);
if (cur_intersection.IsValid()) {
return cur_intersection;
}
......@@ -660,7 +663,7 @@ LifetimePosition LiveRange::FirstIntersection(LiveRange* other) const {
unsigned LiveRange::GetSize() {
if (size_ == kInvalidSize) {
size_ = 0;
for (auto interval = first_interval(); interval != nullptr;
for (const UseInterval* interval = first_interval(); interval != nullptr;
interval = interval->next()) {
size_ += (interval->end().value() - interval->start().value());
}
......@@ -741,14 +744,15 @@ bool TopLevelLiveRange::TryCommitSpillInDeferredBlock(
for (const LiveRange* child = this; child != nullptr; child = child->next()) {
if (!child->spilled() &&
child->NextSlotPosition(child->Start()) != nullptr) {
auto instr = code->InstructionAt(child->Start().ToInstructionIndex());
Instruction* instr =
code->InstructionAt(child->Start().ToInstructionIndex());
// Insert spill at the end to let live range connections happen at START.
auto move =
ParallelMove* move =
instr->GetOrCreateParallelMove(Instruction::END, code->zone());
InstructionOperand assigned = child->GetAssignedOperand();
if (TopLevel()->has_slot_use()) {
bool found = false;
for (auto move_op : *move) {
for (MoveOperands* move_op : *move) {
if (move_op->IsEliminated()) continue;
if (move_op->source().Equals(assigned) &&
move_op->destination().Equals(spill_operand)) {
......@@ -771,17 +775,18 @@ void TopLevelLiveRange::CommitSpillMoves(InstructionSequence* sequence,
const InstructionOperand& op,
bool might_be_duplicated) {
DCHECK_IMPLIES(op.IsConstant(), spill_move_insertion_locations() == nullptr);
auto zone = sequence->zone();
Zone* zone = sequence->zone();
for (auto to_spill = spill_move_insertion_locations(); to_spill != nullptr;
to_spill = to_spill->next) {
auto instr = sequence->InstructionAt(to_spill->gap_index);
auto move = instr->GetOrCreateParallelMove(Instruction::START, zone);
for (SpillMoveInsertionList* to_spill = spill_move_insertion_locations();
to_spill != nullptr; to_spill = to_spill->next) {
Instruction* instr = sequence->InstructionAt(to_spill->gap_index);
ParallelMove* move =
instr->GetOrCreateParallelMove(Instruction::START, zone);
// Skip insertion if it's possible that the move exists already as a
// constraint move from a fixed output register to a slot.
if (might_be_duplicated || has_preassigned_slot()) {
bool found = false;
for (auto move_op : *move) {
for (MoveOperands* move_op : *move) {
if (move_op->IsEliminated()) continue;
if (move_op->source().Equals(*to_spill->operand) &&
move_op->destination().Equals(op)) {
......@@ -815,7 +820,7 @@ void TopLevelLiveRange::SetSpillRange(SpillRange* spill_range) {
AllocatedOperand TopLevelLiveRange::GetSpillRangeOperand() const {
auto spill_range = GetSpillRange();
SpillRange* spill_range = GetSpillRange();
int index = spill_range->assigned_slot();
return AllocatedOperand(LocationOperand::STACK_SLOT, representation(), index);
}
......@@ -1002,7 +1007,7 @@ void TopLevelLiveRange::EnsureInterval(LifetimePosition start,
LifetimePosition end, Zone* zone) {
TRACE("Ensure live range %d in interval [%d %d[\n", vreg(), start.value(),
end.value());
auto new_end = end;
LifetimePosition new_end = end;
while (first_interval_ != nullptr && first_interval_->start() <= end) {
if (first_interval_->end() > end) {
new_end = first_interval_->end();
......@@ -1010,7 +1015,7 @@ void TopLevelLiveRange::EnsureInterval(LifetimePosition start,
first_interval_ = first_interval_->next();
}
auto new_interval = new (zone) UseInterval(start, new_end);
UseInterval* new_interval = new (zone) UseInterval(start, new_end);
new_interval->set_next(first_interval_);
first_interval_ = new_interval;
if (new_interval->next() == nullptr) {
......@@ -1024,14 +1029,14 @@ void TopLevelLiveRange::AddUseInterval(LifetimePosition start,
TRACE("Add to live range %d interval [%d %d[\n", vreg(), start.value(),
end.value());
if (first_interval_ == nullptr) {
auto interval = new (zone) UseInterval(start, end);
UseInterval* interval = new (zone) UseInterval(start, end);
first_interval_ = interval;
last_interval_ = interval;
} else {
if (end == first_interval_->start()) {
first_interval_->set_start(start);
} else if (end < first_interval_->start()) {
auto interval = new (zone) UseInterval(start, end);
UseInterval* interval = new (zone) UseInterval(start, end);
interval->set_next(first_interval_);
first_interval_ = interval;
} else {
......@@ -1047,11 +1052,11 @@ void TopLevelLiveRange::AddUseInterval(LifetimePosition start,
void TopLevelLiveRange::AddUsePosition(UsePosition* use_pos) {
auto pos = use_pos->pos();
LifetimePosition pos = use_pos->pos();
TRACE("Add to live range %d use position %d\n", vreg(), pos.value());
UsePosition* prev_hint = nullptr;
UsePosition* prev = nullptr;
auto current = first_pos_;
UsePosition* current = first_pos_;
while (current != nullptr && current->pos() < pos) {
prev_hint = current->HasHint() ? current : prev_hint;
prev = current;
......@@ -1100,8 +1105,8 @@ std::ostream& operator<<(std::ostream& os,
if (range->TopLevel()->is_non_loop_phi()) os << "nlphi ";
os << "{" << std::endl;
auto interval = range->first_interval();
auto use_pos = range->first_pos();
UseInterval* interval = range->first_interval();
UsePosition* use_pos = range->first_pos();
PrintableInstructionOperand pio;
pio.register_configuration_ = printable_range.register_configuration_;
while (use_pos != nullptr) {
......@@ -1136,9 +1141,9 @@ SpillRange::SpillRange(TopLevelLiveRange* parent, Zone* zone)
UseInterval* node = nullptr;
// Copy the intervals for all ranges.
for (LiveRange* range = parent; range != nullptr; range = range->next()) {
auto src = range->first_interval();
UseInterval* src = range->first_interval();
while (src != nullptr) {
auto new_node = new (zone) UseInterval(src->start(), src->end());
UseInterval* new_node = new (zone) UseInterval(src->start(), src->end());
if (result == nullptr) {
result = new_node;
} else {
......@@ -1178,7 +1183,7 @@ bool SpillRange::TryMerge(SpillRange* other) {
return false;
}
auto max = LifetimePosition::MaxPosition();
LifetimePosition max = LifetimePosition::MaxPosition();
if (End() < other->End() && other->End() != max) {
end_position_ = other->End();
}
......@@ -1187,7 +1192,7 @@ bool SpillRange::TryMerge(SpillRange* other) {
MergeDisjointIntervals(other->use_interval_);
other->use_interval_ = nullptr;
for (auto range : other->live_ranges()) {
for (TopLevelLiveRange* range : other->live_ranges()) {
DCHECK(range->GetSpillRange() == other);
range->SetSpillRange(this);
}
......@@ -1202,7 +1207,7 @@ bool SpillRange::TryMerge(SpillRange* other) {
void SpillRange::MergeDisjointIntervals(UseInterval* other) {
UseInterval* tail = nullptr;
auto current = use_interval_;
UseInterval* current = use_interval_;
while (other != nullptr) {
// Make sure the 'current' list starts first
if (current == nullptr || current->start() > other->start()) {
......@@ -1257,7 +1262,7 @@ void RegisterAllocationData::PhiMapValue::AddOperand(
void RegisterAllocationData::PhiMapValue::CommitAssignment(
const InstructionOperand& assigned) {
for (auto operand : incoming_operands_) {
for (InstructionOperand* operand : incoming_operands_) {
InstructionOperand::ReplaceWith(operand, &assigned);
}
}
......@@ -1306,8 +1311,8 @@ RegisterAllocationData::RegisterAllocationData(
MoveOperands* RegisterAllocationData::AddGapMove(
int index, Instruction::GapPosition position,
const InstructionOperand& from, const InstructionOperand& to) {
auto instr = code()->InstructionAt(index);
auto moves = instr->GetOrCreateParallelMove(position, code_zone());
Instruction* instr = code()->InstructionAt(index);
ParallelMove* moves = instr->GetOrCreateParallelMove(position, code_zone());
return moves->AddMove(from, to);
}
......@@ -1323,7 +1328,7 @@ TopLevelLiveRange* RegisterAllocationData::GetOrCreateLiveRangeFor(int index) {
if (index >= static_cast<int>(live_ranges().size())) {
live_ranges().resize(index + 1, nullptr);
}
auto result = live_ranges()[index];
TopLevelLiveRange* result = live_ranges()[index];
if (result == nullptr) {
result = NewLiveRange(index, RepresentationFor(index));
live_ranges()[index] = result;
......@@ -1357,7 +1362,7 @@ TopLevelLiveRange* RegisterAllocationData::NextLiveRange(
RegisterAllocationData::PhiMapValue* RegisterAllocationData::InitializePhiMap(
const InstructionBlock* block, PhiInstruction* phi) {
auto map_value = new (allocation_zone())
RegisterAllocationData::PhiMapValue* map_value = new (allocation_zone())
RegisterAllocationData::PhiMapValue(phi, block, allocation_zone());
auto res =
phi_map_.insert(std::make_pair(phi->virtual_register(), map_value));
......@@ -1457,7 +1462,7 @@ SpillRange* RegisterAllocationData::CreateSpillRangeForLiveRange(
TopLevelLiveRange* range) {
DCHECK(!range->HasSpillOperand());
DCHECK(!range->IsSplinter());
auto spill_range =
SpillRange* spill_range =
new (allocation_zone()) SpillRange(range, allocation_zone());
return spill_range;
}
......@@ -1512,7 +1517,7 @@ InstructionOperand* ConstraintBuilder::AllocateFixed(
InstructionOperand::ReplaceWith(operand, &allocated);
if (is_tagged) {
TRACE("Fixed reg is tagged at %d\n", pos);
auto instr = code()->InstructionAt(pos);
Instruction* instr = code()->InstructionAt(pos);
if (instr->HasReferenceMap()) {
instr->reference_map()->RecordReference(*AllocatedOperand::cast(operand));
}
......@@ -1522,7 +1527,7 @@ InstructionOperand* ConstraintBuilder::AllocateFixed(
void ConstraintBuilder::MeetRegisterConstraints() {
for (auto block : code()->instruction_blocks()) {
for (InstructionBlock* block : code()->instruction_blocks()) {
MeetRegisterConstraints(block);
}
}
......@@ -1544,13 +1549,13 @@ void ConstraintBuilder::MeetRegisterConstraints(const InstructionBlock* block) {
void ConstraintBuilder::MeetRegisterConstraintsForLastInstructionInBlock(
const InstructionBlock* block) {
int end = block->last_instruction_index();
auto last_instruction = code()->InstructionAt(end);
Instruction* last_instruction = code()->InstructionAt(end);
for (size_t i = 0; i < last_instruction->OutputCount(); i++) {
auto output_operand = last_instruction->OutputAt(i);
InstructionOperand* output_operand = last_instruction->OutputAt(i);
DCHECK(!output_operand->IsConstant());
auto output = UnallocatedOperand::cast(output_operand);
UnallocatedOperand* output = UnallocatedOperand::cast(output_operand);
int output_vreg = output->virtual_register();
auto range = data()->GetOrCreateLiveRangeFor(output_vreg);
TopLevelLiveRange* range = data()->GetOrCreateLiveRangeFor(output_vreg);
bool assigned = false;
if (output->HasFixedPolicy()) {
AllocateFixed(output, -1, false);
......@@ -1563,7 +1568,7 @@ void ConstraintBuilder::MeetRegisterConstraintsForLastInstructionInBlock(
assigned = true;
}
for (auto succ : block->successors()) {
for (const RpoNumber& succ : block->successors()) {
const InstructionBlock* successor = code()->InstructionBlockAt(succ);
DCHECK(successor->PredecessorCount() == 1);
int gap_index = successor->first_instruction_index();
......@@ -1575,7 +1580,7 @@ void ConstraintBuilder::MeetRegisterConstraintsForLastInstructionInBlock(
}
if (!assigned) {
for (auto succ : block->successors()) {
for (const RpoNumber& succ : block->successors()) {
const InstructionBlock* successor = code()->InstructionBlockAt(succ);
DCHECK(successor->PredecessorCount() == 1);
int gap_index = successor->first_instruction_index();
......@@ -1588,10 +1593,10 @@ void ConstraintBuilder::MeetRegisterConstraintsForLastInstructionInBlock(
void ConstraintBuilder::MeetConstraintsAfter(int instr_index) {
auto first = code()->InstructionAt(instr_index);
Instruction* first = code()->InstructionAt(instr_index);
// Handle fixed temporaries.
for (size_t i = 0; i < first->TempCount(); i++) {
auto temp = UnallocatedOperand::cast(first->TempAt(i));
UnallocatedOperand* temp = UnallocatedOperand::cast(first->TempAt(i));
if (temp->HasFixedPolicy()) AllocateFixed(temp, instr_index, false);
}
// Handle constant/fixed output operands.
......@@ -1599,13 +1604,13 @@ void ConstraintBuilder::MeetConstraintsAfter(int instr_index) {
InstructionOperand* output = first->OutputAt(i);
if (output->IsConstant()) {
int output_vreg = ConstantOperand::cast(output)->virtual_register();
auto range = data()->GetOrCreateLiveRangeFor(output_vreg);
TopLevelLiveRange* range = data()->GetOrCreateLiveRangeFor(output_vreg);
range->SetSpillStartIndex(instr_index + 1);
range->SetSpillOperand(output);
continue;
}
auto first_output = UnallocatedOperand::cast(output);
auto range =
UnallocatedOperand* first_output = UnallocatedOperand::cast(output);
TopLevelLiveRange* range =
data()->GetOrCreateLiveRangeFor(first_output->virtual_register());
bool assigned = false;
if (first_output->HasFixedPolicy()) {
......@@ -1642,14 +1647,14 @@ void ConstraintBuilder::MeetConstraintsAfter(int instr_index) {
void ConstraintBuilder::MeetConstraintsBefore(int instr_index) {
auto second = code()->InstructionAt(instr_index);
Instruction* second = code()->InstructionAt(instr_index);
// Handle fixed input operands of second instruction.
for (size_t i = 0; i < second->InputCount(); i++) {
auto input = second->InputAt(i);
InstructionOperand* input = second->InputAt(i);
if (input->IsImmediate() || input->IsExplicit()) {
continue; // Ignore immediates and explicitly reserved registers.
}
auto cur_input = UnallocatedOperand::cast(input);
UnallocatedOperand* cur_input = UnallocatedOperand::cast(input);
if (cur_input->HasFixedPolicy()) {
int input_vreg = cur_input->virtual_register();
UnallocatedOperand input_copy(UnallocatedOperand::ANY, input_vreg);
......@@ -1660,9 +1665,9 @@ void ConstraintBuilder::MeetConstraintsBefore(int instr_index) {
}
// Handle "output same as input" for second instruction.
for (size_t i = 0; i < second->OutputCount(); i++) {
auto output = second->OutputAt(i);
InstructionOperand* output = second->OutputAt(i);
if (!output->IsUnallocated()) continue;
auto second_output = UnallocatedOperand::cast(output);
UnallocatedOperand* second_output = UnallocatedOperand::cast(output);
if (!second_output->HasSameAsInputPolicy()) continue;
DCHECK(i == 0); // Only valid for first output.
UnallocatedOperand* cur_input =
......@@ -1671,7 +1676,7 @@ void ConstraintBuilder::MeetConstraintsBefore(int instr_index) {
int input_vreg = cur_input->virtual_register();
UnallocatedOperand input_copy(UnallocatedOperand::ANY, input_vreg);
cur_input->set_virtual_register(second_output->virtual_register());
auto gap_move = data()->AddGapMove(instr_index, Instruction::END,
MoveOperands* gap_move = data()->AddGapMove(instr_index, Instruction::END,
input_copy, *cur_input);
if (code()->IsReference(input_vreg) && !code()->IsReference(output_vreg)) {
if (second->HasReferenceMap()) {
......@@ -1701,23 +1706,24 @@ void ConstraintBuilder::ResolvePhis() {
void ConstraintBuilder::ResolvePhis(const InstructionBlock* block) {
for (auto phi : block->phis()) {
for (PhiInstruction* phi : block->phis()) {
int phi_vreg = phi->virtual_register();
auto map_value = data()->InitializePhiMap(block, phi);
auto& output = phi->output();
RegisterAllocationData::PhiMapValue* map_value =
data()->InitializePhiMap(block, phi);
InstructionOperand& output = phi->output();
// Map the destination operands, so the commitment phase can find them.
for (size_t i = 0; i < phi->operands().size(); ++i) {
InstructionBlock* cur_block =
code()->InstructionBlockAt(block->predecessors()[i]);
UnallocatedOperand input(UnallocatedOperand::ANY, phi->operands()[i]);
auto move = data()->AddGapMove(cur_block->last_instruction_index(),
Instruction::END, input, output);
MoveOperands* move = data()->AddGapMove(
cur_block->last_instruction_index(), Instruction::END, input, output);
map_value->AddOperand(&move->destination());
DCHECK(!code()
->InstructionAt(cur_block->last_instruction_index())
->HasReferenceMap());
}
auto live_range = data()->GetOrCreateLiveRangeFor(phi_vreg);
TopLevelLiveRange* live_range = data()->GetOrCreateLiveRangeFor(phi_vreg);
int gap_index = block->first_instruction_index();
live_range->RecordSpillLocation(allocation_zone(), gap_index, &output);
live_range->SetSpillStartIndex(gap_index);
......@@ -1754,7 +1760,7 @@ BitVector* LiveRangeBuilder::ComputeLiveOut(const InstructionBlock* block,
// All phi input operands corresponding to this successor edge are live
// out from this block.
auto successor = code->InstructionBlockAt(succ);
const InstructionBlock* successor = code->InstructionBlockAt(succ);
size_t index = successor->PredecessorIndexOf(block->rpo_number());
DCHECK(index < successor->PredecessorCount());
for (PhiInstruction* phi : successor->phis()) {
......@@ -1771,14 +1777,15 @@ void LiveRangeBuilder::AddInitialIntervals(const InstructionBlock* block,
BitVector* live_out) {
// Add an interval that includes the entire block to the live range for
// each live_out value.
auto start = LifetimePosition::GapFromInstructionIndex(
LifetimePosition start = LifetimePosition::GapFromInstructionIndex(
block->first_instruction_index());
auto end = LifetimePosition::InstructionFromInstructionIndex(
block->last_instruction_index()).NextStart();
LifetimePosition end = LifetimePosition::InstructionFromInstructionIndex(
block->last_instruction_index())
.NextStart();
BitVector::Iterator iterator(live_out);
while (!iterator.Done()) {
int operand_index = iterator.Current();
auto range = data()->GetOrCreateLiveRangeFor(operand_index);
TopLevelLiveRange* range = data()->GetOrCreateLiveRangeFor(operand_index);
range->AddUseInterval(start, end, allocation_zone());
iterator.Advance();
}
......@@ -1792,7 +1799,7 @@ int LiveRangeBuilder::FixedDoubleLiveRangeID(int index) {
TopLevelLiveRange* LiveRangeBuilder::FixedLiveRangeFor(int index) {
DCHECK(index < config()->num_general_registers());
auto result = data()->fixed_live_ranges()[index];
TopLevelLiveRange* result = data()->fixed_live_ranges()[index];
if (result == nullptr) {
result = data()->NewLiveRange(FixedLiveRangeID(index),
InstructionSequence::DefaultRepresentation());
......@@ -1807,7 +1814,7 @@ TopLevelLiveRange* LiveRangeBuilder::FixedLiveRangeFor(int index) {
TopLevelLiveRange* LiveRangeBuilder::FixedDoubleLiveRangeFor(int index) {
DCHECK(index < config()->num_double_registers());
auto result = data()->fixed_double_live_ranges()[index];
TopLevelLiveRange* result = data()->fixed_double_live_ranges()[index];
if (result == nullptr) {
result = data()->NewLiveRange(FixedDoubleLiveRangeID(index),
MachineRepresentation::kFloat64);
......@@ -1850,7 +1857,7 @@ UsePosition* LiveRangeBuilder::NewUsePosition(LifetimePosition pos,
UsePosition* LiveRangeBuilder::Define(LifetimePosition position,
InstructionOperand* operand, void* hint,
UsePositionHintType hint_type) {
auto range = LiveRangeFor(operand);
TopLevelLiveRange* range = LiveRangeFor(operand);
if (range == nullptr) return nullptr;
if (range->IsEmpty() || range->Start() > position) {
......@@ -1861,8 +1868,9 @@ UsePosition* LiveRangeBuilder::Define(LifetimePosition position,
range->ShortenTo(position);
}
if (!operand->IsUnallocated()) return nullptr;
auto unalloc_operand = UnallocatedOperand::cast(operand);
auto use_pos = NewUsePosition(position, unalloc_operand, hint, hint_type);
UnallocatedOperand* unalloc_operand = UnallocatedOperand::cast(operand);
UsePosition* use_pos =
NewUsePosition(position, unalloc_operand, hint, hint_type);
range->AddUsePosition(use_pos);
return use_pos;
}
......@@ -1872,7 +1880,7 @@ UsePosition* LiveRangeBuilder::Use(LifetimePosition block_start,
LifetimePosition position,
InstructionOperand* operand, void* hint,
UsePositionHintType hint_type) {
auto range = LiveRangeFor(operand);
TopLevelLiveRange* range = LiveRangeFor(operand);
if (range == nullptr) return nullptr;
UsePosition* use_pos = nullptr;
if (operand->IsUnallocated()) {
......@@ -1888,19 +1896,19 @@ UsePosition* LiveRangeBuilder::Use(LifetimePosition block_start,
void LiveRangeBuilder::ProcessInstructions(const InstructionBlock* block,
BitVector* live) {
int block_start = block->first_instruction_index();
auto block_start_position =
LifetimePosition block_start_position =
LifetimePosition::GapFromInstructionIndex(block_start);
for (int index = block->last_instruction_index(); index >= block_start;
index--) {
auto curr_position =
LifetimePosition curr_position =
LifetimePosition::InstructionFromInstructionIndex(index);
auto instr = code()->InstructionAt(index);
Instruction* instr = code()->InstructionAt(index);
DCHECK(instr != nullptr);
DCHECK(curr_position.IsInstructionPosition());
// Process output, inputs, and temps of this instruction.
for (size_t i = 0; i < instr->OutputCount(); i++) {
auto output = instr->OutputAt(i);
InstructionOperand* output = instr->OutputAt(i);
if (output->IsUnallocated()) {
// Unsupported.
DCHECK(!UnallocatedOperand::cast(output)->HasSlotPolicy());
......@@ -1925,7 +1933,7 @@ void LiveRangeBuilder::ProcessInstructions(const InstructionBlock* block,
for (int i = 0; i < config()->num_allocatable_general_registers(); ++i) {
int code = config()->GetAllocatableGeneralCode(i);
if (!IsOutputRegisterOf(instr, Register::from_code(code))) {
auto range = FixedLiveRangeFor(code);
TopLevelLiveRange* range = FixedLiveRangeFor(code);
range->AddUseInterval(curr_position, curr_position.End(),
allocation_zone());
}
......@@ -1937,7 +1945,7 @@ void LiveRangeBuilder::ProcessInstructions(const InstructionBlock* block,
++i) {
int code = config()->GetAllocatableDoubleCode(i);
if (!IsOutputDoubleRegisterOf(instr, DoubleRegister::from_code(code))) {
auto range = FixedDoubleLiveRangeFor(code);
TopLevelLiveRange* range = FixedDoubleLiveRangeFor(code);
range->AddUseInterval(curr_position, curr_position.End(),
allocation_zone());
}
......@@ -1945,7 +1953,7 @@ void LiveRangeBuilder::ProcessInstructions(const InstructionBlock* block,
}
for (size_t i = 0; i < instr->InputCount(); i++) {
auto input = instr->InputAt(i);
InstructionOperand* input = instr->InputAt(i);
if (input->IsImmediate() || input->IsExplicit()) {
continue; // Ignore immediates and explicitly reserved registers.
}
......@@ -1969,7 +1977,7 @@ void LiveRangeBuilder::ProcessInstructions(const InstructionBlock* block,
}
for (size_t i = 0; i < instr->TempCount(); i++) {
auto temp = instr->TempAt(i);
InstructionOperand* temp = instr->TempAt(i);
// Unsupported.
DCHECK_IMPLIES(temp->IsUnallocated(),
!UnallocatedOperand::cast(temp)->HasSlotPolicy());
......@@ -1991,24 +1999,25 @@ void LiveRangeBuilder::ProcessInstructions(const InstructionBlock* block,
Instruction::START};
curr_position = curr_position.PrevStart();
DCHECK(curr_position.IsGapPosition());
for (auto position : kPositions) {
auto move = instr->GetParallelMove(position);
for (const Instruction::GapPosition& position : kPositions) {
ParallelMove* move = instr->GetParallelMove(position);
if (move == nullptr) continue;
if (position == Instruction::END) {
curr_position = curr_position.End();
} else {
curr_position = curr_position.Start();
}
for (auto cur : *move) {
auto& from = cur->source();
auto& to = cur->destination();
for (MoveOperands* cur : *move) {
InstructionOperand& from = cur->source();
InstructionOperand& to = cur->destination();
void* hint = &to;
UsePositionHintType hint_type = UsePosition::HintTypeForOperand(to);
UsePosition* to_use = nullptr;
int phi_vreg = -1;
if (to.IsUnallocated()) {
int to_vreg = UnallocatedOperand::cast(to).virtual_register();
auto to_range = data()->GetOrCreateLiveRangeFor(to_vreg);
TopLevelLiveRange* to_range =
data()->GetOrCreateLiveRangeFor(to_vreg);
if (to_range->is_phi()) {
phi_vreg = to_vreg;
if (to_range->is_non_loop_phi()) {
......@@ -2032,7 +2041,7 @@ void LiveRangeBuilder::ProcessInstructions(const InstructionBlock* block,
} else {
Define(curr_position, &to);
}
auto from_use =
UsePosition* from_use =
Use(block_start_position, curr_position, &from, hint, hint_type);
// Mark range live.
if (from.IsUnallocated()) {
......@@ -2055,16 +2064,16 @@ void LiveRangeBuilder::ProcessInstructions(const InstructionBlock* block,
void LiveRangeBuilder::ProcessPhis(const InstructionBlock* block,
BitVector* live) {
for (auto phi : block->phis()) {
for (PhiInstruction* phi : block->phis()) {
// The live range interval already ends at the first instruction of the
// block.
int phi_vreg = phi->virtual_register();
live->Remove(phi_vreg);
InstructionOperand* hint = nullptr;
auto instr = GetLastInstruction(
Instruction* instr = GetLastInstruction(
code(), code()->InstructionBlockAt(block->predecessors()[0]));
for (auto move : *instr->GetParallelMove(Instruction::END)) {
auto& to = move->destination();
for (MoveOperands* move : *instr->GetParallelMove(Instruction::END)) {
InstructionOperand& to = move->destination();
if (to.IsUnallocated() &&
UnallocatedOperand::cast(to).virtual_register() == phi_vreg) {
hint = &move->source();
......@@ -2072,9 +2081,9 @@ void LiveRangeBuilder::ProcessPhis(const InstructionBlock* block,
}
}
DCHECK(hint != nullptr);
auto block_start = LifetimePosition::GapFromInstructionIndex(
LifetimePosition block_start = LifetimePosition::GapFromInstructionIndex(
block->first_instruction_index());
auto use_pos = Define(block_start, &phi->output(), hint,
UsePosition* use_pos = Define(block_start, &phi->output(), hint,
UsePosition::HintTypeForOperand(*hint));
MapPhiHint(hint, use_pos);
}
......@@ -2087,10 +2096,11 @@ void LiveRangeBuilder::ProcessLoopHeader(const InstructionBlock* block,
// Add a live range stretching from the first loop instruction to the last
// for each value live on entry to the header.
BitVector::Iterator iterator(live);
auto start = LifetimePosition::GapFromInstructionIndex(
LifetimePosition start = LifetimePosition::GapFromInstructionIndex(
block->first_instruction_index());
auto end = LifetimePosition::GapFromInstructionIndex(
code()->LastLoopInstructionIndex(block)).NextFullStart();
LifetimePosition end = LifetimePosition::GapFromInstructionIndex(
code()->LastLoopInstructionIndex(block))
.NextFullStart();
while (!iterator.Done()) {
int operand_index = iterator.Current();
TopLevelLiveRange* range = data()->GetOrCreateLiveRangeFor(operand_index);
......@@ -2109,8 +2119,9 @@ void LiveRangeBuilder::BuildLiveRanges() {
// Process the blocks in reverse order.
for (int block_id = code()->InstructionBlockCount() - 1; block_id >= 0;
--block_id) {
auto block = code()->InstructionBlockAt(RpoNumber::FromInt(block_id));
auto live = ComputeLiveOut(block, data());
InstructionBlock* block =
code()->InstructionBlockAt(RpoNumber::FromInt(block_id));
BitVector* live = ComputeLiveOut(block, data());
// Initially consider all live_out values live for the entire block. We
// will shorten these intervals if necessary.
AddInitialIntervals(block, live);
......@@ -2125,7 +2136,7 @@ void LiveRangeBuilder::BuildLiveRanges() {
live_in_sets()[block_id] = live;
}
// Postprocess the ranges.
for (auto range : data()->live_ranges()) {
for (TopLevelLiveRange* range : data()->live_ranges()) {
if (range == nullptr) continue;
// Give slots to all ranges with a non fixed slot use.
if (range->has_slot_use() && range->HasNoSpillType()) {
......@@ -2136,7 +2147,8 @@ void LiveRangeBuilder::BuildLiveRanges() {
// Without this hack, all uses with "any" policy would get the constant
// operand assigned.
if (range->HasSpillOperand() && range->GetSpillOperand()->IsConstant()) {
for (auto pos = range->first_pos(); pos != nullptr; pos = pos->next()) {
for (UsePosition* pos = range->first_pos(); pos != nullptr;
pos = pos->next()) {
if (pos->type() == UsePositionType::kRequiresSlot) continue;
UsePositionType new_type = UsePositionType::kAny;
// Can't mark phis as needing a register.
......@@ -2279,7 +2291,7 @@ LiveRange* RegisterAllocator::SplitBetween(LiveRange* range,
range->TopLevel()->vreg(), range->relative_id(), start.value(),
end.value());
auto split_pos = FindOptimalSplitPos(start, end);
LifetimePosition split_pos = FindOptimalSplitPos(start, end);
DCHECK(split_pos >= start);
return SplitRangeAt(range, split_pos);
}
......@@ -2294,8 +2306,8 @@ LifetimePosition RegisterAllocator::FindOptimalSplitPos(LifetimePosition start,
// We have no choice
if (start_instr == end_instr) return end;
auto start_block = GetInstructionBlock(code(), start);
auto end_block = GetInstructionBlock(code(), end);
const InstructionBlock* start_block = GetInstructionBlock(code(), start);
const InstructionBlock* end_block = GetInstructionBlock(code(), end);
if (end_block == start_block) {
// The interval is split in the same basic block. Split at the latest
......@@ -2303,7 +2315,7 @@ LifetimePosition RegisterAllocator::FindOptimalSplitPos(LifetimePosition start,
return end;
}
auto block = end_block;
const InstructionBlock* block = end_block;
// Find header of outermost loop.
// TODO(titzer): fix redundancy below.
while (GetContainingLoop(code(), block) != nullptr &&
......@@ -2323,19 +2335,20 @@ LifetimePosition RegisterAllocator::FindOptimalSplitPos(LifetimePosition start,
LifetimePosition RegisterAllocator::FindOptimalSpillingPos(
LiveRange* range, LifetimePosition pos) {
auto block = GetInstructionBlock(code(), pos.Start());
auto loop_header =
const InstructionBlock* block = GetInstructionBlock(code(), pos.Start());
const InstructionBlock* loop_header =
block->IsLoopHeader() ? block : GetContainingLoop(code(), block);
if (loop_header == nullptr) return pos;
auto prev_use = range->PreviousUsePositionRegisterIsBeneficial(pos);
const UsePosition* prev_use =
range->PreviousUsePositionRegisterIsBeneficial(pos);
while (loop_header != nullptr) {
// We are going to spill live range inside the loop.
// If possible try to move spilling position backwards to loop header.
// This will reduce number of memory moves on the back edge.
auto loop_start = LifetimePosition::GapFromInstructionIndex(
LifetimePosition loop_start = LifetimePosition::GapFromInstructionIndex(
loop_header->first_instruction_index());
if (range->Covers(loop_start)) {
......@@ -2419,7 +2432,7 @@ void LinearScanAllocator::AllocateRegisters() {
DCHECK(UnhandledIsSorted());
auto& fixed_ranges = GetFixedRegisters();
for (auto current : fixed_ranges) {
for (TopLevelLiveRange* current : fixed_ranges) {
if (current != nullptr) {
DCHECK_EQ(mode(), current->kind());
AddToInactive(current);
......@@ -2428,10 +2441,10 @@ void LinearScanAllocator::AllocateRegisters() {
while (!unhandled_live_ranges().empty()) {
DCHECK(UnhandledIsSorted());
auto current = unhandled_live_ranges().back();
LiveRange* current = unhandled_live_ranges().back();
unhandled_live_ranges().pop_back();
DCHECK(UnhandledIsSorted());
auto position = current->Start();
LifetimePosition position = current->Start();
#ifdef DEBUG
allocation_finger_ = position;
#endif
......@@ -2442,7 +2455,7 @@ void LinearScanAllocator::AllocateRegisters() {
continue;
for (size_t i = 0; i < active_live_ranges().size(); ++i) {
auto cur_active = active_live_ranges()[i];
LiveRange* cur_active = active_live_ranges()[i];
if (cur_active->End() <= position) {
ActiveToHandled(cur_active);
--i; // The live range was removed from the list of active live ranges.
......@@ -2453,7 +2466,7 @@ void LinearScanAllocator::AllocateRegisters() {
}
for (size_t i = 0; i < inactive_live_ranges().size(); ++i) {
auto cur_inactive = inactive_live_ranges()[i];
LiveRange* cur_inactive = inactive_live_ranges()[i];
if (cur_inactive->End() <= position) {
InactiveToHandled(cur_inactive);
--i; // Live range was removed from the list of inactive live ranges.
......@@ -2505,7 +2518,7 @@ void LinearScanAllocator::AddToUnhandledSorted(LiveRange* range) {
DCHECK(allocation_finger_ <= range->Start());
for (int i = static_cast<int>(unhandled_live_ranges().size() - 1); i >= 0;
--i) {
auto cur_range = unhandled_live_ranges().at(i);
LiveRange* cur_range = unhandled_live_ranges().at(i);
if (!range->ShouldBeAllocatedBefore(cur_range)) continue;
TRACE("Add live range %d:%d to unhandled at %d\n",
range->TopLevel()->vreg(), range->relative_id(), i + 1);
......@@ -2551,8 +2564,8 @@ void LinearScanAllocator::SortUnhandled() {
bool LinearScanAllocator::UnhandledIsSorted() {
size_t len = unhandled_live_ranges().size();
for (size_t i = 1; i < len; i++) {
auto a = unhandled_live_ranges().at(i - 1);
auto b = unhandled_live_ranges().at(i);
LiveRange* a = unhandled_live_ranges().at(i - 1);
LiveRange* b = unhandled_live_ranges().at(i);
if (a->Start() < b->Start()) return false;
}
return true;
......@@ -2596,7 +2609,7 @@ bool LinearScanAllocator::TryAllocateFreeReg(LiveRange* current) {
free_until_pos[i] = LifetimePosition::MaxPosition();
}
for (auto cur_active : active_live_ranges()) {
for (LiveRange* cur_active : active_live_ranges()) {
free_until_pos[cur_active->assigned_register()] =
LifetimePosition::GapFromInstructionIndex(0);
TRACE("Register %s is free until pos %d (1)\n",
......@@ -2604,9 +2617,10 @@ bool LinearScanAllocator::TryAllocateFreeReg(LiveRange* current) {
LifetimePosition::GapFromInstructionIndex(0).value());
}
for (auto cur_inactive : inactive_live_ranges()) {
for (LiveRange* cur_inactive : inactive_live_ranges()) {
DCHECK(cur_inactive->End() > current->Start());
auto next_intersection = cur_inactive->FirstIntersection(current);
LifetimePosition next_intersection =
cur_inactive->FirstIntersection(current);
if (!next_intersection.IsValid()) continue;
int cur_reg = cur_inactive->assigned_register();
free_until_pos[cur_reg] = Min(free_until_pos[cur_reg], next_intersection);
......@@ -2641,7 +2655,7 @@ bool LinearScanAllocator::TryAllocateFreeReg(LiveRange* current) {
}
}
auto pos = free_until_pos[reg];
LifetimePosition pos = free_until_pos[reg];
if (pos <= current->Start()) {
// All registers are blocked.
......@@ -2651,7 +2665,7 @@ bool LinearScanAllocator::TryAllocateFreeReg(LiveRange* current) {
if (pos < current->End()) {
// Register reg is available at the range start but becomes blocked before
// the range end. Split current at position where it becomes blocked.
auto tail = SplitRangeAt(current, pos);
LiveRange* tail = SplitRangeAt(current, pos);
AddToUnhandledSorted(tail);
}
......@@ -2667,7 +2681,7 @@ bool LinearScanAllocator::TryAllocateFreeReg(LiveRange* current) {
void LinearScanAllocator::AllocateBlockedReg(LiveRange* current) {
auto register_use = current->NextRegisterPosition(current->Start());
UsePosition* register_use = current->NextRegisterPosition(current->Start());
if (register_use == nullptr) {
// There is no use in the current live range that requires a register.
// We can just spill it.
......@@ -2682,14 +2696,14 @@ void LinearScanAllocator::AllocateBlockedReg(LiveRange* current) {
use_pos[i] = block_pos[i] = LifetimePosition::MaxPosition();
}
for (auto range : active_live_ranges()) {
for (LiveRange* range : active_live_ranges()) {
int cur_reg = range->assigned_register();
if (range->TopLevel()->IsFixed() ||
!range->CanBeSpilled(current->Start())) {
block_pos[cur_reg] = use_pos[cur_reg] =
LifetimePosition::GapFromInstructionIndex(0);
} else {
auto next_use =
UsePosition* next_use =
range->NextUsePositionRegisterIsBeneficial(current->Start());
if (next_use == nullptr) {
use_pos[cur_reg] = range->End();
......@@ -2699,9 +2713,9 @@ void LinearScanAllocator::AllocateBlockedReg(LiveRange* current) {
}
}
for (auto range : inactive_live_ranges()) {
for (LiveRange* range : inactive_live_ranges()) {
DCHECK(range->End() > current->Start());
auto next_intersection = range->FirstIntersection(current);
LifetimePosition next_intersection = range->FirstIntersection(current);
if (!next_intersection.IsValid()) continue;
int cur_reg = range->assigned_register();
if (range->TopLevel()->IsFixed()) {
......@@ -2720,7 +2734,7 @@ void LinearScanAllocator::AllocateBlockedReg(LiveRange* current) {
}
}
auto pos = use_pos[reg];
LifetimePosition pos = use_pos[reg];
if (pos < register_use->pos()) {
// All registers are blocked before the first use that requires a register.
......@@ -2753,12 +2767,12 @@ void LinearScanAllocator::AllocateBlockedReg(LiveRange* current) {
void LinearScanAllocator::SplitAndSpillIntersecting(LiveRange* current) {
DCHECK(current->HasRegisterAssigned());
int reg = current->assigned_register();
auto split_pos = current->Start();
LifetimePosition split_pos = current->Start();
for (size_t i = 0; i < active_live_ranges().size(); ++i) {
auto range = active_live_ranges()[i];
LiveRange* range = active_live_ranges()[i];
if (range->assigned_register() == reg) {
auto next_pos = range->NextRegisterPosition(current->Start());
auto spill_pos = FindOptimalSpillingPos(range, split_pos);
UsePosition* next_pos = range->NextRegisterPosition(current->Start());
LifetimePosition spill_pos = FindOptimalSpillingPos(range, split_pos);
if (next_pos == nullptr) {
SpillAfter(range, spill_pos);
} else {
......@@ -2778,7 +2792,7 @@ void LinearScanAllocator::SplitAndSpillIntersecting(LiveRange* current) {
}
for (size_t i = 0; i < inactive_live_ranges().size(); ++i) {
auto range = inactive_live_ranges()[i];
LiveRange* range = inactive_live_ranges()[i];
DCHECK(range->End() > current->Start());
if (range->assigned_register() == reg && !range->TopLevel()->IsFixed()) {
LifetimePosition next_intersection = range->FirstIntersection(current);
......@@ -2802,9 +2816,10 @@ bool LinearScanAllocator::TryReuseSpillForPhi(TopLevelLiveRange* range) {
if (!range->is_phi()) return false;
DCHECK(!range->HasSpillOperand());
auto phi_map_value = data()->GetPhiMapValueFor(range);
auto phi = phi_map_value->phi();
auto block = phi_map_value->block();
RegisterAllocationData::PhiMapValue* phi_map_value =
data()->GetPhiMapValueFor(range);
const PhiInstruction* phi = phi_map_value->phi();
const InstructionBlock* block = phi_map_value->block();
// Count the number of spilled operands.
size_t spilled_count = 0;
LiveRange* first_op = nullptr;
......@@ -2812,8 +2827,10 @@ bool LinearScanAllocator::TryReuseSpillForPhi(TopLevelLiveRange* range) {
int op = phi->operands()[i];
LiveRange* op_range = data()->GetOrCreateLiveRangeFor(op);
if (!op_range->TopLevel()->HasSpillRange()) continue;
auto pred = code()->InstructionBlockAt(block->predecessors()[i]);
auto pred_end = LifetimePosition::InstructionFromInstructionIndex(
const InstructionBlock* pred =
code()->InstructionBlockAt(block->predecessors()[i]);
LifetimePosition pred_end =
LifetimePosition::InstructionFromInstructionIndex(
pred->last_instruction_index());
while (op_range != nullptr && !op_range->CanCover(pred_end)) {
op_range = op_range->next();
......@@ -2834,13 +2851,13 @@ bool LinearScanAllocator::TryReuseSpillForPhi(TopLevelLiveRange* range) {
// Try to merge the spilled operands and count the number of merged spilled
// operands.
DCHECK(first_op != nullptr);
auto first_op_spill = first_op->TopLevel()->GetSpillRange();
SpillRange* first_op_spill = first_op->TopLevel()->GetSpillRange();
size_t num_merged = 1;
for (size_t i = 1; i < phi->operands().size(); i++) {
int op = phi->operands()[i];
auto op_range = data()->GetOrCreateLiveRangeFor(op);
TopLevelLiveRange* op_range = data()->live_ranges()[op];
if (!op_range->HasSpillRange()) continue;
auto op_spill = op_range->GetSpillRange();
SpillRange* op_spill = op_range->GetSpillRange();
if (op_spill == first_op_spill || first_op_spill->TryMerge(op_spill)) {
num_merged++;
}
......@@ -2856,11 +2873,11 @@ bool LinearScanAllocator::TryReuseSpillForPhi(TopLevelLiveRange* range) {
// If the range does not need register soon, spill it to the merged
// spill range.
auto next_pos = range->Start();
LifetimePosition next_pos = range->Start();
if (next_pos.IsGapPosition()) next_pos = next_pos.NextStart();
auto pos = range->NextUsePositionRegisterIsBeneficial(next_pos);
UsePosition* pos = range->NextUsePositionRegisterIsBeneficial(next_pos);
if (pos == nullptr) {
auto spill_range =
SpillRange* spill_range =
range->TopLevel()->HasSpillRange()
? range->TopLevel()->GetSpillRange()
: data()->AssignSpillRangeToLiveRange(range->TopLevel());
......@@ -2869,7 +2886,7 @@ bool LinearScanAllocator::TryReuseSpillForPhi(TopLevelLiveRange* range) {
Spill(range);
return true;
} else if (pos->pos() > range->Start().NextStart()) {
auto spill_range =
SpillRange* spill_range =
range->TopLevel()->HasSpillRange()
? range->TopLevel()->GetSpillRange()
: data()->AssignSpillRangeToLiveRange(range->TopLevel());
......@@ -2884,7 +2901,7 @@ bool LinearScanAllocator::TryReuseSpillForPhi(TopLevelLiveRange* range) {
void LinearScanAllocator::SpillAfter(LiveRange* range, LifetimePosition pos) {
auto second_part = SplitRangeAt(range, pos);
LiveRange* second_part = SplitRangeAt(range, pos);
Spill(second_part);
}
......@@ -2900,17 +2917,17 @@ void LinearScanAllocator::SpillBetweenUntil(LiveRange* range,
LifetimePosition until,
LifetimePosition end) {
CHECK(start < end);
auto second_part = SplitRangeAt(range, start);
LiveRange* second_part = SplitRangeAt(range, start);
if (second_part->Start() < end) {
// The split result intersects with [start, end[.
// Split it at position between ]start+1, end[, spill the middle part
// and put the rest to unhandled.
auto third_part_end = end.PrevStart().End();
LifetimePosition third_part_end = end.PrevStart().End();
if (data()->IsBlockBoundary(end.Start())) {
third_part_end = end.Start();
}
auto third_part = SplitBetween(
LiveRange* third_part = SplitBetween(
second_part, Max(second_part->Start().End(), until), third_part_end);
DCHECK(third_part != second_part);
......@@ -2930,7 +2947,7 @@ SpillSlotLocator::SpillSlotLocator(RegisterAllocationData* data)
void SpillSlotLocator::LocateSpillSlots() {
auto code = data()->code();
const InstructionSequence* code = data()->code();
for (TopLevelLiveRange* range : data()->live_ranges()) {
if (range == nullptr || range->IsEmpty()) continue;
// We care only about ranges which spill in the frame.
......@@ -2943,7 +2960,8 @@ void SpillSlotLocator::LocateSpillSlots() {
}
}
} else {
auto spills = range->spill_move_insertion_locations();
TopLevelLiveRange::SpillMoveInsertionList* spills =
range->spill_move_insertion_locations();
DCHECK_NOT_NULL(spills);
for (; spills != nullptr; spills = spills->next) {
code->GetInstructionBlock(spills->gap_index)->mark_needs_frame();
......@@ -2998,7 +3016,7 @@ void OperandAssigner::CommitAssignment() {
}
for (LiveRange* range = top_range; range != nullptr;
range = range->next()) {
auto assigned = range->GetAssignedOperand();
InstructionOperand assigned = range->GetAssignedOperand();
range->ConvertUsesToOperand(assigned, spill_operand);
}
......@@ -3033,7 +3051,7 @@ ReferenceMapPopulator::ReferenceMapPopulator(RegisterAllocationData* data)
bool ReferenceMapPopulator::SafePointsAreInOrder() const {
int safe_point = 0;
for (auto map : *data()->code()->reference_maps()) {
for (ReferenceMap* map : *data()->code()->reference_maps()) {
if (safe_point > map->instruction_position()) return false;
safe_point = map->instruction_position();
}
......@@ -3044,14 +3062,15 @@ bool ReferenceMapPopulator::SafePointsAreInOrder() const {
void ReferenceMapPopulator::PopulateReferenceMaps() {
DCHECK(SafePointsAreInOrder());
// Map all delayed references.
for (auto& delayed_reference : data()->delayed_references()) {
for (RegisterAllocationData::DelayedReference& delayed_reference :
data()->delayed_references()) {
delayed_reference.map->RecordReference(
AllocatedOperand::cast(*delayed_reference.operand));
}
// Iterate over all safe point positions and record a pointer
// for all spilled live ranges at this point.
int last_range_start = 0;
auto reference_maps = data()->code()->reference_maps();
const ReferenceMapDeque* reference_maps = data()->code()->reference_maps();
ReferenceMapDeque::const_iterator first_it = reference_maps->begin();
for (TopLevelLiveRange* range : data()->live_ranges()) {
if (range == nullptr) continue;
......@@ -3065,7 +3084,7 @@ void ReferenceMapPopulator::PopulateReferenceMaps() {
int start = range->Start().ToInstructionIndex();
int end = 0;
for (LiveRange* cur = range; cur != nullptr; cur = cur->next()) {
auto this_end = cur->End();
LifetimePosition this_end = cur->End();
if (this_end.ToInstructionIndex() > end)
end = this_end.ToInstructionIndex();
DCHECK(cur->Start().ToInstructionIndex() >= start);
......@@ -3079,7 +3098,7 @@ void ReferenceMapPopulator::PopulateReferenceMaps() {
// Step across all the safe points that are before the start of this range,
// recording how far we step in order to save doing this for the next range.
for (; first_it != reference_maps->end(); ++first_it) {
auto map = *first_it;
ReferenceMap* map = *first_it;
if (map->instruction_position() >= start) break;
}
......@@ -3100,7 +3119,7 @@ void ReferenceMapPopulator::PopulateReferenceMaps() {
LiveRange* cur = range;
// Step through the safe points to see whether they are in the range.
for (auto it = first_it; it != reference_maps->end(); ++it) {
auto map = *it;
ReferenceMap* map = *it;
int safe_point = map->instruction_position();
// The safe points are sorted so we can stop searching here.
......@@ -3108,7 +3127,7 @@ void ReferenceMapPopulator::PopulateReferenceMaps() {
// Advance to the next active range that covers the current
// safe point position.
auto safe_point_pos =
LifetimePosition safe_point_pos =
LifetimePosition::InstructionFromInstructionIndex(safe_point);
// Search for the child range (cur) that covers safe_point_pos. If we
......@@ -3154,7 +3173,7 @@ void ReferenceMapPopulator::PopulateReferenceMaps() {
"at safe point %d\n",
range->vreg(), cur->relative_id(), cur->Start().value(),
safe_point);
auto operand = cur->GetAssignedOperand();
InstructionOperand operand = cur->GetAssignedOperand();
DCHECK(!operand.IsStackSlot());
DCHECK_EQ(MachineRepresentation::kTagged,
AllocatedOperand::cast(operand).representation());
......@@ -3220,7 +3239,7 @@ class LiveRangeBoundArray {
while (true) {
size_t current_index = left_index + (right_index - left_index) / 2;
DCHECK(right_index > current_index);
auto bound = &start_[current_index];
LiveRangeBound* bound = &start_[current_index];
if (bound->start_ <= position) {
if (position < bound->end_) return bound;
DCHECK(left_index < current_index);
......@@ -3232,13 +3251,14 @@ class LiveRangeBoundArray {
}
LiveRangeBound* FindPred(const InstructionBlock* pred) {
auto pred_end = LifetimePosition::InstructionFromInstructionIndex(
LifetimePosition pred_end =
LifetimePosition::InstructionFromInstructionIndex(
pred->last_instruction_index());
return Find(pred_end);
}
LiveRangeBound* FindSucc(const InstructionBlock* succ) {
auto succ_start = LifetimePosition::GapFromInstructionIndex(
LifetimePosition succ_start = LifetimePosition::GapFromInstructionIndex(
succ->first_instruction_index());
return Find(succ_start);
}
......@@ -3290,9 +3310,9 @@ class LiveRangeFinder {
LiveRangeBoundArray* ArrayFor(int operand_index) {
DCHECK(operand_index < bounds_length_);
auto range = data_->live_ranges()[operand_index];
TopLevelLiveRange* range = data_->live_ranges()[operand_index];
DCHECK(range != nullptr && !range->IsEmpty());
auto array = &bounds_[operand_index];
LiveRangeBoundArray* array = &bounds_[operand_index];
if (array->ShouldInitialize()) {
array->Initialize(zone_, range);
}
......@@ -3343,21 +3363,21 @@ bool LiveRangeConnector::CanEagerlyResolveControlFlow(
void LiveRangeConnector::ResolveControlFlow(Zone* local_zone) {
// Lazily linearize live ranges in memory for fast lookup.
LiveRangeFinder finder(data(), local_zone);
auto& live_in_sets = data()->live_in_sets();
for (auto block : code()->instruction_blocks()) {
ZoneVector<BitVector*>& live_in_sets = data()->live_in_sets();
for (const InstructionBlock* block : code()->instruction_blocks()) {
if (CanEagerlyResolveControlFlow(block)) continue;
auto live = live_in_sets[block->rpo_number().ToInt()];
BitVector* live = live_in_sets[block->rpo_number().ToInt()];
BitVector::Iterator iterator(live);
while (!iterator.Done()) {
auto* array = finder.ArrayFor(iterator.Current());
for (auto pred : block->predecessors()) {
LiveRangeBoundArray* array = finder.ArrayFor(iterator.Current());
for (const RpoNumber& pred : block->predecessors()) {
FindResult result;
const auto* pred_block = code()->InstructionBlockAt(pred);
const InstructionBlock* pred_block = code()->InstructionBlockAt(pred);
if (!array->FindConnectableSubranges(block, pred_block, &result)) {
continue;
}
auto pred_op = result.pred_cover_->GetAssignedOperand();
auto cur_op = result.cur_cover_->GetAssignedOperand();
InstructionOperand pred_op = result.pred_cover_->GetAssignedOperand();
InstructionOperand cur_op = result.cur_cover_->GetAssignedOperand();
if (pred_op.Equals(cur_op)) continue;
ResolveControlFlow(block, cur_op, pred_block, pred_op);
}
......@@ -3397,7 +3417,7 @@ void LiveRangeConnector::ConnectRanges(Zone* local_zone) {
LiveRange* first_range = top_range;
for (LiveRange *second_range = first_range->next(); second_range != nullptr;
first_range = second_range, second_range = second_range->next()) {
auto pos = second_range->Start();
LifetimePosition pos = second_range->Start();
// Add gap move if the two live ranges touch and there is no block
// boundary.
if (!connect_spilled && second_range->spilled()) continue;
......@@ -3406,8 +3426,8 @@ void LiveRangeConnector::ConnectRanges(Zone* local_zone) {
!CanEagerlyResolveControlFlow(GetInstructionBlock(code(), pos))) {
continue;
}
auto prev_operand = first_range->GetAssignedOperand();
auto cur_operand = second_range->GetAssignedOperand();
InstructionOperand prev_operand = first_range->GetAssignedOperand();
InstructionOperand cur_operand = second_range->GetAssignedOperand();
if (prev_operand.Equals(cur_operand)) continue;
bool delay_insertion = false;
Instruction::GapPosition gap_pos;
......@@ -3422,7 +3442,8 @@ void LiveRangeConnector::ConnectRanges(Zone* local_zone) {
}
gap_pos = delay_insertion ? Instruction::END : Instruction::START;
}
auto move = code()->InstructionAt(gap_index)->GetOrCreateParallelMove(
ParallelMove* move =
code()->InstructionAt(gap_index)->GetOrCreateParallelMove(
gap_pos, code_zone());
if (!delay_insertion) {
move->AddMove(prev_operand, cur_operand);
......@@ -3438,15 +3459,15 @@ void LiveRangeConnector::ConnectRanges(Zone* local_zone) {
ZoneVector<MoveOperands*> to_eliminate(local_zone);
to_insert.reserve(4);
to_eliminate.reserve(4);
auto moves = delayed_insertion_map.begin()->first.first;
ParallelMove* moves = delayed_insertion_map.begin()->first.first;
for (auto it = delayed_insertion_map.begin();; ++it) {
bool done = it == delayed_insertion_map.end();
if (done || it->first.first != moves) {
// Commit the MoveOperands for current ParallelMove.
for (auto move : to_eliminate) {
for (MoveOperands* move : to_eliminate) {
move->Eliminate();
}
for (auto move : to_insert) {
for (MoveOperands* move : to_insert) {
moves->push_back(move);
}
if (done) break;
......@@ -3456,8 +3477,9 @@ void LiveRangeConnector::ConnectRanges(Zone* local_zone) {
moves = it->first.first;
}
// Gather all MoveOperands for a single ParallelMove.
auto move = new (code_zone()) MoveOperands(it->first.second, it->second);
auto eliminate = moves->PrepareInsertAfter(move);
MoveOperands* move =
new (code_zone()) MoveOperands(it->first.second, it->second);
MoveOperands* eliminate = moves->PrepareInsertAfter(move);
to_insert.push_back(move);
if (eliminate != nullptr) to_eliminate.push_back(eliminate);
}
......
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