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

Side by Side Diff: src/interpreter/bytecode-array-builder.cc

Issue 1531273002: [Interpreter] Allocates new temporary register outside the reservation for consecutive registers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: "Allocates a new unallocted temporary register for allocations outside current or outer contexts" 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/interpreter/bytecode-array-builder.h" 5 #include "src/interpreter/bytecode-array-builder.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace interpreter { 9 namespace interpreter {
10 10
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 return last_temporary_register().index(); 981 return last_temporary_register().index();
982 } else { 982 } else {
983 auto pos = free_temporaries_.begin(); 983 auto pos = free_temporaries_.begin();
984 int retval = *pos; 984 int retval = *pos;
985 free_temporaries_.erase(pos); 985 free_temporaries_.erase(pos);
986 return retval; 986 return retval;
987 } 987 }
988 } 988 }
989 989
990 990
991 int BytecodeArrayBuilder::BorrowTemporaryRegisterNotInRange(int start_index,
992 int end_index) {
993 auto index = free_temporaries_.lower_bound(start_index);
994 if (index == free_temporaries_.begin()) {
995 // If start_index is the first free register, check for a register
996 // greater than end_index.
997 index = free_temporaries_.upper_bound(end_index);
998 } else {
999 // If there is a free register < start_index
1000 index--;
1001 }
1002 if (index == free_temporaries_.end()) {
oth 2015/12/21 12:48:19 If this check only applies if upper_bound() has be
1003 temporary_register_count_ += 1;
1004 return last_temporary_register().index();
1005 } else {
1006 int retval = *index;
1007 free_temporaries_.erase(index);
1008 return retval;
1009 }
1010 }
1011
1012
1013 int BytecodeArrayBuilder::AllocateAndBorrowTemporaryRegister() {
1014 temporary_register_count_ += 1;
1015 return last_temporary_register().index();
1016 }
1017
1018
991 void BytecodeArrayBuilder::BorrowConsecutiveTemporaryRegister(int reg_index) { 1019 void BytecodeArrayBuilder::BorrowConsecutiveTemporaryRegister(int reg_index) {
992 DCHECK(free_temporaries_.find(reg_index) != free_temporaries_.end()); 1020 DCHECK(free_temporaries_.find(reg_index) != free_temporaries_.end());
993 free_temporaries_.erase(reg_index); 1021 free_temporaries_.erase(reg_index);
994 } 1022 }
995 1023
996 1024
997 void BytecodeArrayBuilder::ReturnTemporaryRegister(int reg_index) { 1025 void BytecodeArrayBuilder::ReturnTemporaryRegister(int reg_index) {
998 DCHECK(free_temporaries_.find(reg_index) == free_temporaries_.end()); 1026 DCHECK(free_temporaries_.find(reg_index) == free_temporaries_.end());
999 free_temporaries_.insert(reg_index); 1027 free_temporaries_.insert(reg_index);
1000 } 1028 }
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 1420
1393 TemporaryRegisterScope::~TemporaryRegisterScope() { 1421 TemporaryRegisterScope::~TemporaryRegisterScope() {
1394 for (auto i = allocated_.rbegin(); i != allocated_.rend(); i++) { 1422 for (auto i = allocated_.rbegin(); i != allocated_.rend(); i++) {
1395 builder_->ReturnTemporaryRegister(*i); 1423 builder_->ReturnTemporaryRegister(*i);
1396 } 1424 }
1397 allocated_.clear(); 1425 allocated_.clear();
1398 } 1426 }
1399 1427
1400 1428
1401 Register TemporaryRegisterScope::NewRegister() { 1429 Register TemporaryRegisterScope::NewRegister() {
1402 int allocated = builder_->BorrowTemporaryRegister(); 1430 int allocated = -1;
1431 if (next_consecutive_count_ <= 0) {
1432 allocated = builder_->BorrowTemporaryRegister();
1433 } else {
1434 allocated = builder_->BorrowTemporaryRegisterNotInRange(
1435 next_consecutive_register_,
1436 next_consecutive_register_ + next_consecutive_count_ - 1);
1437 }
1403 allocated_.push_back(allocated); 1438 allocated_.push_back(allocated);
1404 return Register(allocated); 1439 return Register(allocated);
1405 } 1440 }
1441
1442
1443 Register TemporaryRegisterScope::AllocateNewRegister() {
1444 int allocated = builder_->AllocateAndBorrowTemporaryRegister();
1445 allocated_.push_back(allocated);
1446 return Register(allocated);
1447 }
1406 1448
1407 1449
1408 bool TemporaryRegisterScope::RegisterIsAllocatedInThisScope( 1450 bool TemporaryRegisterScope::RegisterIsAllocatedInThisScope(
1409 Register reg) const { 1451 Register reg) const {
1410 for (auto i = allocated_.begin(); i != allocated_.end(); i++) { 1452 for (auto i = allocated_.begin(); i != allocated_.end(); i++) {
1411 if (*i == reg.index()) return true; 1453 if (*i == reg.index()) return true;
1412 } 1454 }
1413 return false; 1455 return false;
1414 } 1456 }
1415 1457
(...skipping 12 matching lines...) Expand all
1428 DCHECK_GT(next_consecutive_count_, 0); 1470 DCHECK_GT(next_consecutive_count_, 0);
1429 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); 1471 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_);
1430 allocated_.push_back(next_consecutive_register_); 1472 allocated_.push_back(next_consecutive_register_);
1431 next_consecutive_count_--; 1473 next_consecutive_count_--;
1432 return Register(next_consecutive_register_++); 1474 return Register(next_consecutive_register_++);
1433 } 1475 }
1434 1476
1435 } // namespace interpreter 1477 } // namespace interpreter
1436 } // namespace internal 1478 } // namespace internal
1437 } // namespace v8 1479 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698