| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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-create-lowering.h" | 5 #include "src/compiler/js-create-lowering.h" |
| 6 | 6 |
| 7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.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 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 | 1007 |
| 1008 // Prepare an iterator over argument values recorded in the frame state. | 1008 // Prepare an iterator over argument values recorded in the frame state. |
| 1009 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); | 1009 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); |
| 1010 StateValuesAccess parameters_access(parameters); | 1010 StateValuesAccess parameters_access(parameters); |
| 1011 auto parameters_it = ++parameters_access.begin(); | 1011 auto parameters_it = ++parameters_access.begin(); |
| 1012 | 1012 |
| 1013 // Actually allocate the backing store. | 1013 // Actually allocate the backing store. |
| 1014 AllocationBuilder a(jsgraph(), effect, control); | 1014 AllocationBuilder a(jsgraph(), effect, control); |
| 1015 a.AllocateArray(argument_count, factory()->fixed_array_map()); | 1015 a.AllocateArray(argument_count, factory()->fixed_array_map()); |
| 1016 for (int i = 0; i < argument_count; ++i, ++parameters_it) { | 1016 for (int i = 0; i < argument_count; ++i, ++parameters_it) { |
| 1017 DCHECK_NOT_NULL((*parameters_it).node); |
| 1017 a.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); | 1018 a.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); |
| 1018 } | 1019 } |
| 1019 return a.Finish(); | 1020 return a.Finish(); |
| 1020 } | 1021 } |
| 1021 | 1022 |
| 1022 // Helper that allocates a FixedArray holding argument values recorded in the | 1023 // Helper that allocates a FixedArray holding argument values recorded in the |
| 1023 // given {frame_state}. Serves as backing store for JSCreateArguments nodes. | 1024 // given {frame_state}. Serves as backing store for JSCreateArguments nodes. |
| 1024 Node* JSCreateLowering::AllocateRestArguments(Node* effect, Node* control, | 1025 Node* JSCreateLowering::AllocateRestArguments(Node* effect, Node* control, |
| 1025 Node* frame_state, | 1026 Node* frame_state, |
| 1026 int start_index) { | 1027 int start_index) { |
| 1027 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); | 1028 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); |
| 1028 int argument_count = state_info.parameter_count() - 1; // Minus receiver. | 1029 int argument_count = state_info.parameter_count() - 1; // Minus receiver. |
| 1029 int num_elements = std::max(0, argument_count - start_index); | 1030 int num_elements = std::max(0, argument_count - start_index); |
| 1030 if (num_elements == 0) return jsgraph()->EmptyFixedArrayConstant(); | 1031 if (num_elements == 0) return jsgraph()->EmptyFixedArrayConstant(); |
| 1031 | 1032 |
| 1032 // Prepare an iterator over argument values recorded in the frame state. | 1033 // Prepare an iterator over argument values recorded in the frame state. |
| 1033 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); | 1034 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); |
| 1034 StateValuesAccess parameters_access(parameters); | 1035 StateValuesAccess parameters_access(parameters); |
| 1035 auto parameters_it = ++parameters_access.begin(); | 1036 auto parameters_it = ++parameters_access.begin(); |
| 1036 | 1037 |
| 1037 // Skip unused arguments. | 1038 // Skip unused arguments. |
| 1038 for (int i = 0; i < start_index; i++) { | 1039 for (int i = 0; i < start_index; i++) { |
| 1039 ++parameters_it; | 1040 ++parameters_it; |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 // Actually allocate the backing store. | 1043 // Actually allocate the backing store. |
| 1043 AllocationBuilder a(jsgraph(), effect, control); | 1044 AllocationBuilder a(jsgraph(), effect, control); |
| 1044 a.AllocateArray(num_elements, factory()->fixed_array_map()); | 1045 a.AllocateArray(num_elements, factory()->fixed_array_map()); |
| 1045 for (int i = 0; i < num_elements; ++i, ++parameters_it) { | 1046 for (int i = 0; i < num_elements; ++i, ++parameters_it) { |
| 1047 DCHECK_NOT_NULL((*parameters_it).node); |
| 1046 a.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); | 1048 a.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); |
| 1047 } | 1049 } |
| 1048 return a.Finish(); | 1050 return a.Finish(); |
| 1049 } | 1051 } |
| 1050 | 1052 |
| 1051 // Helper that allocates a FixedArray serving as a parameter map for values | 1053 // Helper that allocates a FixedArray serving as a parameter map for values |
| 1052 // recorded in the given {frame_state}. Some elements map to slots within the | 1054 // recorded in the given {frame_state}. Some elements map to slots within the |
| 1053 // given {context}. Serves as backing store for JSCreateArguments nodes. | 1055 // given {context}. Serves as backing store for JSCreateArguments nodes. |
| 1054 Node* JSCreateLowering::AllocateAliasedArguments( | 1056 Node* JSCreateLowering::AllocateAliasedArguments( |
| 1055 Node* effect, Node* control, Node* frame_state, Node* context, | 1057 Node* effect, Node* control, Node* frame_state, Node* context, |
| 1056 Handle<SharedFunctionInfo> shared, bool* has_aliased_arguments) { | 1058 Handle<SharedFunctionInfo> shared, bool* has_aliased_arguments) { |
| 1057 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); | 1059 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); |
| 1058 int argument_count = state_info.parameter_count() - 1; // Minus receiver. | 1060 int argument_count = state_info.parameter_count() - 1; // Minus receiver. |
| 1059 if (argument_count == 0) return jsgraph()->EmptyFixedArrayConstant(); | 1061 if (argument_count == 0) return jsgraph()->EmptyFixedArrayConstant(); |
| 1060 | 1062 |
| 1061 // If there is no aliasing, the arguments object elements are not special in | 1063 // If there is no aliasing, the arguments object elements are not special in |
| 1062 // any way, we can just return an unmapped backing store instead. | 1064 // any way, we can just return an unmapped backing store instead. |
| 1063 int parameter_count = shared->internal_formal_parameter_count(); | 1065 int parameter_count = shared->internal_formal_parameter_count(); |
| 1064 if (parameter_count == 0) { | 1066 if (parameter_count == 0) { |
| 1065 return AllocateArguments(effect, control, frame_state); | 1067 return AllocateArguments(effect, control, frame_state); |
| 1066 } | 1068 } |
| 1067 | 1069 |
| 1068 // Calculate number of argument values being aliased/mapped. | 1070 // Calculate number of argument values being aliased/mapped. |
| 1069 int mapped_count = Min(argument_count, parameter_count); | 1071 int mapped_count = Min(argument_count, parameter_count); |
| 1070 *has_aliased_arguments = true; | 1072 *has_aliased_arguments = true; |
| 1071 | 1073 |
| 1072 // Prepare an iterator over argument values recorded in the frame state. | 1074 // Prepare an iterator over argument values recorded in the frame state. |
| 1073 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); | 1075 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); |
| 1074 StateValuesAccess parameters_access(parameters); | 1076 StateValuesAccess parameters_access(parameters); |
| 1075 auto paratemers_it = ++parameters_access.begin(); | 1077 auto parameters_it = ++parameters_access.begin(); |
| 1076 | 1078 |
| 1077 // The unmapped argument values recorded in the frame state are stored yet | 1079 // The unmapped argument values recorded in the frame state are stored yet |
| 1078 // another indirection away and then linked into the parameter map below, | 1080 // another indirection away and then linked into the parameter map below, |
| 1079 // whereas mapped argument values are replaced with a hole instead. | 1081 // whereas mapped argument values are replaced with a hole instead. |
| 1080 AllocationBuilder aa(jsgraph(), effect, control); | 1082 AllocationBuilder aa(jsgraph(), effect, control); |
| 1081 aa.AllocateArray(argument_count, factory()->fixed_array_map()); | 1083 aa.AllocateArray(argument_count, factory()->fixed_array_map()); |
| 1082 for (int i = 0; i < mapped_count; ++i, ++paratemers_it) { | 1084 for (int i = 0; i < mapped_count; ++i, ++parameters_it) { |
| 1083 aa.Store(AccessBuilder::ForFixedArraySlot(i), jsgraph()->TheHoleConstant()); | 1085 aa.Store(AccessBuilder::ForFixedArraySlot(i), jsgraph()->TheHoleConstant()); |
| 1084 } | 1086 } |
| 1085 for (int i = mapped_count; i < argument_count; ++i, ++paratemers_it) { | 1087 for (int i = mapped_count; i < argument_count; ++i, ++parameters_it) { |
| 1086 aa.Store(AccessBuilder::ForFixedArraySlot(i), (*paratemers_it).node); | 1088 DCHECK_NOT_NULL((*parameters_it).node); |
| 1089 aa.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); |
| 1087 } | 1090 } |
| 1088 Node* arguments = aa.Finish(); | 1091 Node* arguments = aa.Finish(); |
| 1089 | 1092 |
| 1090 // Actually allocate the backing store. | 1093 // Actually allocate the backing store. |
| 1091 AllocationBuilder a(jsgraph(), arguments, control); | 1094 AllocationBuilder a(jsgraph(), arguments, control); |
| 1092 a.AllocateArray(mapped_count + 2, factory()->sloppy_arguments_elements_map()); | 1095 a.AllocateArray(mapped_count + 2, factory()->sloppy_arguments_elements_map()); |
| 1093 a.Store(AccessBuilder::ForFixedArraySlot(0), context); | 1096 a.Store(AccessBuilder::ForFixedArraySlot(0), context); |
| 1094 a.Store(AccessBuilder::ForFixedArraySlot(1), arguments); | 1097 a.Store(AccessBuilder::ForFixedArraySlot(1), arguments); |
| 1095 for (int i = 0; i < mapped_count; ++i) { | 1098 for (int i = 0; i < mapped_count; ++i) { |
| 1096 int idx = Context::MIN_CONTEXT_SLOTS + parameter_count - 1 - i; | 1099 int idx = Context::MIN_CONTEXT_SLOTS + parameter_count - 1 - i; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 return jsgraph()->simplified(); | 1364 return jsgraph()->simplified(); |
| 1362 } | 1365 } |
| 1363 | 1366 |
| 1364 MachineOperatorBuilder* JSCreateLowering::machine() const { | 1367 MachineOperatorBuilder* JSCreateLowering::machine() const { |
| 1365 return jsgraph()->machine(); | 1368 return jsgraph()->machine(); |
| 1366 } | 1369 } |
| 1367 | 1370 |
| 1368 } // namespace compiler | 1371 } // namespace compiler |
| 1369 } // namespace internal | 1372 } // namespace internal |
| 1370 } // namespace v8 | 1373 } // namespace v8 |
| OLD | NEW |