| 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/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/compiler/control-builders.h" | 8 #include "src/compiler/control-builders.h" |
| 9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 if (should_update) { | 213 if (should_update) { |
| 214 Operator* op = common()->StateValues(count); | 214 Operator* op = common()->StateValues(count); |
| 215 (*state_values) = graph()->NewNode(op, count, env_values); | 215 (*state_values) = graph()->NewNode(op, count, env_values); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 | 219 |
| 220 Node* AstGraphBuilder::Environment::Checkpoint(BailoutId ast_id) { | 220 Node* AstGraphBuilder::Environment::Checkpoint( |
| 221 BailoutId ast_id, OutputFrameStateCombine combine) { |
| 221 UpdateStateValues(¶meters_node_, 0, parameters_count()); | 222 UpdateStateValues(¶meters_node_, 0, parameters_count()); |
| 222 UpdateStateValues(&locals_node_, parameters_count(), locals_count()); | 223 UpdateStateValues(&locals_node_, parameters_count(), locals_count()); |
| 223 UpdateStateValues(&stack_node_, parameters_count() + locals_count(), | 224 UpdateStateValues(&stack_node_, parameters_count() + locals_count(), |
| 224 stack_height()); | 225 stack_height()); |
| 225 | 226 |
| 226 Operator* op = common()->FrameState(ast_id); | 227 Operator* op = common()->FrameState(ast_id, combine); |
| 227 | 228 |
| 228 return graph()->NewNode(op, parameters_node_, locals_node_, stack_node_); | 229 return graph()->NewNode(op, parameters_node_, locals_node_, stack_node_, |
| 230 GetContext()); |
| 229 } | 231 } |
| 230 | 232 |
| 231 | 233 |
| 232 AstGraphBuilder::AstContext::AstContext(AstGraphBuilder* own, | 234 AstGraphBuilder::AstContext::AstContext(AstGraphBuilder* own, |
| 233 Expression::Context kind) | 235 Expression::Context kind) |
| 234 : kind_(kind), owner_(own), outer_(own->ast_context()) { | 236 : kind_(kind), owner_(own), outer_(own->ast_context()) { |
| 235 owner()->set_ast_context(this); // Push. | 237 owner()->set_ast_context(this); // Push. |
| 236 #ifdef DEBUG | 238 #ifdef DEBUG |
| 237 original_height_ = environment()->stack_height(); | 239 original_height_ = environment()->stack_height(); |
| 238 #endif | 240 #endif |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 case VARIABLE: { | 1079 case VARIABLE: { |
| 1078 Variable* variable = expr->target()->AsVariableProxy()->var(); | 1080 Variable* variable = expr->target()->AsVariableProxy()->var(); |
| 1079 old_value = BuildVariableLoad(variable, expr->target()->id()); | 1081 old_value = BuildVariableLoad(variable, expr->target()->id()); |
| 1080 break; | 1082 break; |
| 1081 } | 1083 } |
| 1082 case NAMED_PROPERTY: { | 1084 case NAMED_PROPERTY: { |
| 1083 Node* object = environment()->Top(); | 1085 Node* object = environment()->Top(); |
| 1084 PrintableUnique<Name> name = | 1086 PrintableUnique<Name> name = |
| 1085 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); | 1087 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); |
| 1086 old_value = NewNode(javascript()->LoadNamed(name), object); | 1088 old_value = NewNode(javascript()->LoadNamed(name), object); |
| 1087 PrepareFrameState(old_value, property->LoadId(), PUSH_OUTPUT); | 1089 PrepareFrameState(old_value, property->LoadId(), kPushOutput); |
| 1088 break; | 1090 break; |
| 1089 } | 1091 } |
| 1090 case KEYED_PROPERTY: { | 1092 case KEYED_PROPERTY: { |
| 1091 Node* key = environment()->Top(); | 1093 Node* key = environment()->Top(); |
| 1092 Node* object = environment()->Peek(1); | 1094 Node* object = environment()->Peek(1); |
| 1093 old_value = NewNode(javascript()->LoadProperty(), object, key); | 1095 old_value = NewNode(javascript()->LoadProperty(), object, key); |
| 1094 PrepareFrameState(old_value, property->LoadId(), PUSH_OUTPUT); | 1096 PrepareFrameState(old_value, property->LoadId(), kPushOutput); |
| 1095 break; | 1097 break; |
| 1096 } | 1098 } |
| 1097 } | 1099 } |
| 1098 environment()->Push(old_value); | 1100 environment()->Push(old_value); |
| 1099 VisitForValue(expr->value()); | 1101 VisitForValue(expr->value()); |
| 1100 Node* right = environment()->Pop(); | 1102 Node* right = environment()->Pop(); |
| 1101 Node* left = environment()->Pop(); | 1103 Node* left = environment()->Pop(); |
| 1102 Node* value = BuildBinaryOp(left, right, expr->binary_op()); | 1104 Node* value = BuildBinaryOp(left, right, expr->binary_op()); |
| 1103 PrepareFrameState(value, expr->binary_operation()->id(), PUSH_OUTPUT); | 1105 PrepareFrameState(value, expr->binary_operation()->id(), kPushOutput); |
| 1104 environment()->Push(value); | 1106 environment()->Push(value); |
| 1105 } else { | 1107 } else { |
| 1106 VisitForValue(expr->value()); | 1108 VisitForValue(expr->value()); |
| 1107 } | 1109 } |
| 1108 | 1110 |
| 1109 // Store the value. | 1111 // Store the value. |
| 1110 Node* value = environment()->Pop(); | 1112 Node* value = environment()->Pop(); |
| 1111 switch (assign_type) { | 1113 switch (assign_type) { |
| 1112 case VARIABLE: { | 1114 case VARIABLE: { |
| 1113 Variable* variable = expr->target()->AsVariableProxy()->var(); | 1115 Variable* variable = expr->target()->AsVariableProxy()->var(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 Node* object = environment()->Top(); | 1212 Node* object = environment()->Top(); |
| 1211 if (property->key()->IsPropertyName()) { | 1213 if (property->key()->IsPropertyName()) { |
| 1212 PrintableUnique<Name> name = | 1214 PrintableUnique<Name> name = |
| 1213 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); | 1215 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); |
| 1214 callee_value = NewNode(javascript()->LoadNamed(name), object); | 1216 callee_value = NewNode(javascript()->LoadNamed(name), object); |
| 1215 } else { | 1217 } else { |
| 1216 VisitForValue(property->key()); | 1218 VisitForValue(property->key()); |
| 1217 Node* key = environment()->Pop(); | 1219 Node* key = environment()->Pop(); |
| 1218 callee_value = NewNode(javascript()->LoadProperty(), object, key); | 1220 callee_value = NewNode(javascript()->LoadProperty(), object, key); |
| 1219 } | 1221 } |
| 1220 PrepareFrameState(callee_value, property->LoadId(), PUSH_OUTPUT); | 1222 PrepareFrameState(callee_value, property->LoadId(), kPushOutput); |
| 1221 receiver_value = environment()->Pop(); | 1223 receiver_value = environment()->Pop(); |
| 1222 // Note that a PROPERTY_CALL requires the receiver to be wrapped into an | 1224 // Note that a PROPERTY_CALL requires the receiver to be wrapped into an |
| 1223 // object for sloppy callees. This could also be modeled explicitly here, | 1225 // object for sloppy callees. This could also be modeled explicitly here, |
| 1224 // thereby obsoleting the need for a flag to the call operator. | 1226 // thereby obsoleting the need for a flag to the call operator. |
| 1225 flags = CALL_AS_METHOD; | 1227 flags = CALL_AS_METHOD; |
| 1226 break; | 1228 break; |
| 1227 } | 1229 } |
| 1228 case Call::POSSIBLY_EVAL_CALL: | 1230 case Call::POSSIBLY_EVAL_CALL: |
| 1229 possibly_eval = true; | 1231 possibly_eval = true; |
| 1230 // Fall through. | 1232 // Fall through. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 Handle<String> name = expr->name(); | 1298 Handle<String> name = expr->name(); |
| 1297 | 1299 |
| 1298 // The callee and the receiver both have to be pushed onto the operand stack | 1300 // The callee and the receiver both have to be pushed onto the operand stack |
| 1299 // before arguments are being evaluated. | 1301 // before arguments are being evaluated. |
| 1300 CallFunctionFlags flags = NO_CALL_FUNCTION_FLAGS; | 1302 CallFunctionFlags flags = NO_CALL_FUNCTION_FLAGS; |
| 1301 Node* receiver_value = BuildLoadBuiltinsObject(); | 1303 Node* receiver_value = BuildLoadBuiltinsObject(); |
| 1302 PrintableUnique<String> unique = MakeUnique(name); | 1304 PrintableUnique<String> unique = MakeUnique(name); |
| 1303 Node* callee_value = NewNode(javascript()->LoadNamed(unique), receiver_value); | 1305 Node* callee_value = NewNode(javascript()->LoadNamed(unique), receiver_value); |
| 1304 // TODO(jarin): Find/create a bailout id to deoptimize to (crankshaft | 1306 // TODO(jarin): Find/create a bailout id to deoptimize to (crankshaft |
| 1305 // refuses to optimize functions with jsruntime calls). | 1307 // refuses to optimize functions with jsruntime calls). |
| 1306 PrepareFrameState(callee_value, BailoutId::None(), PUSH_OUTPUT); | 1308 PrepareFrameState(callee_value, BailoutId::None(), kPushOutput); |
| 1307 environment()->Push(callee_value); | 1309 environment()->Push(callee_value); |
| 1308 environment()->Push(receiver_value); | 1310 environment()->Push(receiver_value); |
| 1309 | 1311 |
| 1310 // Evaluate all arguments to the JS runtime call. | 1312 // Evaluate all arguments to the JS runtime call. |
| 1311 ZoneList<Expression*>* args = expr->arguments(); | 1313 ZoneList<Expression*>* args = expr->arguments(); |
| 1312 VisitForValues(args); | 1314 VisitForValues(args); |
| 1313 | 1315 |
| 1314 // Create node to perform the JS runtime call. | 1316 // Create node to perform the JS runtime call. |
| 1315 Operator* call = javascript()->Call(args->length() + 2, flags); | 1317 Operator* call = javascript()->Call(args->length() + 2, flags); |
| 1316 Node* value = ProcessArguments(call, args->length() + 2); | 1318 Node* value = ProcessArguments(call, args->length() + 2); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 old_value = BuildVariableLoad(variable, expr->expression()->id()); | 1380 old_value = BuildVariableLoad(variable, expr->expression()->id()); |
| 1379 stack_depth = 0; | 1381 stack_depth = 0; |
| 1380 break; | 1382 break; |
| 1381 } | 1383 } |
| 1382 case NAMED_PROPERTY: { | 1384 case NAMED_PROPERTY: { |
| 1383 VisitForValue(property->obj()); | 1385 VisitForValue(property->obj()); |
| 1384 Node* object = environment()->Top(); | 1386 Node* object = environment()->Top(); |
| 1385 PrintableUnique<Name> name = | 1387 PrintableUnique<Name> name = |
| 1386 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); | 1388 MakeUnique(property->key()->AsLiteral()->AsPropertyName()); |
| 1387 old_value = NewNode(javascript()->LoadNamed(name), object); | 1389 old_value = NewNode(javascript()->LoadNamed(name), object); |
| 1388 PrepareFrameState(old_value, property->LoadId(), PUSH_OUTPUT); | 1390 PrepareFrameState(old_value, property->LoadId(), kPushOutput); |
| 1389 stack_depth = 1; | 1391 stack_depth = 1; |
| 1390 break; | 1392 break; |
| 1391 } | 1393 } |
| 1392 case KEYED_PROPERTY: { | 1394 case KEYED_PROPERTY: { |
| 1393 VisitForValue(property->obj()); | 1395 VisitForValue(property->obj()); |
| 1394 VisitForValue(property->key()); | 1396 VisitForValue(property->key()); |
| 1395 Node* key = environment()->Top(); | 1397 Node* key = environment()->Top(); |
| 1396 Node* object = environment()->Peek(1); | 1398 Node* object = environment()->Peek(1); |
| 1397 old_value = NewNode(javascript()->LoadProperty(), object, key); | 1399 old_value = NewNode(javascript()->LoadProperty(), object, key); |
| 1398 PrepareFrameState(old_value, property->LoadId(), PUSH_OUTPUT); | 1400 PrepareFrameState(old_value, property->LoadId(), kPushOutput); |
| 1399 stack_depth = 2; | 1401 stack_depth = 2; |
| 1400 break; | 1402 break; |
| 1401 } | 1403 } |
| 1402 } | 1404 } |
| 1403 | 1405 |
| 1404 // Convert old value into a number. | 1406 // Convert old value into a number. |
| 1405 old_value = NewNode(javascript()->ToNumber(), old_value); | 1407 old_value = NewNode(javascript()->ToNumber(), old_value); |
| 1406 | 1408 |
| 1407 // Save result for postfix expressions at correct stack depth. | 1409 // Save result for postfix expressions at correct stack depth. |
| 1408 if (is_postfix) environment()->Poke(stack_depth, old_value); | 1410 if (is_postfix) environment()->Poke(stack_depth, old_value); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 ContextualMode contextual_mode) { | 1741 ContextualMode contextual_mode) { |
| 1740 Node* the_hole = jsgraph()->TheHoleConstant(); | 1742 Node* the_hole = jsgraph()->TheHoleConstant(); |
| 1741 VariableMode mode = variable->mode(); | 1743 VariableMode mode = variable->mode(); |
| 1742 switch (variable->location()) { | 1744 switch (variable->location()) { |
| 1743 case Variable::UNALLOCATED: { | 1745 case Variable::UNALLOCATED: { |
| 1744 // Global var, const, or let variable. | 1746 // Global var, const, or let variable. |
| 1745 Node* global = BuildLoadGlobalObject(); | 1747 Node* global = BuildLoadGlobalObject(); |
| 1746 PrintableUnique<Name> name = MakeUnique(variable->name()); | 1748 PrintableUnique<Name> name = MakeUnique(variable->name()); |
| 1747 Operator* op = javascript()->LoadNamed(name, contextual_mode); | 1749 Operator* op = javascript()->LoadNamed(name, contextual_mode); |
| 1748 Node* node = NewNode(op, global); | 1750 Node* node = NewNode(op, global); |
| 1749 PrepareFrameState(node, bailout_id, PUSH_OUTPUT); | 1751 PrepareFrameState(node, bailout_id, kPushOutput); |
| 1750 return node; | 1752 return node; |
| 1751 } | 1753 } |
| 1752 case Variable::PARAMETER: | 1754 case Variable::PARAMETER: |
| 1753 case Variable::LOCAL: { | 1755 case Variable::LOCAL: { |
| 1754 // Local var, const, or let variable. | 1756 // Local var, const, or let variable. |
| 1755 Node* value = environment()->Lookup(variable); | 1757 Node* value = environment()->Lookup(variable); |
| 1756 if (mode == CONST_LEGACY) { | 1758 if (mode == CONST_LEGACY) { |
| 1757 // Perform check for uninitialized legacy const variables. | 1759 // Perform check for uninitialized legacy const variables. |
| 1758 if (value->op() == the_hole->op()) { | 1760 if (value->op() == the_hole->op()) { |
| 1759 value = jsgraph()->UndefinedConstant(); | 1761 value = jsgraph()->UndefinedConstant(); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2002 } | 2004 } |
| 2003 | 2005 |
| 2004 | 2006 |
| 2005 void AstGraphBuilder::PrepareFrameState(Node* node, BailoutId ast_id, | 2007 void AstGraphBuilder::PrepareFrameState(Node* node, BailoutId ast_id, |
| 2006 OutputFrameStateCombine combine) { | 2008 OutputFrameStateCombine combine) { |
| 2007 if (OperatorProperties::HasFrameStateInput(node->op())) { | 2009 if (OperatorProperties::HasFrameStateInput(node->op())) { |
| 2008 int frame_state_index = NodeProperties::GetFrameStateIndex(node); | 2010 int frame_state_index = NodeProperties::GetFrameStateIndex(node); |
| 2009 | 2011 |
| 2010 DCHECK(node->InputAt(frame_state_index)->op()->opcode() == IrOpcode::kDead); | 2012 DCHECK(node->InputAt(frame_state_index)->op()->opcode() == IrOpcode::kDead); |
| 2011 | 2013 |
| 2012 Node* frame_state_node = environment()->Checkpoint(ast_id); | 2014 Node* frame_state_node = environment()->Checkpoint(ast_id, combine); |
| 2013 node->ReplaceInput(frame_state_index, frame_state_node); | 2015 node->ReplaceInput(frame_state_index, frame_state_node); |
| 2014 } | 2016 } |
| 2015 | |
| 2016 if (OperatorProperties::CanLazilyDeoptimize(node->op())) { | |
| 2017 // The deopting node should have an outgoing control dependency. | |
| 2018 DCHECK(environment()->GetControlDependency() == node); | |
| 2019 | |
| 2020 StructuredGraphBuilder::Environment* continuation_env = environment(); | |
| 2021 // Create environment for the deoptimization block, and build the block. | |
| 2022 StructuredGraphBuilder::Environment* deopt_env = | |
| 2023 CopyEnvironment(continuation_env); | |
| 2024 set_environment(deopt_env); | |
| 2025 | |
| 2026 if (combine == PUSH_OUTPUT) { | |
| 2027 environment()->Push(node); | |
| 2028 } | |
| 2029 | |
| 2030 NewNode(common()->LazyDeoptimization()); | |
| 2031 | |
| 2032 // TODO(jarin) If ast_id.IsNone(), perhaps we should generate an empty | |
| 2033 // deopt block and make sure there is no patch entry for this (so | |
| 2034 // that the deoptimizer dies when trying to deoptimize here). | |
| 2035 Node* state_node = environment()->Checkpoint(ast_id); | |
| 2036 Node* deoptimize_node = NewNode(common()->Deoptimize(), state_node); | |
| 2037 UpdateControlDependencyToLeaveFunction(deoptimize_node); | |
| 2038 | |
| 2039 // Continue with the original environment. | |
| 2040 set_environment(continuation_env); | |
| 2041 NewNode(common()->Continuation()); | |
| 2042 } | |
| 2043 } | 2017 } |
| 2044 | 2018 |
| 2045 } | 2019 } |
| 2046 } | 2020 } |
| 2047 } // namespace v8::internal::compiler | 2021 } // namespace v8::internal::compiler |
| OLD | NEW |