OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.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/compiler/ast-loop-assignment-analyzer.h" | 9 #include "src/compiler/ast-loop-assignment-analyzer.h" |
10 #include "src/compiler/control-builders.h" | 10 #include "src/compiler/control-builders.h" |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 } | 1105 } |
1106 } | 1106 } |
1107 | 1107 |
1108 | 1108 |
1109 void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { | 1109 void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { |
1110 Variable* variable = decl->proxy()->var(); | 1110 Variable* variable = decl->proxy()->var(); |
1111 VariableMode mode = decl->mode(); | 1111 VariableMode mode = decl->mode(); |
1112 bool hole_init = mode == CONST || mode == LET; | 1112 bool hole_init = mode == CONST || mode == LET; |
1113 switch (variable->location()) { | 1113 switch (variable->location()) { |
1114 case VariableLocation::GLOBAL: | 1114 case VariableLocation::GLOBAL: |
1115 case VariableLocation::UNALLOCATED: | 1115 case VariableLocation::UNALLOCATED: { |
1116 DCHECK(!variable->binding_needs_init()); | 1116 DCHECK(!variable->binding_needs_init()); |
1117 globals()->push_back(variable->name()); | 1117 FeedbackVectorSlot slot = decl->proxy()->VariableFeedbackSlot(); |
| 1118 DCHECK(!slot.IsInvalid()); |
| 1119 globals()->push_back(handle(Smi::FromInt(slot.ToInt()), isolate())); |
1118 globals()->push_back(isolate()->factory()->undefined_value()); | 1120 globals()->push_back(isolate()->factory()->undefined_value()); |
1119 break; | 1121 break; |
| 1122 } |
1120 case VariableLocation::PARAMETER: | 1123 case VariableLocation::PARAMETER: |
1121 case VariableLocation::LOCAL: | 1124 case VariableLocation::LOCAL: |
1122 if (hole_init) { | 1125 if (hole_init) { |
1123 Node* value = jsgraph()->TheHoleConstant(); | 1126 Node* value = jsgraph()->TheHoleConstant(); |
1124 environment()->Bind(variable, value); | 1127 environment()->Bind(variable, value); |
1125 } | 1128 } |
1126 break; | 1129 break; |
1127 case VariableLocation::CONTEXT: | 1130 case VariableLocation::CONTEXT: |
1128 if (hole_init) { | 1131 if (hole_init) { |
1129 Node* value = jsgraph()->TheHoleConstant(); | 1132 Node* value = jsgraph()->TheHoleConstant(); |
(...skipping 15 matching lines...) Expand all Loading... |
1145 | 1148 |
1146 void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { | 1149 void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
1147 Variable* variable = decl->proxy()->var(); | 1150 Variable* variable = decl->proxy()->var(); |
1148 switch (variable->location()) { | 1151 switch (variable->location()) { |
1149 case VariableLocation::GLOBAL: | 1152 case VariableLocation::GLOBAL: |
1150 case VariableLocation::UNALLOCATED: { | 1153 case VariableLocation::UNALLOCATED: { |
1151 Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo( | 1154 Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo( |
1152 decl->fun(), info()->script(), info()); | 1155 decl->fun(), info()->script(), info()); |
1153 // Check for stack-overflow exception. | 1156 // Check for stack-overflow exception. |
1154 if (function.is_null()) return SetStackOverflow(); | 1157 if (function.is_null()) return SetStackOverflow(); |
1155 globals()->push_back(variable->name()); | 1158 FeedbackVectorSlot slot = decl->proxy()->VariableFeedbackSlot(); |
| 1159 DCHECK(!slot.IsInvalid()); |
| 1160 globals()->push_back(handle(Smi::FromInt(slot.ToInt()), isolate())); |
1156 globals()->push_back(function); | 1161 globals()->push_back(function); |
1157 break; | 1162 break; |
1158 } | 1163 } |
1159 case VariableLocation::PARAMETER: | 1164 case VariableLocation::PARAMETER: |
1160 case VariableLocation::LOCAL: { | 1165 case VariableLocation::LOCAL: { |
1161 VisitForValue(decl->fun()); | 1166 VisitForValue(decl->fun()); |
1162 Node* value = environment()->Pop(); | 1167 Node* value = environment()->Pop(); |
1163 environment()->Bind(variable, value); | 1168 environment()->Bind(variable, value); |
1164 break; | 1169 break; |
1165 } | 1170 } |
(...skipping 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2969 // Handled entirely in VisitSwitch. | 2974 // Handled entirely in VisitSwitch. |
2970 UNREACHABLE(); | 2975 UNREACHABLE(); |
2971 } | 2976 } |
2972 | 2977 |
2973 | 2978 |
2974 void AstGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { | 2979 void AstGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { |
2975 DCHECK(globals()->empty()); | 2980 DCHECK(globals()->empty()); |
2976 AstVisitor::VisitDeclarations(declarations); | 2981 AstVisitor::VisitDeclarations(declarations); |
2977 if (globals()->empty()) return; | 2982 if (globals()->empty()) return; |
2978 int array_index = 0; | 2983 int array_index = 0; |
| 2984 Handle<TypeFeedbackVector> feedback_vector( |
| 2985 info()->closure()->feedback_vector()); |
2979 Handle<FixedArray> data = isolate()->factory()->NewFixedArray( | 2986 Handle<FixedArray> data = isolate()->factory()->NewFixedArray( |
2980 static_cast<int>(globals()->size()), TENURED); | 2987 static_cast<int>(globals()->size()), TENURED); |
2981 for (Handle<Object> obj : *globals()) data->set(array_index++, *obj); | 2988 for (Handle<Object> obj : *globals()) data->set(array_index++, *obj); |
2982 int encoded_flags = info()->GetDeclareGlobalsFlags(); | 2989 int encoded_flags = info()->GetDeclareGlobalsFlags(); |
2983 Node* flags = jsgraph()->Constant(encoded_flags); | 2990 Node* flags = jsgraph()->Constant(encoded_flags); |
2984 Node* pairs = jsgraph()->Constant(data); | 2991 Node* pairs = jsgraph()->Constant(data); |
| 2992 Node* vector = jsgraph()->Constant(feedback_vector); |
2985 const Operator* op = javascript()->CallRuntime(Runtime::kDeclareGlobals); | 2993 const Operator* op = javascript()->CallRuntime(Runtime::kDeclareGlobals); |
2986 Node* call = NewNode(op, pairs, flags); | 2994 Node* call = NewNode(op, pairs, flags, vector); |
2987 PrepareFrameState(call, BailoutId::Declarations()); | 2995 PrepareFrameState(call, BailoutId::Declarations()); |
2988 globals()->clear(); | 2996 globals()->clear(); |
2989 } | 2997 } |
2990 | 2998 |
2991 | 2999 |
2992 void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { | 3000 void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { |
2993 if (stmt == nullptr) return; | 3001 if (stmt == nullptr) return; |
2994 Visit(stmt); | 3002 Visit(stmt); |
2995 } | 3003 } |
2996 | 3004 |
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4383 // Phi does not exist yet, introduce one. | 4391 // Phi does not exist yet, introduce one. |
4384 value = NewPhi(inputs, value, control); | 4392 value = NewPhi(inputs, value, control); |
4385 value->ReplaceInput(inputs - 1, other); | 4393 value->ReplaceInput(inputs - 1, other); |
4386 } | 4394 } |
4387 return value; | 4395 return value; |
4388 } | 4396 } |
4389 | 4397 |
4390 } // namespace compiler | 4398 } // namespace compiler |
4391 } // namespace internal | 4399 } // namespace internal |
4392 } // namespace v8 | 4400 } // namespace v8 |
OLD | NEW |