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/interpreter-assembler.h" | 5 #include "src/interpreter/interpreter-assembler.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <ostream> | 8 #include <ostream> |
9 | 9 |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 #endif | 708 #endif |
709 } | 709 } |
710 | 710 |
711 Node* InterpreterAssembler::RegisterCount() { | 711 Node* InterpreterAssembler::RegisterCount() { |
712 Node* bytecode_array = LoadRegister(Register::bytecode_array()); | 712 Node* bytecode_array = LoadRegister(Register::bytecode_array()); |
713 Node* frame_size = LoadObjectField( | 713 Node* frame_size = LoadObjectField( |
714 bytecode_array, BytecodeArray::kFrameSizeOffset, MachineType::Int32()); | 714 bytecode_array, BytecodeArray::kFrameSizeOffset, MachineType::Int32()); |
715 return Word32Sar(frame_size, Int32Constant(kPointerSizeLog2)); | 715 return Word32Sar(frame_size, Int32Constant(kPointerSizeLog2)); |
716 } | 716 } |
717 | 717 |
718 Node* InterpreterAssembler::ExportRegisterFile() { | 718 Node* InterpreterAssembler::ExportRegisterFile(Node* array) { |
719 Node* register_count = RegisterCount(); | 719 if (FLAG_debug_code) { |
720 Node* array = | 720 Node* array_size = SmiUntag(LoadFixedArrayBaseLength(array)); |
721 AllocateUninitializedFixedArray(ChangeInt32ToIntPtr(register_count)); | 721 AbortIfWordNotEqual( |
| 722 array_size, RegisterCount(), kInvalidRegisterFileInGenerator); |
| 723 } |
722 | 724 |
723 Variable var_index(this, MachineRepresentation::kWord32); | 725 Variable var_index(this, MachineRepresentation::kWord32); |
724 var_index.Bind(Int32Constant(0)); | 726 var_index.Bind(Int32Constant(0)); |
725 | 727 |
726 // Iterate over register file and write values into array. | 728 // Iterate over register file and write values into array. |
727 Label loop(this, &var_index), done_loop(this); | 729 Label loop(this, &var_index), done_loop(this); |
728 Goto(&loop); | 730 Goto(&loop); |
729 Bind(&loop); | 731 Bind(&loop); |
730 { | 732 { |
731 Node* index = var_index.value(); | 733 Node* index = var_index.value(); |
732 Node* condition = Int32LessThan(index, register_count); | 734 Node* condition = Int32LessThan(index, RegisterCount()); |
733 GotoUnless(condition, &done_loop); | 735 GotoUnless(condition, &done_loop); |
734 | 736 |
735 Node* reg_index = | 737 Node* reg_index = |
736 Int32Sub(Int32Constant(Register(0).ToOperand()), index); | 738 Int32Sub(Int32Constant(Register(0).ToOperand()), index); |
737 Node* value = LoadRegister(ChangeInt32ToIntPtr(reg_index)); | 739 Node* value = LoadRegister(ChangeInt32ToIntPtr(reg_index)); |
738 | 740 |
739 // No write barrier needed for writing into freshly allocated object. | 741 StoreFixedArrayElementInt32Index(array, index, value); |
740 StoreFixedArrayElementNoWriteBarrier( | |
741 array, ChangeInt32ToIntPtr(index), value); | |
742 | 742 |
743 var_index.Bind(Int32Add(index, Int32Constant(1))); | 743 var_index.Bind(Int32Add(index, Int32Constant(1))); |
744 Goto(&loop); | 744 Goto(&loop); |
745 } | 745 } |
746 Bind(&done_loop); | 746 Bind(&done_loop); |
747 | 747 |
748 return array; | 748 return array; |
749 } | 749 } |
750 | 750 |
751 Node* InterpreterAssembler::ImportRegisterFile(Node* array) { | 751 Node* InterpreterAssembler::ImportRegisterFile(Node* array) { |
752 Node* register_count = RegisterCount(); | 752 if (FLAG_debug_code) { |
| 753 Node* array_size = SmiUntag(LoadFixedArrayBaseLength(array)); |
| 754 AbortIfWordNotEqual( |
| 755 array_size, RegisterCount(), kInvalidRegisterFileInGenerator); |
| 756 } |
753 | 757 |
754 Variable var_index(this, MachineRepresentation::kWord32); | 758 Variable var_index(this, MachineRepresentation::kWord32); |
755 var_index.Bind(Int32Constant(0)); | 759 var_index.Bind(Int32Constant(0)); |
756 | 760 |
757 // Iterate over array and write values into register file. | 761 // Iterate over array and write values into register file. Also erase the |
| 762 // array contents to not keep them alive artificially. |
758 Label loop(this, &var_index), done_loop(this); | 763 Label loop(this, &var_index), done_loop(this); |
759 Goto(&loop); | 764 Goto(&loop); |
760 Bind(&loop); | 765 Bind(&loop); |
761 { | 766 { |
762 Node* index = var_index.value(); | 767 Node* index = var_index.value(); |
763 Node* condition = Int32LessThan(index, register_count); | 768 Node* condition = Int32LessThan(index, RegisterCount()); |
764 GotoUnless(condition, &done_loop); | 769 GotoUnless(condition, &done_loop); |
765 | 770 |
766 Node* value = LoadFixedArrayElementInt32Index(array, index); | 771 Node* value = LoadFixedArrayElementInt32Index(array, index); |
767 | 772 |
768 Node* reg_index = | 773 Node* reg_index = |
769 Int32Sub(Int32Constant(Register(0).ToOperand()), index); | 774 Int32Sub(Int32Constant(Register(0).ToOperand()), index); |
770 StoreRegister(value, ChangeInt32ToIntPtr(reg_index)); | 775 StoreRegister(value, ChangeInt32ToIntPtr(reg_index)); |
771 | 776 |
| 777 StoreFixedArrayElementInt32Index(array, index, StaleRegisterConstant()); |
| 778 |
772 var_index.Bind(Int32Add(index, Int32Constant(1))); | 779 var_index.Bind(Int32Add(index, Int32Constant(1))); |
773 Goto(&loop); | 780 Goto(&loop); |
774 } | 781 } |
775 Bind(&done_loop); | 782 Bind(&done_loop); |
776 | 783 |
777 return array; | 784 return array; |
778 } | 785 } |
779 | 786 |
780 } // namespace interpreter | 787 } // namespace interpreter |
781 } // namespace internal | 788 } // namespace internal |
782 } // namespace v8 | 789 } // namespace v8 |
OLD | NEW |