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

Side by Side Diff: src/compiler/register-allocator.cc

Issue 1533723002: [turbofan] More thorough validation of LiveRanges. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « src/compiler/register-allocator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 splitting_pointer_(nullptr), 265 splitting_pointer_(nullptr),
266 size_(kInvalidSize), 266 size_(kInvalidSize),
267 weight_(kInvalidWeight), 267 weight_(kInvalidWeight),
268 group_(nullptr) { 268 group_(nullptr) {
269 DCHECK(AllocatedOperand::IsSupportedRepresentation(rep)); 269 DCHECK(AllocatedOperand::IsSupportedRepresentation(rep));
270 bits_ = AssignedRegisterField::encode(kUnassignedRegister) | 270 bits_ = AssignedRegisterField::encode(kUnassignedRegister) |
271 RepresentationField::encode(rep); 271 RepresentationField::encode(rep);
272 } 272 }
273 273
274 274
275 void LiveRange::Verify() const { 275 void LiveRange::VerifyPositions() const {
276 // Walk the positions, verifying that each is in an interval. 276 // Walk the positions, verifying that each is in an interval.
277 auto interval = first_interval_; 277 auto interval = first_interval_;
278 for (auto pos = first_pos_; pos != nullptr; pos = pos->next()) { 278 for (auto pos = first_pos_; pos != nullptr; pos = pos->next()) {
279 CHECK(Start() <= pos->pos()); 279 CHECK(Start() <= pos->pos());
280 CHECK(pos->pos() <= End()); 280 CHECK(pos->pos() <= End());
281 CHECK(interval != nullptr); 281 CHECK(interval != nullptr);
282 while (!interval->Contains(pos->pos()) && interval->end() != pos->pos()) { 282 while (!interval->Contains(pos->pos()) && interval->end() != pos->pos()) {
283 interval = interval->next(); 283 interval = interval->next();
284 CHECK(interval != nullptr); 284 CHECK(interval != nullptr);
285 } 285 }
286 } 286 }
287 } 287 }
288 288
289 289
290 void LiveRange::VerifyIntervals() const {
291 DCHECK(first_interval()->start() == Start());
292 LifetimePosition last_end = first_interval()->end();
293 for (UseInterval* interval = first_interval()->next(); interval != nullptr;
294 interval = interval->next()) {
295 DCHECK(last_end <= interval->start());
296 last_end = interval->end();
297 }
298 DCHECK(last_end == End());
299 }
300
301
290 void LiveRange::set_assigned_register(int reg) { 302 void LiveRange::set_assigned_register(int reg) {
291 DCHECK(!HasRegisterAssigned() && !spilled()); 303 DCHECK(!HasRegisterAssigned() && !spilled());
292 bits_ = AssignedRegisterField::update(bits_, reg); 304 bits_ = AssignedRegisterField::update(bits_, reg);
293 } 305 }
294 306
295 307
296 void LiveRange::UnsetAssignedRegister() { 308 void LiveRange::UnsetAssignedRegister() {
297 DCHECK(HasRegisterAssigned() && !spilled()); 309 DCHECK(HasRegisterAssigned() && !spilled());
298 bits_ = AssignedRegisterField::update(bits_, kUnassignedRegister); 310 bits_ = AssignedRegisterField::update(bits_, kUnassignedRegister);
299 } 311 }
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 // Discard cached iteration state. It might be pointing 532 // Discard cached iteration state. It might be pointing
521 // to the use that no longer belongs to this live range. 533 // to the use that no longer belongs to this live range.
522 last_processed_use_ = nullptr; 534 last_processed_use_ = nullptr;
523 current_interval_ = nullptr; 535 current_interval_ = nullptr;
524 536
525 // Invalidate size and weight of this range. The child range has them 537 // Invalidate size and weight of this range. The child range has them
526 // invalid at construction. 538 // invalid at construction.
527 size_ = kInvalidSize; 539 size_ = kInvalidSize;
528 weight_ = kInvalidWeight; 540 weight_ = kInvalidWeight;
529 #ifdef DEBUG 541 #ifdef DEBUG
530 Verify(); 542 VerifyChildStructure();
531 result->Verify(); 543 result->VerifyChildStructure();
532 #endif 544 #endif
533 return use_before; 545 return use_before;
534 } 546 }
535 547
536 548
537 void LiveRange::AppendAsChild(TopLevelLiveRange* other) { 549 void LiveRange::AppendAsChild(TopLevelLiveRange* other) {
538 next_ = other; 550 next_ = other;
539 551
540 other->UpdateParentForAllChildren(TopLevel()); 552 other->UpdateParentForAllChildren(TopLevel());
541 TopLevel()->UpdateSpillRangePostMerge(other); 553 TopLevel()->UpdateSpillRangePostMerge(other);
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 951
940 TopLevel()->UpdateParentForAllChildren(TopLevel()); 952 TopLevel()->UpdateParentForAllChildren(TopLevel());
941 TopLevel()->UpdateSpillRangePostMerge(other); 953 TopLevel()->UpdateSpillRangePostMerge(other);
942 954
943 #if DEBUG 955 #if DEBUG
944 Verify(); 956 Verify();
945 #endif 957 #endif
946 } 958 }
947 959
948 960
961 void TopLevelLiveRange::VerifyChildrenInOrder() const {
962 LifetimePosition last_end = End();
963 for (const LiveRange* child = this->next(); child != nullptr;
964 child = child->next()) {
965 DCHECK(last_end <= child->Start());
966 last_end = child->End();
967 }
968 }
969
970
971 void TopLevelLiveRange::Verify() const {
972 VerifyChildrenInOrder();
973 for (const LiveRange* child = this; child != nullptr; child = child->next()) {
974 VerifyChildStructure();
975 }
976 }
977
978
949 void TopLevelLiveRange::ShortenTo(LifetimePosition start) { 979 void TopLevelLiveRange::ShortenTo(LifetimePosition start) {
950 TRACE("Shorten live range %d to [%d\n", vreg(), start.value()); 980 TRACE("Shorten live range %d to [%d\n", vreg(), start.value());
951 DCHECK(first_interval_ != nullptr); 981 DCHECK(first_interval_ != nullptr);
952 DCHECK(first_interval_->start() <= start); 982 DCHECK(first_interval_->start() <= start);
953 DCHECK(start < first_interval_->end()); 983 DCHECK(start < first_interval_->end());
954 first_interval_->set_start(start); 984 first_interval_->set_start(start);
955 } 985 }
956 986
957 987
958 void TopLevelLiveRange::EnsureInterval(LifetimePosition start, 988 void TopLevelLiveRange::EnsureInterval(LifetimePosition start,
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2186 if (it == phi_hints_.end()) return; 2216 if (it == phi_hints_.end()) return;
2187 DCHECK(!it->second->IsResolved()); 2217 DCHECK(!it->second->IsResolved());
2188 it->second->ResolveHint(use_pos); 2218 it->second->ResolveHint(use_pos);
2189 } 2219 }
2190 2220
2191 2221
2192 void LiveRangeBuilder::Verify() const { 2222 void LiveRangeBuilder::Verify() const {
2193 for (auto& hint : phi_hints_) { 2223 for (auto& hint : phi_hints_) {
2194 CHECK(hint.second->IsResolved()); 2224 CHECK(hint.second->IsResolved());
2195 } 2225 }
2196 for (LiveRange* current : data()->live_ranges()) { 2226 for (TopLevelLiveRange* current : data()->live_ranges()) {
2197 if (current != nullptr) current->Verify(); 2227 if (current != nullptr && !current->IsEmpty()) current->Verify();
2198 } 2228 }
2199 } 2229 }
2200 2230
2201 2231
2202 RegisterAllocator::RegisterAllocator(RegisterAllocationData* data, 2232 RegisterAllocator::RegisterAllocator(RegisterAllocationData* data,
2203 RegisterKind kind) 2233 RegisterKind kind)
2204 : data_(data), 2234 : data_(data),
2205 mode_(kind), 2235 mode_(kind),
2206 num_registers_(GetRegisterCount(data->config(), kind)), 2236 num_registers_(GetRegisterCount(data->config(), kind)),
2207 num_allocatable_registers_( 2237 num_allocatable_registers_(
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
3449 auto eliminate = moves->PrepareInsertAfter(move); 3479 auto eliminate = moves->PrepareInsertAfter(move);
3450 to_insert.push_back(move); 3480 to_insert.push_back(move);
3451 if (eliminate != nullptr) to_eliminate.push_back(eliminate); 3481 if (eliminate != nullptr) to_eliminate.push_back(eliminate);
3452 } 3482 }
3453 } 3483 }
3454 3484
3455 3485
3456 } // namespace compiler 3486 } // namespace compiler
3457 } // namespace internal 3487 } // namespace internal
3458 } // namespace v8 3488 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/register-allocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698