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

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 missing comment. 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
869 Register receiver = execution_result()->NewRegister(); 867 Register receiver = execution_result()->NewRegister();
868 // BytecodeGenerator emits a cast here as the BytecodeGraphBuilder
869 // only supports a single de-opt point per bytecode. So whilst the
870 // ast-graph-builder does the cast (semantically) inside
871 // ForInPrepare we need to cast first in case it de-opts.
Benedikt Meurer 2015/12/18 07:55:50 Same here. I'm not sure what that comment is suppo
870 builder()->CastAccumulatorToJSObject(); 872 builder()->CastAccumulatorToJSObject();
873 loop_builder.BreakIfNull();
871 builder()->StoreAccumulatorInRegister(receiver); 874 builder()->StoreAccumulatorInRegister(receiver);
872 builder()->CallRuntime(Runtime::kGetPropertyNamesFast, receiver, 1); 875 Register cache_type = execution_result()->NewRegister();
873 builder()->ForInPrepare(receiver); 876 Register cache_array = execution_result()->NewRegister();
874 loop_builder.BreakIfUndefined(); 877 Register cache_length = execution_result()->NewRegister();
875 878 builder()->ForInPrepare(receiver, cache_type, cache_array, cache_length);
876 Register for_in_state = execution_result()->NewRegister();
877 builder()->StoreAccumulatorInRegister(for_in_state);
878 879
879 // Check loop termination (accumulator holds index). 880 // Check loop termination (accumulator holds index).
880 Register index = receiver; // Re-using register as receiver no longer used. 881 Register index = execution_result()->NewRegister();
881 builder()->LoadLiteral(Smi::FromInt(0)); 882 builder()->LoadLiteral(Smi::FromInt(0));
883 builder()->StoreAccumulatorInRegister(index);
882 loop_builder.LoopHeader(); 884 loop_builder.LoopHeader();
883 loop_builder.Condition(); 885 loop_builder.Condition();
884 builder()->StoreAccumulatorInRegister(index).ForInDone(for_in_state); 886 builder()->ForInDone(index, cache_length);
885 loop_builder.BreakIfTrue(); 887 loop_builder.BreakIfTrue();
886 builder()->ForInNext(for_in_state, index); 888 builder()->ForInNext(receiver, cache_type, cache_array, index);
887 loop_builder.ContinueIfUndefined(); 889 loop_builder.ContinueIfUndefined();
888
889 VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot()); 890 VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot());
890 Visit(stmt->body()); 891 Visit(stmt->body());
891
892 // TODO(oth): replace CountOperation here with ForInStep.
893 loop_builder.Next(); 892 loop_builder.Next();
894 builder()->LoadAccumulatorWithRegister(index).CountOperation( 893 builder()->ForInStep(index);
895 Token::Value::ADD, language_mode_strength());
896 loop_builder.JumpToHeader(); 894 loop_builder.JumpToHeader();
897 loop_builder.LoopEnd(); 895 loop_builder.LoopEnd();
898 } 896 }
899 897
900 898
901 void BytecodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { 899 void BytecodeGenerator::VisitForOfStatement(ForOfStatement* stmt) {
902 UNIMPLEMENTED(); 900 UNIMPLEMENTED();
903 } 901 }
904 902
905 903
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 } 2196 }
2199 2197
2200 2198
2201 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 2199 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
2202 return info()->feedback_vector()->GetIndex(slot); 2200 return info()->feedback_vector()->GetIndex(slot);
2203 } 2201 }
2204 2202
2205 } // namespace interpreter 2203 } // namespace interpreter
2206 } // namespace internal 2204 } // namespace internal
2207 } // namespace v8 2205 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698