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

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

Issue 2542903003: [Interpreter] Templatize AccumulatorUsage and OperandType for bytecode creation. (Closed)
Patch Set: 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
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 =
269 BytecodeNode::Create<Bytecode::kStar, OperandType::kRegOut>(
Leszek Swirski 2016/12/05 10:57:42 This seems error prone -- would it be worth having
rmcilroy 2016/12/09 09:21:05 Good idea, done (as differently named functions ra
270 operand, source_info);
269 next_stage_->Write(&node); 271 next_stage_->Write(&node);
270 } else if (output == accumulator_) { 272 } else if (output == accumulator_) {
271 uint32_t operand = static_cast<uint32_t>(input.ToOperand()); 273 uint32_t operand = static_cast<uint32_t>(input.ToOperand());
272 BytecodeNode node(Bytecode::kLdar, operand, source_info); 274 BytecodeNode node =
275 BytecodeNode::Create<Bytecode::kLdar, OperandType::kReg>(operand,
276 source_info);
273 next_stage_->Write(&node); 277 next_stage_->Write(&node);
274 } else { 278 } else {
275 uint32_t operand0 = static_cast<uint32_t>(input.ToOperand()); 279 uint32_t operand0 = static_cast<uint32_t>(input.ToOperand());
276 uint32_t operand1 = static_cast<uint32_t>(output.ToOperand()); 280 uint32_t operand1 = static_cast<uint32_t>(output.ToOperand());
277 BytecodeNode node(Bytecode::kMov, operand0, operand1, source_info); 281 BytecodeNode node = BytecodeNode::Create<Bytecode::kMov, OperandType::kReg,
282 OperandType::kRegOut>(
283 operand0, operand1, source_info);
278 next_stage_->Write(&node); 284 next_stage_->Write(&node);
279 } 285 }
280 if (output != accumulator_) { 286 if (output != accumulator_) {
281 max_register_index_ = std::max(max_register_index_, output.index()); 287 max_register_index_ = std::max(max_register_index_, output.index());
282 } 288 }
283 output_info->set_materialized(true); 289 output_info->set_materialized(true);
284 } 290 }
285 291
286 void BytecodeRegisterOptimizer::CreateMaterializedEquivalent( 292 void BytecodeRegisterOptimizer::CreateMaterializedEquivalent(
287 RegisterInfo* info) { 293 RegisterInfo* info) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (input_is_observable) { 364 if (input_is_observable) {
359 // If input is observable by the debugger, mark all other temporaries 365 // If input is observable by the debugger, mark all other temporaries
360 // registers as unmaterialized so that this register is used in preference. 366 // registers as unmaterialized so that this register is used in preference.
361 input_info->MarkTemporariesAsUnmaterialized(temporary_base_); 367 input_info->MarkTemporariesAsUnmaterialized(temporary_base_);
362 } 368 }
363 } 369 }
364 370
365 void BytecodeRegisterOptimizer::EmitNopForSourceInfo( 371 void BytecodeRegisterOptimizer::EmitNopForSourceInfo(
366 BytecodeSourceInfo source_info) const { 372 BytecodeSourceInfo source_info) const {
367 DCHECK(source_info.is_valid()); 373 DCHECK(source_info.is_valid());
368 BytecodeNode nop(Bytecode::kNop, source_info); 374 BytecodeNode nop = BytecodeNode::Create<Bytecode::kNop>(source_info);
369 next_stage_->Write(&nop); 375 next_stage_->Write(&nop);
370 } 376 }
371 377
372 void BytecodeRegisterOptimizer::PrepareOutputRegister(Register reg) { 378 void BytecodeRegisterOptimizer::PrepareOutputRegister(Register reg) {
373 RegisterInfo* reg_info = GetRegisterInfo(reg); 379 RegisterInfo* reg_info = GetRegisterInfo(reg);
374 if (reg_info->materialized()) { 380 if (reg_info->materialized()) {
375 CreateMaterializedEquivalent(reg_info); 381 CreateMaterializedEquivalent(reg_info);
376 } 382 }
377 reg_info->MoveToNewEquivalenceSet(NextEquivalenceId(), true); 383 reg_info->MoveToNewEquivalenceSet(NextEquivalenceId(), true);
378 max_register_index_ = 384 max_register_index_ =
(...skipping 30 matching lines...) Expand all
409 int start_index = reg_list.first_register().index(); 415 int start_index = reg_list.first_register().index();
410 for (int i = 0; i < reg_list.register_count(); ++i) { 416 for (int i = 0; i < reg_list.register_count(); ++i) {
411 Register current(start_index + i); 417 Register current(start_index + i);
412 RegisterInfo* input_info = GetRegisterInfo(current); 418 RegisterInfo* input_info = GetRegisterInfo(current);
413 Materialize(input_info); 419 Materialize(input_info);
414 } 420 }
415 return reg_list; 421 return reg_list;
416 } 422 }
417 } 423 }
418 424
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) { 425 void BytecodeRegisterOptimizer::GrowRegisterMap(Register reg) {
446 DCHECK(RegisterIsTemporary(reg)); 426 DCHECK(RegisterIsTemporary(reg));
447 size_t index = GetRegisterInfoTableIndex(reg); 427 size_t index = GetRegisterInfoTableIndex(reg);
448 if (index >= register_info_table_.size()) { 428 if (index >= register_info_table_.size()) {
449 size_t new_size = index + 1; 429 size_t new_size = index + 1;
450 size_t old_size = register_info_table_.size(); 430 size_t old_size = register_info_table_.size();
451 register_info_table_.resize(new_size); 431 register_info_table_.resize(new_size);
452 for (size_t i = old_size; i < new_size; ++i) { 432 for (size_t i = old_size; i < new_size; ++i) {
453 register_info_table_[i] = 433 register_info_table_[i] =
454 new (zone()) RegisterInfo(RegisterFromRegisterInfoTableIndex(i), 434 new (zone()) RegisterInfo(RegisterFromRegisterInfoTableIndex(i),
(...skipping 20 matching lines...) Expand all
475 void BytecodeRegisterOptimizer::RegisterListFreeEvent(RegisterList reg_list) { 455 void BytecodeRegisterOptimizer::RegisterListFreeEvent(RegisterList reg_list) {
476 int first_index = reg_list.first_register().index(); 456 int first_index = reg_list.first_register().index();
477 for (int i = 0; i < reg_list.register_count(); i++) { 457 for (int i = 0; i < reg_list.register_count(); i++) {
478 GetRegisterInfo(Register(first_index + i))->set_allocated(false); 458 GetRegisterInfo(Register(first_index + i))->set_allocated(false);
479 } 459 }
480 } 460 }
481 461
482 } // namespace interpreter 462 } // namespace interpreter
483 } // namespace internal 463 } // namespace internal
484 } // namespace v8 464 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698