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/compiler/js-native-context-specialization.h" | 5 #include "src/compiler/js-native-context-specialization.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 target, frame_state); | 1440 target, frame_state); |
1441 | 1441 |
1442 // Introduce the call to the getter function. | 1442 // Introduce the call to the getter function. |
1443 Node* value; | 1443 Node* value; |
1444 if (access_info.constant()->IsJSFunction()) { | 1444 if (access_info.constant()->IsJSFunction()) { |
1445 value = *effect = *control = graph()->NewNode( | 1445 value = *effect = *control = graph()->NewNode( |
1446 jsgraph()->javascript()->Call(2, CallFrequency(), VectorSlotPair(), | 1446 jsgraph()->javascript()->Call(2, CallFrequency(), VectorSlotPair(), |
1447 ConvertReceiverMode::kNotNullOrUndefined), | 1447 ConvertReceiverMode::kNotNullOrUndefined), |
1448 target, receiver, context, frame_state0, *effect, *control); | 1448 target, receiver, context, frame_state0, *effect, *control); |
1449 } else { | 1449 } else { |
1450 Node* holder = jsgraph()->Constant(access_info.holder().ToHandleChecked()); | |
1451 DCHECK(access_info.constant()->IsFunctionTemplateInfo()); | 1450 DCHECK(access_info.constant()->IsFunctionTemplateInfo()); |
1452 Handle<FunctionTemplateInfo> function_template_info( | 1451 Handle<FunctionTemplateInfo> function_template_info( |
1453 Handle<FunctionTemplateInfo>::cast(access_info.constant())); | 1452 Handle<FunctionTemplateInfo>::cast(access_info.constant())); |
1454 DCHECK(!function_template_info->call_code()->IsUndefined(isolate())); | 1453 DCHECK(!function_template_info->call_code()->IsUndefined(isolate())); |
1455 value = | 1454 value = InlineApiCall(receiver, context, target, frame_state0, nullptr, |
1456 InlineApiCall(receiver, holder, context, target, frame_state0, nullptr, | 1455 effect, control, shared_info, function_template_info); |
1457 effect, control, shared_info, function_template_info); | |
1458 } | 1456 } |
1459 // Remember to rewire the IfException edge if this is inside a try-block. | 1457 // Remember to rewire the IfException edge if this is inside a try-block. |
1460 if (if_exceptions != nullptr) { | 1458 if (if_exceptions != nullptr) { |
1461 // Create the appropriate IfException/IfSuccess projections. | 1459 // Create the appropriate IfException/IfSuccess projections. |
1462 Node* const if_exception = | 1460 Node* const if_exception = |
1463 graph()->NewNode(common()->IfException(), *control, *effect); | 1461 graph()->NewNode(common()->IfException(), *control, *effect); |
1464 Node* const if_success = graph()->NewNode(common()->IfSuccess(), *control); | 1462 Node* const if_success = graph()->NewNode(common()->IfSuccess(), *control); |
1465 if_exceptions->push_back(if_exception); | 1463 if_exceptions->push_back(if_exception); |
1466 *control = if_success; | 1464 *control = if_success; |
1467 } | 1465 } |
(...skipping 21 matching lines...) Expand all Loading... |
1489 jsgraph()->EmptyStateValues(), jsgraph()->EmptyStateValues(), context, | 1487 jsgraph()->EmptyStateValues(), jsgraph()->EmptyStateValues(), context, |
1490 target, frame_state); | 1488 target, frame_state); |
1491 | 1489 |
1492 // Introduce the call to the setter function. | 1490 // Introduce the call to the setter function. |
1493 if (access_info.constant()->IsJSFunction()) { | 1491 if (access_info.constant()->IsJSFunction()) { |
1494 *effect = *control = graph()->NewNode( | 1492 *effect = *control = graph()->NewNode( |
1495 jsgraph()->javascript()->Call(3, CallFrequency(), VectorSlotPair(), | 1493 jsgraph()->javascript()->Call(3, CallFrequency(), VectorSlotPair(), |
1496 ConvertReceiverMode::kNotNullOrUndefined), | 1494 ConvertReceiverMode::kNotNullOrUndefined), |
1497 target, receiver, value, context, frame_state0, *effect, *control); | 1495 target, receiver, value, context, frame_state0, *effect, *control); |
1498 } else { | 1496 } else { |
1499 Node* holder = jsgraph()->Constant(access_info.holder().ToHandleChecked()); | |
1500 DCHECK(access_info.constant()->IsFunctionTemplateInfo()); | 1497 DCHECK(access_info.constant()->IsFunctionTemplateInfo()); |
1501 Handle<FunctionTemplateInfo> function_template_info( | 1498 Handle<FunctionTemplateInfo> function_template_info( |
1502 Handle<FunctionTemplateInfo>::cast(access_info.constant())); | 1499 Handle<FunctionTemplateInfo>::cast(access_info.constant())); |
1503 DCHECK(!function_template_info->call_code()->IsUndefined(isolate())); | 1500 DCHECK(!function_template_info->call_code()->IsUndefined(isolate())); |
1504 value = | 1501 value = InlineApiCall(receiver, context, target, frame_state0, value, |
1505 InlineApiCall(receiver, holder, context, target, frame_state0, value, | 1502 effect, control, shared_info, function_template_info); |
1506 effect, control, shared_info, function_template_info); | |
1507 } | 1503 } |
1508 // Remember to rewire the IfException edge if this is inside a try-block. | 1504 // Remember to rewire the IfException edge if this is inside a try-block. |
1509 if (if_exceptions != nullptr) { | 1505 if (if_exceptions != nullptr) { |
1510 // Create the appropriate IfException/IfSuccess projections. | 1506 // Create the appropriate IfException/IfSuccess projections. |
1511 Node* const if_exception = | 1507 Node* const if_exception = |
1512 graph()->NewNode(common()->IfException(), *control, *effect); | 1508 graph()->NewNode(common()->IfException(), *control, *effect); |
1513 Node* const if_success = graph()->NewNode(common()->IfSuccess(), *control); | 1509 Node* const if_success = graph()->NewNode(common()->IfSuccess(), *control); |
1514 if_exceptions->push_back(if_exception); | 1510 if_exceptions->push_back(if_exception); |
1515 *control = if_success; | 1511 *control = if_success; |
1516 } | 1512 } |
1517 return value; | 1513 return value; |
1518 } | 1514 } |
1519 | 1515 |
1520 Node* JSNativeContextSpecialization::InlineApiCall( | 1516 Node* JSNativeContextSpecialization::InlineApiCall( |
1521 Node* receiver, Node* holder, Node* context, Node* target, | 1517 Node* receiver, Node* context, Node* target, Node* frame_state, Node* value, |
1522 Node* frame_state, Node* value, Node** effect, Node** control, | 1518 Node** effect, Node** control, Handle<SharedFunctionInfo> shared_info, |
1523 Handle<SharedFunctionInfo> shared_info, | |
1524 Handle<FunctionTemplateInfo> function_template_info) { | 1519 Handle<FunctionTemplateInfo> function_template_info) { |
1525 Handle<CallHandlerInfo> call_handler_info = handle( | 1520 Handle<CallHandlerInfo> call_handler_info = handle( |
1526 CallHandlerInfo::cast(function_template_info->call_code()), isolate()); | 1521 CallHandlerInfo::cast(function_template_info->call_code()), isolate()); |
1527 Handle<Object> call_data_object(call_handler_info->data(), isolate()); | 1522 Handle<Object> call_data_object(call_handler_info->data(), isolate()); |
1528 | 1523 |
1529 // Only setters have a value. | 1524 // Only setters have a value. |
1530 int const argc = value == nullptr ? 0 : 1; | 1525 int const argc = value == nullptr ? 0 : 1; |
1531 // The stub always expects the receiver as the first param on the stack. | 1526 // The stub always expects the receiver as the first param on the stack. |
1532 CallApiCallbackStub stub( | 1527 CallApiCallbackStub stub( |
1533 isolate(), argc, | 1528 isolate(), argc, |
1534 true /* FunctionTemplateInfo doesn't have an associated context. */); | 1529 true /* FunctionTemplateInfo doesn't have an associated context. */); |
1535 CallInterfaceDescriptor call_interface_descriptor = | 1530 CallInterfaceDescriptor call_interface_descriptor = |
1536 stub.GetCallInterfaceDescriptor(); | 1531 stub.GetCallInterfaceDescriptor(); |
1537 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | 1532 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( |
1538 isolate(), graph()->zone(), call_interface_descriptor, | 1533 isolate(), graph()->zone(), call_interface_descriptor, |
1539 call_interface_descriptor.GetStackParameterCount() + argc + | 1534 call_interface_descriptor.GetStackParameterCount() + argc + |
1540 1 /* implicit receiver */ + 1 /* accessor holder */, | 1535 1 /* implicit receiver */, |
1541 CallDescriptor::kNeedsFrameState, Operator::kNoProperties, | 1536 CallDescriptor::kNeedsFrameState, Operator::kNoProperties, |
1542 MachineType::AnyTagged(), 1); | 1537 MachineType::AnyTagged(), 1); |
1543 | 1538 |
1544 Node* data = jsgraph()->Constant(call_data_object); | 1539 Node* data = jsgraph()->Constant(call_data_object); |
1545 ApiFunction function(v8::ToCData<Address>(call_handler_info->callback())); | 1540 ApiFunction function(v8::ToCData<Address>(call_handler_info->callback())); |
1546 Node* function_reference = | 1541 Node* function_reference = |
1547 graph()->NewNode(common()->ExternalConstant(ExternalReference( | 1542 graph()->NewNode(common()->ExternalConstant(ExternalReference( |
1548 &function, ExternalReference::DIRECT_API_CALL, isolate()))); | 1543 &function, ExternalReference::DIRECT_API_CALL, isolate()))); |
1549 Node* code = jsgraph()->HeapConstant(stub.GetCode()); | 1544 Node* code = jsgraph()->HeapConstant(stub.GetCode()); |
1550 | 1545 |
1551 // Add CallApiCallbackStub's register argument as well. | 1546 // Add CallApiCallbackStub's register argument as well. |
1552 Node* inputs[12] = { | 1547 Node* inputs[11] = { |
1553 code, target, data, receiver /* holder */, function_reference, | 1548 code, target, data, receiver /* holder */, function_reference, receiver}; |
1554 holder, receiver}; | 1549 int index = 6 + argc; |
1555 int index = 7 + argc; | |
1556 inputs[index++] = context; | 1550 inputs[index++] = context; |
1557 inputs[index++] = frame_state; | 1551 inputs[index++] = frame_state; |
1558 inputs[index++] = *effect; | 1552 inputs[index++] = *effect; |
1559 inputs[index++] = *control; | 1553 inputs[index++] = *control; |
1560 // This needs to stay here because of the edge case described in | 1554 // This needs to stay here because of the edge case described in |
1561 // http://crbug.com/675648. | 1555 // http://crbug.com/675648. |
1562 if (value != nullptr) { | 1556 if (value != nullptr) { |
1563 inputs[7] = value; | 1557 inputs[6] = value; |
1564 } | 1558 } |
1565 | 1559 |
1566 return *effect = *control = | 1560 return *effect = *control = |
1567 graph()->NewNode(common()->Call(call_descriptor), index, inputs); | 1561 graph()->NewNode(common()->Call(call_descriptor), index, inputs); |
1568 } | 1562 } |
1569 | 1563 |
1570 JSNativeContextSpecialization::ValueEffectControl | 1564 JSNativeContextSpecialization::ValueEffectControl |
1571 JSNativeContextSpecialization::BuildPropertyLoad( | 1565 JSNativeContextSpecialization::BuildPropertyLoad( |
1572 Node* receiver, Node* context, Node* frame_state, Node* effect, | 1566 Node* receiver, Node* context, Node* frame_state, Node* effect, |
1573 Node* control, Handle<Name> name, ZoneVector<Node*>* if_exceptions, | 1567 Node* control, Handle<Name> name, ZoneVector<Node*>* if_exceptions, |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2410 return jsgraph()->javascript(); | 2404 return jsgraph()->javascript(); |
2411 } | 2405 } |
2412 | 2406 |
2413 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 2407 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
2414 return jsgraph()->simplified(); | 2408 return jsgraph()->simplified(); |
2415 } | 2409 } |
2416 | 2410 |
2417 } // namespace compiler | 2411 } // namespace compiler |
2418 } // namespace internal | 2412 } // namespace internal |
2419 } // namespace v8 | 2413 } // namespace v8 |
OLD | NEW |