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 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-writer.h" | 8 #include "src/interpreter/bytecode-array-writer.h" |
9 #include "src/interpreter/bytecode-label.h" | 9 #include "src/interpreter/bytecode-label.h" |
10 #include "src/interpreter/bytecode-peephole-optimizer.h" | 10 #include "src/interpreter/bytecode-peephole-optimizer.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 } // namespace | 92 } // namespace |
93 | 93 |
94 void BytecodeArrayBuilder::AttachSourceInfo(BytecodeNode* node) { | 94 void BytecodeArrayBuilder::AttachSourceInfo(BytecodeNode* node) { |
95 if (latest_source_info_.is_valid()) { | 95 if (latest_source_info_.is_valid()) { |
96 // Statement positions need to be emitted immediately. Expression | 96 // Statement positions need to be emitted immediately. Expression |
97 // positions can be pushed back until a bytecode is found that can | 97 // positions can be pushed back until a bytecode is found that can |
98 // throw. Hence we only invalidate the existing source position | 98 // throw. Hence we only invalidate the existing source position |
99 // information if it is used. | 99 // information if it is used. |
100 if (latest_source_info_.is_statement() || | 100 if (latest_source_info_.is_statement() || |
101 ExpressionPositionIsNeeded(node->bytecode())) { | 101 ExpressionPositionIsNeeded(node->bytecode())) { |
102 node->source_info() = latest_source_info_; | 102 node->source_info().MakeInvalidEqualTo(latest_source_info_); |
103 latest_source_info_.set_invalid(); | 103 latest_source_info_.set_invalid(); |
104 } | 104 } |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t operand0, | 108 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t operand0, |
109 uint32_t operand1, uint32_t operand2, | 109 uint32_t operand1, uint32_t operand2, |
110 uint32_t operand3) { | 110 uint32_t operand3) { |
111 DCHECK(OperandsAreValid(bytecode, 4, operand0, operand1, operand2, operand3)); | 111 DCHECK(OperandsAreValid(bytecode, 4, operand0, operand1, operand2, operand3)); |
112 BytecodeNode node(bytecode, operand0, operand1, operand2, operand3); | 112 BytecodeNode node(bytecode, operand0, operand1, operand2, operand3); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 return OutputJump(Bytecode::kJumpIfUndefined, label); | 433 return OutputJump(Bytecode::kJumpIfUndefined, label); |
434 } | 434 } |
435 | 435 |
436 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNotHole( | 436 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNotHole( |
437 BytecodeLabel* label) { | 437 BytecodeLabel* label) { |
438 return OutputJump(Bytecode::kJumpIfNotHole, label); | 438 return OutputJump(Bytecode::kJumpIfNotHole, label); |
439 } | 439 } |
440 | 440 |
441 BytecodeArrayBuilder& BytecodeArrayBuilder::StackCheck(int position) { | 441 BytecodeArrayBuilder& BytecodeArrayBuilder::StackCheck(int position) { |
442 if (position != RelocInfo::kNoPosition) { | 442 if (position != RelocInfo::kNoPosition) { |
443 // We need to attach a non-breakable source position to a stack check, | 443 // We need to attach a non-breakable source position to a stack |
444 // so we simply add it as expression position. | 444 // check, so we simply add it as expression position. There can be |
445 latest_source_info_ = {position, false}; | 445 // a prior statement position from constructs like: |
446 // | |
447 // do var x; while (false); | |
448 // | |
449 // A Nop could be inserted for empty statements, but since no code | |
450 // is associated with these positions, they are ignored for now. | |
rmcilroy
2016/06/20 11:21:39
/s/they are ignored for now/instead we force the s
oth
2016/06/21 10:05:46
Done.
| |
451 latest_source_info_.ForceExpressionPosition(position); | |
446 } | 452 } |
447 Output(Bytecode::kStackCheck); | 453 Output(Bytecode::kStackCheck); |
448 return *this; | 454 return *this; |
449 } | 455 } |
450 | 456 |
451 BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { | 457 BytecodeArrayBuilder& BytecodeArrayBuilder::Throw() { |
452 Output(Bytecode::kThrow); | 458 Output(Bytecode::kThrow); |
453 return *this; | 459 return *this; |
454 } | 460 } |
455 | 461 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 Output(BytecodeForDelete(language_mode), RegisterOperand(object)); | 614 Output(BytecodeForDelete(language_mode), RegisterOperand(object)); |
609 return *this; | 615 return *this; |
610 } | 616 } |
611 | 617 |
612 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { | 618 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { |
613 return constant_array_builder()->Insert(object); | 619 return constant_array_builder()->Insert(object); |
614 } | 620 } |
615 | 621 |
616 void BytecodeArrayBuilder::SetReturnPosition() { | 622 void BytecodeArrayBuilder::SetReturnPosition() { |
617 if (return_position_ == RelocInfo::kNoPosition) return; | 623 if (return_position_ == RelocInfo::kNoPosition) return; |
618 latest_source_info_.Update({return_position_, true}); | 624 latest_source_info_.MakeStatementPosition(return_position_); |
619 } | 625 } |
620 | 626 |
621 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { | 627 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { |
622 if (stmt->position() == RelocInfo::kNoPosition) return; | 628 if (stmt->position() == RelocInfo::kNoPosition) return; |
623 latest_source_info_.Update({stmt->position(), true}); | 629 latest_source_info_.MakeStatementPosition(stmt->position()); |
624 } | 630 } |
625 | 631 |
626 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { | 632 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { |
627 if (expr->position() == RelocInfo::kNoPosition) return; | 633 if (expr->position() == RelocInfo::kNoPosition) return; |
628 if (latest_source_info_.is_expression()) { | 634 if (!latest_source_info_.is_statement()) { |
629 // Ensure the current expression position is overwritten with the | 635 // Ensure the current expression position is overwritten with the |
630 // latest value. | 636 // latest value. |
631 // | 637 latest_source_info_.MakeExpressionPosition(expr->position()); |
632 // TODO(oth): Clean-up BytecodeSourceInfo to have three states and | |
633 // simplify the update logic, taking care to ensure position | |
634 // information is not lost. | |
635 latest_source_info_.set_invalid(); | |
636 } | 638 } |
637 latest_source_info_.Update({expr->position(), false}); | |
638 } | 639 } |
639 | 640 |
640 void BytecodeArrayBuilder::SetExpressionAsStatementPosition(Expression* expr) { | 641 void BytecodeArrayBuilder::SetExpressionAsStatementPosition(Expression* expr) { |
641 if (expr->position() == RelocInfo::kNoPosition) return; | 642 if (expr->position() == RelocInfo::kNoPosition) return; |
642 latest_source_info_.Update({expr->position(), true}); | 643 latest_source_info_.MakeStatementPosition(expr->position()); |
643 } | 644 } |
644 | 645 |
645 bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const { | 646 bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const { |
646 return temporary_register_allocator()->RegisterIsLive(reg); | 647 return temporary_register_allocator()->RegisterIsLive(reg); |
647 } | 648 } |
648 | 649 |
649 bool BytecodeArrayBuilder::RegisterIsValid(Register reg) const { | 650 bool BytecodeArrayBuilder::RegisterIsValid(Register reg) const { |
650 if (!reg.is_valid()) { | 651 if (!reg.is_valid()) { |
651 return false; | 652 return false; |
652 } | 653 } |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 return Bytecode::kTailCall; | 918 return Bytecode::kTailCall; |
918 default: | 919 default: |
919 UNREACHABLE(); | 920 UNREACHABLE(); |
920 } | 921 } |
921 return Bytecode::kIllegal; | 922 return Bytecode::kIllegal; |
922 } | 923 } |
923 | 924 |
924 } // namespace interpreter | 925 } // namespace interpreter |
925 } // namespace internal | 926 } // namespace internal |
926 } // namespace v8 | 927 } // namespace v8 |
OLD | NEW |