| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/base/adapters.h" | 5 #include "src/base/adapters.h" |
| 6 #include "src/compiler/linkage.h" | 6 #include "src/compiler/linkage.h" |
| 7 #include "src/compiler/register-allocator.h" | 7 #include "src/compiler/register-allocator.h" |
| 8 #include "src/string-stream.h" | 8 #include "src/string-stream.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 244 |
| 245 | 245 |
| 246 void LiveRange::CommitSpillOperand(AllocatedOperand* operand) { | 246 void LiveRange::CommitSpillOperand(AllocatedOperand* operand) { |
| 247 DCHECK(HasSpillRange()); | 247 DCHECK(HasSpillRange()); |
| 248 DCHECK(!IsChild()); | 248 DCHECK(!IsChild()); |
| 249 spill_type_ = SpillType::kSpillOperand; | 249 spill_type_ = SpillType::kSpillOperand; |
| 250 spill_operand_ = operand; | 250 spill_operand_ = operand; |
| 251 } | 251 } |
| 252 | 252 |
| 253 | 253 |
| 254 UsePosition* LiveRange::NextUsePosition(LifetimePosition start) { | 254 UsePosition* LiveRange::NextUsePosition(LifetimePosition start) const { |
| 255 UsePosition* use_pos = last_processed_use_; | 255 UsePosition* use_pos = last_processed_use_; |
| 256 if (use_pos == nullptr) use_pos = first_pos(); | 256 if (use_pos == nullptr || use_pos->pos().Value() > start.Value()) { |
| 257 use_pos = first_pos(); |
| 258 } |
| 257 while (use_pos != nullptr && use_pos->pos().Value() < start.Value()) { | 259 while (use_pos != nullptr && use_pos->pos().Value() < start.Value()) { |
| 258 use_pos = use_pos->next(); | 260 use_pos = use_pos->next(); |
| 259 } | 261 } |
| 260 last_processed_use_ = use_pos; | 262 last_processed_use_ = use_pos; |
| 261 return use_pos; | 263 return use_pos; |
| 262 } | 264 } |
| 263 | 265 |
| 264 | 266 |
| 265 UsePosition* LiveRange::NextUsePositionRegisterIsBeneficial( | 267 UsePosition* LiveRange::NextUsePositionRegisterIsBeneficial( |
| 266 LifetimePosition start) { | 268 LifetimePosition start) const { |
| 267 UsePosition* pos = NextUsePosition(start); | 269 UsePosition* pos = NextUsePosition(start); |
| 268 while (pos != nullptr && !pos->RegisterIsBeneficial()) { | 270 while (pos != nullptr && !pos->RegisterIsBeneficial()) { |
| 269 pos = pos->next(); | 271 pos = pos->next(); |
| 270 } | 272 } |
| 271 return pos; | 273 return pos; |
| 272 } | 274 } |
| 273 | 275 |
| 274 | 276 |
| 275 UsePosition* LiveRange::PreviousUsePositionRegisterIsBeneficial( | 277 UsePosition* LiveRange::PreviousUsePositionRegisterIsBeneficial( |
| 276 LifetimePosition start) { | 278 LifetimePosition start) const { |
| 277 auto pos = first_pos(); | 279 auto pos = first_pos(); |
| 278 UsePosition* prev = nullptr; | 280 UsePosition* prev = nullptr; |
| 279 while (pos != nullptr && pos->pos().Value() < start.Value()) { | 281 while (pos != nullptr && pos->pos().Value() < start.Value()) { |
| 280 if (pos->RegisterIsBeneficial()) prev = pos; | 282 if (pos->RegisterIsBeneficial()) prev = pos; |
| 281 pos = pos->next(); | 283 pos = pos->next(); |
| 282 } | 284 } |
| 283 return prev; | 285 return prev; |
| 284 } | 286 } |
| 285 | 287 |
| 286 | 288 |
| 287 UsePosition* LiveRange::NextRegisterPosition(LifetimePosition start) { | 289 UsePosition* LiveRange::NextRegisterPosition(LifetimePosition start) const { |
| 288 UsePosition* pos = NextUsePosition(start); | 290 UsePosition* pos = NextUsePosition(start); |
| 289 while (pos != nullptr && pos->type() != UsePositionType::kRequiresRegister) { | 291 while (pos != nullptr && pos->type() != UsePositionType::kRequiresRegister) { |
| 290 pos = pos->next(); | 292 pos = pos->next(); |
| 291 } | 293 } |
| 292 return pos; | 294 return pos; |
| 293 } | 295 } |
| 294 | 296 |
| 295 | 297 |
| 296 bool LiveRange::CanBeSpilled(LifetimePosition pos) { | 298 bool LiveRange::CanBeSpilled(LifetimePosition pos) const { |
| 297 // We cannot spill a live range that has a use requiring a register | 299 // We cannot spill a live range that has a use requiring a register |
| 298 // at the current or the immediate next position. | 300 // at the current or the immediate next position. |
| 299 auto use_pos = NextRegisterPosition(pos); | 301 auto use_pos = NextRegisterPosition(pos); |
| 300 if (use_pos == nullptr) return true; | 302 if (use_pos == nullptr) return true; |
| 301 return use_pos->pos().Value() > pos.NextStart().End().Value(); | 303 return use_pos->pos().Value() > pos.NextStart().End().Value(); |
| 302 } | 304 } |
| 303 | 305 |
| 304 | 306 |
| 305 InstructionOperand LiveRange::GetAssignedOperand() const { | 307 InstructionOperand LiveRange::GetAssignedOperand() const { |
| 306 if (HasRegisterAssigned()) { | 308 if (HasRegisterAssigned()) { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } | 566 } |
| 565 | 567 |
| 566 | 568 |
| 567 bool LiveRange::CanCover(LifetimePosition position) const { | 569 bool LiveRange::CanCover(LifetimePosition position) const { |
| 568 if (IsEmpty()) return false; | 570 if (IsEmpty()) return false; |
| 569 return Start().Value() <= position.Value() && | 571 return Start().Value() <= position.Value() && |
| 570 position.Value() < End().Value(); | 572 position.Value() < End().Value(); |
| 571 } | 573 } |
| 572 | 574 |
| 573 | 575 |
| 574 bool LiveRange::Covers(LifetimePosition position) { | 576 bool LiveRange::Covers(LifetimePosition position) const { |
| 575 if (!CanCover(position)) return false; | 577 if (!CanCover(position)) return false; |
| 576 auto start_search = FirstSearchIntervalForPosition(position); | 578 auto start_search = FirstSearchIntervalForPosition(position); |
| 577 for (auto interval = start_search; interval != nullptr; | 579 for (auto interval = start_search; interval != nullptr; |
| 578 interval = interval->next()) { | 580 interval = interval->next()) { |
| 579 DCHECK(interval->next() == nullptr || | 581 DCHECK(interval->next() == nullptr || |
| 580 interval->next()->start().Value() >= interval->start().Value()); | 582 interval->next()->start().Value() >= interval->start().Value()); |
| 581 AdvanceLastProcessedMarker(interval, position); | 583 AdvanceLastProcessedMarker(interval, position); |
| 582 if (interval->Contains(position)) return true; | 584 if (interval->Contains(position)) return true; |
| 583 if (interval->start().Value() > position.Value()) return false; | 585 if (interval->start().Value() > position.Value()) return false; |
| 584 } | 586 } |
| 585 return false; | 587 return false; |
| 586 } | 588 } |
| 587 | 589 |
| 588 | 590 |
| 589 LifetimePosition LiveRange::FirstIntersection(LiveRange* other) { | 591 LifetimePosition LiveRange::FirstIntersection(LiveRange* other) const { |
| 590 auto b = other->first_interval(); | 592 auto b = other->first_interval(); |
| 591 if (b == nullptr) return LifetimePosition::Invalid(); | 593 if (b == nullptr) return LifetimePosition::Invalid(); |
| 592 auto advance_last_processed_up_to = b->start(); | 594 auto advance_last_processed_up_to = b->start(); |
| 593 auto a = FirstSearchIntervalForPosition(b->start()); | 595 auto a = FirstSearchIntervalForPosition(b->start()); |
| 594 while (a != nullptr && b != nullptr) { | 596 while (a != nullptr && b != nullptr) { |
| 595 if (a->start().Value() > other->End().Value()) break; | 597 if (a->start().Value() > other->End().Value()) break; |
| 596 if (b->start().Value() > End().Value()) break; | 598 if (b->start().Value() > End().Value()) break; |
| 597 auto cur_intersection = a->Intersect(b); | 599 auto cur_intersection = a->Intersect(b); |
| 598 if (cur_intersection.IsValid()) { | 600 if (cur_intersection.IsValid()) { |
| 599 return cur_intersection; | 601 return cur_intersection; |
| (...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2526 auto move = new (code_zone()) MoveOperands(it->first.second, it->second); | 2528 auto move = new (code_zone()) MoveOperands(it->first.second, it->second); |
| 2527 auto eliminate = moves->PrepareInsertAfter(move); | 2529 auto eliminate = moves->PrepareInsertAfter(move); |
| 2528 to_insert.push_back(move); | 2530 to_insert.push_back(move); |
| 2529 if (eliminate != nullptr) to_eliminate.push_back(eliminate); | 2531 if (eliminate != nullptr) to_eliminate.push_back(eliminate); |
| 2530 } | 2532 } |
| 2531 } | 2533 } |
| 2532 | 2534 |
| 2533 } // namespace compiler | 2535 } // namespace compiler |
| 2534 } // namespace internal | 2536 } // namespace internal |
| 2535 } // namespace v8 | 2537 } // namespace v8 |
| OLD | NEW |