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

Side by Side Diff: src/interpreter/bytecode-register-optimizer.cc

Issue 2542903003: [Interpreter] Templatize AccumulatorUsage and OperandType for bytecode creation. (Closed)
Patch Set: Remove commented code and rebase Created 4 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/interpreter/bytecode-register-optimizer.h ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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-register-optimizer.h" 5 #include "src/interpreter/bytecode-register-optimizer.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace interpreter { 9 namespace interpreter {
10 10
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 void BytecodeRegisterOptimizer::OutputRegisterTransfer( 259 void BytecodeRegisterOptimizer::OutputRegisterTransfer(
260 RegisterInfo* input_info, RegisterInfo* output_info, 260 RegisterInfo* input_info, RegisterInfo* output_info,
261 BytecodeSourceInfo source_info) { 261 BytecodeSourceInfo source_info) {
262 Register input = input_info->register_value(); 262 Register input = input_info->register_value();
263 Register output = output_info->register_value(); 263 Register output = output_info->register_value();
264 DCHECK_NE(input.index(), output.index()); 264 DCHECK_NE(input.index(), output.index());
265 265
266 if (input == accumulator_) { 266 if (input == accumulator_) {
267 uint32_t operand = static_cast<uint32_t>(output.ToOperand()); 267 uint32_t operand = static_cast<uint32_t>(output.ToOperand());
268 BytecodeNode node(Bytecode::kStar, operand, source_info); 268 BytecodeNode node = BytecodeNode::Star(source_info, operand);
269 next_stage_->Write(&node); 269 next_stage_->Write(&node);
270 } else if (output == accumulator_) { 270 } else if (output == accumulator_) {
271 uint32_t operand = static_cast<uint32_t>(input.ToOperand()); 271 uint32_t operand = static_cast<uint32_t>(input.ToOperand());
272 BytecodeNode node(Bytecode::kLdar, operand, source_info); 272 BytecodeNode node = BytecodeNode::Ldar(source_info, operand);
273 next_stage_->Write(&node); 273 next_stage_->Write(&node);
274 } else { 274 } else {
275 uint32_t operand0 = static_cast<uint32_t>(input.ToOperand()); 275 uint32_t operand0 = static_cast<uint32_t>(input.ToOperand());
276 uint32_t operand1 = static_cast<uint32_t>(output.ToOperand()); 276 uint32_t operand1 = static_cast<uint32_t>(output.ToOperand());
277 BytecodeNode node(Bytecode::kMov, operand0, operand1, source_info); 277 BytecodeNode node = BytecodeNode::Mov(source_info, operand0, operand1);
278 next_stage_->Write(&node); 278 next_stage_->Write(&node);
279 } 279 }
280 if (output != accumulator_) { 280 if (output != accumulator_) {
281 max_register_index_ = std::max(max_register_index_, output.index()); 281 max_register_index_ = std::max(max_register_index_, output.index());
282 } 282 }
283 output_info->set_materialized(true); 283 output_info->set_materialized(true);
284 } 284 }
285 285
286 void BytecodeRegisterOptimizer::CreateMaterializedEquivalent( 286 void BytecodeRegisterOptimizer::CreateMaterializedEquivalent(
287 RegisterInfo* info) { 287 RegisterInfo* info) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (input_is_observable) { 358 if (input_is_observable) {
359 // If input is observable by the debugger, mark all other temporaries 359 // If input is observable by the debugger, mark all other temporaries
360 // registers as unmaterialized so that this register is used in preference. 360 // registers as unmaterialized so that this register is used in preference.
361 input_info->MarkTemporariesAsUnmaterialized(temporary_base_); 361 input_info->MarkTemporariesAsUnmaterialized(temporary_base_);
362 } 362 }
363 } 363 }
364 364
365 void BytecodeRegisterOptimizer::EmitNopForSourceInfo( 365 void BytecodeRegisterOptimizer::EmitNopForSourceInfo(
366 BytecodeSourceInfo source_info) const { 366 BytecodeSourceInfo source_info) const {
367 DCHECK(source_info.is_valid()); 367 DCHECK(source_info.is_valid());
368 BytecodeNode nop(Bytecode::kNop, source_info); 368 BytecodeNode nop = BytecodeNode::Nop(source_info);
369 next_stage_->Write(&nop); 369 next_stage_->Write(&nop);
370 } 370 }
371 371
372 void BytecodeRegisterOptimizer::PrepareOutputRegister(Register reg) { 372 void BytecodeRegisterOptimizer::PrepareOutputRegister(Register reg) {
373 RegisterInfo* reg_info = GetRegisterInfo(reg); 373 RegisterInfo* reg_info = GetRegisterInfo(reg);
374 if (reg_info->materialized()) { 374 if (reg_info->materialized()) {
375 CreateMaterializedEquivalent(reg_info); 375 CreateMaterializedEquivalent(reg_info);
376 } 376 }
377 reg_info->MoveToNewEquivalenceSet(NextEquivalenceId(), true); 377 reg_info->MoveToNewEquivalenceSet(NextEquivalenceId(), true);
378 max_register_index_ = 378 max_register_index_ =
(...skipping 30 matching lines...) Expand all
409 int start_index = reg_list.first_register().index(); 409 int start_index = reg_list.first_register().index();
410 for (int i = 0; i < reg_list.register_count(); ++i) { 410 for (int i = 0; i < reg_list.register_count(); ++i) {
411 Register current(start_index + i); 411 Register current(start_index + i);
412 RegisterInfo* input_info = GetRegisterInfo(current); 412 RegisterInfo* input_info = GetRegisterInfo(current);
413 Materialize(input_info); 413 Materialize(input_info);
414 } 414 }
415 return reg_list; 415 return reg_list;
416 } 416 }
417 } 417 }
418 418
419 void BytecodeRegisterOptimizer::PrepareForBytecode(Bytecode bytecode) {
420 if (Bytecodes::IsJump(bytecode) || bytecode == Bytecode::kDebugger ||
421 bytecode == Bytecode::kSuspendGenerator) {
422 // All state must be flushed before emitting
423 // - a jump bytecode (as the register equivalents at the jump target aren't
424 // known.
425 // - a call to the debugger (as it can manipulate locals and parameters),
426 // - a generator suspend (as this involves saving all registers).
427 Flush();
428 }
429
430 // Materialize the accumulator if it is read by the bytecode. The
431 // accumulator is special and no other register can be materialized
432 // in it's place.
433 if (Bytecodes::ReadsAccumulator(bytecode) &&
434 !accumulator_info_->materialized()) {
435 Materialize(accumulator_info_);
436 }
437
438 // Materialize an equivalent to the accumulator if it will be
439 // clobbered when the bytecode is dispatched.
440 if (Bytecodes::WritesAccumulator(bytecode)) {
441 PrepareOutputRegister(accumulator_);
442 }
443 }
444
445 void BytecodeRegisterOptimizer::GrowRegisterMap(Register reg) { 419 void BytecodeRegisterOptimizer::GrowRegisterMap(Register reg) {
446 DCHECK(RegisterIsTemporary(reg)); 420 DCHECK(RegisterIsTemporary(reg));
447 size_t index = GetRegisterInfoTableIndex(reg); 421 size_t index = GetRegisterInfoTableIndex(reg);
448 if (index >= register_info_table_.size()) { 422 if (index >= register_info_table_.size()) {
449 size_t new_size = index + 1; 423 size_t new_size = index + 1;
450 size_t old_size = register_info_table_.size(); 424 size_t old_size = register_info_table_.size();
451 register_info_table_.resize(new_size); 425 register_info_table_.resize(new_size);
452 for (size_t i = old_size; i < new_size; ++i) { 426 for (size_t i = old_size; i < new_size; ++i) {
453 register_info_table_[i] = 427 register_info_table_[i] =
454 new (zone()) RegisterInfo(RegisterFromRegisterInfoTableIndex(i), 428 new (zone()) RegisterInfo(RegisterFromRegisterInfoTableIndex(i),
(...skipping 20 matching lines...) Expand all
475 void BytecodeRegisterOptimizer::RegisterListFreeEvent(RegisterList reg_list) { 449 void BytecodeRegisterOptimizer::RegisterListFreeEvent(RegisterList reg_list) {
476 int first_index = reg_list.first_register().index(); 450 int first_index = reg_list.first_register().index();
477 for (int i = 0; i < reg_list.register_count(); i++) { 451 for (int i = 0; i < reg_list.register_count(); i++) {
478 GetRegisterInfo(Register(first_index + i))->set_allocated(false); 452 GetRegisterInfo(Register(first_index + i))->set_allocated(false);
479 } 453 }
480 } 454 }
481 455
482 } // namespace interpreter 456 } // namespace interpreter
483 } // namespace internal 457 } // namespace internal
484 } // namespace v8 458 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-register-optimizer.h ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698