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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 1531693002: [Interpreter] Implement ForIn in bytecode graph builder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@oth-0009-phi
Patch Set: Fix ForInPrepare. Created 5 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 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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::VisitForInStatement(ForInStatement* stmt) { 852 void BytecodeGenerator::VisitForInStatement(ForInStatement* stmt) {
853 EffectResultScope statement_result_scope(this); 853 EffectResultScope statement_result_scope(this);
854
855 if (stmt->subject()->IsNullLiteral() || 854 if (stmt->subject()->IsNullLiteral() ||
856 stmt->subject()->IsUndefinedLiteral(isolate())) { 855 stmt->subject()->IsUndefinedLiteral(isolate())) {
857 // ForIn generates lots of code, skip if it wouldn't produce any effects. 856 // ForIn generates lots of code, skip if it wouldn't produce any effects.
858 return; 857 return;
859 } 858 }
860 859
861 LoopBuilder loop_builder(builder()); 860 LoopBuilder loop_builder(builder());
862 ControlScopeForIteration control_scope(this, stmt, &loop_builder); 861 ControlScopeForIteration control_scope(this, stmt, &loop_builder);
863 862
864 // Prepare the state for executing ForIn. 863 // Prepare the state for executing ForIn.
865 VisitForAccumulatorValue(stmt->subject()); 864 VisitForAccumulatorValue(stmt->subject());
866 loop_builder.BreakIfUndefined(); 865 loop_builder.BreakIfUndefined();
867 loop_builder.BreakIfNull(); 866 loop_builder.BreakIfNull();
868 867
869 Register receiver = execution_result()->NewRegister(); 868 Register receiver = execution_result()->NewRegister();
870 builder()->CastAccumulatorToJSObject(); 869 builder()->CastAccumulatorToJSObject();
871 builder()->StoreAccumulatorInRegister(receiver); 870 builder()->StoreAccumulatorInRegister(receiver);
872 builder()->CallRuntime(Runtime::kGetPropertyNamesFast, receiver, 1); 871 builder()->CallRuntime(Runtime::kGetPropertyNamesFast, receiver, 1);
873 builder()->ForInPrepare(receiver); 872 Register cache_type = execution_result()->NewRegister();
873 Register cache_array = execution_result()->NewRegister();
874 Register cache_length = execution_result()->NewRegister();
875 builder()->ForInPrepare(receiver, cache_type, cache_array, cache_length);
874 loop_builder.BreakIfUndefined(); 876 loop_builder.BreakIfUndefined();
Benedikt Meurer 2015/12/16 20:00:14 This looks wrong/unnecessary (now). As far as I ca
875 877
876 Register for_in_state = execution_result()->NewRegister();
877 builder()->StoreAccumulatorInRegister(for_in_state);
878
879 // Check loop termination (accumulator holds index). 878 // Check loop termination (accumulator holds index).
880 Register index = receiver; // Re-using register as receiver no longer used. 879 Register index = execution_result()->NewRegister();
881 builder()->LoadLiteral(Smi::FromInt(0)); 880 builder()->LoadLiteral(Smi::FromInt(0));
881 builder()->StoreAccumulatorInRegister(index);
882 loop_builder.LoopHeader(); 882 loop_builder.LoopHeader();
883 loop_builder.Condition(); 883 loop_builder.Condition();
884 builder()->StoreAccumulatorInRegister(index).ForInDone(for_in_state); 884 builder()->ForInDone(index, cache_length);
885 loop_builder.BreakIfTrue(); 885 loop_builder.BreakIfTrue();
886 builder()->ForInNext(for_in_state, index); 886 builder()->ForInNext(receiver, cache_type, cache_array, index);
887 loop_builder.ContinueIfUndefined(); 887 loop_builder.ContinueIfUndefined();
888
889 VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot()); 888 VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot());
890 Visit(stmt->body()); 889 Visit(stmt->body());
891
892 // TODO(oth): replace CountOperation here with ForInStep.
893 loop_builder.Next(); 890 loop_builder.Next();
894 builder()->LoadAccumulatorWithRegister(index).CountOperation( 891 builder()->ForInStep(index);
895 Token::Value::ADD, language_mode_strength());
896 loop_builder.JumpToHeader(); 892 loop_builder.JumpToHeader();
897 loop_builder.LoopEnd(); 893 loop_builder.LoopEnd();
898 } 894 }
899 895
900 896
901 void BytecodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { 897 void BytecodeGenerator::VisitForOfStatement(ForOfStatement* stmt) {
902 UNIMPLEMENTED(); 898 UNIMPLEMENTED();
903 } 899 }
904 900
905 901
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 } 2194 }
2199 2195
2200 2196
2201 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 2197 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
2202 return info()->feedback_vector()->GetIndex(slot); 2198 return info()->feedback_vector()->GetIndex(slot);
2203 } 2199 }
2204 2200
2205 } // namespace interpreter 2201 } // namespace interpreter
2206 } // namespace internal 2202 } // namespace internal
2207 } // namespace v8 2203 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698