| 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-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/interpreter/control-flow-builders.h" | 9 #include "src/interpreter/control-flow-builders.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 language_mode()); | 842 language_mode()); |
| 843 break; | 843 break; |
| 844 } | 844 } |
| 845 case NAMED_SUPER_PROPERTY: | 845 case NAMED_SUPER_PROPERTY: |
| 846 case KEYED_SUPER_PROPERTY: | 846 case KEYED_SUPER_PROPERTY: |
| 847 UNIMPLEMENTED(); | 847 UNIMPLEMENTED(); |
| 848 } | 848 } |
| 849 } | 849 } |
| 850 | 850 |
| 851 | 851 |
| 852 void BytecodeGenerator::GetForInPreparedItem(Register destination, int index, |
| 853 Register prepare_result, |
| 854 Register scratch) { |
| 855 builder()->LoadLiteral(Smi::FromInt(index)); |
| 856 builder()->StoreAccumulatorInRegister(scratch); |
| 857 builder()->CallRuntime(Runtime::kFixedArrayGet, prepare_result, 2); |
| 858 builder()->StoreAccumulatorInRegister(destination); |
| 859 } |
| 860 |
| 861 |
| 852 void BytecodeGenerator::VisitForInStatement(ForInStatement* stmt) { | 862 void BytecodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 853 EffectResultScope statement_result_scope(this); | 863 EffectResultScope statement_result_scope(this); |
| 854 | 864 |
| 855 if (stmt->subject()->IsNullLiteral() || | 865 if (stmt->subject()->IsNullLiteral() || |
| 856 stmt->subject()->IsUndefinedLiteral(isolate())) { | 866 stmt->subject()->IsUndefinedLiteral(isolate())) { |
| 857 // ForIn generates lots of code, skip if it wouldn't produce any effects. | 867 // ForIn generates lots of code, skip if it wouldn't produce any effects. |
| 858 return; | 868 return; |
| 859 } | 869 } |
| 860 | 870 |
| 861 LoopBuilder loop_builder(builder()); | 871 LoopBuilder loop_builder(builder()); |
| 862 ControlScopeForIteration control_scope(this, stmt, &loop_builder); | 872 ControlScopeForIteration control_scope(this, stmt, &loop_builder); |
| 863 | 873 |
| 864 // Prepare the state for executing ForIn. | 874 // Prepare the state for executing ForIn. |
| 865 VisitForAccumulatorValue(stmt->subject()); | 875 VisitForAccumulatorValue(stmt->subject()); |
| 866 loop_builder.BreakIfUndefined(); | 876 loop_builder.BreakIfUndefined(); |
| 867 loop_builder.BreakIfNull(); | 877 loop_builder.BreakIfNull(); |
| 868 | 878 |
| 869 Register receiver = execution_result()->NewRegister(); | 879 Register receiver = execution_result()->NewRegister(); |
| 870 builder()->CastAccumulatorToJSObject(); | 880 builder()->CastAccumulatorToJSObject(); |
| 871 builder()->StoreAccumulatorInRegister(receiver); | 881 builder()->StoreAccumulatorInRegister(receiver); |
| 872 builder()->CallRuntime(Runtime::kGetPropertyNamesFast, receiver, 1); | 882 builder()->CallRuntime(Runtime::kGetPropertyNamesFast, receiver, 1); |
| 873 builder()->ForInPrepare(receiver); | 883 builder()->ForInPrepare(receiver); |
| 874 loop_builder.BreakIfUndefined(); | 884 loop_builder.BreakIfUndefined(); |
| 875 | 885 |
| 876 Register for_in_state = execution_result()->NewRegister(); | 886 // Ensure prepare_result and prepare_index are consecutive for CallRuntime. |
| 877 builder()->StoreAccumulatorInRegister(for_in_state); | 887 execution_result()->PrepareForConsecutiveAllocations(2); |
| 888 Register prepare_result = execution_result()->NewRegister(); |
| 889 Register prepare_index = execution_result()->NewRegister(); |
| 890 builder()->StoreAccumulatorInRegister(prepare_result); |
| 891 |
| 892 // Spill the for_in_state to registers so we can de-opt. |
| 893 Register cache_array = execution_result()->NewRegister(); |
| 894 GetForInPreparedItem(cache_array, 0, prepare_result, prepare_index); |
| 895 Register cache_type = execution_result()->NewRegister(); |
| 896 GetForInPreparedItem(cache_type, 1, prepare_result, prepare_index); |
| 897 Register cache_length = execution_result()->NewRegister(); |
| 898 GetForInPreparedItem(cache_length, 2, prepare_result, prepare_index); |
| 878 | 899 |
| 879 // Check loop termination (accumulator holds index). | 900 // Check loop termination (accumulator holds index). |
| 880 Register index = receiver; // Re-using register as receiver no longer used. | 901 Register index = prepare_result; |
| 881 builder()->LoadLiteral(Smi::FromInt(0)); | 902 builder()->LoadLiteral(Smi::FromInt(0)); |
| 903 builder()->StoreAccumulatorInRegister(index); |
| 882 loop_builder.LoopHeader(); | 904 loop_builder.LoopHeader(); |
| 883 loop_builder.Condition(); | 905 loop_builder.Condition(); |
| 884 builder()->StoreAccumulatorInRegister(index).ForInDone(for_in_state); | 906 builder()->ForInDone(index, cache_length); |
| 885 loop_builder.BreakIfTrue(); | 907 loop_builder.BreakIfTrue(); |
| 886 builder()->ForInNext(for_in_state, index); | 908 builder()->ForInNext(receiver, index, cache_type, cache_array); |
| 887 loop_builder.ContinueIfUndefined(); | 909 loop_builder.ContinueIfUndefined(); |
| 888 | |
| 889 VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot()); | 910 VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot()); |
| 890 Visit(stmt->body()); | 911 Visit(stmt->body()); |
| 891 | |
| 892 // TODO(oth): replace CountOperation here with ForInStep. | |
| 893 loop_builder.Next(); | 912 loop_builder.Next(); |
| 894 builder()->LoadAccumulatorWithRegister(index).CountOperation( | 913 builder()->ForInStep(index); |
| 895 Token::Value::ADD, language_mode_strength()); | |
| 896 loop_builder.JumpToHeader(); | 914 loop_builder.JumpToHeader(); |
| 897 loop_builder.LoopEnd(); | 915 loop_builder.LoopEnd(); |
| 898 } | 916 } |
| 899 | 917 |
| 900 | 918 |
| 901 void BytecodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { | 919 void BytecodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { |
| 902 UNIMPLEMENTED(); | 920 UNIMPLEMENTED(); |
| 903 } | 921 } |
| 904 | 922 |
| 905 | 923 |
| (...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2198 } | 2216 } |
| 2199 | 2217 |
| 2200 | 2218 |
| 2201 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2219 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
| 2202 return info()->feedback_vector()->GetIndex(slot); | 2220 return info()->feedback_vector()->GetIndex(slot); |
| 2203 } | 2221 } |
| 2204 | 2222 |
| 2205 } // namespace interpreter | 2223 } // namespace interpreter |
| 2206 } // namespace internal | 2224 } // namespace internal |
| 2207 } // namespace v8 | 2225 } // namespace v8 |
| OLD | NEW |