 Chromium Code Reviews
 Chromium Code Reviews Issue 1403943004:
  [Interpreter] Add support for local context loads and stores.  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@int_contextchain
    
  
    Issue 1403943004:
  [Interpreter] Add support for local context loads and stores.  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@int_contextchain| OLD | NEW | 
|---|---|
| 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 14 matching lines...) Expand all Loading... | |
| 25 temporary_register_next_(0) {} | 25 temporary_register_next_(0) {} | 
| 26 | 26 | 
| 27 | 27 | 
| 28 void BytecodeArrayBuilder::set_locals_count(int number_of_locals) { | 28 void BytecodeArrayBuilder::set_locals_count(int number_of_locals) { | 
| 29 local_register_count_ = number_of_locals; | 29 local_register_count_ = number_of_locals; | 
| 30 DCHECK_LE(context_register_count_, 0); | 30 DCHECK_LE(context_register_count_, 0); | 
| 31 temporary_register_next_ = local_register_count_; | 31 temporary_register_next_ = local_register_count_; | 
| 32 } | 32 } | 
| 33 | 33 | 
| 34 | 34 | 
| 35 int BytecodeArrayBuilder::locals_count() const { return local_register_count_; } | |
| 36 | |
| 37 | |
| 38 void BytecodeArrayBuilder::set_parameter_count(int number_of_parameters) { | 35 void BytecodeArrayBuilder::set_parameter_count(int number_of_parameters) { | 
| 39 parameter_count_ = number_of_parameters; | 36 parameter_count_ = number_of_parameters; | 
| 40 } | 37 } | 
| 41 | 38 | 
| 42 | 39 | 
| 43 int BytecodeArrayBuilder::parameter_count() const { return parameter_count_; } | |
| 44 | |
| 45 | |
| 46 void BytecodeArrayBuilder::set_context_count(int number_of_contexts) { | 40 void BytecodeArrayBuilder::set_context_count(int number_of_contexts) { | 
| 47 context_register_count_ = number_of_contexts; | 41 context_register_count_ = number_of_contexts; | 
| 48 DCHECK_GE(local_register_count_, 0); | 42 DCHECK_GE(local_register_count_, 0); | 
| 49 temporary_register_next_ = local_register_count_ + context_register_count_; | 43 temporary_register_next_ = local_register_count_ + context_register_count_; | 
| 50 } | 44 } | 
| 51 | 45 | 
| 52 | 46 | 
| 53 Register BytecodeArrayBuilder::first_context_register() const { | 47 Register BytecodeArrayBuilder::first_context_register() const { | 
| 54 DCHECK_GT(context_register_count_, 0); | 48 DCHECK_GT(context_register_count_, 0); | 
| 55 return Register(local_register_count_); | 49 return Register(local_register_count_); | 
| 56 } | 50 } | 
| 57 | 51 | 
| 58 | 52 | 
| 59 Register BytecodeArrayBuilder::last_context_register() const { | 53 Register BytecodeArrayBuilder::last_context_register() const { | 
| 60 DCHECK_GT(context_register_count_, 0); | 54 DCHECK_GT(context_register_count_, 0); | 
| 61 return Register(local_register_count_ + context_register_count_ - 1); | 55 return Register(local_register_count_ + context_register_count_ - 1); | 
| 62 } | 56 } | 
| 63 | 57 | 
| 64 | 58 | 
| 65 Register BytecodeArrayBuilder::Parameter(int parameter_index) const { | 59 Register BytecodeArrayBuilder::Parameter(int parameter_index) const { | 
| 66 DCHECK_GE(parameter_index, 0); | 60 DCHECK_GE(parameter_index, 0); | 
| 67 DCHECK_LT(parameter_index, parameter_count_); | 61 DCHECK_LT(parameter_index, parameter_count_); | 
| 68 return Register::FromParameterIndex(parameter_index, parameter_count_); | 62 return Register::FromParameterIndex(parameter_index, parameter_count_); | 
| 69 } | 63 } | 
| 70 | 64 | 
| 71 | 65 | 
| 72 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 66 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 
| 73 DCHECK_EQ(bytecode_generated_, false); | 67 DCHECK_EQ(bytecode_generated_, false); | 
| 74 DCHECK_GE(parameter_count_, 0); | 68 DCHECK_GE(parameter_count_, 0); | 
| 75 DCHECK_GE(local_register_count_, 0); | |
| 76 | 69 | 
| 77 EnsureReturn(); | 70 EnsureReturn(); | 
| 78 | 71 | 
| 79 int bytecode_size = static_cast<int>(bytecodes_.size()); | 72 int bytecode_size = static_cast<int>(bytecodes_.size()); | 
| 80 int register_count = local_register_count_ + temporary_register_count_; | 73 int register_count = fixed_register_count() + temporary_register_count_; | 
| 81 int frame_size = register_count * kPointerSize; | 74 int frame_size = register_count * kPointerSize; | 
| 82 | 75 | 
| 83 Factory* factory = isolate_->factory(); | 76 Factory* factory = isolate_->factory(); | 
| 84 int constants_count = static_cast<int>(constants_.size()); | 77 int constants_count = static_cast<int>(constants_.size()); | 
| 85 Handle<FixedArray> constant_pool = | 78 Handle<FixedArray> constant_pool = | 
| 86 factory->NewFixedArray(constants_count, TENURED); | 79 factory->NewFixedArray(constants_count, TENURED); | 
| 87 for (int i = 0; i < constants_count; i++) { | 80 for (int i = 0; i < constants_count; i++) { | 
| 88 constant_pool->set(i, *constants_[i]); | 81 constant_pool->set(i, *constants_[i]); | 
| 89 } | 82 } | 
| 90 | 83 | 
| 91 Handle<BytecodeArray> output = | 84 Handle<BytecodeArray> output = | 
| 92 factory->NewBytecodeArray(bytecode_size, &bytecodes_.front(), frame_size, | 85 factory->NewBytecodeArray(bytecode_size, &bytecodes_.front(), frame_size, | 
| 93 parameter_count_, constant_pool); | 86 parameter_count_, constant_pool); | 
| 
Michael Starzinger
2015/10/16 09:10:04
nit: If we use parameter_count() here, then the DC
 
rmcilroy
2015/10/16 11:19:04
Done. (also done in ::Parameter())
 | |
| 94 bytecode_generated_ = true; | 87 bytecode_generated_ = true; | 
| 95 return output; | 88 return output; | 
| 96 } | 89 } | 
| 97 | 90 | 
| 98 | 91 | 
| 99 template <size_t N> | 92 template <size_t N> | 
| 100 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { | 93 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { | 
| 101 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), static_cast<int>(N)); | 94 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), static_cast<int>(N)); | 
| 102 last_bytecode_start_ = bytecodes()->size(); | 95 last_bytecode_start_ = bytecodes()->size(); | 
| 103 bytecodes()->push_back(Bytecodes::ToByte(bytecode)); | 96 bytecodes()->push_back(Bytecodes::ToByte(bytecode)); | 
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 if (FitsInIdx8Operand(slot_index)) { | 277 if (FitsInIdx8Operand(slot_index)) { | 
| 285 Output(Bytecode::kLdaContextSlot, context.ToOperand(), | 278 Output(Bytecode::kLdaContextSlot, context.ToOperand(), | 
| 286 static_cast<uint8_t>(slot_index)); | 279 static_cast<uint8_t>(slot_index)); | 
| 287 } else { | 280 } else { | 
| 288 UNIMPLEMENTED(); | 281 UNIMPLEMENTED(); | 
| 289 } | 282 } | 
| 290 return *this; | 283 return *this; | 
| 291 } | 284 } | 
| 292 | 285 | 
| 293 | 286 | 
| 287 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreContextSlot(Register context, | |
| 288 int slot_index) { | |
| 289 DCHECK(slot_index >= 0); | |
| 290 if (FitsInIdx8Operand(slot_index)) { | |
| 291 Output(Bytecode::kStaContextSlot, context.ToOperand(), | |
| 292 static_cast<uint8_t>(slot_index)); | |
| 293 } else { | |
| 294 UNIMPLEMENTED(); | |
| 295 } | |
| 296 return *this; | |
| 297 } | |
| 298 | |
| 299 | |
| 294 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadNamedProperty( | 300 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadNamedProperty( | 
| 295 Register object, int feedback_slot, LanguageMode language_mode) { | 301 Register object, int feedback_slot, LanguageMode language_mode) { | 
| 296 Bytecode bytecode = BytecodeForLoadIC(language_mode); | 302 Bytecode bytecode = BytecodeForLoadIC(language_mode); | 
| 297 if (FitsInIdx8Operand(feedback_slot)) { | 303 if (FitsInIdx8Operand(feedback_slot)) { | 
| 298 Output(bytecode, object.ToOperand(), static_cast<uint8_t>(feedback_slot)); | 304 Output(bytecode, object.ToOperand(), static_cast<uint8_t>(feedback_slot)); | 
| 299 } else { | 305 } else { | 
| 300 UNIMPLEMENTED(); | 306 UNIMPLEMENTED(); | 
| 301 } | 307 } | 
| 302 return *this; | 308 return *this; | 
| 303 } | 309 } | 
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 entry = constants_map_.Get(object); | 629 entry = constants_map_.Get(object); | 
| 624 *entry = constants_.size(); | 630 *entry = constants_.size(); | 
| 625 constants_.push_back(object); | 631 constants_.push_back(object); | 
| 626 } | 632 } | 
| 627 DCHECK(constants_[*entry].is_identical_to(object)); | 633 DCHECK(constants_[*entry].is_identical_to(object)); | 
| 628 return *entry; | 634 return *entry; | 
| 629 } | 635 } | 
| 630 | 636 | 
| 631 | 637 | 
| 632 int BytecodeArrayBuilder::BorrowTemporaryRegister() { | 638 int BytecodeArrayBuilder::BorrowTemporaryRegister() { | 
| 633 DCHECK_GE(local_register_count_, 0); | |
| 634 int temporary_reg_index = temporary_register_next_++; | 639 int temporary_reg_index = temporary_register_next_++; | 
| 635 int count = temporary_register_next_ - local_register_count_; | 640 int count = temporary_register_next_ - fixed_register_count(); | 
| 636 if (count > temporary_register_count_) { | 641 if (count > temporary_register_count_) { | 
| 637 temporary_register_count_ = count; | 642 temporary_register_count_ = count; | 
| 638 } | 643 } | 
| 639 return temporary_reg_index; | 644 return temporary_reg_index; | 
| 640 } | 645 } | 
| 641 | 646 | 
| 642 | 647 | 
| 643 void BytecodeArrayBuilder::ReturnTemporaryRegister(int reg_index) { | 648 void BytecodeArrayBuilder::ReturnTemporaryRegister(int reg_index) { | 
| 644 DCHECK_EQ(reg_index, temporary_register_next_ - 1); | 649 DCHECK_EQ(reg_index, temporary_register_next_ - 1); | 
| 645 temporary_register_next_ = reg_index; | 650 temporary_register_next_ = reg_index; | 
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 | 850 | 
| 846 Register TemporaryRegisterScope::NewRegister() { | 851 Register TemporaryRegisterScope::NewRegister() { | 
| 847 count_++; | 852 count_++; | 
| 848 last_register_index_ = builder_->BorrowTemporaryRegister(); | 853 last_register_index_ = builder_->BorrowTemporaryRegister(); | 
| 849 return Register(last_register_index_); | 854 return Register(last_register_index_); | 
| 850 } | 855 } | 
| 851 | 856 | 
| 852 } // namespace interpreter | 857 } // namespace interpreter | 
| 853 } // namespace internal | 858 } // namespace internal | 
| 854 } // namespace v8 | 859 } // namespace v8 | 
| OLD | NEW |